improved performance

This commit is contained in:
Suguivy 2023-03-02 18:08:02 +01:00
parent 29f5d4f645
commit 5adde7b48d
1 changed files with 13 additions and 3 deletions

16
game.py
View File

@ -23,10 +23,11 @@ class Game:
Runs the game
"""
self.instance_character(3, 3, self.player)
self.render()
while not self.should_exit:
self.render()
self.step()
self.ticks += 1
action_was_performed = self.step()
if action_was_performed:
self.render()
def instance_character(self, x, y, character: Character):
"""
@ -59,6 +60,9 @@ class Game:
self.term.put_char(x, y, TEXTURES[self.floor.get_tile(x, y)])
def step(self):
"""
Perfoms a step in the game. Returns True if any creature did an action, and False otherwise
"""
creaturas = self.schedule.get(self.ticks)
if creaturas:
for creatura in creaturas:
@ -69,6 +73,12 @@ class Game:
self.reschedule(creatura)
self.perform(creatura)
self.schedule.pop(self.ticks)
self.ticks += 1
return True
else:
self.ticks += 1
return False
def perform(self, character: Character):
"""