Aggiungi supporto per SDL e sostituisci il sistema grafico basato su Tkinter

This commit is contained in:
Matteo Benedetto
2024-12-14 23:00:22 +01:00
parent a6a06d1d54
commit 0ad9cd47c6
8 changed files with 198 additions and 26 deletions
Binary file not shown.
+9 -7
View File
@@ -1,7 +1,7 @@
from .unit import Unit
import random
import uuid
from engine.graphics import GameWindow
from engine.tkinter import GameWindow
# Costanti
AGE_THRESHOLD = 200
@@ -22,6 +22,7 @@ class Rat(Unit):
self.speed = .10
self.partial_move = 0
self.position_before = position
self.fight = True
def calculate_rat_direction(self):
x, y = self.position
@@ -87,9 +88,9 @@ class Rat(Unit):
y2 > oy1 + OVERLAP_TOLERANCE):
continue
if self.id in self.game.units and unit.id in self.game.units:
if self.sex == unit.sex:
if self.sex == unit.sex and self.fight:
self.die(unit)
else:
elif self.sex != unit.sex:
if "fuck" in dir(self):
self.fuck(unit)
@@ -104,6 +105,7 @@ class Rat(Unit):
direction = self.calculate_rat_direction()
sex = self.sex if self.age > AGE_THRESHOLD else "BABY"
image = self.game.rat_assets[sex][direction]
image_size = self.game.engine.get_image_size(image)
self.rat_image = image
partial_x, partial_y = 0, 0
@@ -112,11 +114,11 @@ class Rat(Unit):
else:
partial_x = self.partial_move * self.game.cell_size * (1 if direction == "RIGHT" else -1)
x_pos = self.position_before[0] * self.game.cell_size + (self.game.cell_size - image.width()) // 2 + partial_x
y_pos = self.position_before[1] * self.game.cell_size + (self.game.cell_size - image.height()) // 2 + partial_y
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=image, anchor="nw", tag="unit")
self.bbox = (x_pos, y_pos, x_pos + image.width(), y_pos + image.height())
self.game.engine.draw_image(x_pos, y_pos, image, anchor="nw", tag="unit")
self.bbox = (x_pos, y_pos, x_pos + image_size[0], y_pos + image_size[1])
self.game.engine.draw_rectangle(self.bbox[0], self.bbox[1], self.bbox[2] - self.bbox[0], self.bbox[3] - self.bbox[1], "unit")
class Male(Rat):