This commit is contained in:
2025-08-17 18:49:07 +02:00
parent a910c8f74a
commit 8a32aad877
13 changed files with 259 additions and 30 deletions
+57
View File
@@ -1,9 +1,12 @@
from .unit import Unit
from . import rat
from .points import Point
import uuid
import random
# Costanti
AGE_THRESHOLD = 200
NUCLEAR_TIMER = 50 # 1 second at ~50 FPS
class Bomb(Unit):
@@ -106,4 +109,58 @@ class Explosion(Bomb):
x_pos = self.position_before[0] * self.game.cell_size + (self.game.cell_size - image_size[0]) // 2 + partial_x
y_pos = self.position_before[1] * self.game.cell_size + (self.game.cell_size - image_size[1]) // 2 + partial_y
self.game.render_engine.draw_image(x_pos, y_pos, image, anchor="nw", tag="unit")
class NuclearBomb(Unit):
def __init__(self, game, position=(0,0), id=None):
super().__init__(game, position, id)
self.speed = 1 # Slow countdown
self.fight = False
self.timer = NUCLEAR_TIMER # 1 second timer
def move(self):
"""Count down the nuclear timer"""
self.timer -= 1
if self.timer <= 0:
self.explode()
def collisions(self):
pass
def explode(self):
"""Nuclear explosion that affects all rats on the map"""
print("NUCLEAR EXPLOSION!")
# Play nuclear explosion sound
self.game.render_engine.play_sound("nuke.wav")
# Trigger white screen effect
self.game.render_engine.trigger_white_flash()
# Remove the nuclear bomb from the game
if self.id in self.game.units:
self.game.units.pop(self.id)
# Kill 90% of all rats on the map
rats_to_kill = []
# If unit is a child class of Rat
for unit in self.game.units.values():
if isinstance(unit, rat.Rat):
if random.random() < 0.7: # 70% chance to kill each rat
rats_to_kill.append(unit)
for unit in rats_to_kill:
unit.die(score=None)
print(f"Nuclear explosion killed {len(rats_to_kill)} rats!")
def draw(self):
"""Draw nuclear bomb on position"""
image = self.game.assets["BMP_NUCLEAR"]
image_size = self.game.render_engine.get_image_size(image)
x_pos = self.position[0] * self.game.cell_size + (self.game.cell_size - image_size[0]) // 2
y_pos = self.position[1] * self.game.cell_size + (self.game.cell_size - image_size[1]) // 2
self.game.render_engine.draw_image(x_pos, y_pos, image, anchor="nw", tag="unit")