31
31
32
32
clock = pygame .time .Clock ()
33
33
34
- score = 0 #new
34
+ score = 0
35
35
36
36
class player (object ):
37
37
def __init__ (self , x , y , width , height ):
@@ -116,13 +116,13 @@ def __init__(self, x, y, width, height, end):
116
116
self .walkCount = 0
117
117
self .vel = 3
118
118
self .hitbox = (self .x + 17 , self .y + 2 , 31 , 57 )
119
- self .health = 10 #new
120
- self .visible = True #new
119
+ self .health = 10
120
+ self .visible = True
121
121
122
122
def draw (self , win ):
123
123
self .move ()
124
124
125
- if self .visible : # NEW
125
+ if self .visible :
126
126
if self .walkCount + 1 >= 33 :
127
127
self .walkCount = 0
128
128
@@ -133,11 +133,12 @@ def draw(self, win):
133
133
win .blit (self .walkLeft [self .walkCount // 3 ], (self .x , self .y ))
134
134
self .walkCount += 1
135
135
136
- pygame .draw .rect (win , (255 , 0 , 0 ), (self .hitbox [0 ],
137
- self .hitbox [1 ] - 20 , 50 , 10 )) # NEW
138
- pygame .draw .rect (win , (0 , 128 , 0 ),
139
- (self .hitbox [0 ], self .hitbox [1 ] - 20 , 50 - (5 *
140
- (10 - self .health )), 10 )) # NEW
136
+ pygame .draw .rect (window , (255 ,0 ,0 ), (self .hitbox [0 ],
137
+ self .hitbox [1 ]- 20 ,50 ,10 ))
138
+
139
+ pygame .draw .rect (window ,(0 ,128 ,0 ),
140
+ (self .hitbox [0 ],self .hitbox [1 ]- 20 ,50 - (5 *
141
+ (10 - self .health )),10 ))
141
142
142
143
self .hitbox = (self .x + 17 , self .y + 2 , 31 , 57 )
143
144
#pygame.draw.rect(window, (255,0,0), self.hitbox, 2)
@@ -156,7 +157,7 @@ def move(self):
156
157
self .vel = self .vel * - 1
157
158
self .walkCount = 0
158
159
159
- def hit (self ): #new
160
+ def hit (self ):
160
161
if self .health > 0 :
161
162
self .health -= 1
162
163
else :
@@ -166,16 +167,16 @@ def hit(self): #new
166
167
167
168
def redrawGameWindow ():
168
169
window .blit (bg , (0 , 0 ))
169
- text = font .render ('Score: ' + str (score ), 1 , (0 , 0 , 0 )) #new
170
- window .blit (text , (350 , 10 )) #new
170
+ text = font .render ('Score:' + str (score ), 1 , (0 , 0 , 0 ))
171
+ window .blit (text , (200 , 10 ))
171
172
man .draw (window )
172
173
goblin .draw (window )
173
174
for bullet in bullets :
174
175
bullet .draw (window )
175
176
pygame .display .update ()
176
177
177
178
178
- font = pygame .font .SysFont ('comicsans' , 30 , True ) #new
179
+ font = pygame .font .SysFont ('comicsans' , 30 , True )
179
180
man = player (200 , 410 , 64 , 64 )
180
181
goblin = enemy (100 , 410 , 64 , 64 , 300 ) #NEW
181
182
shootLoop = 0
@@ -200,8 +201,8 @@ def redrawGameWindow():
200
201
if bullet .x + bullet .radius > goblin .hitbox [0 ] and bullet .x - \
201
202
bullet .radius < goblin .hitbox [0 ] + \
202
203
goblin .hitbox [2 ]:
204
+ score += 1
203
205
goblin .hit ()
204
- score += 1 #new
205
206
bullets .pop (bullets .index (bullet ))
206
207
207
208
if bullet .x < 500 and bullet .x > 0 :
0 commit comments