From 783af8cd2dd9977dde639d3b73026e778a327119 Mon Sep 17 00:00:00 2001 From: nilfm Date: Wed, 6 Aug 2025 12:55:45 -0400 Subject: [PATCH] Rename to boink --- main.py | 32 ++++++++++------------------- pyproject.toml | 2 +- src/configuration/configuration.py | 2 +- src/entity/ball/ball.py | 6 +++--- src/entity/ball/ball_prototype.py | 6 +++++- src/visuals/damage_number_effect.py | 16 +++++++++++---- uv.lock | 2 +- 7 files changed, 34 insertions(+), 32 deletions(-) diff --git a/main.py b/main.py index 4e856c2..5425abf 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,5 @@ from pathlib import Path -import pygame - from src.configuration.configuration import Configuration from src.entity.ball.ball_spawn_config_factory import BallSpawnConfigFactory from src.entity.ball.ball_prototype import BallPrototype @@ -9,31 +7,23 @@ from src.game.game import Game -def main(): - configuration = Configuration() - - nil_faces = FaceConfiguration( - Path("resources/nil_happy.png"), - Path("resources/nil_angry.png"), - 2 * configuration.ball_radius, - ) - jin_faces = FaceConfiguration( - Path("resources/jin_happy.png"), - Path("resources/jin_angry.png"), +def _get_faces(name: str, configuration: Configuration) -> FaceConfiguration: + return FaceConfiguration( + Path(f"resources/{name}_happy.png"), + Path(f"resources/{name}_angry.png"), 2 * configuration.ball_radius, ) - ball_prototypes = [ - BallPrototype(name="nil", color=pygame.Color("lightblue"), faces=nil_faces), - BallPrototype(name="jin", color=pygame.Color("lightgreen"), faces=jin_faces), - BallPrototype(name="hehehe", color=pygame.Color("lightcoral")), - BallPrototype(name="anununu", color=pygame.Color("lightpink")), - BallPrototype(name="kachupuchu", color=pygame.Color("lightgray")), - ] + +def main(): + configuration = Configuration() factory = BallSpawnConfigFactory( configuration, - ball_prototypes=ball_prototypes, + ball_prototypes=[ + BallPrototype(name=name, faces=_get_faces(name, configuration)) + for name in ["nil", "jin", "papa", "mama", "martina"] + ], ) game = Game(configuration, factory.make_balls) diff --git a/pyproject.toml b/pyproject.toml index 64b4f9d..c5299bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ authors = [ { name = "Nil Fons Miret", email = "nil.fons@gmail.com" } ] license = "MIT" -name = "ball-game" +name = "boink" version = "0.1.0" description = "Add your description here" readme = "README.md" diff --git a/src/configuration/configuration.py b/src/configuration/configuration.py index 589ad99..7502c34 100644 --- a/src/configuration/configuration.py +++ b/src/configuration/configuration.py @@ -10,7 +10,7 @@ class Configuration: bottom_hud_height: int = 80 hud_color: tuple[int, int, int] = (245, 235, 220) ball_radius: int = 60 - title: str = "Ball game" + title: str = "Boink" @property def min_initial_speed(self) -> float: diff --git a/src/entity/ball/ball.py b/src/entity/ball/ball.py index 71b3541..c3c969a 100644 --- a/src/entity/ball/ball.py +++ b/src/entity/ball/ball.py @@ -80,10 +80,10 @@ def draw(self, display: Display) -> None: pos = (self.body.position.x, self.body.position.y) alpha = self.modifiers.get_pulse_alpha() - if self.prototype.faces is not None: + if self.faces: angle_deg = -self.body.angle * 180 / math.pi display.draw_image(self.get_current_face(), pos, angle_deg, alpha) - else: + elif self.prototype.color: display.draw_circle(pos, self.radius, self.prototype.color, alpha) # Health text below the ball @@ -130,7 +130,7 @@ def receive_damage(self, damage: int, is_crit: bool) -> None: duration=0.5 ) ) - else: + elif self.prototype.color: # TODO: assert this Either in the type system correctly self.visual_effect_manager.add( ImplosionEffect( pos=(self.body.position.x, self.body.position.y), diff --git a/src/entity/ball/ball_prototype.py b/src/entity/ball/ball_prototype.py index 8d3a84e..78908ab 100644 --- a/src/entity/ball/ball_prototype.py +++ b/src/entity/ball/ball_prototype.py @@ -8,5 +8,9 @@ @dataclass(frozen=True) class BallPrototype: name: str - color: pygame.Color + color: pygame.Color | None = None faces: FaceConfiguration | None = None + + def __post_init__(self) -> None: + if (self.color is None and self.faces is None) or (self.color is not None and self.faces is not None): + raise ValueError("Exactly one of 'color' or 'faces' must be provided.") diff --git a/src/visuals/damage_number_effect.py b/src/visuals/damage_number_effect.py index b69df2a..05493f5 100644 --- a/src/visuals/damage_number_effect.py +++ b/src/visuals/damage_number_effect.py @@ -12,15 +12,23 @@ class DamageNumberEffect(VisualEffect): - def __init__(self, ball: Ball, amount: int, is_crit: bool): + def __init__( + self, + ball: Ball, + amount: int, + is_crit: bool, + min_size: int = 20, + max_size: int = 80, + ) -> None: super().__init__(2 if is_crit else 1) self.ball = ball self.amount = amount self.is_crit = is_crit + self.min_size = min_size + self.max_size = max_size - @staticmethod - def _get_font_size(damage: int) -> int: - return 20 + damage // 5 # maps to [20, 40] + def _get_font_size(self, damage: int) -> int: + return self.min_size + (self.max_size - self.min_size) * damage // 100 @override def draw(self, display: Display) -> None: diff --git a/uv.lock b/uv.lock index fdac961..36586ca 100644 --- a/uv.lock +++ b/uv.lock @@ -7,7 +7,7 @@ resolution-markers = [ ] [[package]] -name = "ball-game" +name = "boink" version = "0.1.0" source = { virtual = "." } dependencies = [