pyforgefx 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Drakonosinc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,94 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyforgefx
3
+ Version: 1.0.0
4
+ Summary: Modular 2D SpriteSheet Animation, Procedural Frame Generation, Particles, Motion Trails, and Camera Effects library for Pygame.
5
+ Author: Drakonosinc
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Drakonosinc/PyForgeFX
8
+ Project-URL: Repository, https://github.com/Drakonosinc/PyForgeFX
9
+ Keywords: pygame,spritesheet,animation,particles,visual-effects,2d-graphics,gamedev
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Games/Entertainment
15
+ Classifier: Topic :: Multimedia :: Graphics
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE.md
19
+ Requires-Dist: pygame-ce>=2.4.0; python_version >= "3.12"
20
+ Requires-Dist: Pillow>=10.0.0
21
+ Requires-Dist: numpy>=1.24.0
22
+ Dynamic: license-file
23
+
24
+ # ✨ PyForgeFX — Modular 2D SpriteSheet Animation, Procedural FX & Particle Engine for Pygame
25
+
26
+ [![Ask DeepWiki](https://img.shields.io/badge/Ask-DeepWiki-4B32C3?logo=read-the-docs&logoColor=white)](https://deepwiki.com/Drakonosinc/PyForgeFX)
27
+ ![Python](https://img.shields.io/badge/Python-3.9%2B-3776AB?logo=python&logoColor=white)
28
+ ![Pygame](https://img.shields.io/badge/Pygame--CE-2D_Graphics-00B4AB)
29
+ ![License](https://img.shields.io/badge/License-MIT-green)
30
+
31
+ **PyForgeFX** (`pyforgefx`) is a lightweight, 100% framework-agnostic **2D Animation, Procedural SpriteSheet Generation, Particle System, Motion Trail, and Camera Effects library** built on top of `pygame` / `pygame-ce`.
32
+
33
+ Every component accepts standard Pygame primitives (`pygame.Surface`, `(x, y)` coordinates, `dt: float`) with **zero coupling** to any specific game loop or project structure.
34
+
35
+ ---
36
+
37
+ ## 🚀 Key Features
38
+
39
+ | Module | Classes | Description |
40
+ | :--- | :--- | :--- |
41
+ | **`pyforgefx.sprites`** | `SpriteSheet`, `Animator`, `AnimationClip`, `SpriteFXGenerator` | Slice any spritesheet into frames, manage multi-state animations (`idle`, `thrust`, `hit`, `shield`), or procedurally generate animated spritesheets from a single static PNG. |
42
+ | **`pyforgefx.particles`** | `ParticleEmitter`, `ShockwaveManager` | Emit radial or directional particle bursts (`sparks`, `explosion`, `thruster`, `goal`) and expanding alpha-faded shockwave rings. |
43
+ | **`pyforgefx.trails`** | `TrailRenderer` | Smooth, tapering, color-interpolated motion ribbon behind fast-moving projectiles or characters. |
44
+ | **`pyforgefx.camera`** | `ScreenShake`, `StarfieldParallax` | Damped trauma camera shake `(offset_x, offset_y)` and multi-depth twinkling parallax starfield. |
45
+
46
+ ---
47
+
48
+ ## ⚡ Quick Usage Example (Drop-in into any Pygame script)
49
+
50
+ ```python
51
+ import pygame
52
+ from pyforgefx import (
53
+ Animator,
54
+ ParticleEmitter,
55
+ ScreenShake,
56
+ ShockwaveManager,
57
+ SpriteFXGenerator,
58
+ TrailRenderer,
59
+ )
60
+
61
+ # 1. Turn any static sprite into an animated multi-state Animator
62
+ idle_sheet = SpriteFXGenerator.generate_bobbing_strip("spaceship.png", num_frames=8)
63
+ thrust_sheet = SpriteFXGenerator.generate_thruster_strip("spaceship.png", num_frames=8)
64
+ hit_sheet = SpriteFXGenerator.generate_shield_hit_strip("spaceship.png", num_frames=6)
65
+
66
+ animator = (
67
+ Animator(default_state="idle")
68
+ .add_clip("idle", idle_sheet.slice_strip(8), fps=10, loop=True)
69
+ .add_clip("thrust", thrust_sheet.slice_strip(8), fps=16, loop=True)
70
+ .add_clip("hit", hit_sheet.slice_strip(6), fps=18, loop=False)
71
+ )
72
+
73
+ # 2. Initialize standalone FX controllers
74
+ particles = ParticleEmitter()
75
+ shockwaves = ShockwaveManager()
76
+ trail = TrailRenderer(max_points=18, start_radius=10.0)
77
+ shake = ScreenShake()
78
+
79
+ # Inside your game loop (dt in seconds):
80
+ frame_surface = animator.update(dt)
81
+ ox, oy = shake.update(dt)
82
+ trail.push(ball_x, ball_y)
83
+ trail.draw(screen, offset=(ox, oy))
84
+ particles.update_and_draw(screen, dt, offset=(ox, oy))
85
+ shockwaves.update_and_draw(screen, dt, offset=(ox, oy))
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 🧪 Running Tests
91
+
92
+ ```bash
93
+ python -m unittest discover -s tests -v
94
+ ```
@@ -0,0 +1,71 @@
1
+ # ✨ PyForgeFX — Modular 2D SpriteSheet Animation, Procedural FX & Particle Engine for Pygame
2
+
3
+ [![Ask DeepWiki](https://img.shields.io/badge/Ask-DeepWiki-4B32C3?logo=read-the-docs&logoColor=white)](https://deepwiki.com/Drakonosinc/PyForgeFX)
4
+ ![Python](https://img.shields.io/badge/Python-3.9%2B-3776AB?logo=python&logoColor=white)
5
+ ![Pygame](https://img.shields.io/badge/Pygame--CE-2D_Graphics-00B4AB)
6
+ ![License](https://img.shields.io/badge/License-MIT-green)
7
+
8
+ **PyForgeFX** (`pyforgefx`) is a lightweight, 100% framework-agnostic **2D Animation, Procedural SpriteSheet Generation, Particle System, Motion Trail, and Camera Effects library** built on top of `pygame` / `pygame-ce`.
9
+
10
+ Every component accepts standard Pygame primitives (`pygame.Surface`, `(x, y)` coordinates, `dt: float`) with **zero coupling** to any specific game loop or project structure.
11
+
12
+ ---
13
+
14
+ ## 🚀 Key Features
15
+
16
+ | Module | Classes | Description |
17
+ | :--- | :--- | :--- |
18
+ | **`pyforgefx.sprites`** | `SpriteSheet`, `Animator`, `AnimationClip`, `SpriteFXGenerator` | Slice any spritesheet into frames, manage multi-state animations (`idle`, `thrust`, `hit`, `shield`), or procedurally generate animated spritesheets from a single static PNG. |
19
+ | **`pyforgefx.particles`** | `ParticleEmitter`, `ShockwaveManager` | Emit radial or directional particle bursts (`sparks`, `explosion`, `thruster`, `goal`) and expanding alpha-faded shockwave rings. |
20
+ | **`pyforgefx.trails`** | `TrailRenderer` | Smooth, tapering, color-interpolated motion ribbon behind fast-moving projectiles or characters. |
21
+ | **`pyforgefx.camera`** | `ScreenShake`, `StarfieldParallax` | Damped trauma camera shake `(offset_x, offset_y)` and multi-depth twinkling parallax starfield. |
22
+
23
+ ---
24
+
25
+ ## ⚡ Quick Usage Example (Drop-in into any Pygame script)
26
+
27
+ ```python
28
+ import pygame
29
+ from pyforgefx import (
30
+ Animator,
31
+ ParticleEmitter,
32
+ ScreenShake,
33
+ ShockwaveManager,
34
+ SpriteFXGenerator,
35
+ TrailRenderer,
36
+ )
37
+
38
+ # 1. Turn any static sprite into an animated multi-state Animator
39
+ idle_sheet = SpriteFXGenerator.generate_bobbing_strip("spaceship.png", num_frames=8)
40
+ thrust_sheet = SpriteFXGenerator.generate_thruster_strip("spaceship.png", num_frames=8)
41
+ hit_sheet = SpriteFXGenerator.generate_shield_hit_strip("spaceship.png", num_frames=6)
42
+
43
+ animator = (
44
+ Animator(default_state="idle")
45
+ .add_clip("idle", idle_sheet.slice_strip(8), fps=10, loop=True)
46
+ .add_clip("thrust", thrust_sheet.slice_strip(8), fps=16, loop=True)
47
+ .add_clip("hit", hit_sheet.slice_strip(6), fps=18, loop=False)
48
+ )
49
+
50
+ # 2. Initialize standalone FX controllers
51
+ particles = ParticleEmitter()
52
+ shockwaves = ShockwaveManager()
53
+ trail = TrailRenderer(max_points=18, start_radius=10.0)
54
+ shake = ScreenShake()
55
+
56
+ # Inside your game loop (dt in seconds):
57
+ frame_surface = animator.update(dt)
58
+ ox, oy = shake.update(dt)
59
+ trail.push(ball_x, ball_y)
60
+ trail.draw(screen, offset=(ox, oy))
61
+ particles.update_and_draw(screen, dt, offset=(ox, oy))
62
+ shockwaves.update_and_draw(screen, dt, offset=(ox, oy))
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🧪 Running Tests
68
+
69
+ ```bash
70
+ python -m unittest discover -s tests -v
71
+ ```
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pyforgefx"
7
+ version = "1.0.0"
8
+ description = "Modular 2D SpriteSheet Animation, Procedural Frame Generation, Particles, Motion Trails, and Camera Effects library for Pygame."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [
12
+ { name = "Drakonosinc" }
13
+ ]
14
+ requires-python = ">=3.9"
15
+ dependencies = [
16
+ "pygame-ce>=2.4.0; python_version>='3.12'",
17
+ "Pillow>=10.0.0",
18
+ "numpy>=1.24.0",
19
+ ]
20
+ keywords = ["pygame", "spritesheet", "animation", "particles", "visual-effects", "2d-graphics", "gamedev"]
21
+ classifiers = [
22
+ "Development Status :: 5 - Production/Stable",
23
+ "Intended Audience :: Developers",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Programming Language :: Python :: 3",
26
+ "Topic :: Games/Entertainment",
27
+ "Topic :: Multimedia :: Graphics",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/Drakonosinc/PyForgeFX"
32
+ Repository = "https://github.com/Drakonosinc/PyForgeFX"
33
+
34
+ [tool.setuptools.packages.find]
35
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ """PyForgeFX: Modular 2D SpriteSheet Animation, Procedural Frame Generation, Particles, Motion Trails, and Camera Effects library for Pygame."""
2
+
3
+ from .camera import ScreenShake, StarNode, StarfieldParallax
4
+ from .particles import Particle, ParticleEmitter, ShockwaveManager, ShockwaveRing
5
+ from .sprites import AnimationClip, Animator, SpriteFXGenerator, SpriteSheet
6
+ from .trails import TrailRenderer
7
+
8
+ __version__ = "1.0.0"
9
+ __author__ = "Drakonosinc"
10
+
11
+ __all__ = [
12
+ "__version__",
13
+ "AnimationClip",
14
+ "Animator",
15
+ "Particle",
16
+ "ParticleEmitter",
17
+ "ScreenShake",
18
+ "ShockwaveManager",
19
+ "ShockwaveRing",
20
+ "SpriteFXGenerator",
21
+ "SpriteSheet",
22
+ "StarNode",
23
+ "StarfieldParallax",
24
+ "TrailRenderer",
25
+ ]
@@ -0,0 +1,4 @@
1
+ from .parallax import StarNode, StarfieldParallax
2
+ from .screen_shake import ScreenShake
3
+
4
+ __all__ = ["ScreenShake", "StarNode", "StarfieldParallax"]
@@ -0,0 +1,83 @@
1
+ """Multi-layer procedural twinkling starfield & parallax overlay (`StarfieldParallax`)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ import math
7
+ import random
8
+ import pygame
9
+
10
+
11
+ @dataclass(slots=True)
12
+ class StarNode:
13
+ x: float
14
+ y: float
15
+ speed: float
16
+ radius: int
17
+ phase: float
18
+ color: tuple[int, int, int]
19
+
20
+
21
+ class StarfieldParallax:
22
+ """Renders a multi-depth scrolling and twinkling starfield over or behind any background."""
23
+
24
+ def __init__(
25
+ self,
26
+ width: int,
27
+ height: int,
28
+ num_stars: int = 55,
29
+ seed: int | None = 42,
30
+ ) -> None:
31
+ self.width = max(64, int(width))
32
+ self.height = max(64, int(height))
33
+ self._rng = random.Random(seed)
34
+ self.time: float = 0.0
35
+ self.stars: list[StarNode] = []
36
+ self._init_stars(int(num_stars))
37
+
38
+ def _init_stars(self, count: int) -> None:
39
+ palette = [
40
+ (226, 232, 240),
41
+ (125, 211, 252),
42
+ (196, 181, 253),
43
+ (253, 230, 138),
44
+ ]
45
+ self.stars.clear()
46
+ for _ in range(max(5, count)):
47
+ depth = self._rng.choice((1, 2, 3))
48
+ self.stars.append(
49
+ StarNode(
50
+ x=self._rng.uniform(0, self.width),
51
+ y=self._rng.uniform(0, self.height),
52
+ speed=12.0 * depth,
53
+ radius=1 if depth < 3 else 2,
54
+ phase=self._rng.uniform(0.0, math.pi * 2.0),
55
+ color=self._rng.choice(palette),
56
+ )
57
+ )
58
+
59
+ def resize(self, width: int, height: int) -> None:
60
+ if (int(width), int(height)) != (self.width, self.height):
61
+ self.width = max(64, int(width))
62
+ self.height = max(64, int(height))
63
+ self._init_stars(len(self.stars))
64
+
65
+ def update_and_draw(
66
+ self,
67
+ surface: pygame.Surface,
68
+ dt: float,
69
+ drift_x: float = -1.0,
70
+ drift_y: float = 0.2,
71
+ ) -> None:
72
+ step = max(0.0, float(dt))
73
+ self.time += step
74
+ for star in self.stars:
75
+ star.x = (star.x + drift_x * star.speed * step) % self.width
76
+ star.y = (star.y + drift_y * star.speed * step) % self.height
77
+ twinkle = 0.55 + 0.45 * math.sin(self.time * 3.2 + star.phase)
78
+ c = (
79
+ int(star.color[0] * twinkle),
80
+ int(star.color[1] * twinkle),
81
+ int(star.color[2] * twinkle),
82
+ )
83
+ pygame.draw.circle(surface, c, (int(star.x), int(star.y)), star.radius)
@@ -0,0 +1,34 @@
1
+ """Camera trauma and screen-shake controller (`ScreenShake`) for 2D games."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import random
6
+
7
+
8
+ class ScreenShake:
9
+ """Computes damped `(offset_x, offset_y)` camera shake displacements on impacts."""
10
+
11
+ def __init__(self, seed: int | None = None) -> None:
12
+ self.intensity: float = 0.0
13
+ self.duration: float = 0.0
14
+ self.elapsed: float = 0.0
15
+ self._rng = random.Random(seed)
16
+
17
+ def trigger(self, intensity: float = 7.0, duration: float = 0.22) -> None:
18
+ """Start or amplify a screen-shake impulse."""
19
+ self.intensity = max(self.intensity, float(intensity))
20
+ self.duration = max(0.05, float(duration))
21
+ self.elapsed = 0.0
22
+
23
+ def update(self, dt: float) -> tuple[int, int]:
24
+ """Advance the shake timer by `dt` seconds and return `(offset_x, offset_y)`."""
25
+ if self.intensity <= 0.01 or self.elapsed >= self.duration:
26
+ self.intensity = 0.0
27
+ return 0, 0
28
+
29
+ self.elapsed += max(0.0, float(dt))
30
+ remaining = max(0.0, 1.0 - (self.elapsed / self.duration))
31
+ mag = self.intensity * remaining
32
+ ox = int(round(self._rng.uniform(-mag, mag)))
33
+ oy = int(round(self._rng.uniform(-mag, mag)))
34
+ return ox, oy
@@ -0,0 +1,4 @@
1
+ from .emitter import Particle, ParticleEmitter
2
+ from .shockwave import ShockwaveManager, ShockwaveRing
3
+
4
+ __all__ = ["Particle", "ParticleEmitter", "ShockwaveManager", "ShockwaveRing"]
@@ -0,0 +1,178 @@
1
+ """Lightweight 2D Particle System and preset emitter (`ParticleEmitter`) for Pygame."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ import math
7
+ import random
8
+ import pygame
9
+
10
+
11
+ @dataclass(slots=True)
12
+ class Particle:
13
+ x: float
14
+ y: float
15
+ vx: float
16
+ vy: float
17
+ radius: float
18
+ color: tuple[int, int, int]
19
+ life: float
20
+ max_life: float
21
+ gravity: float = 0.0
22
+ drag: float = 0.98
23
+ glow: bool = True
24
+
25
+
26
+ class ParticleEmitter:
27
+ """Standalone 2D particle emitter supporting sparks, explosions, thrusters, and ambient effects."""
28
+
29
+ def __init__(self, max_particles: int = 450, seed: int | None = None) -> None:
30
+ self.max_particles = max(10, int(max_particles))
31
+ self.particles: list[Particle] = []
32
+ self._rng = random.Random(seed)
33
+
34
+ def clear(self) -> None:
35
+ self.particles.clear()
36
+
37
+ def emit_burst(
38
+ self,
39
+ x: float,
40
+ y: float,
41
+ count: int = 18,
42
+ color: tuple[int, int, int] = (255, 190, 80),
43
+ secondary_color: tuple[int, int, int] | None = (255, 90, 30),
44
+ speed_range: tuple[float, float] = (60.0, 240.0),
45
+ size_range: tuple[float, float] = (2.5, 6.0),
46
+ life_range: tuple[float, float] = (0.22, 0.55),
47
+ angle_range_deg: tuple[float, float] = (0.0, 360.0),
48
+ gravity: float = 0.0,
49
+ ) -> None:
50
+ """Spawn a radial or directional burst of particles at `(x, y)`."""
51
+ palette = [color]
52
+ if secondary_color is not None:
53
+ palette.append(secondary_color)
54
+
55
+ for _ in range(int(count)):
56
+ if len(self.particles) >= self.max_particles:
57
+ self.particles.pop(0)
58
+ angle = math.radians(self._rng.uniform(angle_range_deg[0], angle_range_deg[1]))
59
+ speed = self._rng.uniform(speed_range[0], speed_range[1])
60
+ life = self._rng.uniform(life_range[0], life_range[1])
61
+ radius = self._rng.uniform(size_range[0], size_range[1])
62
+ chosen_color = self._rng.choice(palette)
63
+ self.particles.append(
64
+ Particle(
65
+ x=float(x),
66
+ y=float(y),
67
+ vx=math.cos(angle) * speed,
68
+ vy=math.sin(angle) * speed,
69
+ radius=radius,
70
+ color=chosen_color,
71
+ life=life,
72
+ max_life=life,
73
+ gravity=float(gravity),
74
+ )
75
+ )
76
+
77
+ def emit_preset(self, x: float, y: float, preset: str = "sparks") -> None:
78
+ """Emit particles using a built-in visual preset (`sparks`, `explosion`, `thruster`, `goal`)."""
79
+ mode = preset.strip().lower()
80
+ if mode == "explosion":
81
+ self.emit_burst(
82
+ x,
83
+ y,
84
+ count=32,
85
+ color=(255, 220, 90),
86
+ secondary_color=(255, 70, 30),
87
+ speed_range=(80.0, 310.0),
88
+ size_range=(3.0, 7.5),
89
+ life_range=(0.3, 0.75),
90
+ )
91
+ elif mode == "goal":
92
+ self.emit_burst(
93
+ x,
94
+ y,
95
+ count=40,
96
+ color=(56, 189, 248),
97
+ secondary_color=(168, 85, 247),
98
+ speed_range=(90.0, 340.0),
99
+ size_range=(3.5, 8.0),
100
+ life_range=(0.4, 0.85),
101
+ )
102
+ elif mode == "thruster":
103
+ self.emit_burst(
104
+ x,
105
+ y,
106
+ count=3,
107
+ color=(125, 211, 252),
108
+ secondary_color=(59, 130, 246),
109
+ speed_range=(25.0, 75.0),
110
+ size_range=(2.0, 4.2),
111
+ life_range=(0.12, 0.26),
112
+ )
113
+ else:
114
+ # Default: collision sparks
115
+ self.emit_burst(
116
+ x,
117
+ y,
118
+ count=16,
119
+ color=(255, 240, 150),
120
+ secondary_color=(56, 189, 248),
121
+ speed_range=(70.0, 220.0),
122
+ size_range=(2.2, 5.0),
123
+ life_range=(0.18, 0.42),
124
+ )
125
+
126
+ def update(self, dt: float) -> None:
127
+ """Advance particle physics by `dt` seconds and prune expired particles."""
128
+ step = max(0.0, float(dt))
129
+ alive: list[Particle] = []
130
+ for p in self.particles:
131
+ p.life -= step
132
+ if p.life <= 0.0:
133
+ continue
134
+ p.vy += p.gravity * step
135
+ p.vx *= p.drag
136
+ p.vy *= p.drag
137
+ p.x += p.vx * step
138
+ p.y += p.vy * step
139
+ alive.append(p)
140
+ self.particles = alive
141
+
142
+ def draw(self, surface: pygame.Surface, offset: tuple[int, int] = (0, 0)) -> None:
143
+ """Render active particles with smooth alpha decay onto `surface`."""
144
+ ox, oy = int(offset[0]), int(offset[1])
145
+ for p in self.particles:
146
+ ratio = max(0.0, min(1.0, p.life / max(1e-5, p.max_life)))
147
+ cur_r = max(1, int(round(p.radius * ratio)))
148
+ alpha = int(245 * ratio)
149
+ px = int(round(p.x)) + ox
150
+ py = int(round(p.y)) + oy
151
+
152
+ if p.glow and cur_r >= 2:
153
+ glow_r = cur_r * 2
154
+ glow_surf = pygame.Surface((glow_r * 2 + 2, glow_r * 2 + 2), pygame.SRCALPHA)
155
+ pygame.draw.circle(
156
+ glow_surf,
157
+ (*p.color[:3], max(15, alpha // 3)),
158
+ (glow_r + 1, glow_r + 1),
159
+ glow_r,
160
+ )
161
+ pygame.draw.circle(
162
+ glow_surf,
163
+ (*p.color[:3], alpha),
164
+ (glow_r + 1, glow_r + 1),
165
+ cur_r,
166
+ )
167
+ surface.blit(glow_surf, (px - glow_r - 1, py - glow_r - 1))
168
+ else:
169
+ pygame.draw.circle(surface, p.color, (px, py), cur_r)
170
+
171
+ def update_and_draw(
172
+ self,
173
+ surface: pygame.Surface,
174
+ dt: float,
175
+ offset: tuple[int, int] = (0, 0),
176
+ ) -> None:
177
+ self.update(dt)
178
+ self.draw(surface, offset=offset)
@@ -0,0 +1,85 @@
1
+ """Expanding shockwave ring effect (`ShockwaveManager`) for impact and scoring feedback."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ import pygame
7
+
8
+
9
+ @dataclass(slots=True)
10
+ class ShockwaveRing:
11
+ x: float
12
+ y: float
13
+ radius: float
14
+ max_radius: float
15
+ speed: float
16
+ color: tuple[int, int, int]
17
+ width: int = 3
18
+
19
+
20
+ class ShockwaveManager:
21
+ """Manages expanding circular shockwaves with smooth alpha fade."""
22
+
23
+ def __init__(self) -> None:
24
+ self.rings: list[ShockwaveRing] = []
25
+
26
+ def clear(self) -> None:
27
+ self.rings.clear()
28
+
29
+ def spawn(
30
+ self,
31
+ x: float,
32
+ y: float,
33
+ max_radius: float = 65.0,
34
+ speed: float = 240.0,
35
+ color: tuple[int, int, int] = (56, 189, 248),
36
+ width: int = 3,
37
+ ) -> None:
38
+ self.rings.append(
39
+ ShockwaveRing(
40
+ x=float(x),
41
+ y=float(y),
42
+ radius=4.0,
43
+ max_radius=max(10.0, float(max_radius)),
44
+ speed=max(20.0, float(speed)),
45
+ color=color,
46
+ width=max(1, int(width)),
47
+ )
48
+ )
49
+
50
+ def update(self, dt: float) -> None:
51
+ step = max(0.0, float(dt))
52
+ active: list[ShockwaveRing] = []
53
+ for r in self.rings:
54
+ r.radius += r.speed * step
55
+ if r.radius < r.max_radius:
56
+ active.append(r)
57
+ self.rings = active
58
+
59
+ def draw(self, surface: pygame.Surface, offset: tuple[int, int] = (0, 0)) -> None:
60
+ ox, oy = int(offset[0]), int(offset[1])
61
+ for r in self.rings:
62
+ progress = max(0.0, min(1.0, r.radius / r.max_radius))
63
+ alpha = int(210 * (1.0 - progress))
64
+ rad = int(round(r.radius))
65
+ if alpha <= 4 or rad <= 1:
66
+ continue
67
+ diam = rad * 2 + 4
68
+ ring_surf = pygame.Surface((diam, diam), pygame.SRCALPHA)
69
+ pygame.draw.circle(
70
+ ring_surf,
71
+ (*r.color[:3], alpha),
72
+ (diam // 2, diam // 2),
73
+ rad,
74
+ width=min(rad, r.width),
75
+ )
76
+ surface.blit(ring_surf, (int(round(r.x)) + ox - diam // 2, int(round(r.y)) + oy - diam // 2))
77
+
78
+ def update_and_draw(
79
+ self,
80
+ surface: pygame.Surface,
81
+ dt: float,
82
+ offset: tuple[int, int] = (0, 0),
83
+ ) -> None:
84
+ self.update(dt)
85
+ self.draw(surface, offset=offset)
@@ -0,0 +1,5 @@
1
+ from .animator import AnimationClip, Animator
2
+ from .generator import SpriteFXGenerator
3
+ from .spritesheet import SpriteSheet
4
+
5
+ __all__ = ["AnimationClip", "Animator", "SpriteFXGenerator", "SpriteSheet"]