-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbk.py
More file actions
251 lines (178 loc) · 8.5 KB
/
bk.py
File metadata and controls
251 lines (178 loc) · 8.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# was pretty sleepy tried to explaint he best i can
# some silly mistakes might be there but logic is solid
# just go through
# see if you can get a better idea
import pygame
from _typeshed import wsgi
from pygame import fastevent
pygame.init()
green = (0, 255, 0)
maxhealth = 100
pchealth = 100
phealth = 100
scalefactor = 2
dmg = -20
heal = 10
m = True
playerattack = True
screen = pygame.display.set_mode((100, 100))
a = False # a is an arbitrary value
attack_img = pygame.image.load('imglocation.png')
heal_img = pygame.image.load('imglocation.png')
class attack():
def __init__(self, x, y, image): # i saw this online didn understand everything but i can explain most of it
self.image = image # just assigns image a callable objext
self.rect = self.image.rect() # makes the image a rect
self.rect.topleft = (x, y) # coordinates of img
self.clicked = False # checking for click event( if this isnt there multiple clicks are registered)
def draw():
action = False
pos = pygame.mouse.get_pos() # gives position of mouse
if self.rect.collidepoint(pos): # if mouse pos collides withe rect
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False: # if it does and they left click
self.clicked = True # our variable changes
action = True # retruns true
if pygame.mouse.get_pressed()[0] == 0: # when they arent pressing
self.clicked = False # variable resets
screen.blit(self.image, (self.rect.x, self.rect.y)) # bliting button img
return action
attack_button = attack(x, y, attack_img) # assigns the calling of the class to a variable
heal_button = attack(x, y, heal_img)
# call attack_button.draw()
def phealthbar(currenthealth, value): # since for the player value can be -ve or +ve for heal or dmg
while m:
temp = currenthealth
if currenthealth + value < temp: # after damage the new value will be less than old so this is a way to check if we actually hurt ourpokemon
for i in range(0,
value + 1): # i wante dlike a decending health bar but if this doesnt work we can directly blit the new health
pygame.draw.rect(screen, green, (
x, y, scalefactor * (temp - i), 7)) # change values of rectangle (the actual health bar )
m = False
elif currenthealth + value > temp: # same concept except its a heal so we heal our selves
for i in range(0, value + 1):
pygame.draw.rect(screen, green, (x, y, scalefactor * (temp + i), 7)) # change values
m = False
def pchealthbar(currenthealth, damage): # health bar for pc pokemon
while True:
temp = currenthealth
for i in range(0, damage + 1):
pygame.draw.rect(screen, green, (x, y, scalefactor * (temp - i), 7)) # change values
break
def heal_mod():
if heal_button.draw():
if playerattack == True:
phealthbar(phealth, heal)
playerattack = False
phealth += heal
def pattackmod():
if attack_button.draw(): # if action is true that is they pressed attack
if playerattack = True: # registers players move
if pchealth > 20: # same logiv as below
pygame.blit('teh pokemon has attacked', (x, y))
pchealthbar(pchealth, dmg)
pchealth = pchealth + dmg
elif pchealth - dmg == 0:
pygame.blit('teh pokemon has faint', (x, y))
pchealth = 0
pchealthbar(pchealth, dmg)
playerattack = False
def pcattackmod():
if playerattack == False:
if phealth > 20: # checking to see if the pokemon can withstand attack
pygame.blit('teh wild pokemon has attacked', (x, y)) # we have to blit an img sayign that
phealthbar(phealth, dmg)
phealth = phealth + dmg
elif phealth - dmg == 0: # if health is 20 rather than addign <= 20 i just did this
pygame.blit('ur pokemon has faint', (x, y))
phealth = 0
phealthbar(phealth, dmg)
playerattack = True # resets value now its players tur
# was pretty sleepy tried to explaint he best i can
# some silly mistakes might be there but logic is solid
# just go through
# see if you can get a better idea
import pygame
from _typeshed import Self
from pygame import fastevent
pygame.init()
green = (0, 255, 0)
maxhealth = 100
pchealth = 100
phealth = 100
scalefactor = 2
dmg = -20
heal = 10
m = True
playerattack = True
screen = pygame.display.set_mode((100, 100))
a = False # a is an arbitrary value
attack_img = pygame.image.load('imglocation.png')
heal_img = pygame.image.load('imglocation.png')
class attack():
def __init__(self, x, y, image): # i saw this online didn understand everything but i can explain most of it
self.image = image # just assigns image a callable objext
self.rect = self.image.rect() # makes the image a rect
self.rect.topleft = (x, y) # coordinates of img
self.clicked = False # checking for click event( if this isnt there multiple clicks are registered)
def draw():
action = False
pos = pygame.mouse.get_pos() # gives position of mouse
if self.rect.collidepoint(pos): # if mouse pos collides withe rect
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False: # if it does and they left click
self.clicked = True # our variable changes
action = True # retruns true
if pygame.mouse.get_pressed()[0] == 0: # when they arent pressing
self.clicked = False # variable resets
screen.blit(self.image, (self.rect.x, self.rect.y)) # bliting button img
return action
attack_button = attack(x, y, attack_img) # assigns the calling of the class to a variable
heal_button = attack(x, y, heal_img)
# call attack_button.draw()
def phealthbar(currenthealth, value): # since for the player value can be -ve or +ve for heal or dmg
while m:
temp = currenthealth
if currenthealth + value < temp: # after damage the new value will be less than old so this is a way to check if we actually hurt ourpokemon
for i in range(0,
value + 1): # i wante dlike a decending health bar but if this doesnt work we can directly blit the new health
pygame.draw.rect(screen, green, (
x, y, scalefactor * (temp - i), 7)) # change values of rectangle (the actual health bar )
m = False
elif currenthealth + value > temp: # same concept except its a heal so we heal our selves
for i in range(0, value + 1):
pygame.draw.rect(screen, green, (x, y, scalefactor * (temp + i), 7)) # change values
m = False
def pchealthbar(currenthealth, damage): # health bar for pc pokemon
while True:
temp = currenthealth
for i in range(0, damage + 1):
pygame.draw.rect(screen, green, (x, y, scalefactor * (temp - i), 7)) # change values
break
def heal_mod():
if heal_button.draw():
if playerattack == True:
phealthbar(phealth, heal)
playerattack = False
phealth += heal
def pattackmod():
if attack_button.draw(): # if action is true that is they pressed attack
if playerattack = True: # registers players move
if pchealth > 20: # same logiv as below
pygame.blit('teh pokemon has attacked', (x, y))
pchealthbar(pchealth, dmg)
pchealth = pchealth + dmg
elif pchealth - dmg == 0:
pygame.blit('teh pokemon has faint', (x, y))
pchealth = 0
pchealthbar(pchealth, dmg)
playerattack = False
def pcattackmod():
if playerattack == False:
if phealth > 20: # checking to see if the pokemon can withstand attack
pygame.blit('teh wild pokemon has attacked', (x, y)) # we have to blit an img sayign that
phealthbar(phealth, dmg)
phealth = phealth + dmg
elif phealth - dmg == 0: # if health is 20 rather than addign <= 20 i just did this
pygame.blit('ur pokemon has faint', (x, y))
phealth = 0
phealthbar(phealth, dmg)
playerattack = True # resets value now its players tur