Add sprites made by Darya.
@@ -6,19 +6,31 @@ WIDTH, HEIGHT = 800, 600
|
|||||||
class GameObject:
|
class GameObject:
|
||||||
x = 0
|
x = 0
|
||||||
y = 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.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.rect = self.image.get_rect(topleft=(x,y)) # Set the rectangle for the image
|
||||||
self.set_position(x, y) # Set initial position
|
self.set_position(x, y) # Set initial position
|
||||||
|
self.offset = offset
|
||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect) # Draw the image on the 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):
|
def set_position(self, x, y):
|
||||||
self.rect.x = x # Update rectangle position
|
self.rect.x = x # Update rectangle position
|
||||||
self.rect.y = y
|
self.rect.y = y
|
||||||
self.x = x # Update object position
|
self.x = x # Update object position
|
||||||
self.y = y
|
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):
|
def move(self, dx, dy):
|
||||||
self.set_position(self.rect.x + dx, self.rect.y + dy) # Move object by dx and 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):
|
def set_size(self, width, height):
|
||||||
self.image = pygame.transform.scale(self.image, (width,height)) # Resize the image
|
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
|
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
|
self.rect = self.image.get_rect(topleft=(self.x,self.y)) # Update rectangle size
|
||||||
def get_position(self):
|
def get_position(self):
|
||||||
return (self.x, self.y) # Return current position
|
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):
|
class Horse(GameObject):
|
||||||
default_vacceleration = 0.5 # Default acceleration value
|
default_vacceleration = 0.5 # Default acceleration value
|
||||||
@@ -34,12 +51,19 @@ class Horse(GameObject):
|
|||||||
vacceleration = 0 # Vertical acceleration
|
vacceleration = 0 # Vertical acceleration
|
||||||
stopped = False # Whether the horse is stopped
|
stopped = False # Whether the horse is stopped
|
||||||
color = () # Color of the horse's mark
|
color = () # Color of the horse's mark
|
||||||
|
ribbon_fill = None
|
||||||
|
ribbon_out = None
|
||||||
def __init__(self, image_path, x, y):
|
def __init__(self, image_path, x, y):
|
||||||
|
super().__init__(image_path, x, y)
|
||||||
self.vspeed = 0
|
self.vspeed = 0
|
||||||
self.vacceleration = 0
|
self.vacceleration = 0
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Random color for the mark
|
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
|
self.set_size(75, 75) # Set the size of the horse
|
||||||
def apply_vspeed(self):
|
def apply_vspeed(self):
|
||||||
pos = self.get_position()
|
pos = self.get_position()
|
||||||
@@ -63,8 +87,8 @@ class Horse(GameObject):
|
|||||||
self.set_vacceleration(0)
|
self.set_vacceleration(0)
|
||||||
self.set_vspeed(0)
|
self.set_vspeed(0)
|
||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect) # 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
|
||||||
|
|
||||||
class Background(GameObject):
|
class Background(GameObject):
|
||||||
def __init__(self, image_path, x, y):
|
def __init__(self, image_path, x, y):
|
||||||
@@ -115,6 +139,7 @@ class UI:
|
|||||||
yu += self.vertical_offset
|
yu += self.vertical_offset
|
||||||
xu = unactive_marks_section_pos[0]
|
xu = unactive_marks_section_pos[0]
|
||||||
|
|
||||||
|
|
||||||
class Spawner:
|
class Spawner:
|
||||||
active = True # Whether the spawner is active
|
active = True # Whether the spawner is active
|
||||||
frequency = 500 # Number of ticks between spawns
|
frequency = 500 # Number of ticks between spawns
|
||||||
|
|||||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 186 KiB |
@@ -11,22 +11,22 @@ WHITE = (255, 255, 255) # Define white color
|
|||||||
|
|
||||||
UI = UI() # Initialize UI
|
UI = UI() # Initialize UI
|
||||||
grass = Background("images/grass.jpg", 0, 0) # Create background
|
grass = Background("images/grass.jpg", 0, 0) # Create background
|
||||||
horse1 = Horse("images/horse.png", 50, 50) # Create a horse
|
horse1 = Horse("images/Horse_1.png", 50, 50) # Create a horse
|
||||||
barrier1 = Barrier("images/barrier.png", 400, 300) # Create a barrier
|
barrier1 = Barrier("images/Barrier.png", 400, 300) # Create a barrier
|
||||||
|
|
||||||
BARRIER_SPEED = 1 # Speed of the barriers
|
BARRIER_SPEED = 1 # Speed of the barriers
|
||||||
|
|
||||||
grass.set_size(WIDTH, HEIGHT) # Set background size
|
grass.set_size(WIDTH, HEIGHT) # Set background size
|
||||||
|
|
||||||
gameobjects = [] # List of all game objects
|
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
|
barriers = [barrier1] # List of barriers
|
||||||
|
|
||||||
gameobjects.extend([grass]) # Add background to game objects
|
gameobjects.extend([grass]) # Add background to game objects
|
||||||
gameobjects.extend(horses) # Add horses to game objects
|
gameobjects.extend(horses) # Add horses to game objects
|
||||||
gameobjects.extend(barriers) # Add barriers 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
|
UI.add_children(horses) # Add horses to UI
|
||||||
while True:
|
while True:
|
||||||
|
|||||||