ed-game 4.0.0.dev1__tar.gz → 5.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.
- ed_game-5.0.0/MANIFEST.in +1 -0
- ed_game-5.0.0/PKG-INFO +61 -0
- ed_game-5.0.0/README.md +39 -0
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/edgame_core.cpp +3 -2
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/pyproject.toml +2 -8
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/src/ed_game/__init__.py +6 -24
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/src/ed_game/game_2.py +3 -5
- ed_game-5.0.0/src/ed_game.egg-info/PKG-INFO +61 -0
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/src/ed_game.egg-info/SOURCES.txt +1 -4
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/src/ed_game.egg-info/requires.txt +0 -1
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/src/ed_game.egg-info/top_level.txt +0 -1
- ed_game-4.0.0.dev1/MANIFEST.in +0 -1
- ed_game-4.0.0.dev1/PKG-INFO +0 -68
- ed_game-4.0.0.dev1/README.md +0 -45
- ed_game-4.0.0.dev1/src/ed_game/game_1.py +0 -436
- ed_game-4.0.0.dev1/src/ed_game.egg-info/PKG-INFO +0 -68
- ed_game-4.0.0.dev1/src/new/__init__.py +0 -1
- ed_game-4.0.0.dev1/src/new/game.py +0 -158
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/LICENSE +0 -0
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/setup.cfg +0 -0
- {ed_game-4.0.0.dev1 → ed_game-5.0.0}/src/ed_game.egg-info/dependency_links.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include edgame_core.cpp
|
ed_game-5.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ed-game
|
|
3
|
+
Version: 5.0.0
|
|
4
|
+
Summary: Earth Defense Game
|
|
5
|
+
Author-email: qq-name <your@email.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/ed-game/
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.16
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Topic :: Games/Entertainment
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pygame-ce>=2.5.3
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
Installing:
|
|
24
|
+
|
|
25
|
+
pip install ed-game
|
|
26
|
+
|
|
27
|
+
or:
|
|
28
|
+
|
|
29
|
+
pip3 install ed-game
|
|
30
|
+
|
|
31
|
+
Usage:
|
|
32
|
+
|
|
33
|
+
import ed_game
|
|
34
|
+
ed_game.run()
|
|
35
|
+
|
|
36
|
+
ed-game dependencies:
|
|
37
|
+
1. setuptools>=77.3.4 (build dependency)
|
|
38
|
+
2. pygame-ce >= 2.5.3 (core of ed-game)
|
|
39
|
+
3. CPython >= 3.13
|
|
40
|
+
|
|
41
|
+
## Version Support
|
|
42
|
+
|
|
43
|
+
| Series | Status | Note |
|
|
44
|
+
|--------|--------|------|
|
|
45
|
+
| **5.x** | ✅ **Recommended** | Active development, new features |
|
|
46
|
+
| 4.x | ❌ Discontinued | Unresolved low-level OpenGL error in module `a1`; cannot be fixed |
|
|
47
|
+
| 3.x | 🛠 Maintenance | Critical bug fixes only |
|
|
48
|
+
| 2.x | 🛠 Maintenance | Critical bug fixes only |
|
|
49
|
+
|
|
50
|
+
> **Notice:** The 4.x line has reached end-of-life due to an unfixable OpenGL defect in `a1`. Please use **5.x** for new projects; 3.x remains available for legacy users who cannot upgrade.
|
|
51
|
+
|
|
52
|
+
## About
|
|
53
|
+
|
|
54
|
+
**Earth Defense Game** — a cross-platform shooter.
|
|
55
|
+
- **Windows:** accelerated via a compiled C++ extension (with optional pure Python fallback).
|
|
56
|
+
- **Other platforms:** runs on a 100% pure-Python fallback.
|
|
57
|
+
|
|
58
|
+
### 🆕 What's New in 5.0.0
|
|
59
|
+
- **Pygame Returns**: Abandoned the buggy Pyglet (4.x) experiment and fully restored the rock-solid Pygame engine.
|
|
60
|
+
- **Dynamic Mode Selection**: Windows users now get a CLI prompt to choose between the C++ accelerated mode or the Pure Python fallback mode on startup.
|
|
61
|
+
- **Platform Optimization**: Separate wheels for Windows (with DLL) and Mac/Linux (pure Python) to ensure maximum compatibility and minimal package size.
|
ed_game-5.0.0/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Installing:
|
|
2
|
+
|
|
3
|
+
pip install ed-game
|
|
4
|
+
|
|
5
|
+
or:
|
|
6
|
+
|
|
7
|
+
pip3 install ed-game
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
|
|
11
|
+
import ed_game
|
|
12
|
+
ed_game.run()
|
|
13
|
+
|
|
14
|
+
ed-game dependencies:
|
|
15
|
+
1. setuptools>=77.3.4 (build dependency)
|
|
16
|
+
2. pygame-ce >= 2.5.3 (core of ed-game)
|
|
17
|
+
3. CPython >= 3.13
|
|
18
|
+
|
|
19
|
+
## Version Support
|
|
20
|
+
|
|
21
|
+
| Series | Status | Note |
|
|
22
|
+
|--------|--------|------|
|
|
23
|
+
| **5.x** | ✅ **Recommended** | Active development, new features |
|
|
24
|
+
| 4.x | ❌ Discontinued | Unresolved low-level OpenGL error in module `a1`; cannot be fixed |
|
|
25
|
+
| 3.x | 🛠 Maintenance | Critical bug fixes only |
|
|
26
|
+
| 2.x | 🛠 Maintenance | Critical bug fixes only |
|
|
27
|
+
|
|
28
|
+
> **Notice:** The 4.x line has reached end-of-life due to an unfixable OpenGL defect in `a1`. Please use **5.x** for new projects; 3.x remains available for legacy users who cannot upgrade.
|
|
29
|
+
|
|
30
|
+
## About
|
|
31
|
+
|
|
32
|
+
**Earth Defense Game** — a cross-platform shooter.
|
|
33
|
+
- **Windows:** accelerated via a compiled C++ extension (with optional pure Python fallback).
|
|
34
|
+
- **Other platforms:** runs on a 100% pure-Python fallback.
|
|
35
|
+
|
|
36
|
+
### 🆕 What's New in 5.0.0
|
|
37
|
+
- **Pygame Returns**: Abandoned the buggy Pyglet (4.x) experiment and fully restored the rock-solid Pygame engine.
|
|
38
|
+
- **Dynamic Mode Selection**: Windows users now get a CLI prompt to choose between the C++ accelerated mode or the Pure Python fallback mode on startup.
|
|
39
|
+
- **Platform Optimization**: Separate wheels for Windows (with DLL) and Mac/Linux (pure Python) to ensure maximum compatibility and minimal package size.
|
|
@@ -63,13 +63,14 @@ EXPORT void update_all() {
|
|
|
63
63
|
if (g_boss_fire_cooldown > 0) {
|
|
64
64
|
g_boss_fire_cooldown--;
|
|
65
65
|
} else {
|
|
66
|
+
bool any_boss_fired = false;
|
|
66
67
|
for (auto& e : g_enemies) {
|
|
67
68
|
if (e.is_boss) {
|
|
68
69
|
g_bullets.push_back({e.x, e.y + e.radius, 0.0f, 5.0f, 8, 1});
|
|
69
|
-
|
|
70
|
-
break;
|
|
70
|
+
any_boss_fired = true;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
if (any_boss_fired) g_boss_fire_cooldown = 180;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -4,16 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ed-game"
|
|
7
|
-
version = "
|
|
7
|
+
version = "5.0.0"
|
|
8
8
|
description = "Earth Defense Game"
|
|
9
9
|
authors = [{name = "qq-name", email = "your@email.com"}]
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.13"
|
|
12
12
|
license = "MIT"
|
|
13
|
-
dependencies = [
|
|
14
|
-
"pygame-ce>=2.5.3",
|
|
15
|
-
"pyglet>=2.0"
|
|
16
|
-
]
|
|
13
|
+
dependencies = ["pygame-ce>=2.5.3"]
|
|
17
14
|
|
|
18
15
|
classifiers = [
|
|
19
16
|
"Programming Language :: Python :: 3",
|
|
@@ -27,9 +24,6 @@ classifiers = [
|
|
|
27
24
|
"Topic :: Games/Entertainment",
|
|
28
25
|
]
|
|
29
26
|
|
|
30
|
-
[tool.setuptools.package-data]
|
|
31
|
-
ed_game = ["*.dll"]
|
|
32
|
-
|
|
33
27
|
[tool.setuptools.packages.find]
|
|
34
28
|
where = ["src"]
|
|
35
29
|
|
|
@@ -14,24 +14,13 @@ def _check():
|
|
|
14
14
|
s.run("python -m pip install pygame-ce")
|
|
15
15
|
except:
|
|
16
16
|
raise ImportError("pygame-ce not installed. Run: pip install pygame-ce")
|
|
17
|
-
|
|
18
|
-
import os
|
|
19
|
-
if not os.path.exists('edgame_core.dll'):
|
|
20
|
-
raise Exception('DLL is not found')
|
|
21
|
-
|
|
22
|
-
|
|
23
17
|
if not _check():
|
|
24
18
|
sys.exit(1)
|
|
25
19
|
|
|
26
|
-
# ===== Platform detection =====
|
|
27
|
-
def is_windows():
|
|
28
|
-
return sys.platform == 'win32' and platform.system() == 'Windows'
|
|
29
20
|
|
|
30
21
|
# ===== Import appropriate module =====
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
else:
|
|
34
|
-
from . import game_2 as _game
|
|
22
|
+
|
|
23
|
+
from . import game_2 as _game
|
|
35
24
|
|
|
36
25
|
FPS = _game.FPS
|
|
37
26
|
|
|
@@ -45,18 +34,11 @@ def run(speed_multiplier=1.0):
|
|
|
45
34
|
Range: 0.1 ~ 5.0
|
|
46
35
|
< 1.0 = slower, > 1.0 = faster
|
|
47
36
|
"""
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
game.run()
|
|
52
|
-
except AttributeError:
|
|
53
|
-
raise AttributeError("Loading C++ Error")
|
|
54
|
-
else:
|
|
55
|
-
game = _game.StarGuardian(speed_multiplier=speed_multiplier)
|
|
56
|
-
game.run()
|
|
37
|
+
|
|
38
|
+
game = _game.StarGuardian(speed_multiplier=speed_multiplier)
|
|
39
|
+
game.run()
|
|
57
40
|
|
|
58
41
|
del _check
|
|
59
|
-
del is_windows
|
|
60
42
|
|
|
61
|
-
__version__ = "
|
|
43
|
+
__version__ = "5.0.0"
|
|
62
44
|
__all__ = ["run", "FPS"]
|
|
@@ -29,7 +29,7 @@ BASE_SPAWN_DELAY = 48
|
|
|
29
29
|
STAR_COUNT = 220
|
|
30
30
|
BOSS_SIZE_MULTIPLIER = 4
|
|
31
31
|
BOSS_SPAWN_INTERVAL = 20 * 1000
|
|
32
|
-
NUKE_COOLDOWN =
|
|
32
|
+
NUKE_COOLDOWN = 7.2 * 1000
|
|
33
33
|
|
|
34
34
|
def generate_sound(frequency, duration, volume=0.5, type='square'):
|
|
35
35
|
sample_rate = 22050
|
|
@@ -200,7 +200,7 @@ class StarGuardian:
|
|
|
200
200
|
self.last_boss_spawn_time = current_time
|
|
201
201
|
self.spawn_enemy(is_boss=True)
|
|
202
202
|
self.status_message = "👑 Giant Overlord Arrives! 👑"
|
|
203
|
-
self.status_msg_timer =
|
|
203
|
+
self.status_msg_timer = 180
|
|
204
204
|
|
|
205
205
|
for b in self.bullets[:]:
|
|
206
206
|
b['y'] += b['speed_y']
|
|
@@ -245,15 +245,13 @@ class StarGuardian:
|
|
|
245
245
|
self.invincible = INVINCIBLE_DURATION
|
|
246
246
|
self.add_explosion(self.player_x, self.player_y)
|
|
247
247
|
self.enemies.remove(e)
|
|
248
|
-
# BOSS 开火
|
|
249
248
|
if getattr(self, 'boss_fire_timer', 0) > 0:
|
|
250
249
|
self.boss_fire_timer -= 1
|
|
251
250
|
else:
|
|
252
251
|
for e in self.enemies:
|
|
253
252
|
if e.get('is_boss'):
|
|
254
253
|
self.enemy_bullets.append({'x': e['x'], 'y': e['y'] + e['radius'], 'speed_y': 5.0, 'radius': 8})
|
|
255
|
-
self.boss_fire_timer =
|
|
256
|
-
break
|
|
254
|
+
self.boss_fire_timer = 180
|
|
257
255
|
|
|
258
256
|
|
|
259
257
|
for eb in self.enemy_bullets[:]:
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ed-game
|
|
3
|
+
Version: 5.0.0
|
|
4
|
+
Summary: Earth Defense Game
|
|
5
|
+
Author-email: qq-name <your@email.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/ed-game/
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.16
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Topic :: Games/Entertainment
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pygame-ce>=2.5.3
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
Installing:
|
|
24
|
+
|
|
25
|
+
pip install ed-game
|
|
26
|
+
|
|
27
|
+
or:
|
|
28
|
+
|
|
29
|
+
pip3 install ed-game
|
|
30
|
+
|
|
31
|
+
Usage:
|
|
32
|
+
|
|
33
|
+
import ed_game
|
|
34
|
+
ed_game.run()
|
|
35
|
+
|
|
36
|
+
ed-game dependencies:
|
|
37
|
+
1. setuptools>=77.3.4 (build dependency)
|
|
38
|
+
2. pygame-ce >= 2.5.3 (core of ed-game)
|
|
39
|
+
3. CPython >= 3.13
|
|
40
|
+
|
|
41
|
+
## Version Support
|
|
42
|
+
|
|
43
|
+
| Series | Status | Note |
|
|
44
|
+
|--------|--------|------|
|
|
45
|
+
| **5.x** | ✅ **Recommended** | Active development, new features |
|
|
46
|
+
| 4.x | ❌ Discontinued | Unresolved low-level OpenGL error in module `a1`; cannot be fixed |
|
|
47
|
+
| 3.x | 🛠 Maintenance | Critical bug fixes only |
|
|
48
|
+
| 2.x | 🛠 Maintenance | Critical bug fixes only |
|
|
49
|
+
|
|
50
|
+
> **Notice:** The 4.x line has reached end-of-life due to an unfixable OpenGL defect in `a1`. Please use **5.x** for new projects; 3.x remains available for legacy users who cannot upgrade.
|
|
51
|
+
|
|
52
|
+
## About
|
|
53
|
+
|
|
54
|
+
**Earth Defense Game** — a cross-platform shooter.
|
|
55
|
+
- **Windows:** accelerated via a compiled C++ extension (with optional pure Python fallback).
|
|
56
|
+
- **Other platforms:** runs on a 100% pure-Python fallback.
|
|
57
|
+
|
|
58
|
+
### 🆕 What's New in 5.0.0
|
|
59
|
+
- **Pygame Returns**: Abandoned the buggy Pyglet (4.x) experiment and fully restored the rock-solid Pygame engine.
|
|
60
|
+
- **Dynamic Mode Selection**: Windows users now get a CLI prompt to choose between the C++ accelerated mode or the Pure Python fallback mode on startup.
|
|
61
|
+
- **Platform Optimization**: Separate wheels for Windows (with DLL) and Mac/Linux (pure Python) to ensure maximum compatibility and minimal package size.
|
|
@@ -4,12 +4,9 @@ README.md
|
|
|
4
4
|
edgame_core.cpp
|
|
5
5
|
pyproject.toml
|
|
6
6
|
src/ed_game/__init__.py
|
|
7
|
-
src/ed_game/game_1.py
|
|
8
7
|
src/ed_game/game_2.py
|
|
9
8
|
src/ed_game.egg-info/PKG-INFO
|
|
10
9
|
src/ed_game.egg-info/SOURCES.txt
|
|
11
10
|
src/ed_game.egg-info/dependency_links.txt
|
|
12
11
|
src/ed_game.egg-info/requires.txt
|
|
13
|
-
src/ed_game.egg-info/top_level.txt
|
|
14
|
-
src/new/__init__.py
|
|
15
|
-
src/new/game.py
|
|
12
|
+
src/ed_game.egg-info/top_level.txt
|
ed_game-4.0.0.dev1/MANIFEST.in
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
include edgame_core.cpp
|
ed_game-4.0.0.dev1/PKG-INFO
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ed-game
|
|
3
|
-
Version: 4.0.0.dev1
|
|
4
|
-
Summary: Earth Defense Game
|
|
5
|
-
Author-email: qq-name <your@email.com>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://pypi.org/project/ed-game/
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.16
|
|
13
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
-
Classifier: Operating System :: MacOS
|
|
15
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
-
Classifier: Topic :: Games/Entertainment
|
|
17
|
-
Requires-Python: >=3.13
|
|
18
|
-
Description-Content-Type: text/markdown
|
|
19
|
-
License-File: LICENSE
|
|
20
|
-
Requires-Dist: pygame-ce>=2.5.3
|
|
21
|
-
Requires-Dist: pyglet>=2.0
|
|
22
|
-
Dynamic: license-file
|
|
23
|
-
|
|
24
|
-
Installing:
|
|
25
|
-
```bash
|
|
26
|
-
pip install ed-game
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
or:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip3 install ed-game
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Usage:
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
import ed_game
|
|
39
|
-
ed_game.run()
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
ed-game dependencies:
|
|
43
|
-
|
|
44
|
-
setuptools>=77.3.4 (is build)
|
|
45
|
-
|
|
46
|
-
pygame-ce >= 2.5.3 (core of 2.x / 3.x /4.x)
|
|
47
|
-
|
|
48
|
-
pyglet >= 2.0 (core of 4.x New Game)
|
|
49
|
-
|
|
50
|
-
CPython >= 3.13
|
|
51
|
-
|
|
52
|
-
Earth Defense Game - A cross-platform shooter.
|
|
53
|
-
|
|
54
|
-
Windows / 2.x & 3.x: Uses a high-performance C++ extension for precise, ultra-slow enemy movement and fast collision detection.
|
|
55
|
-
|
|
56
|
-
Other platforms / 2.x & 3.x: Runs a 100% Pure Python fallback.
|
|
57
|
-
|
|
58
|
-
4.x New Game: A brand new implementation using the Pyglet library.
|
|
59
|
-
|
|
60
|
-
🆕 What's New in 4.0.0dev1
|
|
61
|
-
New Ed-Game Engine: Added a completely new implementation (ed_game.new) built with the Pyglet library, moving away from Pygame.
|
|
62
|
-
|
|
63
|
-
Early Access: Please note that this is an early dev release. There may be bugs and performance issues before 4.0.0rc1.
|
|
64
|
-
|
|
65
|
-
⚠️ Known Issues
|
|
66
|
-
We have identified runtime visual bugs in ed_game 4.0.0dev1 and ed_game 3.2.0.
|
|
67
|
-
|
|
68
|
-
These issues will be fixed in the upcoming ed_game 4.0.0dev2 and ed_game 3.2.1 (or 3.3.0).
|
ed_game-4.0.0.dev1/README.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Installing:
|
|
2
|
-
```bash
|
|
3
|
-
pip install ed-game
|
|
4
|
-
```
|
|
5
|
-
|
|
6
|
-
or:
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
pip3 install ed-game
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
|
|
14
|
-
```python
|
|
15
|
-
import ed_game
|
|
16
|
-
ed_game.run()
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
ed-game dependencies:
|
|
20
|
-
|
|
21
|
-
setuptools>=77.3.4 (is build)
|
|
22
|
-
|
|
23
|
-
pygame-ce >= 2.5.3 (core of 2.x / 3.x /4.x)
|
|
24
|
-
|
|
25
|
-
pyglet >= 2.0 (core of 4.x New Game)
|
|
26
|
-
|
|
27
|
-
CPython >= 3.13
|
|
28
|
-
|
|
29
|
-
Earth Defense Game - A cross-platform shooter.
|
|
30
|
-
|
|
31
|
-
Windows / 2.x & 3.x: Uses a high-performance C++ extension for precise, ultra-slow enemy movement and fast collision detection.
|
|
32
|
-
|
|
33
|
-
Other platforms / 2.x & 3.x: Runs a 100% Pure Python fallback.
|
|
34
|
-
|
|
35
|
-
4.x New Game: A brand new implementation using the Pyglet library.
|
|
36
|
-
|
|
37
|
-
🆕 What's New in 4.0.0dev1
|
|
38
|
-
New Ed-Game Engine: Added a completely new implementation (ed_game.new) built with the Pyglet library, moving away from Pygame.
|
|
39
|
-
|
|
40
|
-
Early Access: Please note that this is an early dev release. There may be bugs and performance issues before 4.0.0rc1.
|
|
41
|
-
|
|
42
|
-
⚠️ Known Issues
|
|
43
|
-
We have identified runtime visual bugs in ed_game 4.0.0dev1 and ed_game 3.2.0.
|
|
44
|
-
|
|
45
|
-
These issues will be fixed in the upcoming ed_game 4.0.0dev2 and ed_game 3.2.1 (or 3.3.0).
|
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import random
|
|
3
|
-
import math
|
|
4
|
-
import sys
|
|
5
|
-
import ctypes
|
|
6
|
-
import os
|
|
7
|
-
import array
|
|
8
|
-
|
|
9
|
-
WIDTH = 1800
|
|
10
|
-
HEIGHT = 1050
|
|
11
|
-
FPS = 60
|
|
12
|
-
|
|
13
|
-
COLORS = {
|
|
14
|
-
'bg': (2, 6, 23), 'enemy': (255, 58, 111), 'enemy_elite': (255, 136, 68),
|
|
15
|
-
'enemy_boss': (180, 50, 255), 'bullet': (255, 255, 128), 'bullet_core': (255, 204, 68),
|
|
16
|
-
'player_main': (62, 255, 250), 'player_core': (0, 204, 255), 'player_fire': (255, 102, 0),
|
|
17
|
-
'score': (0, 255, 255), 'lives': (255, 51, 102), 'status': (255, 215, 0),
|
|
18
|
-
'gameover': (255, 68, 102), 'white': (255, 255, 255), 'gold': (255, 215, 0), 'heart': (255, 80, 120),
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
BASE_ENEMY_SPEED = 0.31
|
|
22
|
-
MAX_ENEMY_SPEED = 0.85
|
|
23
|
-
ELITE_SPEED_FACTOR = 0.84
|
|
24
|
-
BOSS_SPEED_FACTOR = 0.2
|
|
25
|
-
BULLET_SPEED = -8.5
|
|
26
|
-
PLAYER_SPEED = 6.2
|
|
27
|
-
PLAYER_RADIUS = 15
|
|
28
|
-
INVINCIBLE_DURATION = 55
|
|
29
|
-
SHOOT_COOLDOWN_FRAMES = 9
|
|
30
|
-
BASE_SPAWN_DELAY = 48
|
|
31
|
-
STAR_COUNT = 220
|
|
32
|
-
BOSS_SIZE_MULTIPLIER = 4
|
|
33
|
-
BOSS_SPAWN_INTERVAL = 20 * 1000
|
|
34
|
-
NUKE_COOLDOWN = 120 * 1000
|
|
35
|
-
|
|
36
|
-
lib = None
|
|
37
|
-
|
|
38
|
-
def generate_sound(frequency, duration, volume=0.5, type='square'):
|
|
39
|
-
sample_rate = 22050
|
|
40
|
-
n_samples = int(sample_rate * duration)
|
|
41
|
-
buf = array.array('h', [0] * n_samples)
|
|
42
|
-
for i in range(n_samples):
|
|
43
|
-
t = float(i) / sample_rate
|
|
44
|
-
if type == 'square':
|
|
45
|
-
val = 1.0 if math.sin(2 * math.pi * frequency * t) > 0 else -1.0
|
|
46
|
-
else:
|
|
47
|
-
val = math.sin(2 * math.pi * frequency * t)
|
|
48
|
-
envelope = max(0.0, 1.0 - (i / n_samples))
|
|
49
|
-
buf[i] = int(val * volume * envelope * 32767)
|
|
50
|
-
return pygame.mixer.Sound(buffer=buf.tobytes())
|
|
51
|
-
|
|
52
|
-
def load_dll():
|
|
53
|
-
global lib
|
|
54
|
-
try:
|
|
55
|
-
lib_dir = os.path.dirname(__file__)
|
|
56
|
-
lib_path = os.path.join(lib_dir, 'edgame_core.dll')
|
|
57
|
-
lib = ctypes.CDLL(lib_path)
|
|
58
|
-
return True
|
|
59
|
-
except Exception:
|
|
60
|
-
return False
|
|
61
|
-
|
|
62
|
-
class CBullet(ctypes.Structure):
|
|
63
|
-
_fields_ = [("x", ctypes.c_float), ("y", ctypes.c_float), ("speed_x", ctypes.c_float), ("speed_y", ctypes.c_float), ("radius", ctypes.c_int32), ("damage", ctypes.c_int32)]
|
|
64
|
-
class CEnemy(ctypes.Structure):
|
|
65
|
-
_fields_ = [("x", ctypes.c_float), ("y", ctypes.c_float), ("speed_y", ctypes.c_float), ("radius", ctypes.c_int32), ("hp", ctypes.c_int32), ("max_hp", ctypes.c_int32), ("elite", ctypes.c_int32), ("is_boss", ctypes.c_int32)]
|
|
66
|
-
|
|
67
|
-
class KillInfo(ctypes.Structure):
|
|
68
|
-
_fields_ = [("x", ctypes.c_float), ("y", ctypes.c_float), ("score", ctypes.c_int32), ("is_boss", ctypes.c_int32), ("elite", ctypes.c_int32)]
|
|
69
|
-
|
|
70
|
-
def setup_c_functions():
|
|
71
|
-
if lib is None: return
|
|
72
|
-
lib.update_all.restype = None
|
|
73
|
-
lib.add_bullet.argtypes = (ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_int32, ctypes.c_int32)
|
|
74
|
-
lib.add_bullet.restype = ctypes.c_int32
|
|
75
|
-
lib.add_enemy.argtypes = (ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32)
|
|
76
|
-
lib.add_enemy.restype = ctypes.c_int32
|
|
77
|
-
lib.clear_all.restype = None
|
|
78
|
-
lib.get_bullet_count.restype = ctypes.c_int32
|
|
79
|
-
lib.get_enemy_count.restype = ctypes.c_int32
|
|
80
|
-
lib.get_bullets.argtypes = (ctypes.POINTER(CBullet),)
|
|
81
|
-
lib.get_enemies.argtypes = (ctypes.POINTER(CEnemy),)
|
|
82
|
-
lib.remove_offscreen_bullets.argtypes = (ctypes.c_float, ctypes.c_float)
|
|
83
|
-
lib.remove_offscreen_bullets.restype = ctypes.c_int32
|
|
84
|
-
lib.remove_offscreen_enemies.argtypes = (ctypes.c_float,)
|
|
85
|
-
lib.remove_offscreen_enemies.restype = ctypes.c_int32
|
|
86
|
-
lib.process_bullet_enemy_collision.argtypes = (ctypes.POINTER(KillInfo), ctypes.c_int32)
|
|
87
|
-
lib.process_bullet_enemy_collision.restype = ctypes.c_int32
|
|
88
|
-
lib.process_player_enemy_collision.argtypes = (ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float))
|
|
89
|
-
lib.process_player_enemy_collision.restype = ctypes.c_int32
|
|
90
|
-
|
|
91
|
-
class StarGuardian:
|
|
92
|
-
def __init__(self, speed_multiplier=1.0):
|
|
93
|
-
pygame.init()
|
|
94
|
-
pygame.mixer.init(frequency=22050, size=-16, channels=1)
|
|
95
|
-
|
|
96
|
-
self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
|
97
|
-
pygame.display.set_caption("Star Guardian 3.1.0 · Mobile & PC")
|
|
98
|
-
self.clock = pygame.time.Clock()
|
|
99
|
-
self.speed_multiplier = speed_multiplier
|
|
100
|
-
|
|
101
|
-
self.sfx_shoot = generate_sound(800, 0.05, 0.3, 'square')
|
|
102
|
-
self.sfx_boom = generate_sound(100, 0.3, 0.6, 'sine')
|
|
103
|
-
|
|
104
|
-
self.bullet_surface = pygame.Surface((12, 12), pygame.SRCALPHA)
|
|
105
|
-
pygame.draw.circle(self.bullet_surface, COLORS['bullet'], (6, 6), 5)
|
|
106
|
-
pygame.draw.circle(self.bullet_surface, COLORS['bullet_core'], (6, 6), 3)
|
|
107
|
-
|
|
108
|
-
self.player_surface = pygame.Surface((40, 40), pygame.SRCALPHA)
|
|
109
|
-
pygame.draw.circle(self.player_surface, COLORS['player_main'], (20, 20), 16)
|
|
110
|
-
pygame.draw.circle(self.player_surface, COLORS['player_core'], (20, 16), 6)
|
|
111
|
-
pygame.draw.circle(self.player_surface, COLORS['white'], (17, 14), 2)
|
|
112
|
-
pygame.draw.circle(self.player_surface, COLORS['white'], (23, 14), 2)
|
|
113
|
-
pygame.draw.circle(self.player_surface, COLORS['player_fire'], (20, 38), 6)
|
|
114
|
-
pygame.draw.circle(self.player_surface, COLORS['player_fire'], (17, 36), 4)
|
|
115
|
-
pygame.draw.circle(self.player_surface, COLORS['player_fire'], (23, 36), 4)
|
|
116
|
-
|
|
117
|
-
self.stars = []
|
|
118
|
-
for _ in range(250):
|
|
119
|
-
self.stars.append({
|
|
120
|
-
'x': random.randint(0, WIDTH),
|
|
121
|
-
'y': random.randint(0, HEIGHT),
|
|
122
|
-
'radius': random.uniform(1.0, 2.5)
|
|
123
|
-
})
|
|
124
|
-
self.stars = []
|
|
125
|
-
for _ in range(250):
|
|
126
|
-
self.stars.append({
|
|
127
|
-
'x': random.randint(0, WIDTH),
|
|
128
|
-
'y': random.randint(0, HEIGHT),
|
|
129
|
-
'radius': random.uniform(1.0, 2.5)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
self._load_fonts()
|
|
133
|
-
load_dll()
|
|
134
|
-
setup_c_functions()
|
|
135
|
-
self.high_score = 0
|
|
136
|
-
self.reset_game()
|
|
137
|
-
|
|
138
|
-
def _load_fonts(self):
|
|
139
|
-
self.font_large = pygame.font.SysFont("arial", 48, bold=True)
|
|
140
|
-
self.font_medium = pygame.font.SysFont("arial", 28, bold=True)
|
|
141
|
-
self.font_small = pygame.font.SysFont("arial", 20)
|
|
142
|
-
self.font_tiny = pygame.font.SysFont("arial", 14)
|
|
143
|
-
self._text_cache = {}
|
|
144
|
-
|
|
145
|
-
def render_text(self, text, font, color):
|
|
146
|
-
key = (text, id(font), color)
|
|
147
|
-
if key not in self._text_cache:
|
|
148
|
-
self._text_cache[key] = font.render(text, True, color)
|
|
149
|
-
return self._text_cache[key]
|
|
150
|
-
|
|
151
|
-
def reset_game(self):
|
|
152
|
-
if hasattr(self, 'score'):
|
|
153
|
-
self.high_score = max(self.high_score, self.score)
|
|
154
|
-
|
|
155
|
-
self.game_active = True
|
|
156
|
-
self.score = 0
|
|
157
|
-
self.wave_level = 1
|
|
158
|
-
self.lives = 3
|
|
159
|
-
self.invincible = 0
|
|
160
|
-
self.player_x = WIDTH // 2
|
|
161
|
-
self.player_y = HEIGHT - 60
|
|
162
|
-
self.shoot_cooldown = 0
|
|
163
|
-
self.nuke_timer = 0
|
|
164
|
-
self.screen_shake = 0
|
|
165
|
-
self.flash_timer = 0
|
|
166
|
-
self.enemies = []
|
|
167
|
-
self.bullets = []
|
|
168
|
-
self.explosions = []
|
|
169
|
-
self.particles = []
|
|
170
|
-
self.player_trail = []
|
|
171
|
-
self.enemy_spawn_timer = 20
|
|
172
|
-
self.spawn_delay_current = BASE_SPAWN_DELAY
|
|
173
|
-
self.last_boss_spawn_time = pygame.time.get_ticks()
|
|
174
|
-
|
|
175
|
-
self.btn_left = False
|
|
176
|
-
self.btn_right = False
|
|
177
|
-
self.btn_fire = False
|
|
178
|
-
|
|
179
|
-
if lib is not None: lib.clear_all()
|
|
180
|
-
for _ in range(3): self.spawn_enemy()
|
|
181
|
-
|
|
182
|
-
def spawn_enemy(self, is_boss=False):
|
|
183
|
-
if lib is None: return
|
|
184
|
-
|
|
185
|
-
if is_boss:
|
|
186
|
-
radius = 12 * BOSS_SIZE_MULTIPLIER
|
|
187
|
-
x = random.randint(radius, WIDTH - radius)
|
|
188
|
-
speed = (0.06) * self.speed_multiplier
|
|
189
|
-
hp = 50
|
|
190
|
-
lib.add_enemy(float(x), float(-radius), float(speed), radius, hp, hp, 0, 1)
|
|
191
|
-
else:
|
|
192
|
-
radius = 12
|
|
193
|
-
x = random.randint(radius, WIDTH - radius)
|
|
194
|
-
speed = 0.31 * self.speed_multiplier
|
|
195
|
-
hp = 1
|
|
196
|
-
|
|
197
|
-
is_elite = (random.random() < 0.18)
|
|
198
|
-
if is_elite:
|
|
199
|
-
radius = 16
|
|
200
|
-
hp = 2
|
|
201
|
-
speed *= 0.84
|
|
202
|
-
|
|
203
|
-
lib.add_enemy(float(x), float(-radius), float(speed), radius, hp, hp, 1 if is_elite else 0, 0)
|
|
204
|
-
def add_explosion(self, px, py, is_boss=False):
|
|
205
|
-
self.explosions.append({'x': px, 'y': py, 'life': 6 if not is_boss else 20, 'max_life': 6 if not is_boss else 20, 'radius': 12 if not is_boss else 30})
|
|
206
|
-
for _ in range(8 if not is_boss else 30):
|
|
207
|
-
self.particles.append({'x': px, 'y': py, 'vx': (random.random() - 0.5) * 3.5, 'vy': (random.random() - 0.5) * 3 - 1, 'life': 6 if not is_boss else 20, 'size': random.random() * 3 + 1.5, 'color': (255, random.randint(100, 255), 50)})
|
|
208
|
-
|
|
209
|
-
def update(self):
|
|
210
|
-
if not self.game_active: return
|
|
211
|
-
if self.invincible > 0: self.invincible -= 1
|
|
212
|
-
if self.shoot_cooldown > 0: self.shoot_cooldown -= 1
|
|
213
|
-
if self.nuke_timer > 0: self.nuke_timer -= 1
|
|
214
|
-
|
|
215
|
-
if self.btn_left: self.player_x -= PLAYER_SPEED
|
|
216
|
-
if self.btn_right: self.player_x += PLAYER_SPEED
|
|
217
|
-
self.player_x = max(PLAYER_RADIUS + 5, min(WIDTH - PLAYER_RADIUS - 5, self.player_x))
|
|
218
|
-
|
|
219
|
-
if self.btn_fire and self.shoot_cooldown == 0:
|
|
220
|
-
if lib is not None:
|
|
221
|
-
# x, y, speed_x(0.0), speed_y, radius, damage
|
|
222
|
-
lib.add_bullet(float(self.player_x), float(self.player_y - 12), 0.0, float(BULLET_SPEED), 5, 1)
|
|
223
|
-
self.sfx_shoot.play()
|
|
224
|
-
self.shoot_cooldown = SHOOT_COOLDOWN_FRAMES
|
|
225
|
-
|
|
226
|
-
# BOSS Spawn Timer
|
|
227
|
-
current_time = pygame.time.get_ticks()
|
|
228
|
-
if current_time - self.last_boss_spawn_time >= BOSS_SPAWN_INTERVAL:
|
|
229
|
-
self.last_boss_spawn_time = current_time
|
|
230
|
-
self.spawn_enemy(is_boss=True)
|
|
231
|
-
|
|
232
|
-
if lib is not None:
|
|
233
|
-
lib.update_all()
|
|
234
|
-
lib.remove_offscreen_bullets(float(WIDTH), float(HEIGHT))
|
|
235
|
-
lib.remove_offscreen_enemies(float(HEIGHT))
|
|
236
|
-
|
|
237
|
-
kills = (KillInfo * 256)()
|
|
238
|
-
kill_count = lib.process_bullet_enemy_collision(kills, 256)
|
|
239
|
-
for k in range(kill_count):
|
|
240
|
-
ki = kills[k]
|
|
241
|
-
self.score += ki.score
|
|
242
|
-
|
|
243
|
-
# Update wave level for elite spawns
|
|
244
|
-
raw_wave = min(1 + self.score // 550, 9)
|
|
245
|
-
if raw_wave > self.wave_level:
|
|
246
|
-
self.wave_level = raw_wave
|
|
247
|
-
self.spawn_delay_current = max(20, 48 - int(self.wave_level * 2))
|
|
248
|
-
|
|
249
|
-
self.add_explosion(ki.x, ki.y, is_boss=bool(ki.is_boss))
|
|
250
|
-
self.sfx_boom.play()
|
|
251
|
-
|
|
252
|
-
out_x, out_y = ctypes.c_float(0), ctypes.c_float(0)
|
|
253
|
-
hit = lib.process_player_enemy_collision(float(self.player_x), float(self.player_y), float(PLAYER_RADIUS), ctypes.byref(out_x), ctypes.byref(out_y))
|
|
254
|
-
if hit and self.invincible <= 0 and self.game_active:
|
|
255
|
-
self.lives -= 1
|
|
256
|
-
self.screen_shake = 15
|
|
257
|
-
if self.lives <= 0:
|
|
258
|
-
self.lives = 0
|
|
259
|
-
self.game_active = False
|
|
260
|
-
return
|
|
261
|
-
else:
|
|
262
|
-
self.invincible = INVINCIBLE_DURATION
|
|
263
|
-
self.add_explosion(self.player_x, self.player_y)
|
|
264
|
-
|
|
265
|
-
self.enemy_spawn_timer -= 1
|
|
266
|
-
if self.enemy_spawn_timer <= 0:
|
|
267
|
-
self.spawn_enemy()
|
|
268
|
-
self.enemy_spawn_timer = self.spawn_delay_current
|
|
269
|
-
|
|
270
|
-
for p in self.particles[:]:
|
|
271
|
-
p['x'] += p['vx']
|
|
272
|
-
p['y'] += p['vy']
|
|
273
|
-
p['life'] -= 1
|
|
274
|
-
if p['life'] <= 0: self.particles.remove(p)
|
|
275
|
-
for ex in self.explosions[:]:
|
|
276
|
-
ex['life'] -= 1
|
|
277
|
-
if ex['life'] <= 0: self.explosions.remove(ex)
|
|
278
|
-
|
|
279
|
-
self.player_trail.append((self.player_x, self.player_y))
|
|
280
|
-
if len(self.player_trail) > 6: self.player_trail.pop(0)
|
|
281
|
-
|
|
282
|
-
def draw(self):
|
|
283
|
-
shake_x = random.randint(-8, 8) if self.screen_shake > 0 else 0
|
|
284
|
-
shake_y = random.randint(-8, 8) if self.screen_shake > 0 else 0
|
|
285
|
-
if self.screen_shake > 0: self.screen_shake -= 1
|
|
286
|
-
|
|
287
|
-
self.screen.fill(COLORS['bg'])
|
|
288
|
-
|
|
289
|
-
for star in self.stars:
|
|
290
|
-
pygame.draw.circle(self.screen, (255, 240, 200), (int(star['x']), int(star['y'])), int(star['radius']))
|
|
291
|
-
|
|
292
|
-
if lib is not None:
|
|
293
|
-
n_e = lib.get_enemy_count()
|
|
294
|
-
if n_e > 0:
|
|
295
|
-
arr_e = (CEnemy * n_e)()
|
|
296
|
-
lib.get_enemies(arr_e)
|
|
297
|
-
for e in arr_e:
|
|
298
|
-
# Different colors for different enemy types
|
|
299
|
-
if e.is_boss:
|
|
300
|
-
color = COLORS['enemy_boss']
|
|
301
|
-
elif e.elite:
|
|
302
|
-
color = COLORS['enemy_elite']
|
|
303
|
-
else:
|
|
304
|
-
color = COLORS['enemy']
|
|
305
|
-
|
|
306
|
-
pygame.draw.circle(self.screen, color, (int(e.x) + shake_x, int(e.y) + shake_y), e.radius - 1)
|
|
307
|
-
|
|
308
|
-
# Draw Boss crown and health bar
|
|
309
|
-
if e.is_boss:
|
|
310
|
-
pygame.draw.polygon(self.screen, COLORS['gold'], [
|
|
311
|
-
(e.x - 15 + shake_x, e.y - e.radius // 2 + 10 + shake_y),
|
|
312
|
-
(e.x - 8 + shake_x, e.y - e.radius // 2 - 10 + shake_y),
|
|
313
|
-
(e.x + shake_x, e.y - e.radius // 2 + shake_y),
|
|
314
|
-
(e.x + 8 + shake_x, e.y - e.radius // 2 - 10 + shake_y),
|
|
315
|
-
(e.x + 15 + shake_x, e.y - e.radius // 2 + 10 + shake_y)
|
|
316
|
-
])
|
|
317
|
-
bar_w = 80 * (e.hp / e.max_hp)
|
|
318
|
-
pygame.draw.rect(self.screen, (255, 50, 50), (int(e.x) - 40 + shake_x, int(e.y) - e.radius - 15 + shake_y, 80, 6))
|
|
319
|
-
pygame.draw.rect(self.screen, (0, 255, 0), (int(e.x) - 40 + shake_x, int(e.y) - e.radius - 15 + shake_y, int(bar_w), 6))
|
|
320
|
-
|
|
321
|
-
# Draw Elite white ring
|
|
322
|
-
elif e.elite:
|
|
323
|
-
pygame.draw.circle(self.screen, COLORS['white'], (int(e.x) + shake_x, int(e.y) + shake_y), e.radius - 1, 2)
|
|
324
|
-
|
|
325
|
-
n_b = lib.get_bullet_count()
|
|
326
|
-
if n_b > 0:
|
|
327
|
-
arr_b = (CBullet * n_b)()
|
|
328
|
-
lib.get_bullets(arr_b)
|
|
329
|
-
for b in arr_b:
|
|
330
|
-
# If speed_y > 0, it's a Boss bullet, draw it red
|
|
331
|
-
if b.speed_y > 0:
|
|
332
|
-
pygame.draw.circle(self.screen, (255, 0, 0), (int(b.x) + shake_x, int(b.y) + shake_y), b.radius)
|
|
333
|
-
pygame.draw.circle(self.screen, (255, 255, 255), (int(b.x) + shake_x, int(b.y) + shake_y), b.radius // 2)
|
|
334
|
-
else:
|
|
335
|
-
self.screen.blit(self.bullet_surface, (int(b.x) - 6 + shake_x, int(b.y) - 6 + shake_y))
|
|
336
|
-
for i, (tx, ty) in enumerate(self.player_trail[:-1]):
|
|
337
|
-
alpha = int(150 * (i / len(self.player_trail)))
|
|
338
|
-
surf = pygame.Surface((40, 40), pygame.SRCALPHA)
|
|
339
|
-
pygame.draw.circle(surf, (*COLORS['player_main'][:3], alpha), (20, 20), 16)
|
|
340
|
-
self.screen.blit(surf, (int(tx) - 20 + shake_x, int(ty) - 20 + shake_y))
|
|
341
|
-
|
|
342
|
-
if self.invincible <= 0 or (self.invincible // 5) % 2 == 0:
|
|
343
|
-
self.screen.blit(self.player_surface, (int(self.player_x) - 20 + shake_x, int(self.player_y) - 20 + shake_y))
|
|
344
|
-
|
|
345
|
-
for ex in self.explosions:
|
|
346
|
-
ratio = ex['life'] / ex['max_life']
|
|
347
|
-
pygame.draw.circle(self.screen, (255, 100, 30), (int(ex['x']), int(ex['y'])), int(ex['radius'] * (0.5 + ratio * 0.5)))
|
|
348
|
-
for p in self.particles:
|
|
349
|
-
pygame.draw.circle(self.screen, p['color'], (int(p['x']), int(p['y'])), int(p['size']))
|
|
350
|
-
|
|
351
|
-
# UI Buttons
|
|
352
|
-
pygame.draw.circle(self.screen, (100, 100, 100, 128), (100, HEIGHT - 100), 50)
|
|
353
|
-
pygame.draw.circle(self.screen, (255, 255, 255), (80, HEIGHT - 100), 15)
|
|
354
|
-
pygame.draw.circle(self.screen, (100, 100, 100, 128), (250, HEIGHT - 100), 50)
|
|
355
|
-
pygame.draw.circle(self.screen, (255, 255, 255), (270, HEIGHT - 100), 15)
|
|
356
|
-
|
|
357
|
-
pygame.draw.circle(self.screen, (255, 100, 100, 180), (WIDTH - 120, HEIGHT - 120), 60)
|
|
358
|
-
self.draw_text("FIRE", WIDTH - 120, HEIGHT - 120, COLORS['white'], center=True, font=self.font_medium)
|
|
359
|
-
|
|
360
|
-
if self.nuke_timer <= 0:
|
|
361
|
-
pygame.draw.circle(self.screen, (255, 215, 0, 200), (WIDTH - 300, HEIGHT - 100), 50)
|
|
362
|
-
self.draw_text("NUKE", WIDTH - 300, HEIGHT - 100, (0,0,0), center=True, font=self.font_medium)
|
|
363
|
-
else:
|
|
364
|
-
pygame.draw.circle(self.screen, (100, 100, 100, 100), (WIDTH - 300, HEIGHT - 100), 50)
|
|
365
|
-
cd_sec = math.ceil(self.nuke_timer / 60)
|
|
366
|
-
self.draw_text(f"{cd_sec}s", WIDTH - 300, HEIGHT - 100, COLORS['white'], center=True, font=self.font_medium)
|
|
367
|
-
|
|
368
|
-
self.draw_text(f"Score: {self.score}", 30, 20, COLORS['score'], font=self.font_medium)
|
|
369
|
-
self.draw_text(f"Lives: {self.lives}", WIDTH - 220, 20, COLORS['lives'], font=self.font_medium)
|
|
370
|
-
|
|
371
|
-
if not self.game_active:
|
|
372
|
-
self.draw_text("GAME OVER", WIDTH // 2, HEIGHT // 2 - 30, COLORS['gameover'], center=True, font=self.font_large)
|
|
373
|
-
self.draw_text("Press [ R ] to Restart", WIDTH // 2, HEIGHT // 2 + 20, (187, 221, 255), center=True, font=self.font_small)
|
|
374
|
-
pygame.display.flip()
|
|
375
|
-
|
|
376
|
-
def handle_events(self):
|
|
377
|
-
for event in pygame.event.get():
|
|
378
|
-
if event.type == pygame.QUIT: return False
|
|
379
|
-
elif event.type == pygame.KEYDOWN:
|
|
380
|
-
if event.key in (pygame.K_LEFT, pygame.K_a): self.btn_left = True
|
|
381
|
-
if event.key in (pygame.K_RIGHT, pygame.K_d): self.btn_right = True
|
|
382
|
-
if event.key in (pygame.K_SPACE, pygame.K_UP, pygame.K_k): self.btn_fire = True
|
|
383
|
-
if event.key == pygame.K_r: self.reset_game()
|
|
384
|
-
if event.key == pygame.K_ESCAPE: return False
|
|
385
|
-
elif event.type == pygame.KEYUP:
|
|
386
|
-
if event.key in (pygame.K_LEFT, pygame.K_a): self.btn_left = False
|
|
387
|
-
if event.key in (pygame.K_RIGHT, pygame.K_d): self.btn_right = False
|
|
388
|
-
if event.key in (pygame.K_SPACE, pygame.K_UP, pygame.K_k): self.btn_fire = False
|
|
389
|
-
|
|
390
|
-
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
391
|
-
mx, my = event.pos
|
|
392
|
-
if math.hypot(mx - 100, my - (HEIGHT - 100)) < 50:
|
|
393
|
-
self.btn_left = True
|
|
394
|
-
elif math.hypot(mx - 250, my - (HEIGHT - 100)) < 50:
|
|
395
|
-
self.btn_right = True
|
|
396
|
-
elif math.hypot(mx - (WIDTH - 120), my - (HEIGHT - 120)) < 60:
|
|
397
|
-
self.btn_fire = True
|
|
398
|
-
elif math.hypot(mx - (WIDTH - 300), my - (HEIGHT - 100)) < 50 and self.nuke_timer <= 0:
|
|
399
|
-
# Nuke triggered: 50 vertical bullets
|
|
400
|
-
self.nuke_timer = NUKE_COOLDOWN
|
|
401
|
-
self.flash_timer = 15
|
|
402
|
-
self.screen_shake = 20
|
|
403
|
-
self.sfx_boom.play()
|
|
404
|
-
self.screen.fill((255, 255, 255))
|
|
405
|
-
|
|
406
|
-
# Fire 50 vertical bullets across the screen
|
|
407
|
-
for i in range(50):
|
|
408
|
-
spawn_x = 50 + i * ((WIDTH - 100) / 49)
|
|
409
|
-
lib.add_bullet(float(spawn_x), float(self.player_y), 0.0, float(BULLET_SPEED * 1.2), 6, 2)
|
|
410
|
-
|
|
411
|
-
elif event.type == pygame.MOUSEBUTTONUP:
|
|
412
|
-
self.btn_left = False
|
|
413
|
-
self.btn_right = False
|
|
414
|
-
self.btn_fire = False
|
|
415
|
-
return True
|
|
416
|
-
|
|
417
|
-
def draw_text(self, text, x, y, color, center=False, font=None):
|
|
418
|
-
if font is None: font = self.font_medium
|
|
419
|
-
surface = self.render_text(text, font, color)
|
|
420
|
-
rect = surface.get_rect()
|
|
421
|
-
if center: rect.center = (x, y)
|
|
422
|
-
else: rect.topleft = (x, y)
|
|
423
|
-
self.screen.blit(surface, rect)
|
|
424
|
-
|
|
425
|
-
def run(self):
|
|
426
|
-
while True:
|
|
427
|
-
if not self.handle_events(): break
|
|
428
|
-
self.update()
|
|
429
|
-
self.draw()
|
|
430
|
-
self.clock.tick(FPS)
|
|
431
|
-
pygame.quit()
|
|
432
|
-
sys.exit()
|
|
433
|
-
|
|
434
|
-
if __name__ == "__main__":
|
|
435
|
-
game = StarGuardian()
|
|
436
|
-
game.run()
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ed-game
|
|
3
|
-
Version: 4.0.0.dev1
|
|
4
|
-
Summary: Earth Defense Game
|
|
5
|
-
Author-email: qq-name <your@email.com>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://pypi.org/project/ed-game/
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.16
|
|
13
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
-
Classifier: Operating System :: MacOS
|
|
15
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
-
Classifier: Topic :: Games/Entertainment
|
|
17
|
-
Requires-Python: >=3.13
|
|
18
|
-
Description-Content-Type: text/markdown
|
|
19
|
-
License-File: LICENSE
|
|
20
|
-
Requires-Dist: pygame-ce>=2.5.3
|
|
21
|
-
Requires-Dist: pyglet>=2.0
|
|
22
|
-
Dynamic: license-file
|
|
23
|
-
|
|
24
|
-
Installing:
|
|
25
|
-
```bash
|
|
26
|
-
pip install ed-game
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
or:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip3 install ed-game
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Usage:
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
import ed_game
|
|
39
|
-
ed_game.run()
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
ed-game dependencies:
|
|
43
|
-
|
|
44
|
-
setuptools>=77.3.4 (is build)
|
|
45
|
-
|
|
46
|
-
pygame-ce >= 2.5.3 (core of 2.x / 3.x /4.x)
|
|
47
|
-
|
|
48
|
-
pyglet >= 2.0 (core of 4.x New Game)
|
|
49
|
-
|
|
50
|
-
CPython >= 3.13
|
|
51
|
-
|
|
52
|
-
Earth Defense Game - A cross-platform shooter.
|
|
53
|
-
|
|
54
|
-
Windows / 2.x & 3.x: Uses a high-performance C++ extension for precise, ultra-slow enemy movement and fast collision detection.
|
|
55
|
-
|
|
56
|
-
Other platforms / 2.x & 3.x: Runs a 100% Pure Python fallback.
|
|
57
|
-
|
|
58
|
-
4.x New Game: A brand new implementation using the Pyglet library.
|
|
59
|
-
|
|
60
|
-
🆕 What's New in 4.0.0dev1
|
|
61
|
-
New Ed-Game Engine: Added a completely new implementation (ed_game.new) built with the Pyglet library, moving away from Pygame.
|
|
62
|
-
|
|
63
|
-
Early Access: Please note that this is an early dev release. There may be bugs and performance issues before 4.0.0rc1.
|
|
64
|
-
|
|
65
|
-
⚠️ Known Issues
|
|
66
|
-
We have identified runtime visual bugs in ed_game 4.0.0dev1 and ed_game 3.2.0.
|
|
67
|
-
|
|
68
|
-
These issues will be fixed in the upcoming ed_game 4.0.0dev2 and ed_game 3.2.1 (or 3.3.0).
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .game import run
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import pyglet
|
|
2
|
-
from pyglet import shapes
|
|
3
|
-
from pyglet.window import key
|
|
4
|
-
import random
|
|
5
|
-
import math
|
|
6
|
-
|
|
7
|
-
WIDTH, HEIGHT = 1800, 1050
|
|
8
|
-
|
|
9
|
-
class NewGame:
|
|
10
|
-
def __init__(self):
|
|
11
|
-
self.window = pyglet.window.Window(WIDTH, HEIGHT, "Star Guardian 4.0.0dev1 (Pyglet)")
|
|
12
|
-
self.batch = pyglet.graphics.Batch()
|
|
13
|
-
|
|
14
|
-
self.player = shapes.Circle(WIDTH // 2, 100, 16, color=(62, 255, 250), batch=self.batch)
|
|
15
|
-
self.player_core = shapes.Circle(WIDTH // 2, 96, 6, color=(0, 204, 255), batch=self.batch)
|
|
16
|
-
|
|
17
|
-
self.bullets = []
|
|
18
|
-
self.enemies = []
|
|
19
|
-
self.particles = []
|
|
20
|
-
|
|
21
|
-
self.score = 0
|
|
22
|
-
self.lives = 3
|
|
23
|
-
self.boss_timer = 20.0
|
|
24
|
-
self.state = {"left": False, "right": False, "shoot": False, "cooldown": 0}
|
|
25
|
-
|
|
26
|
-
self.label_score = pyglet.text.Label('Score: 0', font_name='Arial', font_size=28, x=30, y=HEIGHT - 40, batch=self.batch, color=(0, 255, 255, 255))
|
|
27
|
-
self.label_lives = pyglet.text.Label('Lives: 3', font_name='Arial', font_size=28, x=WIDTH - 150, y=HEIGHT - 40, batch=self.batch, color=(255, 51, 102, 255))
|
|
28
|
-
self.label_status = pyglet.text.Label('Slow Galaxy', font_name='Arial', font_size=20, x=WIDTH//2, y=HEIGHT - 40, batch=self.batch, color=(255, 215, 0, 255), anchor_x='center')
|
|
29
|
-
|
|
30
|
-
self.window.push_handlers(self)
|
|
31
|
-
pyglet.clock.schedule_interval(self.update, 1/60.0)
|
|
32
|
-
pyglet.app.run()
|
|
33
|
-
|
|
34
|
-
def on_key_press(self, symbol, modifiers):
|
|
35
|
-
if symbol in (key.A, key.LEFT): self.state["left"] = True
|
|
36
|
-
if symbol in (key.D, key.RIGHT): self.state["right"] = True
|
|
37
|
-
if symbol in (key.SPACE, key.K, key.UP): self.state["shoot"] = True
|
|
38
|
-
if symbol == key.R: self.reset()
|
|
39
|
-
|
|
40
|
-
def on_key_release(self, symbol, modifiers):
|
|
41
|
-
if symbol in (key.A, key.LEFT): self.state["left"] = False
|
|
42
|
-
if symbol in (key.D, key.RIGHT): self.state["right"] = False
|
|
43
|
-
if symbol in (key.SPACE, key.K, key.UP): self.state["shoot"] = False
|
|
44
|
-
|
|
45
|
-
def reset(self):
|
|
46
|
-
self.score = 0
|
|
47
|
-
self.lives = 3
|
|
48
|
-
self.player.x, self.player.y = WIDTH // 2, 100
|
|
49
|
-
for b in self.bullets: b['node'].delete()
|
|
50
|
-
for e in self.enemies: e['node'].delete()
|
|
51
|
-
self.bullets.clear()
|
|
52
|
-
self.enemies.clear()
|
|
53
|
-
self.update_labels()
|
|
54
|
-
|
|
55
|
-
def update_labels(self):
|
|
56
|
-
self.label_score.text = f"Score: {self.score}"
|
|
57
|
-
self.label_lives.text = f"Lives: {self.lives}"
|
|
58
|
-
|
|
59
|
-
def on_draw(self):
|
|
60
|
-
self.window.clear()
|
|
61
|
-
self.batch.draw()
|
|
62
|
-
|
|
63
|
-
def update(self, dt):
|
|
64
|
-
if self.lives <= 0: return
|
|
65
|
-
|
|
66
|
-
if self.state["left"]: self.player.x -= 500 * dt
|
|
67
|
-
if self.state["right"]: self.player.x += 500 * dt
|
|
68
|
-
self.player.x = max(20, min(WIDTH - 20, self.player.x))
|
|
69
|
-
self.player_core.x = self.player.x
|
|
70
|
-
self.player_core.y = self.player.y - 4
|
|
71
|
-
|
|
72
|
-
self.state["cooldown"] -= dt
|
|
73
|
-
if self.state["shoot"] and self.state["cooldown"] <= 0:
|
|
74
|
-
b = shapes.Circle(self.player.x, self.player.y + 15, 5, color=(255, 255, 128), batch=self.batch)
|
|
75
|
-
self.bullets.append({"node": b, "vy": 900})
|
|
76
|
-
self.state["cooldown"] = 0.15
|
|
77
|
-
|
|
78
|
-
for b in self.bullets[:]:
|
|
79
|
-
b["node"].y += b["vy"] * dt
|
|
80
|
-
if b["node"].y > HEIGHT:
|
|
81
|
-
b["node"].delete()
|
|
82
|
-
self.bullets.remove(b)
|
|
83
|
-
|
|
84
|
-
self.boss_timer -= dt
|
|
85
|
-
if self.boss_timer <= 0:
|
|
86
|
-
self.boss_timer = 20.0
|
|
87
|
-
boss = shapes.Circle(random.randint(100, WIDTH - 100), HEIGHT + 50, 48, color=(180, 50, 255), batch=self.batch)
|
|
88
|
-
self.enemies.append({"node": boss, "hp": 50, "max_hp": 50, "vy": -15, "is_boss": True})
|
|
89
|
-
|
|
90
|
-
crown = shapes.Polygon([(boss.x - 20, boss.y + 40), (boss.x, boss.y + 60), (boss.x + 20, boss.y + 40)], color=(255, 215, 0), batch=self.batch)
|
|
91
|
-
bg_bar = shapes.Rectangle(boss.x - 40, boss.y + 55, 80, 6, color=(255, 50, 50), batch=self.batch)
|
|
92
|
-
fg_bar = shapes.Rectangle(boss.x - 40, boss.y + 55, 80, 6, color=(0, 255, 0), batch=self.batch)
|
|
93
|
-
boss["ui"] = {"crown": crown, "bg_bar": bg_bar, "fg_bar": fg_bar}
|
|
94
|
-
|
|
95
|
-
if random.random() < 0.03:
|
|
96
|
-
e = shapes.Circle(random.randint(20, WIDTH - 20), HEIGHT + 20, 12, color=(255, 58, 111), batch=self.batch)
|
|
97
|
-
self.enemies.append({"node": e, "hp": 1, "max_hp": 1, "vy": -80, "is_boss": False})
|
|
98
|
-
|
|
99
|
-
for e in self.enemies[:]:
|
|
100
|
-
e["node"].y += e["vy"] * dt
|
|
101
|
-
if e.get("is_boss") and "ui" in e:
|
|
102
|
-
ui = e["ui"]
|
|
103
|
-
ui["bg_bar"].x = e["node"].x - 40
|
|
104
|
-
ui["bg_bar"].y = e["node"].y + 55
|
|
105
|
-
ui["fg_bar"].x = e["node"].x - 40
|
|
106
|
-
ui["fg_bar"].y = e["node"].y + 55
|
|
107
|
-
ui["fg_bar"].width = 80 * (e["hp"] / e["max_hp"])
|
|
108
|
-
|
|
109
|
-
if math.hypot(self.player.x - e["node"].x, self.player.y - e["node"].y) < 16 + e["node"].radius:
|
|
110
|
-
self.lives -= 1
|
|
111
|
-
self.update_labels()
|
|
112
|
-
self.create_explosion(e["node"].x, e["node"].y)
|
|
113
|
-
if "ui" in e:
|
|
114
|
-
for u in e["ui"].values(): u.delete()
|
|
115
|
-
e["node"].delete()
|
|
116
|
-
self.enemies.remove(e)
|
|
117
|
-
if self.lives <= 0: return
|
|
118
|
-
continue
|
|
119
|
-
|
|
120
|
-
if e["node"].y < -100:
|
|
121
|
-
if "ui" in e:
|
|
122
|
-
for u in e["ui"].values(): u.delete()
|
|
123
|
-
e["node"].delete()
|
|
124
|
-
self.enemies.remove(e)
|
|
125
|
-
|
|
126
|
-
for b in self.bullets[:]:
|
|
127
|
-
for e in self.enemies[:]:
|
|
128
|
-
if math.hypot(b["node"].x - e["node"].x, b["node"].y - e["node"].y) < 5 + e["node"].radius:
|
|
129
|
-
e["hp"] -= 1
|
|
130
|
-
b["node"].delete()
|
|
131
|
-
self.bullets.remove(b)
|
|
132
|
-
|
|
133
|
-
if e["hp"] <= 0:
|
|
134
|
-
self.score += 200 if e.get("is_boss") else 10
|
|
135
|
-
self.update_labels()
|
|
136
|
-
self.create_explosion(e["node"].x, e["node"].y)
|
|
137
|
-
if "ui" in e:
|
|
138
|
-
for u in e["ui"].values(): u.delete()
|
|
139
|
-
e["node"].delete()
|
|
140
|
-
self.enemies.remove(e)
|
|
141
|
-
break
|
|
142
|
-
|
|
143
|
-
for p in self.particles[:]:
|
|
144
|
-
p["node"].x += p["vx"] * dt
|
|
145
|
-
p["node"].y += p["vy"] * dt
|
|
146
|
-
p["life"] -= dt
|
|
147
|
-
if p["life"] <= 0:
|
|
148
|
-
p["node"].delete()
|
|
149
|
-
self.particles.remove(p)
|
|
150
|
-
|
|
151
|
-
def create_explosion(self, x, y):
|
|
152
|
-
for _ in range(8):
|
|
153
|
-
p = shapes.Circle(x, y, random.uniform(2, 5), color=(255, random.randint(100, 200), 50), batch=self.batch)
|
|
154
|
-
self.particles.append({"node": p, "vx": random.uniform(-300, 300), "vy": random.uniform(-300, 300), "life": 0.5})
|
|
155
|
-
|
|
156
|
-
def run():
|
|
157
|
-
NewGame()
|
|
158
|
-
run()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|