Add animation for horses
This commit is contained in:
@@ -55,6 +55,13 @@ class Horse(GameObject):
|
|||||||
ribbon_out = None
|
ribbon_out = None
|
||||||
def __init__(self, image_path, x, y):
|
def __init__(self, image_path, x, y):
|
||||||
super().__init__(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.vspeed = 0
|
||||||
self.vacceleration = 0
|
self.vacceleration = 0
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
@@ -89,6 +96,12 @@ class Horse(GameObject):
|
|||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
super().draw(surface) # Draw the horse
|
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
|
#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):
|
class Background(GameObject):
|
||||||
def __init__(self, image_path, x, y):
|
def __init__(self, image_path, x, y):
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ while True:
|
|||||||
barrier.move(-BARRIER_SPEED, 0) # Move barriers to the left
|
barrier.move(-BARRIER_SPEED, 0) # Move barriers to the left
|
||||||
|
|
||||||
for horse in horses:
|
for horse in horses:
|
||||||
|
horse.update_animation()
|
||||||
if horse.stopped == False: # Check for collisions between horses and barriers
|
if horse.stopped == False: # Check for collisions between horses and barriers
|
||||||
for barrier in barriers:
|
for barrier in barriers:
|
||||||
if horse.rect.colliderect(barrier.rect): # If collision detected
|
if horse.rect.colliderect(barrier.rect): # If collision detected
|
||||||
|
|||||||
Reference in New Issue
Block a user