qgame 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.
- qgame-1.0.0/LICENSE +21 -0
- qgame-1.0.0/PKG-INFO +414 -0
- qgame-1.0.0/README.md +397 -0
- qgame-1.0.0/qgame/__init__.py +57 -0
- qgame-1.0.0/qgame/__main__.py +566 -0
- qgame-1.0.0/qgame/anim_data.py +9 -0
- qgame-1.0.0/qgame/animation.py +372 -0
- qgame-1.0.0/qgame/animation_sprite.py +170 -0
- qgame-1.0.0/qgame/audio.py +70 -0
- qgame-1.0.0/qgame/camera.py +220 -0
- qgame-1.0.0/qgame/collision.py +38 -0
- qgame-1.0.0/qgame/core.py +280 -0
- qgame-1.0.0/qgame/examples/__init__.py +0 -0
- qgame-1.0.0/qgame/examples/hero.jpg +0 -0
- qgame-1.0.0/qgame/examples/music.mp3 +0 -0
- qgame-1.0.0/qgame/examples/player.png +0 -0
- qgame-1.0.0/qgame/examples/sound.wav +0 -0
- qgame-1.0.0/qgame/graphics.py +205 -0
- qgame-1.0.0/qgame/input.py +123 -0
- qgame-1.0.0/qgame/py.typed +0 -0
- qgame-1.0.0/qgame/scene.py +75 -0
- qgame-1.0.0/qgame/spritesheet.py +81 -0
- qgame-1.0.0/qgame/ui.py +140 -0
- qgame-1.0.0/qgame.egg-info/PKG-INFO +414 -0
- qgame-1.0.0/qgame.egg-info/SOURCES.txt +29 -0
- qgame-1.0.0/qgame.egg-info/dependency_links.txt +1 -0
- qgame-1.0.0/qgame.egg-info/entry_points.txt +2 -0
- qgame-1.0.0/qgame.egg-info/requires.txt +1 -0
- qgame-1.0.0/qgame.egg-info/top_level.txt +1 -0
- qgame-1.0.0/setup.cfg +4 -0
- qgame-1.0.0/setup.py +27 -0
qgame-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WatermelonCode
|
|
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.
|
qgame-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qgame
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A professional game library based on PySide6
|
|
5
|
+
Author: WatermelonCode
|
|
6
|
+
License: MIT
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: PySide6>=6.0.0
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: description-content-type
|
|
13
|
+
Dynamic: license
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
Dynamic: requires-dist
|
|
16
|
+
Dynamic: summary
|
|
17
|
+
|
|
18
|
+
# QGame Engine
|
|
19
|
+
|
|
20
|
+
A lightweight, modern, and high-performance 2D game framework built on PySide6. Designed to draw like Pygame, yet harness the power of modern UI systems, absolute path scaling, high-performance memory image operations, and smooth matrix transformations.
|
|
21
|
+
|
|
22
|
+
# English Reference
|
|
23
|
+
|
|
24
|
+
## Installation & Running Demo
|
|
25
|
+
If installed via setuptools, run the demo directly in the terminal:
|
|
26
|
+
```bash
|
|
27
|
+
run-qgame-examples
|
|
28
|
+
```
|
|
29
|
+
Or run as a module:
|
|
30
|
+
```bash
|
|
31
|
+
python -m qgame
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Core Module (`qgame`)
|
|
37
|
+
|
|
38
|
+
### Functions
|
|
39
|
+
* **`init()`**
|
|
40
|
+
Initializes the PySide6 Application context. Must be called before any graphics operations.
|
|
41
|
+
* **`set_settings(*, width: int, height: int, title: str = "QGame") -> QImage`**
|
|
42
|
+
Sets the game window resolution and title. Returns the primary QImage canvas for rendering.
|
|
43
|
+
|
|
44
|
+
### `window` (Window Instance)
|
|
45
|
+
* **`update()`**
|
|
46
|
+
Redraws the window and processes window events. Call once per frame inside the game loop.
|
|
47
|
+
* **`set_title(title: str)`**
|
|
48
|
+
Dynamically changes the window title.
|
|
49
|
+
* **`set_icon(icon_path: str)`**
|
|
50
|
+
Loads and sets the window icon.
|
|
51
|
+
* **`set_size(width: int, height: int) -> QImage`**
|
|
52
|
+
Changes the canvas dimensions dynamically.
|
|
53
|
+
* **`toggle_fullscreen()`**
|
|
54
|
+
Toggles between fullscreen and windowed modes.
|
|
55
|
+
* **`show_cursor(visible: bool)`**
|
|
56
|
+
Shows or hides the OS cursor.
|
|
57
|
+
|
|
58
|
+
### `events` (Events Instance)
|
|
59
|
+
* **`get() -> List[Event]`**
|
|
60
|
+
Pulls and returns all pending events in the queue.
|
|
61
|
+
|
|
62
|
+
### `Clock` (Class)
|
|
63
|
+
* **`tick(fps: int) -> float`**
|
|
64
|
+
Controls the game frame rate and returns `dt` (Delta Time in seconds).
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Input Module (`qgame.keyboard`, `qgame.mouse`)
|
|
69
|
+
|
|
70
|
+
### `keys` (Key Mapping Constants)
|
|
71
|
+
Contains PySide6 key code constants, e.g., `keys.W`, `keys.ESCAPE`, `keys.UP`, `keys.SPACE`, `keys.SHIFT`, etc.
|
|
72
|
+
|
|
73
|
+
### `keyboard` (Keyboard Detection)
|
|
74
|
+
* **`is_pressed(key_code: int) -> bool`**
|
|
75
|
+
Returns `True` if the specified key is currently down.
|
|
76
|
+
|
|
77
|
+
### `mouse` (Mouse Detection)
|
|
78
|
+
* **`get_pos() -> tuple[int, int]`**
|
|
79
|
+
Returns virtual canvas coordinates `(x, y)` of the mouse.
|
|
80
|
+
* **`is_pressed(button: int) -> bool`**
|
|
81
|
+
Returns `True` if the specified mouse button is down (`mouseButtons.LEFT`, `mouseButtons.RIGHT`, `mouseButtons.MIDDLE`).
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Graphics Module (`qgame.graphics`)
|
|
86
|
+
|
|
87
|
+
### `Image` (Class)
|
|
88
|
+
Represents a source image cached in memory.
|
|
89
|
+
* **`__init__(source: str | Image | QImage)`**
|
|
90
|
+
Wraps a path, another image instance, or QImage. Performs zero-IO memory copy when using an existing image.
|
|
91
|
+
* **`resize(width: int, height: int, keep_aspect: bool = False)`**
|
|
92
|
+
Rescales the active image.
|
|
93
|
+
* **`scale(factor_x: float, factor_y: float = None, keep_aspect: bool = True)`**
|
|
94
|
+
Scales by percentage multipliers.
|
|
95
|
+
* **`rotate(angle: float)`**
|
|
96
|
+
Rotates the image (degrees, clockwise).
|
|
97
|
+
* **`flip(horizontal: bool = True, vertical: bool = False)`**
|
|
98
|
+
Flips the image.
|
|
99
|
+
* **`reset()`**
|
|
100
|
+
Reverts the image to its original clean state.
|
|
101
|
+
* **`width` / `height`**
|
|
102
|
+
Properties returning active resolution.
|
|
103
|
+
|
|
104
|
+
### `Rect` (Class)
|
|
105
|
+
* **`__init__(x, y, width, height)`**
|
|
106
|
+
A float-precision 2D rectangle container.
|
|
107
|
+
* **`center` / `centerx` / `centery`**
|
|
108
|
+
Properties to read/write center coordinates.
|
|
109
|
+
* **`collidepoint(pos: tuple) -> bool`**
|
|
110
|
+
Returns `True` if a coordinate is inside the boundary.
|
|
111
|
+
|
|
112
|
+
### `draw` (Draw Utility)
|
|
113
|
+
* **`fill(canvas, color)`**
|
|
114
|
+
Clears the canvas with a solid color `(r, g, b)`.
|
|
115
|
+
* **`rect(canvas, color, rect, width=0)`**
|
|
116
|
+
Draws a rectangle. `width=0` fills it.
|
|
117
|
+
* **`rounded_rect(canvas, color, rect, radius, width=0)`**
|
|
118
|
+
Draws an antialiased rounded rectangle.
|
|
119
|
+
* **`circle(canvas, color, center, radius, width=0)`**
|
|
120
|
+
Draws an antialiased circle.
|
|
121
|
+
* **`ellipse(canvas, color, rect, width=0)`**
|
|
122
|
+
Draws an ellipse inside a bounding box.
|
|
123
|
+
* **`line(canvas, color, start, end, width=1)`**
|
|
124
|
+
Draws an antialiased segment line.
|
|
125
|
+
* **`text(canvas, text, coords, size=16, color=(255,255,255), font_name="")`**
|
|
126
|
+
Draws a high-fidelity antialiased text.
|
|
127
|
+
* **`image(canvas, img, coords, center=False, src_rect=None, opacity=1.0)`**
|
|
128
|
+
Draws a fast-blended image, supports center tracking, sub-rect cropping, and transparency.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Collision Module (`qgame.collision`)
|
|
133
|
+
|
|
134
|
+
### Methods
|
|
135
|
+
* **`check_rect(rect1: tuple, rect2: tuple) -> bool`**
|
|
136
|
+
Rect-to-Rect AABB intersection.
|
|
137
|
+
* **`check_circle(pos1, r1, pos2, r2) -> bool`**
|
|
138
|
+
Circle-to-Circle intersection.
|
|
139
|
+
* **`check_rect_circle(rect, center, radius) -> bool`**
|
|
140
|
+
Rect-to-Circle intersection.
|
|
141
|
+
* **`check_point_rect(point, rect) -> bool`**
|
|
142
|
+
Point-in-Rect containment.
|
|
143
|
+
* **`check_point_circle(point, center, radius) -> bool`**
|
|
144
|
+
Point-in-Circle containment.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Audio Module (`qgame.audio`)
|
|
149
|
+
|
|
150
|
+
### `Sound` (Class)
|
|
151
|
+
For rapid playback of short sound effects (`.wav`).
|
|
152
|
+
* **`play()`, `stop()`**
|
|
153
|
+
* **`set_volume(volume: float)`** (0.0 to 1.0)
|
|
154
|
+
* **`set_loop(loop: bool)`**
|
|
155
|
+
|
|
156
|
+
### `Music` (Class)
|
|
157
|
+
For streaming long background music tracks (`.mp3`).
|
|
158
|
+
* **`play(loop: bool = True)`, `pause()`, `unpause()`, `stop()`**
|
|
159
|
+
* **`set_volume(volume: float)`** (0.0 to 1.0)
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## UI Components (`qgame.ui`)
|
|
164
|
+
|
|
165
|
+
### `TextBox` (Class)
|
|
166
|
+
An advanced GUI input box fully supporting system IME, cursor focus, select all, copy-paste, and scale adaptation.
|
|
167
|
+
* **`__init__(x, y, w, h, placeholder="", multi_line=True)`**
|
|
168
|
+
* **`set_theme(bg_color, text_color, border_color, border_radius=6, font_size=14)`**
|
|
169
|
+
* **`get_text() -> str`, `set_text(text: str)`, `clear()`**
|
|
170
|
+
* **`set_focus()`, `set_visible(visible: bool)`**
|
|
171
|
+
* **`set_position(x, y)`, `set_size(w, h)`**
|
|
172
|
+
* **`destroy()`**
|
|
173
|
+
Completely unmounts and gets garbage-collected.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Scene Management (`qgame.scene`)
|
|
178
|
+
|
|
179
|
+
### `Scene` (Base Class)
|
|
180
|
+
Extend this to organize game states (e.g. MenuScene, LevelScene).
|
|
181
|
+
* **`on_enter(*args, **kwargs)`**
|
|
182
|
+
Triggered when switching *into* this scene.
|
|
183
|
+
* **`on_exit()`**
|
|
184
|
+
Triggered when switching *out of* this scene. UI children registered via `add_ui()` are automatically destroyed.
|
|
185
|
+
* **`handle_event(event)`, `update(dt)`, `draw(canvas)`**
|
|
186
|
+
* **`add_ui(widget)`**
|
|
187
|
+
Registers and auto-binds UI components to the lifecycle of this scene.
|
|
188
|
+
|
|
189
|
+
### `scene_manager`
|
|
190
|
+
* **`switch(new_scene_instance, *args, **kwargs)`**
|
|
191
|
+
* **`handle_event(event)`, `update(dt)`, `draw(canvas)`**
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Advanced Render Accessories
|
|
196
|
+
|
|
197
|
+
### `Camera` (`qgame.Camera`)
|
|
198
|
+
* **`follow(target, lerp_speed)`**, **`update(dt)`**
|
|
199
|
+
Smoothly interpolates camera positioning.
|
|
200
|
+
* **`set_deadzone(w, h)`**
|
|
201
|
+
Enforces a static delay window.
|
|
202
|
+
* **`set_bounds(min_x, min_y, max_x, max_y)`**
|
|
203
|
+
Locks camera bounding boxes.
|
|
204
|
+
* **`shake(intensity, duration)`**
|
|
205
|
+
Creates screen shake impulses.
|
|
206
|
+
* **`apply(coord_or_rect) -> tuple`**
|
|
207
|
+
Transforms world coordinates to screen coordinate outputs.
|
|
208
|
+
|
|
209
|
+
### `Spritesheet` (`qgame.Spritesheet`)
|
|
210
|
+
* **`get_image(x, y, w, h) -> Image`**
|
|
211
|
+
Crops segment coordinate.
|
|
212
|
+
* **`parse_grid(tile_width, tile_height, margin=0, spacing=0) -> list[Image]`**
|
|
213
|
+
Slices uniform sheets.
|
|
214
|
+
* **`parse_atlas(json_path) -> dict[str, Image]`**
|
|
215
|
+
Loads TexturePacker configuration sheets.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
# 中文参考文档
|
|
221
|
+
|
|
222
|
+
## 安装与运行演示
|
|
223
|
+
如果通过 setuptools 安装了库,可以在终端直接运行演示:
|
|
224
|
+
```bash
|
|
225
|
+
run-qgame-examples
|
|
226
|
+
```
|
|
227
|
+
或作为模块运行:
|
|
228
|
+
```bash
|
|
229
|
+
python -m qgame
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 核心模块 (`qgame`)
|
|
235
|
+
|
|
236
|
+
### 全局函数
|
|
237
|
+
* **`init()`**
|
|
238
|
+
初始化 PySide6 的 Application 上下文。在一切绘制开始前必须最先调用。
|
|
239
|
+
* **`set_settings(*, width: int, height: int, title: str = "QGame") -> QImage`**
|
|
240
|
+
设定游戏的分辨率和主窗口标题。返回渲染使用的主画布(`QImage` 实例)。
|
|
241
|
+
|
|
242
|
+
### `window` (窗口实例)
|
|
243
|
+
* **`update()`**
|
|
244
|
+
刷新渲染画面并接收系统事件,在游戏主循环中每帧调用一次。
|
|
245
|
+
* **`set_title(title: str)`**
|
|
246
|
+
动态更改窗口标题。
|
|
247
|
+
* **`set_icon(icon_path: str)`**
|
|
248
|
+
加载并应用窗口图标。
|
|
249
|
+
* **`set_size(width: int, height: int) -> QImage`**
|
|
250
|
+
动态调整画面虚拟画布尺寸。
|
|
251
|
+
* **`toggle_fullscreen()`**
|
|
252
|
+
在全屏模式与窗口模式之间无缝切换。
|
|
253
|
+
* **`show_cursor(visible: bool)`**
|
|
254
|
+
显示或隐藏系统鼠标光标。
|
|
255
|
+
|
|
256
|
+
### `events` (事件获取)
|
|
257
|
+
* **`get() -> List[Event]`**
|
|
258
|
+
取出事件队列中所有的挂起事件。
|
|
259
|
+
|
|
260
|
+
### `Clock` (时钟类)
|
|
261
|
+
* **`tick(fps: int) -> float`**
|
|
262
|
+
锁定帧率并返回两帧之间的间隔时长 `dt`(单位:秒)。
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 输入处理 (`qgame.keyboard`, `qgame.mouse`)
|
|
267
|
+
|
|
268
|
+
### `keys` (按键常量映射)
|
|
269
|
+
封装了 PySide6 常用的按键码,如 `keys.W`、`keys.ESCAPE`、`keys.UP`、`keys.SPACE`、`keys.SHIFT` 等。
|
|
270
|
+
|
|
271
|
+
### `keyboard` (键盘状态侦测)
|
|
272
|
+
* **`is_pressed(key_code: int) -> bool`**
|
|
273
|
+
检测某按键当前是否正被按住。
|
|
274
|
+
|
|
275
|
+
### `mouse` (鼠标状态侦测)
|
|
276
|
+
* **`get_pos() -> tuple[int, int]`**
|
|
277
|
+
获取鼠标在虚拟画布分辨率上的相对坐标点 `(x, y)`。
|
|
278
|
+
* **`is_pressed(button: int) -> bool`**
|
|
279
|
+
检测某鼠标键当前是否被按住(传参例如 `mouseButtons.LEFT`、`mouseButtons.RIGHT` 等)。
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 2D 绘图与渲染 (`qgame.graphics`)
|
|
284
|
+
|
|
285
|
+
### `Image` (图像类)
|
|
286
|
+
代表一份缓存在内存中的图片资源。
|
|
287
|
+
* **`__init__(source: str | Image | QImage)`**
|
|
288
|
+
接收文件路径、其他图片实例或原生 QImage。在克隆已有的图片时为 0 IO 机制。
|
|
289
|
+
* **`resize(width: int, height: int, keep_aspect: bool = False)`**
|
|
290
|
+
重置本张图片分辨率。
|
|
291
|
+
* **`scale(factor_x: float, factor_y: float = None, keep_aspect: bool = True)`**
|
|
292
|
+
缩放图片比例。
|
|
293
|
+
* **`rotate(angle: float)`**
|
|
294
|
+
旋转图片(单位度,顺时针)。
|
|
295
|
+
* **`flip(horizontal: bool = True, vertical: bool = False)`**
|
|
296
|
+
翻转(支持左右、上下镜像翻转)。
|
|
297
|
+
* **`reset()`**
|
|
298
|
+
重置图像为没有缩放和旋转前的最初原始数据。
|
|
299
|
+
* **`width` / `height`**
|
|
300
|
+
返回当前最新长宽数值的属性。
|
|
301
|
+
|
|
302
|
+
### `Rect` (矩形容器)
|
|
303
|
+
* **`__init__(x, y, width, height)`**
|
|
304
|
+
高精度浮点数矩形存储容器。
|
|
305
|
+
* **`center` / `centerx` / `centery`**
|
|
306
|
+
可快速读取和对齐的中心点属性。
|
|
307
|
+
* **`collidepoint(pos: tuple) -> bool`**
|
|
308
|
+
判断坐标点是否在该矩形内。
|
|
309
|
+
|
|
310
|
+
### `draw` (渲染静态方法集合)
|
|
311
|
+
* **`fill(canvas, color)`**
|
|
312
|
+
以指定颜色 `(r, g, b)` 填充重刷画布背景。
|
|
313
|
+
* **`rect(canvas, color, rect, width=0)`**
|
|
314
|
+
绘制空心/实心矩形(`width=0` 时为实心填充)。
|
|
315
|
+
* **`rounded_rect(canvas, color, rect, radius, width=0)`**
|
|
316
|
+
绘制高画质抗锯齿圆角矩形。
|
|
317
|
+
* **`circle(canvas, color, center, radius, width=0)`**
|
|
318
|
+
绘制抗锯齿空心/实心圆形。
|
|
319
|
+
* **`ellipse(canvas, color, rect, width=0)`**
|
|
320
|
+
绘制包围圈内的椭圆形。
|
|
321
|
+
* **`line(canvas, color, start, end, width=1)`**
|
|
322
|
+
绘制抗锯齿直线。
|
|
323
|
+
* **`text(canvas, text, coords, size=16, color=(255,255,255), font_name="")`**
|
|
324
|
+
高渲染帧率下的抗锯齿文本绘制。
|
|
325
|
+
* **`image(canvas, img, coords, center=False, src_rect=None, opacity=1.0)`**
|
|
326
|
+
快速渲染图面,支持居中校对、局部区域裁剪(`src_rect`)以及透明度叠加。
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 碰撞检测系统 (`qgame.collision`)
|
|
331
|
+
|
|
332
|
+
### 函数方法
|
|
333
|
+
* **`check_rect(rect1: tuple, rect2: tuple) -> bool`**
|
|
334
|
+
检测两个矩形是否相交。
|
|
335
|
+
* **`check_circle(pos1, r1, pos2, r2) -> bool`**
|
|
336
|
+
检测两圆碰撞冲突。
|
|
337
|
+
* **`check_rect_circle(rect, center, radius) -> bool`**
|
|
338
|
+
检测圆与矩形是否相碰。
|
|
339
|
+
* **`check_point_rect(point, rect) -> bool`**
|
|
340
|
+
检测点是否在矩形内。
|
|
341
|
+
* **`check_point_circle(point, center, radius) -> bool`**
|
|
342
|
+
检测点是否在圆形内。
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## 音频控制系统 (`qgame.audio`)
|
|
347
|
+
|
|
348
|
+
### `Sound` (音效类)
|
|
349
|
+
用于快速播放时间短、反复调用的音效(支持扩展如 `.wav`)。
|
|
350
|
+
* **`play()`, `stop()`**
|
|
351
|
+
* **`set_volume(volume: float)`** (范围 0.0 - 1.0)
|
|
352
|
+
* **`set_loop(loop: bool)`**
|
|
353
|
+
|
|
354
|
+
### `Music` (背景音乐类)
|
|
355
|
+
用于低资源播发大型的背景音乐文件(支持机制如 `.mp3`)。
|
|
356
|
+
* **`play(loop: bool = True)`, `pause()`, `unpause()`, `stop()`**
|
|
357
|
+
* **`set_volume(volume: float)`** (范围 0.0 - 1.0)
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## UI 输入控件 (`qgame.ui`)
|
|
362
|
+
|
|
363
|
+
### `TextBox` (可自适应输入类)
|
|
364
|
+
提供游戏内置的多行或单行输入控制。完美支持系统的拼音输入法、光标闪烁、全选、复制粘贴,并支持全屏窗口尺寸改变时的相对比例缩放。
|
|
365
|
+
* **`__init__(x, y, w, h, placeholder="", multi_line=True)`**
|
|
366
|
+
* **`set_theme(bg_color, text_color, border_color, border_radius=6, font_size=14)`**
|
|
367
|
+
* **`get_text() -> str`, `set_text(text: str)`, `clear()`**
|
|
368
|
+
* **`set_focus()`, `set_visible(visible: bool)`**
|
|
369
|
+
* **`set_position(x, y)`, `set_size(w, h)`**
|
|
370
|
+
* **`destroy()`**
|
|
371
|
+
将输入组件彻底从画布卸载销毁并自动回收内存,杜绝视觉残留问题。
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## 游戏场景结构 (`qgame.scene`)
|
|
376
|
+
|
|
377
|
+
### `Scene` (场景基类)
|
|
378
|
+
实现各种游戏阶段(如 `MenuScene` 菜单场景、`PlayScene` 核心玩法场景)。
|
|
379
|
+
* **`on_enter(*args, **kwargs)`**
|
|
380
|
+
进入场景时调用。
|
|
381
|
+
* **`on_exit()`**
|
|
382
|
+
退出场景时调用。由 `add_ui()` 挂载的所有组件,在此阶段都会顺便全自动销毁。
|
|
383
|
+
* **`handle_event(event)`, `update(dt)`, `draw(canvas)`**
|
|
384
|
+
* **`add_ui(widget)`**
|
|
385
|
+
绑定一个 UI 控件到当前的场景生命周期中。
|
|
386
|
+
|
|
387
|
+
### `scene_manager` (管理器)
|
|
388
|
+
* **`switch(new_scene_instance, *args, **kwargs)`**
|
|
389
|
+
* **`handle_event(event)`, `update(dt)`, `draw(canvas)`**
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## 进阶引擎工具
|
|
394
|
+
|
|
395
|
+
### `Camera` 摄像机对象
|
|
396
|
+
* **`follow(target, lerp_speed)`, `update(dt)`**
|
|
397
|
+
平滑追踪绑定物体。
|
|
398
|
+
* **`set_deadzone(w, h)`**
|
|
399
|
+
设置相机死区,使其在此长宽区域移动时背景不平移。
|
|
400
|
+
* **`set_bounds(min_x, min_y, max_x, max_y)`**
|
|
401
|
+
配置大地图边界限制。
|
|
402
|
+
* **`shake(intensity, duration)`**
|
|
403
|
+
对相机触发一定强度和时长的抖动效果(震屏)。
|
|
404
|
+
* **`apply(coord_or_rect)`**
|
|
405
|
+
将游戏内世界坐标在渲染时映射成屏幕的最终像素点配置。
|
|
406
|
+
|
|
407
|
+
### `Spritesheet` 雪碧图包分析器
|
|
408
|
+
* **`get_image(x, y, w, h) -> Image`**
|
|
409
|
+
抓取大图中的单个位置物体图像。
|
|
410
|
+
* **`parse_grid(tile_width, tile_height, margin=0, spacing=0) -> list[Image]`**
|
|
411
|
+
规则网格划分图层(适合帧动画等)。
|
|
412
|
+
* **`parse_atlas(json_path) -> dict[str, Image]`**
|
|
413
|
+
解析来自 TexturePacker 的 JSON 配置文件字典。
|
|
414
|
+
```
|