Debug mode

This commit is contained in:
s475275 2023-03-18 23:59:13 +01:00
parent 8e1c43aaba
commit 060531d208

View File

@ -2,6 +2,7 @@ from pathlib import Path
import pygame as pg import pygame as pg
import random import random
class SimulationState: class SimulationState:
def __init__(self): def __init__(self):
self.agent_pos = pg.Vector2(0, 0) self.agent_pos = pg.Vector2(0, 0)
@ -12,12 +13,12 @@ class SimulationState:
if self.agent_pos.x < 0: if self.agent_pos.x < 0:
self.agent_pos.x = 0 self.agent_pos.x = 0
elif self.agent_pos.x > self.world_limits.x: elif self.agent_pos.x >= self.world_limits.x:
self.agent_pos.x = self.world_limits.x - 1 self.agent_pos.x = self.world_limits.x - 1
if self.agent_pos.y < 0: if self.agent_pos.y < 0:
self.agent_pos.y = 0 self.agent_pos.y = 0
elif self.agent_pos.y > self.world_limits.y: elif self.agent_pos.y >= self.world_limits.y:
self.agent_pos.y = self.world_limits.y - 1 self.agent_pos.y = self.world_limits.y - 1
@ -43,6 +44,8 @@ class Interface:
self.clock = pg.time.Clock() self.clock = pg.time.Clock()
self.run_simulation = True self.run_simulation = True
self.debug_mode = False
def processUserInput(self): def processUserInput(self):
self.move_agent = pg.Vector2(0, 0) self.move_agent = pg.Vector2(0, 0)
@ -54,6 +57,20 @@ class Interface:
if event.key == pg.K_ESCAPE: if event.key == pg.K_ESCAPE:
self.run_simulation = False self.run_simulation = False
break break
elif event.key == pg.K_BACKQUOTE:
if not self.debug_mode:
self.debug_mode = True
else:
self.debug_mode = False
elif self.debug_mode:
if event.key == pg.K_RIGHT:
self.move_agent.x = 1
elif event.key == pg.K_LEFT:
self.move_agent.x = -1
elif event.key == pg.K_DOWN:
self.move_agent.y = 1
elif event.key == pg.K_UP:
self.move_agent.y = -1
def processSimulationInput(self): def processSimulationInput(self):
move_x = random.randint(-1, 1) move_x = random.randint(-1, 1)
@ -65,8 +82,10 @@ class Interface:
self.simulation_state.updateAgent(self.move_agent) self.simulation_state.updateAgent(self.move_agent)
def render(self): def render(self):
if not self.debug_mode:
self.window.fill((8, 68, 0)) self.window.fill((8, 68, 0))
else:
self.window.fill((68, 8, 0))
agent_pos = self.simulation_state.agent_pos.elementwise() * self.cell_size agent_pos = self.simulation_state.agent_pos.elementwise() * self.cell_size
agent_texture_pos = pg.Vector2(2, 0).elementwise() * self.cell_size agent_texture_pos = pg.Vector2(2, 0).elementwise() * self.cell_size
@ -82,6 +101,7 @@ class Interface:
def loop(self): def loop(self):
while self.run_simulation: while self.run_simulation:
self.processUserInput() self.processUserInput()
if not self.debug_mode:
self.processSimulationInput() self.processSimulationInput()
self.update() self.update()
self.render() self.render()