gamekit2d 0.2.0__py3-none-any.whl

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.
gamekit/__init__.py ADDED
@@ -0,0 +1,63 @@
1
+ """gamekit —— 一个零第三方依赖的极简 2D 游戏库。
2
+
3
+ 只使用 Python 标准库(tkinter + winsound),API 简单到极致:
4
+ 创建一个 ``Game``、创建几个 ``Sprite``、注册几个回调、``run()`` 一行开跑。
5
+
6
+ 快速上手::
7
+
8
+ from gamekit import Game, Key
9
+
10
+ game = Game(title="我的第一个游戏", width=800, height=600, fps=60)
11
+
12
+ player = game.sprite(color="red", x=400, y=500, width=60, height=40)
13
+
14
+ @game.on_key(Key.LEFT)
15
+ def left():
16
+ player.vx = -300
17
+
18
+ @game.on_key(Key.RIGHT)
19
+ def right():
20
+ player.vx = 300
21
+
22
+ @game.on_key(Key.SPACE)
23
+ def stop():
24
+ player.vx = 0
25
+
26
+ game.run()
27
+ """
28
+
29
+ from .core.game import Game
30
+ from .core.scene import Scene
31
+ from .core.keys import Key, normalize
32
+ from .sprites.sprite import Sprite
33
+ from .sprites.animation import Animation
34
+ from .physics.collision import (rect_collide, circle_collide, point_in_rect,
35
+ point_in_circle, distance, collides,
36
+ pixel_collide)
37
+ from .audio.sound import Sound
38
+ from .ui.text import Text
39
+ from .ui.widgets import Button, ProgressBar
40
+ from .fx.particles import ParticleSystem
41
+ from .fx.draw import Line, Polygon, Ellipse, Arc
42
+ from .utils.color import (Color, to_color, mix, random_color,
43
+ RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, PINK,
44
+ CYAN, LIME, MAGENTA, BROWN, WHITE, BLACK, GRAY,
45
+ LIGHT_GRAY, DARK_GRAY, NAVY)
46
+ from .utils.vector import Vec2
47
+
48
+ __version__ = "0.2.0"
49
+ __all__ = [
50
+ "Game", "Scene", "Key", "normalize",
51
+ "Sprite", "Animation",
52
+ "rect_collide", "circle_collide", "point_in_rect", "point_in_circle",
53
+ "distance", "collides", "pixel_collide",
54
+ "Sound",
55
+ "Text", "Button", "ProgressBar",
56
+ "ParticleSystem",
57
+ "Line", "Polygon", "Ellipse", "Arc",
58
+ "Color", "to_color", "mix", "random_color",
59
+ "RED", "GREEN", "BLUE", "YELLOW", "ORANGE", "PURPLE", "PINK",
60
+ "CYAN", "LIME", "MAGENTA", "BROWN", "WHITE", "BLACK", "GRAY",
61
+ "LIGHT_GRAY", "DARK_GRAY", "NAVY",
62
+ "Vec2",
63
+ ]
@@ -0,0 +1 @@
1
+ """audio:WAV 音效与音乐(Windows winsound,零第三方依赖)。"""
gamekit/audio/sound.py ADDED
@@ -0,0 +1,69 @@
1
+ """音频模块:WAV 音效与背景音乐。
2
+
3
+ 实现说明(零第三方依赖):
4
+ - Windows 平台使用标准库 ``winsound`` 异步播放 WAV 文件
5
+ - 其他平台(Linux / macOS)标准库没有音频播放能力,
6
+ ``Sound.play()`` 会打印提示并静默,不影响游戏逻辑运行
7
+
8
+ 限制:
9
+ - 仅支持 ``.wav`` 文件(标准库只能解码 wav)
10
+ - Windows 下一次只能播放一个音频(winsound 限制),
11
+ 音乐与音效无法同时响,按需取舍
12
+ """
13
+
14
+ import os
15
+ import sys
16
+
17
+ _WIN = sys.platform == "win32"
18
+ if _WIN:
19
+ import winsound
20
+
21
+ _HAS_AUDIO = True
22
+ else:
23
+ _HAS_AUDIO = False
24
+
25
+
26
+ class Sound:
27
+ """一个 WAV 音频。
28
+
29
+ :param path: .wav 文件路径
30
+ :param volume: 音量 0.0 ~ 1.0(winsound 不支持调音量,仅作记录保留)
31
+ :param loop: 是否循环播放
32
+ """
33
+
34
+ def __init__(self, path, volume=1.0, loop=False):
35
+ if not os.path.exists(path):
36
+ raise FileNotFoundError("音频文件不存在: %s" % path)
37
+ if not path.lower().endswith(".wav"):
38
+ raise ValueError(
39
+ "gamekit 音频仅支持 .wav 文件(标准库能力限制),收到: %s" % path
40
+ )
41
+ self.path = path
42
+ self.volume = max(0.0, min(1.0, float(volume)))
43
+ self._looping = bool(loop)
44
+ self._playing = False
45
+
46
+ @property
47
+ def playing(self):
48
+ return self._playing
49
+
50
+ def play(self, loop=None):
51
+ """播放音频。``loop=True`` 循环播放,``loop=False`` 播放一次。"""
52
+ if not _HAS_AUDIO:
53
+ print("[gamekit] 当前平台不支持音频播放(仅 Windows 支持): %s" % self.path)
54
+ return self
55
+ if loop is not None:
56
+ self._looping = bool(loop)
57
+ flags = winsound.SND_FILENAME | winsound.SND_ASYNC
58
+ if self._looping:
59
+ flags |= winsound.SND_LOOP
60
+ winsound.PlaySound(self.path, flags)
61
+ self._playing = True
62
+ return self
63
+
64
+ def stop(self):
65
+ """停止播放。"""
66
+ if _HAS_AUDIO:
67
+ winsound.PlaySound(None, winsound.SND_PURGE)
68
+ self._playing = False
69
+ return self
@@ -0,0 +1 @@
1
+ """core:游戏引擎核心(Game 主类、场景管理、按键常量)。"""