Add animation for horses

This commit is contained in:
Emil Shanaty
2025-03-21 03:51:08 +03:00
parent ca9b417f37
commit 46ae823bfd
2 changed files with 14 additions and 0 deletions
+13
View File
@@ -55,6 +55,13 @@ class Horse(GameObject):
ribbon_out = None
def __init__(self, image_path, x, y):
super().__init__(image_path, x, y)
self.images = []
self.images.append(pygame.image.load("images/Horse_1.png"))
self.images.append(pygame.image.load("images/Horse_2.png"))
self.images.append(pygame.image.load("images/Horse_3.png"))
self.animation_speed = 25
self.frame_counter = 0
self.current_frame = 0
self.vspeed = 0
self.vacceleration = 0
self.stopped = False
@@ -89,6 +96,12 @@ class Horse(GameObject):
def draw(self, surface):
super().draw(surface) # Draw the horse
#pygame.draw.rect(surface, self.color, (self.x + 40, self.y + 20, 25, 25)) # Draw the horse's mark
def update_animation(self):
self.frame_counter += 1
if self.frame_counter >= self.animation_speed:
self.frame_counter = 0
self.current_frame = (self.current_frame + 1) % len(self.images)
self.image = self.images[self.current_frame]
class Background(GameObject):
def __init__(self, image_path, x, y):
+1
View File
@@ -62,6 +62,7 @@ while True:
barrier.move(-BARRIER_SPEED, 0) # Move barriers to the left
for horse in horses:
horse.update_animation()
if horse.stopped == False: # Check for collisions between horses and barriers
for barrier in barriers:
if horse.rect.colliderect(barrier.rect): # If collision detected