Modifica il sistema di rendering SDL e migliora la gestione delle unità nel gioco
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import cProfile
|
||||
import pstats
|
||||
import random
|
||||
from units import rat
|
||||
import uuid
|
||||
@@ -7,11 +9,13 @@ from engine import maze, sdl2 as engine
|
||||
class MiceMaze:
|
||||
def __init__(self, maze_file):
|
||||
self.map = maze.Map(maze_file)
|
||||
self.audio = True
|
||||
self.audio = False
|
||||
self.cell_size = 60
|
||||
self.engine = engine.GameWindow(self.map.width, self.map.height, self.cell_size, "Mice!", key_callback=self.key_pressed)
|
||||
self.graphics_load()
|
||||
self.units = {}
|
||||
self.unit_positions = {}
|
||||
self.unit_positions_before = {}
|
||||
for _ in range(5):
|
||||
self.new_rat()
|
||||
|
||||
@@ -40,6 +44,11 @@ class MiceMaze:
|
||||
|
||||
def update_maze(self):
|
||||
self.engine.delete_tag("unit")
|
||||
self.unit_positions.clear()
|
||||
self.unit_positions_before.clear()
|
||||
for unit in self.units.values():
|
||||
self.unit_positions.setdefault(unit.position, []).append(unit)
|
||||
self.unit_positions_before.setdefault(unit.position_before, []).append(unit)
|
||||
for unit in self.units.copy().values():
|
||||
unit.move()
|
||||
unit.collisions()
|
||||
@@ -62,6 +71,10 @@ class MiceMaze:
|
||||
self.units[random.choice(list(self.units.keys()))].die()
|
||||
elif event.keysym == "m":
|
||||
self.audio = not self.audio
|
||||
elif event.keysym == "s":
|
||||
profiler.disable()
|
||||
stats = pstats.Stats(profiler).sort_stats('cumtime')
|
||||
stats.print_stats()
|
||||
|
||||
def play_sound(self, sound_file):
|
||||
if self.audio:
|
||||
@@ -75,5 +88,10 @@ class MiceMaze:
|
||||
self.rat_assets[sex] = {}
|
||||
for direction in ["UP", "DOWN", "LEFT", "RIGHT"]:
|
||||
self.rat_assets[sex][direction] = self.engine.load_image(f"Rat/BMP_{sex}_{direction}.png", transparent_color=(128, 128, 128))
|
||||
solver = MiceMaze('maze.json')
|
||||
solver.run()
|
||||
if __name__ == "__main__":
|
||||
profiler = cProfile.Profile()
|
||||
profiler.enable()
|
||||
|
||||
solver = MiceMaze('maze.json')
|
||||
solver.run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user