Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
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
from src.faces.face_configuration import FaceConfiguration
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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/entity/ball/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion src/entity/ball/ball_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
16 changes: 12 additions & 4 deletions src/visuals/damage_number_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.