diff --git a/gameobjects.py b/gameobjects.py index e003d92..4eaab23 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -2,7 +2,7 @@ import pygame import random WIDTH, HEIGHT = 800, 600 - +HUD_HEIGHT = 150 class GameObject: x = 0 y = 0 @@ -122,8 +122,10 @@ class UI: horizontal_offset = 25 # Horizontal spacing between marks vertical_offset = -25 # Vertical spacing between marks mark_size = 25 # Size of the marks - def __init__(self): + def __init__(self, hud_image_path, x=0, y=HEIGHT): self.horses = [] # Initialize children list + self.hud_image = pygame.image.load(hud_image_path) + self.hud_rect = self.hud_image.get_rect(topleft=(x,y)) def add_horses(self, children): new_horses = [child for child in children if child not in self.horses] # Add new children self.horses.extend(new_horses) @@ -138,7 +140,7 @@ class UI: unactive_marks.append(self.horses[i]) # Add inactive horses width = 10 # Number of marks per row - active_marks_section_pos = (0 - self.mark_size, 600 - self.mark_size) # Starting position for active marks + active_marks_section_pos = (0 - self.mark_size, HEIGHT + HUD_HEIGHT - self.mark_size) # Starting position for active marks xa = active_marks_section_pos[0] ya = active_marks_section_pos[1] for i in range(len(active_marks)): @@ -148,15 +150,19 @@ class UI: ya += self.vertical_offset xa = active_marks_section_pos[0] - unactive_marks_section_pos = (800, 600 - self.mark_size) # Starting position for inactive marks + unactive_marks_section_pos = (WIDTH, HEIGHT + HUD_HEIGHT - self.mark_size) # Starting position for inactive marks xu = unactive_marks_section_pos[0] yu = unactive_marks_section_pos[1] for i in range(len(unactive_marks)): xu -= self.horizontal_offset pygame.draw.rect(screen, unactive_marks[i].color, (xu, yu, self.mark_size, self.mark_size)) # Draw inactive marks - if 800 - xu >= width * self.mark_size: # Move to the next row if the row is full + if WIDTH - xu >= width * self.mark_size: # Move to the next row if the row is full yu += self.vertical_offset xu = unactive_marks_section_pos[0] + def draw(self, surface): + surface.blit(self.hud_image, self.hud_rect) + + class Spawner: diff --git a/images/HUD.png b/images/HUD.png new file mode 100644 index 0000000..27c644d Binary files /dev/null and b/images/HUD.png differ diff --git a/main.py b/main.py index 381f61c..f12dcbf 100644 --- a/main.py +++ b/main.py @@ -10,12 +10,12 @@ FRAME_RATE = 160 #TODO: FIX THE INCORRECT FRAME RATE CORRELATION pygame.init() -screen = pygame.display.set_mode((WIDTH, HEIGHT)) # Initialize the screen +screen = pygame.display.set_mode((WIDTH, HEIGHT + HUD_HEIGHT)) # Initialize the screen pygame.display.set_caption("NIC_Project") # Set window title WHITE = (255, 255, 255) # Define white color -UI = UI() # Initialize UI +UI = UI("images/HUD.png") # Initialize UI gameobjects = [] horses = [] barriers = [] @@ -118,8 +118,10 @@ while True: for object in gameobjects: object.draw(screen) # Draw all game objects - UI.draw_marks(screen) # Draw UI marks + UI.draw(screen) + UI.draw_marks(screen) # Draw UI marks + if all(horse.stopped for horse in horses): UI.iteration_num += 1 init_game()