Final 2.0

This commit is contained in:
2025-08-20 16:43:16 +02:00
parent 0141063baa
commit 17e5abc7df
8 changed files with 112 additions and 11 deletions
+3 -3
View File
@@ -266,7 +266,7 @@ class GameWindow:
def update_ammo(self, ammo, assets):
"""Update and display the ammo count"""
ammo_text = f"{ammo['bomb']['count']}/{ammo['bomb']['max']} {ammo['mine']['count']}/{ammo['mine']['max']} {ammo['nuclear']['count']}/{ammo['nuclear']['max']} "
ammo_text = f"{ammo['bomb']['count']}/{ammo['bomb']['max']} {ammo['mine']['count']}/{ammo['mine']['max']} {ammo['gas']['count']}/{ammo['gas']['max']} "
if self.ammo_text != ammo_text:
self.ammo_text = ammo_text
font = self.fonts[20]
@@ -279,8 +279,8 @@ class GameWindow:
self.renderer.copy(self.ammo_background, dstrect=sdl2.SDL_Rect(position[0] - 5, position[1] - 2, text_width + 10, text_height + 4))
self.renderer.copy(self.ammo_sprite, dstrect=sdl2.SDL_Rect(position[0], position[1], text_width, text_height))
self.renderer.copy(assets["BMP_BOMB0"], dstrect=sdl2.SDL_Rect(position[0]+25, position[1], 20, 20))
self.renderer.copy(assets["BMP_POISON"], dstrect=sdl2.SDL_Rect(position[0]+80, position[1], 20, 20))
self.renderer.copy(assets["BMP_NUCLEAR"], dstrect=sdl2.SDL_Rect(position[0]+130, position[1], 20, 20))
self.renderer.copy(assets["BMP_POISON"], dstrect=sdl2.SDL_Rect(position[0]+85, position[1], 20, 20))
self.renderer.copy(assets["BMP_GAS"], dstrect=sdl2.SDL_Rect(position[0]+140, position[1], 20, 20))
# ======================
# VIEW & NAVIGATION
# ======================
+16 -2
View File
@@ -1,6 +1,8 @@
import random
import uuid
from units import rat, bomb, mine, points
from units import gas, rat, bomb, mine
class UnitManager:
def count_rats(self):
@@ -9,7 +11,16 @@ class UnitManager:
if isinstance(unit, rat.Rat):
count += 1
return count
def spawn_gas(self, parent_id=None):
if self.map.is_wall(self.pointer[0], self.pointer[1]):
return
if self.ammo["gas"]["count"] <= 0:
return
self.ammo["gas"]["count"] -= 1
self.render_engine.play_sound("GAS.WAV")
self.spawn_unit(gas.Gas, self.pointer, parent_id=parent_id)
def spawn_rat(self, position=None):
if position is None:
position = self.choose_start()
@@ -57,3 +68,6 @@ class UnitManager:
if self.map.matrix[y][x]
]
return random.choice(self._valid_positions)
def get_unit_by_id(self, id):
return self.units.get(id) or None