Add sprites made by Darya.

This commit is contained in:
Emil Shanaty
2025-03-21 03:07:52 +03:00
parent f1a0918dd3
commit f8551d4f3a
9 changed files with 34 additions and 9 deletions
+30 -5
View File
@@ -6,19 +6,31 @@ WIDTH, HEIGHT = 800, 600
class GameObject:
x = 0
y = 0
def __init__(self, image_path, x=0, y=0):
def __init__(self, image_path, x=0, y=0, offset = (0, 0)):
self.children = []
self.image = pygame.image.load(image_path) # Load the image
self.rect = self.image.get_rect(topleft=(x,y)) # Set the rectangle for the image
self.set_position(x, y) # Set initial position
self.offset = offset
def draw(self, surface):
surface.blit(self.image, self.rect) # Draw the image on the surface
if len(self.children) == 0: return
for child in self.children:
child.draw(surface)
def set_position(self, x, y):
self.rect.x = x # Update rectangle position
self.rect.y = y
self.x = x # Update object position
self.y = y
if len(self.children) == 0: return
for child in self.children:
child.set_position(x + child.offset[0], y + child.offset[1])
def move(self, dx, dy):
self.set_position(self.rect.x + dx, self.rect.y + dy) # Move object by dx and dy
if len(self.children) == 0: return
for child in self.children:
self.set_position(self.rect.x + dx, self.rect.y + dy)
def set_size(self, width, height):
self.image = pygame.transform.scale(self.image, (width,height)) # Resize the image
self.rect = self.image.get_rect(topleft=(self.x,self.y)) # Update rectangle size
@@ -27,6 +39,11 @@ class GameObject:
self.rect = self.image.get_rect(topleft=(self.x,self.y)) # Update rectangle size
def get_position(self):
return (self.x, self.y) # Return current position
def set_children(self, child):
self.children.append(child)
def recolor(self, color): #Method to recolor
self.image.fill(color, special_flags=pygame.BLEND_MULT)
self.image.set_colorkey(None) # Explicitly disable colorkey
class Horse(GameObject):
default_vacceleration = 0.5 # Default acceleration value
@@ -34,12 +51,19 @@ class Horse(GameObject):
vacceleration = 0 # Vertical acceleration
stopped = False # Whether the horse is stopped
color = () # Color of the horse's mark
ribbon_fill = None
ribbon_out = None
def __init__(self, image_path, x, y):
super().__init__(image_path, x, y)
self.vspeed = 0
self.vacceleration = 0
self.stopped = False
self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Random color for the mark
super().__init__(image_path, x, y)
self.ribbon_fill = GameObject("images/Ribbon_fill.png", self.x, self.y, (-13, -26))
self.ribbon_fill.recolor(self.color)
self.ribbon_out = GameObject("images/Ribbon_out.png", self.x, self.y, (-13, -26))
self.set_children(self.ribbon_fill)
self.set_children(self.ribbon_out)
self.set_size(75, 75) # Set the size of the horse
def apply_vspeed(self):
pos = self.get_position()
@@ -63,8 +87,8 @@ class Horse(GameObject):
self.set_vacceleration(0)
self.set_vspeed(0)
def draw(self, surface):
surface.blit(self.image, self.rect) # Draw the horse
pygame.draw.rect(surface, self.color, (self.x + 40, self.y + 20, 25, 25)) # Draw the horse's mark
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
class Background(GameObject):
def __init__(self, image_path, x, y):
@@ -115,6 +139,7 @@ class UI:
yu += self.vertical_offset
xu = unactive_marks_section_pos[0]
class Spawner:
active = True # Whether the spawner is active
frequency = 500 # Number of ticks between spawns
@@ -133,4 +158,4 @@ class Spawner:
def spawn(self):
random_y = random.randint(0, HEIGHT - 100) # Random Y position for the barrier
new_barrier = Barrier(self.barrier_image_path, WIDTH, random_y) # Create a new barrier
return new_barrier
return new_barrier
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 KiB

+4 -4
View File
@@ -11,22 +11,22 @@ WHITE = (255, 255, 255) # Define white color
UI = UI() # Initialize UI
grass = Background("images/grass.jpg", 0, 0) # Create background
horse1 = Horse("images/horse.png", 50, 50) # Create a horse
barrier1 = Barrier("images/barrier.png", 400, 300) # Create a barrier
horse1 = Horse("images/Horse_1.png", 50, 50) # Create a horse
barrier1 = Barrier("images/Barrier.png", 400, 300) # Create a barrier
BARRIER_SPEED = 1 # Speed of the barriers
grass.set_size(WIDTH, HEIGHT) # Set background size
gameobjects = [] # List of all game objects
horses = [Horse("images/horse.png", 50, 50 * i) for i in range(50)] # Create 50 horses
horses = [Horse("images/Horse_1.png", 50, 50 * i) for i in range(50)] # Create 50 horses
barriers = [barrier1] # List of barriers
gameobjects.extend([grass]) # Add background to game objects
gameobjects.extend(horses) # Add horses to game objects
gameobjects.extend(barriers) # Add barriers to game objects
spawner = Spawner("images/barrier.png") # Initialize spawner
spawner = Spawner("images/Barrier.png") # Initialize spawner
UI.add_children(horses) # Add horses to UI
while True: