Update screen dimensions and integrate pygame_gui for HUD management
Some checks failed
Build Simulation and Test / Run All Tests (push) Failing after 45s

This commit is contained in:
Sam 2025-06-18 17:36:24 -05:00
parent 3b64ef62e1
commit ff43022b3a
4 changed files with 12 additions and 4 deletions

View File

@ -2,8 +2,8 @@
"""Configuration constants for the simulation.""" """Configuration constants for the simulation."""
# Screen settings # Screen settings
SCREEN_WIDTH = 1920 // 2 SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080 // 2 SCREEN_HEIGHT = 1080
# Colors # Colors
BLACK = (0, 0, 0) BLACK = (0, 0, 0)

View File

@ -27,11 +27,13 @@ class InputHandler:
self.default_tps = DEFAULT_TPS self.default_tps = DEFAULT_TPS
self.sprint_mode = False self.sprint_mode = False
def handle_events(self, events): def handle_events(self, events, ui_manager):
"""Process all pygame events and return game state.""" """Process all pygame events and return game state."""
running = True running = True
for event in events: for event in events:
ui_manager.process_events(event)
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
running = False running = False
elif event.type == pygame.KEYDOWN: elif event.type == pygame.KEYDOWN:

View File

@ -69,7 +69,8 @@ class SimulationEngine:
tick_interval = 1.0 / self.input_handler.tps tick_interval = 1.0 / self.input_handler.tps
# Handle events # Handle events
self.running = self.input_handler.handle_events(pygame.event.get()) events = pygame.event.get()
self.running = self.input_handler.handle_events(events, self.hud.manager)
if self.input_handler.sprint_mode: if self.input_handler.sprint_mode:
# Sprint mode: run as many ticks as possible, skip rendering # Sprint mode: run as many ticks as possible, skip rendering
@ -104,6 +105,7 @@ class SimulationEngine:
self.input_handler.update_selected_objects() self.input_handler.update_selected_objects()
self.world.tick_all() self.world.tick_all()
self.hud.manager.update(deltatime)
if current_time - self.last_tps_time >= 1.0: if current_time - self.last_tps_time >= 1.0:
self.actual_tps = self.tick_counter self.actual_tps = self.tick_counter
@ -113,6 +115,7 @@ class SimulationEngine:
self.last_tick_time = time.perf_counter() self.last_tick_time = time.perf_counter()
self.last_tps_time = time.perf_counter() self.last_tps_time = time.perf_counter()
self.hud.manager.draw_ui(self.screen)
self._update(deltatime) self._update(deltatime)
self._render() self._render()

View File

@ -2,6 +2,7 @@
"""Handles HUD elements and text overlays.""" """Handles HUD elements and text overlays."""
import pygame import pygame
import pygame_gui
from config.constants import * from config.constants import *
from world.base.brain import CellBrain, FlexibleNeuralNetwork from world.base.brain import CellBrain, FlexibleNeuralNetwork
from world.objects import DefaultCell from world.objects import DefaultCell
@ -13,6 +14,8 @@ class HUD:
self.font = pygame.font.Font("freesansbold.ttf", FONT_SIZE) self.font = pygame.font.Font("freesansbold.ttf", FONT_SIZE)
self.legend_font = pygame.font.Font("freesansbold.ttf", LEGEND_FONT_SIZE) self.legend_font = pygame.font.Font("freesansbold.ttf", LEGEND_FONT_SIZE)
self.manager = pygame_gui.UIManager((SCREEN_WIDTH, SCREEN_HEIGHT), "ui/theme.json")
def render_mouse_position(self, screen, camera): def render_mouse_position(self, screen, camera):
"""Render mouse position in top left.""" """Render mouse position in top left."""
mouse_x, mouse_y = camera.get_real_coordinates(*pygame.mouse.get_pos()) mouse_x, mouse_y = camera.get_real_coordinates(*pygame.mouse.get_pos())