@@ -203,6 +203,46 @@ def draw(self, win, offset_x):
203
203
win .blit (self .sprite , (self .rect .x - offset_x , self .rect .y ))
204
204
205
205
206
+ class Enemy (pygame .sprite .Sprite ):
207
+ SPRITES = load_sprite_sheets ("Enemies" , "Skateboarder" , 32 , 32 , True )
208
+ GRAVITY = 1
209
+ ANIMATION_DELAY = 3
210
+
211
+ def __init__ (self , x , y , width , height ):
212
+ super ().__init__ ()
213
+ self .rect = pygame .Rect (x , y , width , height )
214
+ self .x_vel = - 3
215
+ self .y_vel = 0
216
+ self .mask = None
217
+ self .direction = "left"
218
+ self .animation_count = 0
219
+ self .walkCount = 0
220
+
221
+ def move (self , dx , dy ):
222
+ self .rect .x += dx
223
+ self .rect .y += dy
224
+
225
+ def update_sprite (self ):
226
+ sprite_sheet = "walk"
227
+ if self .x_vel != 0 :
228
+ sprite_sheet = "walk"
229
+
230
+ sprite_sheet_name = sprite_sheet + "_" + self .direction
231
+ sprites = self .SPRITES [sprite_sheet_name ]
232
+ sprite_index = (self .animation_count //
233
+ self .ANIMATION_DELAY ) % len (sprites )
234
+ self .sprite = sprites [sprite_index ]
235
+ self .animation_count += 1
236
+ self .update ()
237
+
238
+ def update (self ):
239
+ self .rect = self .sprite .get_rect (topleft = (self .rect .x , self .rect .y ))
240
+ self .mask = pygame .mask .from_surface (self .sprite )
241
+
242
+ def draw (self , win , offset_x ):
243
+ win .blit (self .sprite , (self .rect .x - offset_x , self .rect .y ))
244
+
245
+
206
246
class Object (pygame .sprite .Sprite ):
207
247
def __init__ (self , x , y , width , height , name = None ):
208
248
super ().__init__ ()
@@ -364,6 +404,7 @@ def main(window):
364
404
block_size = 96
365
405
366
406
player = Player (100 , 100 , 50 , 50 )
407
+ enemy = Enemy (200 , 200 , 50 , 50 )
367
408
fire = Fire (100 , HEIGHT - block_size - 64 , 16 , 32 )
368
409
fire .on ()
369
410
0 commit comments