gh-space-shooter 0.0.3__tar.gz → 0.0.4__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.
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/.github/workflows/publish.yml +1 -1
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/PKG-INFO +7 -1
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/README.md +6 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/action.yml +6 -1
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/pyproject.toml +2 -2
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/cli.py +16 -5
- gh_space_shooter-0.0.4/src/gh_space_shooter/constants.py +30 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/animator.py +10 -7
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/bullet.py +9 -5
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/drawable.py +6 -2
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/enemy.py +1 -1
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/explosion.py +13 -9
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/ship.py +13 -8
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/starfield.py +31 -15
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/game_state.py +13 -9
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/tests/test_bullet_collision.py +15 -12
- gh_space_shooter-0.0.4/uv.lock +305 -0
- gh_space_shooter-0.0.3/src/gh_space_shooter/constants.py +0 -19
- gh_space_shooter-0.0.3/uv.lock +0 -305
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/.github/dependabot.yml +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/.github/workflows/test.yml +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/.gitignore +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/.python-version +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/LICENSE +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/example.gif +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/__init__.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/console_printer.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/__init__.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/__init__.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/render_context.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/renderer.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/strategies/__init__.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/strategies/base_strategy.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/strategies/column_strategy.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/strategies/random_strategy.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/strategies/row_strategy.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/github_client.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/py.typed +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/tests/conftest.py +0 -0
- {gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/tests/test_strategies.py +0 -0
|
@@ -48,7 +48,7 @@ jobs:
|
|
|
48
48
|
- name: GitHub Release v${{ steps.bump.outputs.current-version }}
|
|
49
49
|
uses: ncipollo/release-action@v1
|
|
50
50
|
with:
|
|
51
|
-
name:
|
|
51
|
+
name: gh-space-shooter v${{ steps.bump.outputs.current-version }}
|
|
52
52
|
tag: v${{ steps.bump.outputs.current-version }}
|
|
53
53
|
body: "Automated release of version v${{ steps.bump.outputs.current-version }}"
|
|
54
54
|
artifacts: dist/*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gh-space-shooter
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: A CLI tool that visualizes GitHub contribution graphs as gamified GIFs
|
|
5
5
|
Author-email: zane <czl970721@gmail.com>
|
|
6
6
|
License-File: LICENSE
|
|
@@ -60,6 +60,7 @@ Then display it in your README:
|
|
|
60
60
|
- `username` (optional): Username to generate game for (defaults to repo owner)
|
|
61
61
|
- `output-path` (optional): Where to save the GIF (default: `gh-space-shooter.gif`)
|
|
62
62
|
- `strategy` (optional): Attack pattern - `column`, `row`, or `random` (default: `random`)
|
|
63
|
+
- `fps` (optional): Frames per second for the animation (default: `40`)
|
|
63
64
|
- `commit-message` (optional): Commit message for the update
|
|
64
65
|
|
|
65
66
|
### From PyPI
|
|
@@ -124,6 +125,11 @@ gh-space-shooter torvalds -o my-game.gif
|
|
|
124
125
|
gh-space-shooter torvalds --strategy column # Enemies attack in columns
|
|
125
126
|
gh-space-shooter torvalds --strategy row # Enemies attack in rows
|
|
126
127
|
gh-space-shooter torvalds -s random # Random chaos (default)
|
|
128
|
+
|
|
129
|
+
# Adjust animation frame rate
|
|
130
|
+
gh-space-shooter torvalds --fps 25 # Slower, smaller file size
|
|
131
|
+
gh-space-shooter torvalds --fps 40 # Default frame rate
|
|
132
|
+
gh-space-shooter torvalds --fps 50 # Smoother animation
|
|
127
133
|
```
|
|
128
134
|
|
|
129
135
|
This creates an animated GIF showing:
|
|
@@ -44,6 +44,7 @@ Then display it in your README:
|
|
|
44
44
|
- `username` (optional): Username to generate game for (defaults to repo owner)
|
|
45
45
|
- `output-path` (optional): Where to save the GIF (default: `gh-space-shooter.gif`)
|
|
46
46
|
- `strategy` (optional): Attack pattern - `column`, `row`, or `random` (default: `random`)
|
|
47
|
+
- `fps` (optional): Frames per second for the animation (default: `40`)
|
|
47
48
|
- `commit-message` (optional): Commit message for the update
|
|
48
49
|
|
|
49
50
|
### From PyPI
|
|
@@ -108,6 +109,11 @@ gh-space-shooter torvalds -o my-game.gif
|
|
|
108
109
|
gh-space-shooter torvalds --strategy column # Enemies attack in columns
|
|
109
110
|
gh-space-shooter torvalds --strategy row # Enemies attack in rows
|
|
110
111
|
gh-space-shooter torvalds -s random # Random chaos (default)
|
|
112
|
+
|
|
113
|
+
# Adjust animation frame rate
|
|
114
|
+
gh-space-shooter torvalds --fps 25 # Slower, smaller file size
|
|
115
|
+
gh-space-shooter torvalds --fps 40 # Default frame rate
|
|
116
|
+
gh-space-shooter torvalds --fps 50 # Smoother animation
|
|
111
117
|
```
|
|
112
118
|
|
|
113
119
|
This creates an animated GIF showing:
|
|
@@ -22,6 +22,10 @@ inputs:
|
|
|
22
22
|
description: 'Enemy attack strategy (column, row, or random)'
|
|
23
23
|
required: false
|
|
24
24
|
default: 'random'
|
|
25
|
+
fps:
|
|
26
|
+
description: 'Frames per second for the animation (default: 40)'
|
|
27
|
+
required: false
|
|
28
|
+
default: '40'
|
|
25
29
|
commit-message:
|
|
26
30
|
description: 'Commit message for the GIF update'
|
|
27
31
|
required: false
|
|
@@ -54,7 +58,8 @@ runs:
|
|
|
54
58
|
run: |
|
|
55
59
|
gh-space-shooter ${{ inputs.username }} \
|
|
56
60
|
--output ${{ inputs.output-path }} \
|
|
57
|
-
--strategy ${{ inputs.strategy }}
|
|
61
|
+
--strategy ${{ inputs.strategy }} \
|
|
62
|
+
--fps ${{ inputs.fps }}
|
|
58
63
|
|
|
59
64
|
- name: Commit and push GIF
|
|
60
65
|
shell: bash
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "gh-space-shooter"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.4"
|
|
4
4
|
description = "A CLI tool that visualizes GitHub contribution graphs as gamified GIFs"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -29,7 +29,7 @@ build-backend = "hatchling.build"
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
[tool.bumpversion]
|
|
32
|
-
current_version = "0.0.
|
|
32
|
+
current_version = "0.0.4"
|
|
33
33
|
parse = """(?x)
|
|
34
34
|
(?P<major>0|[1-9]\\d*)\\.
|
|
35
35
|
(?P<minor>0|[1-9]\\d*)\\.
|
|
@@ -8,8 +8,8 @@ import typer
|
|
|
8
8
|
from dotenv import load_dotenv
|
|
9
9
|
from rich.console import Console
|
|
10
10
|
|
|
11
|
-
from
|
|
12
|
-
|
|
11
|
+
from .constants import DEFAULT_FPS
|
|
12
|
+
from .game.strategies.base_strategy import BaseStrategy
|
|
13
13
|
from .console_printer import ContributionConsolePrinter
|
|
14
14
|
from .game import Animator, ColumnStrategy, RandomStrategy, RowStrategy
|
|
15
15
|
from .github_client import ContributionData, GitHubAPIError, GitHubClient
|
|
@@ -55,6 +55,11 @@ def main(
|
|
|
55
55
|
"-s",
|
|
56
56
|
help="Strategy for clearing enemies (column, row, random)",
|
|
57
57
|
),
|
|
58
|
+
fps: int = typer.Option(
|
|
59
|
+
DEFAULT_FPS,
|
|
60
|
+
"--fps",
|
|
61
|
+
help="Frames per second for the animation",
|
|
62
|
+
),
|
|
58
63
|
) -> None:
|
|
59
64
|
"""
|
|
60
65
|
Fetch or load GitHub contribution graph data and display it.
|
|
@@ -90,7 +95,7 @@ def main(
|
|
|
90
95
|
_save_data_to_file(data, raw_output)
|
|
91
96
|
|
|
92
97
|
# Generate GIF if requested
|
|
93
|
-
_generate_gif(data, out, strategy)
|
|
98
|
+
_generate_gif(data, out, strategy, fps)
|
|
94
99
|
|
|
95
100
|
except CLIError as e:
|
|
96
101
|
err_console.print(f"[bold red]Error:[/bold red] {e}")
|
|
@@ -146,8 +151,14 @@ def _save_data_to_file(data: ContributionData, file_path: str) -> None:
|
|
|
146
151
|
raise CLIError(f"Failed to save file '{file_path}': {e}")
|
|
147
152
|
|
|
148
153
|
|
|
149
|
-
def _generate_gif(data: ContributionData, file_path: str, strategy_name: str) -> None:
|
|
154
|
+
def _generate_gif(data: ContributionData, file_path: str, strategy_name: str, fps: int) -> None:
|
|
150
155
|
"""Generate animated GIF visualization."""
|
|
156
|
+
# GIF format limitation: delays below 20ms (>50 FPS) are clamped by most browsers
|
|
157
|
+
if fps > 50:
|
|
158
|
+
console.print(
|
|
159
|
+
f"[yellow]Warning:[/yellow] FPS > 50 may not display correctly in browsers "
|
|
160
|
+
f"(GIF delay will be {1000 // fps}ms, but browsers clamp delays < 20ms to ~100ms)"
|
|
161
|
+
)
|
|
151
162
|
console.print("\n[bold blue]Generating GIF animation...[/bold blue]")
|
|
152
163
|
|
|
153
164
|
if strategy_name == "column":
|
|
@@ -163,7 +174,7 @@ def _generate_gif(data: ContributionData, file_path: str, strategy_name: str) ->
|
|
|
163
174
|
|
|
164
175
|
# Create animator and generate GIF
|
|
165
176
|
try:
|
|
166
|
-
animator = Animator(data, strategy)
|
|
177
|
+
animator = Animator(data, strategy, fps=fps)
|
|
167
178
|
animator.generate_gif(file_path)
|
|
168
179
|
console.print(f"[green]✓[/green] GIF saved to {file_path}")
|
|
169
180
|
except Exception as e:
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Global constants for the application."""
|
|
2
|
+
|
|
3
|
+
# Animation settings
|
|
4
|
+
DEFAULT_FPS = 40 # Default frames per second for animation
|
|
5
|
+
|
|
6
|
+
# GitHub contribution graph dimensions
|
|
7
|
+
NUM_WEEKS = 52 # Number of weeks in contribution graph
|
|
8
|
+
NUM_DAYS = 7 # Number of days in a week (Sun-Sat)
|
|
9
|
+
SHIP_POSITION_Y = NUM_DAYS + 3 # Ship is positioned just below the grid
|
|
10
|
+
|
|
11
|
+
# Speeds in cells per second (frame-rate independent)
|
|
12
|
+
SHIP_SPEED = 12.5 # Cells per second the ship moves
|
|
13
|
+
BULLET_SPEED = 7.5 # Cells per second the bullet moves
|
|
14
|
+
BULLET_TRAILING_LENGTH = 3 # Number of trailing segments for bullets
|
|
15
|
+
BULLET_TRAIL_SPACING = 0.15 # Spacing between trail segments in cells
|
|
16
|
+
|
|
17
|
+
# Durations in seconds (frame-rate independent)
|
|
18
|
+
SHIP_SHOOT_COOLDOWN = 0.2 # Seconds between ship shots
|
|
19
|
+
|
|
20
|
+
# Explosion settings
|
|
21
|
+
EXPLOSION_PARTICLE_COUNT_LARGE = 8 # Number of particles in a large explosion
|
|
22
|
+
EXPLOSION_PARTICLE_COUNT_SMALL = 4 # Number of particles in a small explosion
|
|
23
|
+
EXPLOSION_MAX_RADIUS_LARGE = 20 # Max radius for large explosions
|
|
24
|
+
EXPLOSION_MAX_RADIUS_SMALL = 10 # Max radius for small explosions
|
|
25
|
+
EXPLOSION_DURATION_LARGE = 0.4 # Seconds for large explosion animation
|
|
26
|
+
EXPLOSION_DURATION_SMALL = 0.12 # Seconds for small explosion animation
|
|
27
|
+
|
|
28
|
+
# Starfield settings (speeds in cells per second)
|
|
29
|
+
STAR_SPEED_MIN = 1.0 # Minimum star speed (dimmer/farther stars)
|
|
30
|
+
STAR_SPEED_MAX = 2.5 # Maximum star speed (brighter/closer stars)
|
|
@@ -5,7 +5,6 @@ from typing import Iterator
|
|
|
5
5
|
from PIL import Image
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
from ..constants import FRAME_DURATION_MS
|
|
9
8
|
from ..github_client import ContributionData
|
|
10
9
|
from .game_state import GameState
|
|
11
10
|
from .renderer import Renderer
|
|
@@ -20,7 +19,7 @@ class Animator:
|
|
|
20
19
|
self,
|
|
21
20
|
contribution_data: ContributionData,
|
|
22
21
|
strategy: BaseStrategy,
|
|
23
|
-
|
|
22
|
+
fps: int,
|
|
24
23
|
):
|
|
25
24
|
"""
|
|
26
25
|
Initialize animator.
|
|
@@ -28,11 +27,15 @@ class Animator:
|
|
|
28
27
|
Args:
|
|
29
28
|
contribution_data: The GitHub contribution data
|
|
30
29
|
strategy: The strategy to use for clearing enemies
|
|
31
|
-
|
|
30
|
+
fps: Frames per second for the animation
|
|
32
31
|
"""
|
|
33
32
|
self.contribution_data = contribution_data
|
|
34
33
|
self.strategy = strategy
|
|
35
|
-
self.
|
|
34
|
+
self.fps = fps
|
|
35
|
+
self.frame_duration = 1000 // fps
|
|
36
|
+
# Delta time in seconds per frame
|
|
37
|
+
# Used to scale all speeds (cells/second) to per-frame movement
|
|
38
|
+
self.delta_time = 1.0 / fps
|
|
36
39
|
|
|
37
40
|
def generate_gif(self, output_path: str) -> None:
|
|
38
41
|
"""
|
|
@@ -79,18 +82,18 @@ class Animator:
|
|
|
79
82
|
for action in self.strategy.generate_actions(game_state):
|
|
80
83
|
game_state.ship.move_to(action.x)
|
|
81
84
|
while game_state.can_take_action() is False:
|
|
82
|
-
game_state.animate()
|
|
85
|
+
game_state.animate(self.delta_time)
|
|
83
86
|
yield renderer.render_frame()
|
|
84
87
|
|
|
85
88
|
if action.shoot:
|
|
86
89
|
game_state.shoot()
|
|
87
|
-
game_state.animate()
|
|
90
|
+
game_state.animate(self.delta_time)
|
|
88
91
|
yield renderer.render_frame()
|
|
89
92
|
|
|
90
93
|
force_kill_countdown = 100
|
|
91
94
|
# Add final frames showing completion
|
|
92
95
|
while not game_state.is_complete():
|
|
93
|
-
game_state.animate()
|
|
96
|
+
game_state.animate(self.delta_time)
|
|
94
97
|
yield renderer.render_frame()
|
|
95
98
|
|
|
96
99
|
force_kill_countdown -= 1
|
{gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/bullet.py
RENAMED
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
|
|
4
4
|
|
|
5
5
|
from PIL import ImageDraw
|
|
6
6
|
|
|
7
|
-
from ...constants import BULLET_SPEED, BULLET_TRAILING_LENGTH, SHIP_POSITION_Y
|
|
7
|
+
from ...constants import BULLET_SPEED, BULLET_TRAILING_LENGTH, BULLET_TRAIL_SPACING, SHIP_POSITION_Y
|
|
8
8
|
from .drawable import Drawable
|
|
9
9
|
from .explosion import Explosion
|
|
10
10
|
|
|
@@ -37,9 +37,13 @@ class Bullet(Drawable):
|
|
|
37
37
|
return enemy
|
|
38
38
|
return None
|
|
39
39
|
|
|
40
|
-
def animate(self) -> None:
|
|
41
|
-
"""Update bullet position, check for collisions, and remove on hit.
|
|
42
|
-
|
|
40
|
+
def animate(self, delta_time: float) -> None:
|
|
41
|
+
"""Update bullet position, check for collisions, and remove on hit.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
delta_time: Time elapsed since last frame in seconds.
|
|
45
|
+
"""
|
|
46
|
+
self.y -= BULLET_SPEED * delta_time
|
|
43
47
|
hit_enemy = self._check_collision()
|
|
44
48
|
if hit_enemy:
|
|
45
49
|
explosion = Explosion(self.x, self.y, "small", self.game_state)
|
|
@@ -53,7 +57,7 @@ class Bullet(Drawable):
|
|
|
53
57
|
"""Draw the bullet with trailing tail effect."""
|
|
54
58
|
|
|
55
59
|
for i in range(BULLET_TRAILING_LENGTH):
|
|
56
|
-
trail_y = self.y + (i + 1) *
|
|
60
|
+
trail_y = self.y + (i + 1) * BULLET_TRAIL_SPACING
|
|
57
61
|
fade_factor = (i + 1) / BULLET_TRAILING_LENGTH / 2
|
|
58
62
|
self._draw_bullet(draw, context, (self.x, trail_y), fade_factor=fade_factor)
|
|
59
63
|
|
{gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/drawable.py
RENAMED
|
@@ -13,8 +13,12 @@ class Drawable(ABC):
|
|
|
13
13
|
"""Interface for objects that can be animated and drawn."""
|
|
14
14
|
|
|
15
15
|
@abstractmethod
|
|
16
|
-
def animate(self) -> None:
|
|
17
|
-
"""Update the object's state for the next animation frame.
|
|
16
|
+
def animate(self, delta_time: float) -> None:
|
|
17
|
+
"""Update the object's state for the next animation frame.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
delta_time: Time elapsed since last frame in seconds.
|
|
21
|
+
"""
|
|
18
22
|
pass
|
|
19
23
|
|
|
20
24
|
@abstractmethod
|
{gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/enemy.py
RENAMED
|
@@ -42,7 +42,7 @@ class Enemy(Drawable):
|
|
|
42
42
|
self.game_state.explosions.append(explosion)
|
|
43
43
|
self.game_state.enemies.remove(self)
|
|
44
44
|
|
|
45
|
-
def animate(self) -> None:
|
|
45
|
+
def animate(self, delta_time: float) -> None:
|
|
46
46
|
"""Update enemy state for next frame (enemies don't animate currently)."""
|
|
47
47
|
pass
|
|
48
48
|
|
{gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/explosion.py
RENAMED
|
@@ -7,8 +7,8 @@ from typing import TYPE_CHECKING, Literal
|
|
|
7
7
|
from PIL import ImageDraw
|
|
8
8
|
|
|
9
9
|
from ...constants import (
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
EXPLOSION_DURATION_LARGE,
|
|
11
|
+
EXPLOSION_DURATION_SMALL,
|
|
12
12
|
EXPLOSION_MAX_RADIUS_LARGE,
|
|
13
13
|
EXPLOSION_MAX_RADIUS_SMALL,
|
|
14
14
|
EXPLOSION_PARTICLE_COUNT_LARGE,
|
|
@@ -37,22 +37,26 @@ class Explosion(Drawable):
|
|
|
37
37
|
self.x = x
|
|
38
38
|
self.y = y
|
|
39
39
|
self.game_state = game_state
|
|
40
|
-
self.
|
|
41
|
-
self.
|
|
40
|
+
self.elapsed_time = 0.0 # Seconds elapsed since explosion started
|
|
41
|
+
self.duration = EXPLOSION_DURATION_SMALL if size == "small" else EXPLOSION_DURATION_LARGE
|
|
42
42
|
self.max_radius = EXPLOSION_MAX_RADIUS_SMALL if size == "small" else EXPLOSION_MAX_RADIUS_LARGE
|
|
43
43
|
self.particle_count = EXPLOSION_PARTICLE_COUNT_SMALL if size == "small" else EXPLOSION_PARTICLE_COUNT_LARGE
|
|
44
44
|
self.particle_angles = [random.uniform(0, 2 * math.pi) for _ in range(self.particle_count)]
|
|
45
45
|
|
|
46
|
-
def animate(self) -> None:
|
|
47
|
-
"""Progress the explosion animation and remove when complete.
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
def animate(self, delta_time: float) -> None:
|
|
47
|
+
"""Progress the explosion animation and remove when complete.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
delta_time: Time elapsed since last frame in seconds.
|
|
51
|
+
"""
|
|
52
|
+
self.elapsed_time += delta_time
|
|
53
|
+
if self.elapsed_time >= self.duration:
|
|
50
54
|
self.game_state.explosions.remove(self)
|
|
51
55
|
|
|
52
56
|
def draw(self, draw: ImageDraw.ImageDraw, context: "RenderContext") -> None:
|
|
53
57
|
"""Draw expanding particle explosion with fade effect."""
|
|
54
58
|
|
|
55
|
-
progress = self.
|
|
59
|
+
progress = self.elapsed_time / self.duration
|
|
56
60
|
fade = 1 - progress # Fade out as animation progresses
|
|
57
61
|
|
|
58
62
|
center_x, center_y = context.get_cell_position(self.x, self.y)
|
{gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/ship.py
RENAMED
|
@@ -19,7 +19,7 @@ class Ship(Drawable):
|
|
|
19
19
|
"""Initialize the ship at starting position."""
|
|
20
20
|
self.x: float = 25 # Start middle of screen
|
|
21
21
|
self.target_x = self.x
|
|
22
|
-
self.shoot_cooldown = 0 #
|
|
22
|
+
self.shoot_cooldown = 0.0 # Seconds until ship can shoot again
|
|
23
23
|
self.game_state = game_state
|
|
24
24
|
|
|
25
25
|
def move_to(self, x: int):
|
|
@@ -37,18 +37,23 @@ class Ship(Drawable):
|
|
|
37
37
|
|
|
38
38
|
def can_shoot(self) -> bool:
|
|
39
39
|
"""Check if ship can shoot (cooldown has finished)."""
|
|
40
|
-
return self.shoot_cooldown
|
|
40
|
+
return self.shoot_cooldown <= 0
|
|
41
41
|
|
|
42
|
-
def animate(self) -> None:
|
|
43
|
-
"""Update ship position, moving toward target at constant speed.
|
|
42
|
+
def animate(self, delta_time: float) -> None:
|
|
43
|
+
"""Update ship position, moving toward target at constant speed.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
delta_time: Time elapsed since last frame in seconds.
|
|
47
|
+
"""
|
|
48
|
+
delta_x = SHIP_SPEED * delta_time
|
|
44
49
|
if self.x < self.target_x:
|
|
45
|
-
self.x = min(self.x +
|
|
50
|
+
self.x = min(self.x + delta_x, self.target_x)
|
|
46
51
|
elif self.x > self.target_x:
|
|
47
|
-
self.x = max(self.x -
|
|
52
|
+
self.x = max(self.x - delta_x, self.target_x)
|
|
48
53
|
|
|
49
|
-
# Decrement shoot cooldown
|
|
54
|
+
# Decrement shoot cooldown (scaled by delta_time)
|
|
50
55
|
if self.shoot_cooldown > 0:
|
|
51
|
-
self.shoot_cooldown -=
|
|
56
|
+
self.shoot_cooldown -= delta_time
|
|
52
57
|
|
|
53
58
|
def draw(self, draw: ImageDraw.ImageDraw, context: "RenderContext") -> None:
|
|
54
59
|
"""Draw a simple Galaga-style ship."""
|
{gh_space_shooter-0.0.3 → gh_space_shooter-0.0.4}/src/gh_space_shooter/game/drawables/starfield.py
RENAMED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
"""Animated starfield background."""
|
|
2
2
|
|
|
3
3
|
import random
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING, TypedDict
|
|
5
5
|
|
|
6
6
|
from PIL import ImageDraw
|
|
7
7
|
|
|
8
|
-
from ...constants import NUM_WEEKS, SHIP_POSITION_Y
|
|
8
|
+
from ...constants import NUM_WEEKS, SHIP_POSITION_Y, STAR_SPEED_MIN, STAR_SPEED_MAX
|
|
9
9
|
from .drawable import Drawable
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
12
12
|
from ..render_context import RenderContext
|
|
13
13
|
|
|
14
|
+
class Star(TypedDict):
|
|
15
|
+
x: float
|
|
16
|
+
y: float
|
|
17
|
+
brightness: float
|
|
18
|
+
size: int
|
|
19
|
+
speed: float
|
|
20
|
+
|
|
14
21
|
|
|
15
22
|
class Starfield(Drawable):
|
|
16
23
|
"""Animated starfield background with slowly moving stars."""
|
|
17
24
|
|
|
18
|
-
def __init__(self):
|
|
25
|
+
def __init__(self) -> None:
|
|
19
26
|
"""Initialize the starfield with random stars."""
|
|
20
|
-
self.stars = []
|
|
27
|
+
self.stars: list[Star] = []
|
|
21
28
|
# Generate about 100 stars across the play area
|
|
22
29
|
for _ in range(100):
|
|
23
30
|
# Random position across the entire grid area
|
|
@@ -27,25 +34,34 @@ class Starfield(Drawable):
|
|
|
27
34
|
brightness = random.uniform(0.2, 1.0)
|
|
28
35
|
# Size: 1-2 pixels
|
|
29
36
|
size = random.choice([1, 1, 1, 2]) # More 1-pixel stars
|
|
30
|
-
# Speed: slower for dimmer (farther) stars
|
|
31
|
-
speed =
|
|
32
|
-
self.stars.append(
|
|
37
|
+
# Speed: slower for dimmer (farther) stars (in cells per second)
|
|
38
|
+
speed = STAR_SPEED_MIN + (brightness * (STAR_SPEED_MAX - STAR_SPEED_MIN))
|
|
39
|
+
self.stars.append(
|
|
40
|
+
{"x": x, "y": y, "brightness": brightness, "size": size, "speed": speed}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def animate(self, delta_time: float) -> None:
|
|
44
|
+
"""Move stars downward, wrapping around when they go off screen.
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
Args:
|
|
47
|
+
delta_time: Time elapsed since last frame in seconds.
|
|
48
|
+
"""
|
|
36
49
|
for star in self.stars:
|
|
37
|
-
|
|
38
|
-
star[1] += star[4]
|
|
50
|
+
star["y"] += star["speed"] * delta_time
|
|
39
51
|
|
|
40
52
|
# Wrap around: if star goes below the screen, move it back to the top
|
|
41
|
-
if star[
|
|
42
|
-
star[
|
|
53
|
+
if star["y"] > SHIP_POSITION_Y + 4:
|
|
54
|
+
star["y"] = -2
|
|
43
55
|
# Randomize x position when wrapping for variety
|
|
44
|
-
star[
|
|
56
|
+
star["x"] = random.uniform(-2, NUM_WEEKS + 2)
|
|
45
57
|
|
|
46
58
|
def draw(self, draw: ImageDraw.ImageDraw, context: "RenderContext") -> None:
|
|
47
59
|
"""Draw all stars at their current positions."""
|
|
48
|
-
for
|
|
60
|
+
for star in self.stars:
|
|
61
|
+
star_x = star["x"]
|
|
62
|
+
star_y = star["y"]
|
|
63
|
+
brightness = star["brightness"]
|
|
64
|
+
size = star["size"]
|
|
49
65
|
# Convert grid position to pixel position
|
|
50
66
|
x, y = context.get_cell_position(star_x, star_y)
|
|
51
67
|
|
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, List
|
|
|
4
4
|
|
|
5
5
|
from PIL import ImageDraw
|
|
6
6
|
|
|
7
|
-
from ..constants import
|
|
7
|
+
from ..constants import SHIP_SHOOT_COOLDOWN
|
|
8
8
|
from ..github_client import ContributionData
|
|
9
9
|
from .drawables import Bullet, Drawable, Enemy, Explosion, Ship, Starfield
|
|
10
10
|
|
|
@@ -47,7 +47,7 @@ class GameState(Drawable):
|
|
|
47
47
|
"""
|
|
48
48
|
bullet = Bullet(int(self.ship.x), game_state=self)
|
|
49
49
|
self.bullets.append(bullet)
|
|
50
|
-
self.ship.shoot_cooldown =
|
|
50
|
+
self.ship.shoot_cooldown = SHIP_SHOOT_COOLDOWN
|
|
51
51
|
|
|
52
52
|
def is_complete(self) -> bool:
|
|
53
53
|
"""Check if game is complete (all enemies destroyed)."""
|
|
@@ -57,16 +57,20 @@ class GameState(Drawable):
|
|
|
57
57
|
"""Check if ship can take an action (not moving and can shoot)."""
|
|
58
58
|
return not self.ship.is_moving() and self.ship.can_shoot()
|
|
59
59
|
|
|
60
|
-
def animate(self) -> None:
|
|
61
|
-
"""Update all game objects for next frame.
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
def animate(self, delta_time: float) -> None:
|
|
61
|
+
"""Update all game objects for next frame.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
delta_time: Time elapsed since last frame in seconds.
|
|
65
|
+
"""
|
|
66
|
+
self.starfield.animate(delta_time)
|
|
67
|
+
self.ship.animate(delta_time)
|
|
64
68
|
for enemy in self.enemies:
|
|
65
|
-
enemy.animate()
|
|
69
|
+
enemy.animate(delta_time)
|
|
66
70
|
for bullet in self.bullets:
|
|
67
|
-
bullet.animate()
|
|
71
|
+
bullet.animate(delta_time)
|
|
68
72
|
for explosion in self.explosions:
|
|
69
|
-
explosion.animate()
|
|
73
|
+
explosion.animate(delta_time)
|
|
70
74
|
|
|
71
75
|
def draw(self, draw: ImageDraw.ImageDraw, context: "RenderContext") -> None:
|
|
72
76
|
"""Draw all game objects including the grid."""
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
from gh_space_shooter.game.game_state import GameState
|
|
4
4
|
from gh_space_shooter.game.drawables import Bullet, Enemy
|
|
5
|
-
from gh_space_shooter.constants import
|
|
5
|
+
from gh_space_shooter.constants import DEFAULT_FPS, EXPLOSION_DURATION_SMALL, EXPLOSION_DURATION_LARGE
|
|
6
|
+
|
|
7
|
+
# Delta time for tests (1/fps seconds per frame)
|
|
8
|
+
TEST_DELTA_TIME = 1.0 / DEFAULT_FPS
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
class TestBulletCollision:
|
|
@@ -20,7 +23,7 @@ class TestBulletCollision:
|
|
|
20
23
|
hit_enemy = bullet._check_collision()
|
|
21
24
|
assert hit_enemy is enemy
|
|
22
25
|
|
|
23
|
-
bullet.animate()
|
|
26
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
24
27
|
assert bullet not in default_game_state.bullets
|
|
25
28
|
|
|
26
29
|
def test_collision_detection_enemy_above_bullet(self, default_game_state: GameState) -> None:
|
|
@@ -35,7 +38,7 @@ class TestBulletCollision:
|
|
|
35
38
|
hit_enemy = bullet._check_collision()
|
|
36
39
|
assert hit_enemy is enemy
|
|
37
40
|
|
|
38
|
-
bullet.animate()
|
|
41
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
39
42
|
assert bullet not in default_game_state.bullets
|
|
40
43
|
|
|
41
44
|
def test_no_collision_different_x_position(self, default_game_state: GameState) -> None:
|
|
@@ -60,7 +63,7 @@ class TestBulletCollision:
|
|
|
60
63
|
bullet.y = 2.0
|
|
61
64
|
default_game_state.bullets.append(bullet)
|
|
62
65
|
|
|
63
|
-
bullet.animate()
|
|
66
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
64
67
|
assert enemy.health == 2
|
|
65
68
|
|
|
66
69
|
def test_enemy_destroyed_when_health_zero(self, default_game_state: GameState) -> None:
|
|
@@ -73,7 +76,7 @@ class TestBulletCollision:
|
|
|
73
76
|
bullet.y = 2.0
|
|
74
77
|
default_game_state.bullets.append(bullet)
|
|
75
78
|
|
|
76
|
-
bullet.animate()
|
|
79
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
77
80
|
assert enemy not in default_game_state.enemies
|
|
78
81
|
|
|
79
82
|
def test_explosion_created_on_collision(self, default_game_state: GameState) -> None:
|
|
@@ -86,9 +89,9 @@ class TestBulletCollision:
|
|
|
86
89
|
bullet.y = 2.0
|
|
87
90
|
default_game_state.bullets.append(bullet)
|
|
88
91
|
|
|
89
|
-
bullet.animate()
|
|
92
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
90
93
|
assert len(default_game_state.explosions) == 1
|
|
91
|
-
assert default_game_state.explosions[0].
|
|
94
|
+
assert default_game_state.explosions[0].duration == EXPLOSION_DURATION_SMALL
|
|
92
95
|
|
|
93
96
|
def test_large_explosion_on_enemy_destroyed(self, default_game_state: GameState) -> None:
|
|
94
97
|
"""Test that large explosion is created when enemy is destroyed."""
|
|
@@ -100,12 +103,12 @@ class TestBulletCollision:
|
|
|
100
103
|
bullet.y = 2.0
|
|
101
104
|
default_game_state.bullets.append(bullet)
|
|
102
105
|
|
|
103
|
-
bullet.animate()
|
|
106
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
104
107
|
# Should have 2 explosions: small from bullet hit, large from enemy destruction
|
|
105
108
|
assert len(default_game_state.explosions) == 2
|
|
106
|
-
|
|
107
|
-
assert
|
|
108
|
-
assert
|
|
109
|
+
explosion_durations = [exp.duration for exp in default_game_state.explosions]
|
|
110
|
+
assert EXPLOSION_DURATION_SMALL in explosion_durations
|
|
111
|
+
assert EXPLOSION_DURATION_LARGE in explosion_durations
|
|
109
112
|
|
|
110
113
|
def test_bullet_removed_when_off_screen(self, default_game_state: GameState) -> None:
|
|
111
114
|
"""Test that bullet is removed when it goes off screen (y < -10)."""
|
|
@@ -116,6 +119,6 @@ class TestBulletCollision:
|
|
|
116
119
|
|
|
117
120
|
for _ in range(50):
|
|
118
121
|
if bullet in default_game_state.bullets:
|
|
119
|
-
bullet.animate()
|
|
122
|
+
bullet.animate(TEST_DELTA_TIME)
|
|
120
123
|
|
|
121
124
|
assert bullet not in default_game_state.bullets
|