Aggiungi la classe Point e implementa la gestione delle esplosioni nel gioco
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from .unit import Unit
|
||||
import random
|
||||
import uuid
|
||||
|
||||
# Costanti
|
||||
AGE_THRESHOLD = 200
|
||||
|
||||
|
||||
class Point(Unit):
|
||||
def __init__(self, game, position=(0,0), id=None, value=5):
|
||||
super().__init__(position)
|
||||
self.id = id if id else uuid.uuid4()
|
||||
self.game = game
|
||||
self.position = position
|
||||
self.bbox = (0, 0, 0, 0)
|
||||
self.stop = 0
|
||||
self.age = 0
|
||||
self.speed = 4
|
||||
self.partial_move = 0
|
||||
self.position_before = position
|
||||
self.fight = False
|
||||
self.value = value
|
||||
self.game.add_point(self.value)
|
||||
|
||||
def move(self):
|
||||
self.age += self.speed
|
||||
if self.age == AGE_THRESHOLD:
|
||||
self.die()
|
||||
|
||||
def collisions(self):
|
||||
pass
|
||||
|
||||
def die(self, unit=None):
|
||||
if not unit:
|
||||
unit = self
|
||||
self.game.units.pop(unit.id)
|
||||
|
||||
|
||||
def draw(self):
|
||||
image = self.game.assets[f"BMP_BONUS_{self.value}"]
|
||||
image_size = self.game.engine.get_image_size(image)
|
||||
self.rat_image = image
|
||||
partial_x, partial_y = 0, 0
|
||||
|
||||
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.engine.draw_image(x_pos, y_pos, image, anchor="nw", tag="unit")
|
||||
Reference in New Issue
Block a user