From 46ae823bfd394a534e663aae8175b6b2762163de Mon Sep 17 00:00:00 2001 From: Emil Shanaty Date: Fri, 21 Mar 2025 03:51:08 +0300 Subject: [PATCH] Add animation for horses --- gameobjects.py | 13 +++++++++++++ main.py | 1 + 2 files changed, 14 insertions(+) diff --git a/gameobjects.py b/gameobjects.py index 6a35292..3d18860 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -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): diff --git a/main.py b/main.py index d2bae17..ccd2517 100644 --- a/main.py +++ b/main.py @@ -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