Metadata-Version: 2.4
Name: WaliGame
Version: 2026.11.11
Summary: WaliGame - a Python game engine designed for educational purposes
Author-email: WaliGame Project <waligame@example.com>
Maintainer-email: WaliGame Maintainers <waligame@example.com>
License: MIT
Project-URL: PyPI, https://pypi.org/project/waligame/
Keywords: game,pygame,pymunk,education,game-engine
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Education
Classifier: Topic :: Games/Entertainment
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Environment :: MacOS X
Classifier: Environment :: Win32 (MS Windows)
Classifier: Environment :: X11 Applications
Requires-Python: >=3.8.1
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: pygame>=2.5.0
Requires-Dist: pymunk>=6.5.0
Requires-Dist: pytmx>=3.32
Provides-Extra: dev
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: flake8>=6.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: twine>=4.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.4; extra == "docs"
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
Dynamic: license-file

# 🎮 WaliGame 2026.11.11

> 面向少儿编程的 2D 游戏引擎。基座来自 **Walimaker 4.0.2**（MIT），
> 在其工程化架构上合并了 2026.11.1 的教学功能，并重命名为 **WaliGame**。
> 游戏代码里使用 `import waligame` / `from waligame import *`。
>
> 版本记录：`VERSION_LOG.md`（每次更新必须升版本号并记录）。

完整 API 参考见 `WaliGame API 文档.md`（安装包内）。

## 安装

```bash
# 本地 wheel
python -m pip install "waligame-2026.11.6-py3-none-any.whl"

# 依赖
python -m pip install "pygame>=2.5.0" "pymunk>=6.5.0" "pytmx>=3.32"
```

> `pymunk` 必须 **6.5+**（4.0.2 的物理/类型基础）；`pygame` 2.5+。

> **2026.11.6 安装器会先检测旧包**：`Walimaker`（含 2026.11.1 / 上游 4.0.2）
> 和最早的 `WalimakerPythonGameEngine`（2023.8.1）。
> 如果检测到，会询问是否卸载；选择“不卸载”会直接退出，不会安装 WaliGame。
> 选择“卸载”会先卸载旧包，再安装 WaliGame。

## 第一个游戏

```python
import waligame

waligame.setup(800, 600)
waligame.title("我的第一个 WaliGame 游戏")

player = waligame.Character("player.png", size=(40, 60), tag="player")
player.goto(0, 0)

while True:
    if waligame.key_pressed(waligame.K_RIGHT):
        player.velocity = (250, player.velocity[1])
    elif waligame.key_pressed(waligame.K_LEFT):
        player.velocity = (-250, player.velocity[1])
    else:
        player.velocity = (0, player.velocity[1])
    waligame.update()
```

也可以 `from waligame import *`，和旧版 Walimaker 的写法一致。

## 这一版保留/新增了什么

在 **4.0.2 的底子**上：

- `Object → GameObject → Character/Sensor/Wall/Mouse` 继承链
- 多世界 `World`、`setup(..., world=w2)`、`update(world=w2)`
- `ResourceManager`：图片 LRU、弱引用 mask 缓存、`preload()`
- 60 FPS + 固定物理步长累加器 + 防隧穿子步
- 相机 `shake` / `deadzone` / `zoom_to` / 平滑缩放
- 约束 `connect()` / `Spring()`、`TiledMap.create_objects()`
- 中文报错助手 `error_help`、字体回退 `fonts`
- 类型信息 `py.typed`、MIT 许可、src 布局

在 **2026.11.1 的教学功能**上：
- 兼容旧课件的星号导入：`from waligame import *` 也会带出 `random` / `time` / `os` / `math` / `sys` / `pygame`（旧 Walimaker 课件常用 `random.randint` 而不写 import）
- 主包内置 `Walimaker` 别名：安装 WaliGame 后，`from Walimaker import *` 等价于 `from waligame import *`。

- `every(秒, 函数)` / `after(秒, 函数)` / `clear_timers()` 计时器
- `tag="zombie"` + `find_all()` / `find()` / `collide_tag()`
- `clone()` 复制对象（模板做子弹/僵尸）
- `follow(目标, speed, stop)` / `stop_follow()`
- `on_screen` 判断是否在镜头内
- `Score` / `Label` 屏幕 HUD
- 没有物理体的对象也支持 `velocity`（像素/帧）
- DPI 适配默认关闭：`setup(宽, 高)`；需要 Windows 物理像素时 `setup(..., dpi_aware=True)`
- 控制台：隐藏 pygame/pymunk 横幅、第一帧打印
  `【欢迎使用 WaliGame 2026.11.6】游戏启动成功！`
- `get_angle` 兼容别名（新代码用 `angle`）
- 鼠标“按住”状态每帧维护：松手发生在滑梯/动画等没有查询鼠标的状态里，也不会再卡住
- 音频失败只警告一次并静音继续：`bgmusic` / `play_snd` / `music_*` 不再因没有音频设备而崩溃
- `key_just_pressed` / `key_just_released` 默认“任意一个”，
  `require_all=True` 恢复“全部按下”

## 典型用法

### 计时器 + 标签 + 碰撞

```python
import waligame
from waligame import *

setup(900, 600)

player = Character("player.png", size=(40, 60), tag="player")
zombie = Character("zombie.png", size=(40, 80), tag="zombie")
score = Score()

def shoot():
    bullet = Character("pea.png", tag="bullet")
    bullet.goto(player.pos)
    bullet.velocity = (8, 0)

every(1.2, shoot)

while True:
    for bullet in find_all("bullet"):
        hit = bullet.collide_tag("zombie")
        if hit:
            hit.kill()
            bullet.kill()
            score.add(10)
        elif not bullet.on_screen:
            bullet.kill()
    update()
```

### 复制模板

```python
template = Character("pea.png")
pea = template.clone()
pea.goto(player.pos)
pea.velocity = (8, 0)
```

### 没有图片也能创建角色

不准备图片也能直接创建默认角色：

```python
player = Character(size=40)              # 内置白色圆形
box = Character(size=40, shape="square") # 内置白色方形
```

- 不传 `imgs` 时自动使用包内 `static/circle.png`
- `shape="square"` / `"方形"` 使用 `static/square.png`
- 默认贴图是白色，可用 `player.color = (255, 80, 80, 255)` 染色
- 不传 `size` 时只有贴图、没有刚体；要碰撞请传 `size`

### 没有物理体的角色

```python
bullet = Character("pea.png")   # 不传 size
bullet.velocity = (8, 0)         # 每帧 8 像素，不受重力，不会被推
```

### 多世界

```python
from waligame import World, setup, update

w2 = World()
setup(800, 600, world=w2)
update(world=w2)
```

## 通用联机房间

从 2026.11.6 起，WaliGame 提供通用局域网房间，不只为石头剪刀布写：

```python
from waligame import *

net = 联机("我的游戏", 最多人数=4)

if not net.大厅():
    raise SystemExit

setup(800, 600)

while True:
    for msg in net.收到():
        print(msg["玩家"], msg["内容"])

    net.发送({"type": "操作", "data": ...})
    update()
```

- `大厅()`：创建/查找房间、密码、玩家列表、房主开始；返回 `True` 表示开始。
- 创建房间可设置：房间号/房间名、最多人数、玩家名、密码。
- `net.是房主`、`net.玩家列表`、`net.我的编号`。
- `net.发送()` 发给其他玩家；`net.收到()` 返回 `{"玩家", "编号", "内容"}`。
- `大厅()` 要在 `setup()` 之前调用；大厅结束后再 `setup()`。
- 房主大厅会显示 `房间地址：IP:端口`，朋友找不到房间时用“直接输入 IP”。
- 只负责房间和消息转发；游戏规则由孩子写。
- `联机(..., 允许中途加入=True)` 支持游戏开始后加入；本版另附 `彩色食材大作战.py` 示例。

## 旧写法兼容

从 **2026.11.6** 起，`Walimaker` 别名直接内置在主 wheel 里：

```python
from Walimaker import *
# 等价于 from waligame import *
```

安装 WaliGame 就同时有了 `waligame` 和 `Walimaker`，不需要再单独安装 compat 包。

注意：如果环境里还装着旧的 `walimaker`（2026.11.1 或 PyPI 4.0.2），它的
`Walimaker/` 包目录会遮住别名；请先卸载旧包：

```powershell
python -m pip uninstall -y walimaker
```

## 音频

- `setup()` 会尝试 48000/44100、2/1 声道打开 mixer；全部失败时只打印一次
  `【WaliGame 音频提示】`，游戏继续静音运行。
- `bgmusic()` 返回 `True/False`；`play_snd()` / `music_*()` 在音频不可用时安全跳过。
- 需要判断音频状态时用：
  ```python
  from waligame import audio_available, ensure_audio, audio_info
  if audio_available:      # 动态反映当前 mixer 状态
      bgmusic("bgm.mp3")
  ensure_audio()           # 再尝试打开一次
  print(audio_info())      # 诊断信息
  ```
- 安装包的 `安装完在这里进行测试\音频诊断.py` 可打印 SDL 设备并尝试多种格式。

## 与 Walimaker 4.0.2 的差异

- 包名：`waligame`；发行名：`WaliGame`；版本：`2026.11.6`
- 新增上面列出的计时器、tag、clone、follow、on_screen、Score/Label、
  无物理体 velocity、DPI、欢迎语
- `get_angle` 保留为 `angle` 的兼容别名
- `key_just_pressed` 默认改为“任意一个”
- 控制台默认干净（pygame/pymunk 横幅、libpng 警告）

## 许可证与来源

WaliGame 基于 **Walimaker 4.0.2**（MIT，Copyright (c) 2026 Walimaker Project
Contributors）做了大幅修改与扩展。原始 MIT 许可证保留在 `LICENSE`，
来源说明见 `NOTICE`。4.0.2 的原始 README 保留为 `README_4.0.2.md` 供对照。

<!-- API_REFERENCE_START -->
# WaliGame 完整 API 参考

> 版本：`2026.11.11`  
> 由 `tools/generate_api_reference.py` 从 `waligame.__all__` 自动生成。

## 使用方式

```python
from waligame import *

setup(800, 600)
player = Character(size=40)          # 无图片时使用内置圆形
player.goto(0, 0)

while True:
    update()
```

> 下面的签名省略了方法定义中的 `self` / `cls`。
> 继承成员在基类章节中列出，子类只列自己新增的成员。
> pygame 的 `K_*`、`KEYDOWN`、`MOUSEBUTTONDOWN` 等常量也由 `from waligame import *` 导出，数量太多，未逐条展开。

## 基础与生命周期

### `setup`

```python
setup(*size: int, world: Optional[waligame.config.World] = None, dpi_aware: bool = False) -> 'Screen'
```

初始化一个世界：窗口、相机、精灵组、物理空间。

`world=None`（默认）初始化默认世界 `global_var`，保持既有用法不变；
传入自己创建的世界即可获得互不干扰的第二套状态：
`w2 = World(); setup(800, 600, world=w2)`。
`dpi_aware` 默认 False；需要 Windows 按物理像素显示时手动传 True。


### `update`

```python
update(world: Optional[waligame.config.World] = None) -> None
```

推进一个世界一帧（默认世界可省略参数）。


### `title`

```python
title(title: str) -> None
```


### `done`

```python
done(world: Optional[waligame.config.World] = None) -> None
```


### `save_screen`

```python
save_screen(name: str, world: Optional[waligame.config.World] = None) -> None
```


### `bgpic`

```python
bgpic(img, world=None)
```

把一张图片 / Surface / TileMap 作为背景铺上，并把相机尺寸设成它的大小。

* 传 ``TiledMap``：用 ``TiledMapStrategy`` 把整张地图渲染成一个精灵。
  历史实现只改相机尺寸、并不会渲染地图（想显示必须绕道 ``Character(tiledmap)``），现已修正。
* 传图片路径 / ``Surface``：按普通精灵渲染。

返回背景对象，便于后续移动或销毁（例如 ``bgpic("bg.png").kill()``）。


### `debug`

```python
debug(world=None)
```


### `set_depth`

```python
set_depth(i: int = 1) -> str
```

返回向上 i 级的相对路径字符串（例如 set_depth(2) -> "../../"）。

**行为变更**：历史版本会直接 ``os.chdir()``——库函数擅自改变调用进程的工作目录，
之后所有相对路径（含资源加载）都会跟着漂移，极难排查。现在只返回路径字符串，
并发出一次 ``DeprecationWarning``；确实需要切换目录时请在自己的代码里显式：

.. code-block:: python

    import os
    os.chdir(set_depth(2))


## 对象与角色

### `Object`

```python
Object(world: Optional[waligame.config.World] = None) -> None
```

所有游戏对象的根类（对齐 Unity 的 ``Object`` → ``GameObject`` 链条）。

负责两件事：

* **状态**：缓存坐标 ``pos``、旋转 ``rot``、缩放 ``scl``、生命周期 ``alive``，
  以及三个可选组件——精灵（显示层）、刚体（物理层）、瓦片刚体（地图对象层）；
* **组件属性代理**：颜色 / 可见性 / 图层 / 速度 / 质量 … 这些接口只读写上面的组件槽位，
  不需要任何玩法状态，因此也放在根类。组件不存在时不会抛 ``AttributeError``，
  而是给一次性中英双语提示并返回中性值（见 :meth:`_need_sprite` / :meth:`_warn_missing_body`）。

组件用 ``set_parent(self)`` 反向持有宿主；物理层每帧通过 :meth:`sync_pos` /
:meth:`sync_rot` 单向同步显示状态。子类 :class:`GameObject` 在此之上提供行为与交互接口。

| 成员 | 类型 | 签名 |
|---|---|---|
| `alpha` | property | — |
| `angular_velocity` | property | — |
| `apply_force` | method | `(x, *y)` |
| `blue` | property | — |
| `body` | property | — |
| `body_scale` | method | `(scalex, scaley)` |
| `color` | property | — |
| `elasticity` | property | — |
| `flipx` | method | `(h)` |
| `flipy` | method | `(v)` |
| `friction` | property | — |
| `green` | property | — |
| `height` | property | — |
| `hide` | method | `()` |
| `kill` | method | `()` |
| `layer` | property | — |
| `mass` | property | — |
| `move_to_back` | method | `()` |
| `move_to_front` | method | `()` |
| `pos` | property | — |
| `red` | property | — |
| `rot` | property | — |
| `scale` | method | `(scalex, scaley=None)` |
| `scl` | property | — |
| `set_body` | method | `(body)` |
| `set_sprite` | method | `(sprite)` |
| `set_tiledmap_bodies` | method | `(tiledmap_bodies)` |
| `shift_by` | method | `(delta)` |
| `show` | method | `()` |
| `sprite` | property | — |
| `sync_pos` | method | `(pos)` |
| `sync_rot` | method | `(rot)` |
| `tiledmap_bodies` | property | — |
| `velocity` | property | — |
| `visible` | property | — |
| `width` | property | — |
| `x` | property | — |
| `y` | property | — |

#### `Object.alpha`

属性（property）。

#### `Object.angular_velocity`

属性（property）。

#### `Object.apply_force`

```python
apply_force(x, *y)
```

#### `Object.blue`

属性（property）。

#### `Object.body`

属性（property）。

#### `Object.body_scale`

```python
body_scale(scalex, scaley)
```

#### `Object.color`

属性（property）。

#### `Object.elasticity`

属性（property）。

#### `Object.flipx`

```python
flipx(h)
```

#### `Object.flipy`

```python
flipy(v)
```

#### `Object.friction`

属性（property）。

#### `Object.green`

属性（property）。

#### `Object.height`

属性（property）。

#### `Object.hide`

```python
hide()
```

#### `Object.kill`

```python
kill()
```

销毁对象：销毁三个组件、清空槽位、置 ``alive = False``，最后回调 :meth:`_on_kill`。

#### `Object.layer`

属性（property）。

#### `Object.mass`

属性（property）。

#### `Object.move_to_back`

```python
move_to_back()
```

#### `Object.move_to_front`

```python
move_to_front()
```

#### `Object.pos`

属性（property）。

#### `Object.red`

属性（property）。

#### `Object.rot`

属性（property）。

#### `Object.scale`

```python
scale(scalex, scaley=None)
```

#### `Object.scl`

属性（property）。

#### `Object.set_body`

```python
set_body(body)
```

#### `Object.set_sprite`

```python
set_sprite(sprite)
```

#### `Object.set_tiledmap_bodies`

```python
set_tiledmap_bodies(tiledmap_bodies)
```

#### `Object.shift_by`

```python
shift_by(delta)
```

按增量直接位移，**不改变速度**（这是它与 ``pos`` setter 的区别）。

内部按键位移 / 滑行动画用它：只挪位置，重力等已有速度继续生效。
直接写 ``obj.pos = ...`` / ``goto()`` 则视为瞬移，会清零速度。

#### `Object.show`

```python
show()
```

#### `Object.sprite`

属性（property）。

#### `Object.sync_pos`

```python
sync_pos(pos)
```

由物理层同步显示坐标（只改缓存）。

物理每帧把刚体位置回写自身会触发无意义的 reindex_shapes_for_body（宽相重排），
因此这里既不写回刚体、也不清速度，只更新缓存坐标。

#### `Object.sync_rot`

```python
sync_rot(rot)
```

由物理层同步显示角度（只改缓存与重绘标记）。

与 ``rot`` setter 的区别：不反向写回刚体 / 瓦片刚体，避免每帧
reindex_shapes_for_body（宽相重排）。与 :meth:`sync_pos` 对称。

#### `Object.tiledmap_bodies`

属性（property）。

#### `Object.velocity`

属性（property）。

#### `Object.visible`

属性（property）。

#### `Object.width`

属性（property）。

#### `Object.x`

属性（property）。

#### `Object.y`

属性（property）。


### `GameObject`

```python
GameObject(imgs: Any = None, size: Any = None, body_type: Any = 1, sensor: bool = False, world: Optional[waligame.config.World] = None, tag: Any = None) -> None
```

继承：`Object`, `AnimationMixin`, `CollisionMixin`, `MouseInputMixin`

游戏对象基类（4.0 之前叫 `NewGameObject`）。

从根类 :class:`Object` 继承坐标、组件槽位（`sprite` / `body` / `tiledmap_bodies`）
与生命周期，再通过 mixin 组合三组职责（动画 / 碰撞 / 鼠标交互，见模块 docstring）；
本类自身保留位置、方向、变换、颜色、可见性、图层、音效、对话、生命期与物理属性等
核心对象模型代码。

| 成员 | 类型 | 签名 |
|---|---|---|
| `angle` | property | — |
| `backward` | method | `(d: float) -> None` |
| `clone` | method | `()` |
| `collide` | method (mixin) | `(other: Any) -> Any` |
| `collide_tag` | method | `(tag)` |
| `dir` | property | — |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `face_to` | method | `(x, *y, VEC=False)` |
| `follow` | method | `(target, speed=2, stop=0)` |
| `forward` | method | `(d: float) -> None` |
| `frame` | property (mixin) | — |
| `get_angle` | property | — |
| `get_mouse_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_released` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_upon` | method (mixin) | `() -> bool` |
| `goto` | method | `(x: Any, *y: Any) -> None` |
| `left` | method | `(a)` |
| `on_screen` | property | — |
| `play_anim` | method (mixin) | `() -> None` |
| `play_snd` | method | `(snd=None, volume=None)` |
| `right` | method | `(a)` |
| `rotate_direction` | method | `(rot)` |
| `rotate_image` | method | `(rot)` |
| `say` | method | `(text: Any = None, textColor: Any = (0, 0, 0)) -> None` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_angle` | method | `(angle)` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_next_state` | method (mixin) | `(state: str, next_state: str) -> None` |
| `set_start_func` | method (mixin) | `(state, func)` |
| `set_volume` | method | `(volume)` |
| `slide_to` | method | `(pos, v=1)` |
| `state` | property (mixin) | — |
| `stop_anim` | method (mixin) | `() -> None` |
| `stop_follow` | method | `()` |
| `update` | method | `()` |

#### `GameObject.angle`

属性（property）。

朝向角度（度，float）。

与 `rot` 的区别：`angle` 由朝向向量 `dir` 算出，`rot` 是贴图 / 刚体的旋转角。
4.0 之前这个方法叫 `get_angle`，且返回保留一位小数的**字符串**（形如 "12.3"）；
现在改名为 `angle` 并返回 float，需要格式化请自行 `round()`。

#### `GameObject.backward`

```python
backward(d: float) -> None
```

#### `GameObject.clone`

```python
clone()
```

复制一个自己（图片/大小/位置/缩放/旋转/颜色/tag/物理属性）。

#### `GameObject.collide`

```python
collide(other: Any) -> Any
```

#### `GameObject.collide_tag`

```python
collide_tag(tag)
```

和某个 tag 的任意对象碰撞，返回碰到的对象（没有就返回 None）。

#### `GameObject.dir`

属性（property）。

#### `GameObject.distance`

```python
distance(other: Any) -> float
```

#### `GameObject.dt`

属性（property）。

#### `GameObject.face_to`

```python
face_to(x, *y, VEC=False)
```

#### `GameObject.follow`

```python
follow(target, speed=2, stop=0)
```

每帧朝 target（对象或坐标）移动 speed，距离小于 stop 时停下。

#### `GameObject.forward`

```python
forward(d: float) -> None
```

#### `GameObject.frame`

属性（property）。

#### `GameObject.get_angle`

属性（property）。

兼容旧代码的 `get_angle`；新代码用 `angle`。

#### `GameObject.get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
```

#### `GameObject.get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
```

#### `GameObject.get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
```

#### `GameObject.get_mouse_upon`

```python
get_mouse_upon() -> bool
```

#### `GameObject.goto`

```python
goto(x: Any, *y: Any) -> None
```

#### `GameObject.left`

```python
left(a)
```

#### `GameObject.on_screen`

属性（property）。

是否在摄像机可见范围内（用来清理飞出屏幕的子弹）。

#### `GameObject.play_anim`

```python
play_anim() -> None
```

#### `GameObject.play_snd`

```python
play_snd(snd=None, volume=None)
```

#### `GameObject.right`

```python
right(a)
```

#### `GameObject.rotate_direction`

```python
rotate_direction(rot)
```

#### `GameObject.rotate_image`

```python
rotate_image(rot)
```

#### `GameObject.say`

```python
say(text: Any = None, textColor: Any = (0, 0, 0)) -> None
```

#### `GameObject.separate`

```python
separate(other: Any) -> bool
```

#### `GameObject.set_angle`

```python
set_angle(angle)
```

#### `GameObject.set_dt`

```python
set_dt(*args: Any) -> None
```

#### `GameObject.set_end_func`

```python
set_end_func(state, func)
```

#### `GameObject.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `GameObject.set_start_func`

```python
set_start_func(state, func)
```

#### `GameObject.set_volume`

```python
set_volume(volume)
```

#### `GameObject.slide_to`

```python
slide_to(pos, v=1)
```

#### `GameObject.state`

属性（property）。

#### `GameObject.stop_anim`

```python
stop_anim() -> None
```

#### `GameObject.stop_follow`

```python
stop_follow()
```

#### `GameObject.update`

```python
update()
```


### `NewGameObject`

```python
NewGameObject(imgs: Any = None, size: Any = None, body_type: Any = 1, sensor: bool = False, world: Optional[waligame.config.World] = None, tag: Any = None) -> None
```

继承：`Object`, `AnimationMixin`, `CollisionMixin`, `MouseInputMixin`

游戏对象基类（4.0 之前叫 `NewGameObject`）。

从根类 :class:`Object` 继承坐标、组件槽位（`sprite` / `body` / `tiledmap_bodies`）
与生命周期，再通过 mixin 组合三组职责（动画 / 碰撞 / 鼠标交互，见模块 docstring）；
本类自身保留位置、方向、变换、颜色、可见性、图层、音效、对话、生命期与物理属性等
核心对象模型代码。

| 成员 | 类型 | 签名 |
|---|---|---|
| `angle` | property | — |
| `backward` | method | `(d: float) -> None` |
| `clone` | method | `()` |
| `collide` | method (mixin) | `(other: Any) -> Any` |
| `collide_tag` | method | `(tag)` |
| `dir` | property | — |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `face_to` | method | `(x, *y, VEC=False)` |
| `follow` | method | `(target, speed=2, stop=0)` |
| `forward` | method | `(d: float) -> None` |
| `frame` | property (mixin) | — |
| `get_angle` | property | — |
| `get_mouse_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_released` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_upon` | method (mixin) | `() -> bool` |
| `goto` | method | `(x: Any, *y: Any) -> None` |
| `left` | method | `(a)` |
| `on_screen` | property | — |
| `play_anim` | method (mixin) | `() -> None` |
| `play_snd` | method | `(snd=None, volume=None)` |
| `right` | method | `(a)` |
| `rotate_direction` | method | `(rot)` |
| `rotate_image` | method | `(rot)` |
| `say` | method | `(text: Any = None, textColor: Any = (0, 0, 0)) -> None` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_angle` | method | `(angle)` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_next_state` | method (mixin) | `(state: str, next_state: str) -> None` |
| `set_start_func` | method (mixin) | `(state, func)` |
| `set_volume` | method | `(volume)` |
| `slide_to` | method | `(pos, v=1)` |
| `state` | property (mixin) | — |
| `stop_anim` | method (mixin) | `() -> None` |
| `stop_follow` | method | `()` |
| `update` | method | `()` |

#### `NewGameObject.angle`

属性（property）。

朝向角度（度，float）。

与 `rot` 的区别：`angle` 由朝向向量 `dir` 算出，`rot` 是贴图 / 刚体的旋转角。
4.0 之前这个方法叫 `get_angle`，且返回保留一位小数的**字符串**（形如 "12.3"）；
现在改名为 `angle` 并返回 float，需要格式化请自行 `round()`。

#### `NewGameObject.backward`

```python
backward(d: float) -> None
```

#### `NewGameObject.clone`

```python
clone()
```

复制一个自己（图片/大小/位置/缩放/旋转/颜色/tag/物理属性）。

#### `NewGameObject.collide`

```python
collide(other: Any) -> Any
```

#### `NewGameObject.collide_tag`

```python
collide_tag(tag)
```

和某个 tag 的任意对象碰撞，返回碰到的对象（没有就返回 None）。

#### `NewGameObject.dir`

属性（property）。

#### `NewGameObject.distance`

```python
distance(other: Any) -> float
```

#### `NewGameObject.dt`

属性（property）。

#### `NewGameObject.face_to`

```python
face_to(x, *y, VEC=False)
```

#### `NewGameObject.follow`

```python
follow(target, speed=2, stop=0)
```

每帧朝 target（对象或坐标）移动 speed，距离小于 stop 时停下。

#### `NewGameObject.forward`

```python
forward(d: float) -> None
```

#### `NewGameObject.frame`

属性（property）。

#### `NewGameObject.get_angle`

属性（property）。

兼容旧代码的 `get_angle`；新代码用 `angle`。

#### `NewGameObject.get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
```

#### `NewGameObject.get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
```

#### `NewGameObject.get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
```

#### `NewGameObject.get_mouse_upon`

```python
get_mouse_upon() -> bool
```

#### `NewGameObject.goto`

```python
goto(x: Any, *y: Any) -> None
```

#### `NewGameObject.left`

```python
left(a)
```

#### `NewGameObject.on_screen`

属性（property）。

是否在摄像机可见范围内（用来清理飞出屏幕的子弹）。

#### `NewGameObject.play_anim`

```python
play_anim() -> None
```

#### `NewGameObject.play_snd`

```python
play_snd(snd=None, volume=None)
```

#### `NewGameObject.right`

```python
right(a)
```

#### `NewGameObject.rotate_direction`

```python
rotate_direction(rot)
```

#### `NewGameObject.rotate_image`

```python
rotate_image(rot)
```

#### `NewGameObject.say`

```python
say(text: Any = None, textColor: Any = (0, 0, 0)) -> None
```

#### `NewGameObject.separate`

```python
separate(other: Any) -> bool
```

#### `NewGameObject.set_angle`

```python
set_angle(angle)
```

#### `NewGameObject.set_dt`

```python
set_dt(*args: Any) -> None
```

#### `NewGameObject.set_end_func`

```python
set_end_func(state, func)
```

#### `NewGameObject.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `NewGameObject.set_start_func`

```python
set_start_func(state, func)
```

#### `NewGameObject.set_volume`

```python
set_volume(volume)
```

#### `NewGameObject.slide_to`

```python
slide_to(pos, v=1)
```

#### `NewGameObject.state`

属性（property）。

#### `NewGameObject.stop_anim`

```python
stop_anim() -> None
```

#### `NewGameObject.stop_follow`

```python
stop_follow()
```

#### `NewGameObject.update`

```python
update()
```


### `Character`

```python
Character(imgs: Any = None, size: Any = None, world: Optional[waligame.config.World] = None, tag: Any = None, shape: Any = None) -> None
```

继承：`GameObject`

可以通过代码控制、并参与物理的角色。

.. important::

    想让角色**受重力、能碰撞**，必须同时满足两点：

    1. 创建时传 ``size`` —— 例如 ``Character(图片, size=(32, 32))``（矩形）或
       ``Character(图片, size=16)``（半径 16 的圆）。**只传图片不会创建刚体**，
       此时重力/速度/冲量都不生效（框架会给一次中文提示）；
    2. 调用 ``set_gravity(0, -1200)`` —— ``setup()`` 之后默认重力是 ``(0, 0)``（零重力）。

如果没有图片，可以省略第一个参数：``Character(size=40)`` 会自动使用内置白色
圆形贴图；``Character(size=40, shape="square")`` 使用内置方形贴图。

| 成员 | 类型 | 签名 |
|---|---|---|
| `collide` | method (mixin) | `(other: Any) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `get_mouse_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_released` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_upon` | method (mixin) | `() -> bool` |
| `play_anim` | method (mixin) | `() -> None` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_next_state` | method (mixin) | `(state: str, next_state: str) -> None` |
| `set_start_func` | method (mixin) | `(state, func)` |
| `state` | property (mixin) | — |
| `stop_anim` | method (mixin) | `() -> None` |

#### `Character.collide`

```python
collide(other: Any) -> Any
```

#### `Character.distance`

```python
distance(other: Any) -> float
```

#### `Character.dt`

属性（property）。

#### `Character.frame`

属性（property）。

#### `Character.get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Character.get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Character.get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
```

#### `Character.get_mouse_upon`

```python
get_mouse_upon() -> bool
```

#### `Character.play_anim`

```python
play_anim() -> None
```

#### `Character.separate`

```python
separate(other: Any) -> bool
```

#### `Character.set_dt`

```python
set_dt(*args: Any) -> None
```

#### `Character.set_end_func`

```python
set_end_func(state, func)
```

#### `Character.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `Character.set_start_func`

```python
set_start_func(state, func)
```

#### `Character.state`

属性（property）。

#### `Character.stop_anim`

```python
stop_anim() -> None
```


### `Sensor`

```python
Sensor(imgs=None, size=None, world=None, tag=None)
```

继承：`GameObject`

游戏对象基类（4.0 之前叫 `NewGameObject`）。

从根类 :class:`Object` 继承坐标、组件槽位（`sprite` / `body` / `tiledmap_bodies`）
与生命周期，再通过 mixin 组合三组职责（动画 / 碰撞 / 鼠标交互，见模块 docstring）；
本类自身保留位置、方向、变换、颜色、可见性、图层、音效、对话、生命期与物理属性等
核心对象模型代码。

| 成员 | 类型 | 签名 |
|---|---|---|
| `collide` | method (mixin) | `(other: Any) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `get_mouse_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_released` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_upon` | method (mixin) | `() -> bool` |
| `play_anim` | method (mixin) | `() -> None` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_next_state` | method (mixin) | `(state: str, next_state: str) -> None` |
| `set_start_func` | method (mixin) | `(state, func)` |
| `state` | property (mixin) | — |
| `stop_anim` | method (mixin) | `() -> None` |

#### `Sensor.collide`

```python
collide(other: Any) -> Any
```

#### `Sensor.distance`

```python
distance(other: Any) -> float
```

#### `Sensor.dt`

属性（property）。

#### `Sensor.frame`

属性（property）。

#### `Sensor.get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Sensor.get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Sensor.get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
```

#### `Sensor.get_mouse_upon`

```python
get_mouse_upon() -> bool
```

#### `Sensor.play_anim`

```python
play_anim() -> None
```

#### `Sensor.separate`

```python
separate(other: Any) -> bool
```

#### `Sensor.set_dt`

```python
set_dt(*args: Any) -> None
```

#### `Sensor.set_end_func`

```python
set_end_func(state, func)
```

#### `Sensor.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `Sensor.set_start_func`

```python
set_start_func(state, func)
```

#### `Sensor.state`

属性（property）。

#### `Sensor.stop_anim`

```python
stop_anim() -> None
```


### `Wall`

```python
Wall(imgs=None, size=None, world=None, tag=None)
```

继承：`GameObject`

墙壁,无法运动的物体

| 成员 | 类型 | 签名 |
|---|---|---|
| `collide` | method (mixin) | `(other: Any) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `get_mouse_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_released` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_upon` | method (mixin) | `() -> bool` |
| `play_anim` | method (mixin) | `() -> None` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_next_state` | method (mixin) | `(state: str, next_state: str) -> None` |
| `set_start_func` | method (mixin) | `(state, func)` |
| `state` | property (mixin) | — |
| `stop_anim` | method (mixin) | `() -> None` |
| `velocity` | property | — |

#### `Wall.collide`

```python
collide(other: Any) -> Any
```

#### `Wall.distance`

```python
distance(other: Any) -> float
```

#### `Wall.dt`

属性（property）。

#### `Wall.frame`

属性（property）。

#### `Wall.get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Wall.get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Wall.get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
```

#### `Wall.get_mouse_upon`

```python
get_mouse_upon() -> bool
```

#### `Wall.play_anim`

```python
play_anim() -> None
```

#### `Wall.separate`

```python
separate(other: Any) -> bool
```

#### `Wall.set_dt`

```python
set_dt(*args: Any) -> None
```

#### `Wall.set_end_func`

```python
set_end_func(state, func)
```

#### `Wall.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `Wall.set_start_func`

```python
set_start_func(state, func)
```

#### `Wall.state`

属性（property）。

#### `Wall.stop_anim`

```python
stop_anim() -> None
```

#### `Wall.velocity`

属性（property）。


### `Mouse`

```python
Mouse(imgs: Any = None, world: Optional[waligame.config.World] = None, tag: Any = None) -> None
```

继承：`Character`

可以通过代码控制、并参与物理的角色。

.. important::

    想让角色**受重力、能碰撞**，必须同时满足两点：

    1. 创建时传 ``size`` —— 例如 ``Character(图片, size=(32, 32))``（矩形）或
       ``Character(图片, size=16)``（半径 16 的圆）。**只传图片不会创建刚体**，
       此时重力/速度/冲量都不生效（框架会给一次中文提示）；
    2. 调用 ``set_gravity(0, -1200)`` —— ``setup()`` 之后默认重力是 ``(0, 0)``（零重力）。

如果没有图片，可以省略第一个参数：``Character(size=40)`` 会自动使用内置白色
圆形贴图；``Character(size=40, shape="square")`` 使用内置方形贴图。

| 成员 | 类型 | 签名 |
|---|---|---|
| `body_scale` | method | `(scalex, scaley=None)` |
| `collide` | method (mixin) | `(other: Any) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `get_clicked` | method | `()` |
| `get_just_clicked` | method | `()` |
| `get_just_released` | method | `()` |
| `get_mouse_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_clicked` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_just_released` | method (mixin) | `(b: Union[int, str] = 'all') -> bool` |
| `get_mouse_upon` | method (mixin) | `() -> bool` |
| `get_pos` | method | `()` |
| `get_rel` | method | `()` |
| `play_anim` | method (mixin) | `() -> None` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_next_state` | method (mixin) | `(state: str, next_state: str) -> None` |
| `set_start_func` | method (mixin) | `(state, func)` |
| `state` | property (mixin) | — |
| `stop_anim` | method (mixin) | `() -> None` |
| `update` | method | `()` |

#### `Mouse.body_scale`

```python
body_scale(scalex, scaley=None)
```

#### `Mouse.collide`

```python
collide(other: Any) -> Any
```

#### `Mouse.distance`

```python
distance(other: Any) -> float
```

#### `Mouse.dt`

属性（property）。

#### `Mouse.frame`

属性（property）。

#### `Mouse.get_clicked`

```python
get_clicked()
```

#### `Mouse.get_just_clicked`

```python
get_just_clicked()
```

#### `Mouse.get_just_released`

```python
get_just_released()
```

#### `Mouse.get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Mouse.get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
```

#### `Mouse.get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
```

#### `Mouse.get_mouse_upon`

```python
get_mouse_upon() -> bool
```

#### `Mouse.get_pos`

```python
get_pos()
```

#### `Mouse.get_rel`

```python
get_rel()
```

#### `Mouse.play_anim`

```python
play_anim() -> None
```

#### `Mouse.separate`

```python
separate(other: Any) -> bool
```

#### `Mouse.set_dt`

```python
set_dt(*args: Any) -> None
```

#### `Mouse.set_end_func`

```python
set_end_func(state, func)
```

#### `Mouse.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `Mouse.set_start_func`

```python
set_start_func(state, func)
```

#### `Mouse.state`

属性（property）。

#### `Mouse.stop_anim`

```python
stop_anim() -> None
```

#### `Mouse.update`

```python
update()
```


### `find_all`

```python
find_all(tag, world=None)
```

返回所有 tag 相同的、还活着的对象。


### `find`

```python
find(tag, world=None)
```

返回第一个 tag 相同的、还活着的对象；没有则返回 None。


### `every`

```python
every(seconds: float, func, *args, world: Optional[waligame.config.World] = None, **kwargs)
```

每隔 seconds 秒执行一次 func（第一次在 seconds 秒后），返回可 cancel() 的 timer。


### `after`

```python
after(seconds: float, func, *args, world: Optional[waligame.config.World] = None, **kwargs)
```

seconds 秒后执行一次 func。


### `clear_timers`

```python
clear_timers(world: Optional[waligame.config.World] = None) -> None
```


## 精灵与动画

### `Sprite`

```python
Sprite(imgs: Any, world: Optional[waligame.config.World] = None) -> None
```

继承：`DirtySprite`

Only allow one image

| 成员 | 类型 | 签名 |
|---|---|---|
| `alpha` | property | — |
| `blue` | property | — |
| `green` | property | — |
| `height` | property | — |
| `is_flip_h` | property | — |
| `is_flip_v` | property | — |
| `kill` | method | `() -> None` |
| `red` | property | — |
| `set_parent` | method | `(parent: Any) -> None` |
| `sprite_strategy` | property | — |
| `update` | method | `() -> None` |
| `visible` | property | — |
| `width` | property | — |

#### `Sprite.alpha`

属性（property）。

#### `Sprite.blue`

属性（property）。

#### `Sprite.green`

属性（property）。

#### `Sprite.height`

属性（property）。

#### `Sprite.is_flip_h`

属性（property）。

#### `Sprite.is_flip_v`

属性（property）。

#### `Sprite.kill`

```python
kill() -> None
```

remove the Sprite from all Groups

Sprite.kill(): return None

The Sprite is removed from all the Groups that contain it. This won't
change anything about the state of the Sprite. It is possible to
continue to use the Sprite after this method has been called, including
adding it to Groups.

#### `Sprite.red`

属性（property）。

#### `Sprite.set_parent`

```python
set_parent(parent: Any) -> None
```

#### `Sprite.sprite_strategy`

属性（property）。

#### `Sprite.update`

```python
update() -> None
```

method to control sprite behavior

Sprite.update(*args, **kwargs):

The default implementation of this method does nothing; it's just a
convenient "hook" that you can override. This method is called by
Group.update() with whatever arguments you give it.

There is no need to use this method if not using the convenience
method by the same name in the Group class.

#### `Sprite.visible`

属性（property）。

You can make this sprite disappear without removing it from the group
assign 0 for invisible and 1 for visible

#### `Sprite.width`

属性（property）。


### `SpriteSheet`

```python
SpriteSheet(sheet: Any, w: int, h: int, world: Optional[waligame.config.World] = None) -> None
```


### `EasySpriteStrategy`

```python
EasySpriteStrategy(img: Any, world: Optional[waligame.config.World] = None) -> None
```

这是一个动画精灵类
输入：一张图片名称
方法：调用update方法来输出图片

| 成员 | 类型 | 签名 |
|---|---|---|
| `update` | method | `() -> pygame.surface.Surface` |

#### `EasySpriteStrategy.update`

```python
update() -> pygame.surface.Surface
```


### `ListSpriteStrategy`

```python
ListSpriteStrategy(imgs: List[Any], world: Optional[waligame.config.World] = None) -> None
```

这是一个动画精灵类
输入：以列表形式存储的图片名称
方法：调用update方法来输出图片

| 成员 | 类型 | 签名 |
|---|---|---|
| `frame` | property | — |
| `set_dt` | method | `(dt: float) -> None` |
| `update` | method | `() -> pygame.surface.Surface` |

#### `ListSpriteStrategy.frame`

属性（property）。

#### `ListSpriteStrategy.set_dt`

```python
set_dt(dt: float) -> None
```

#### `ListSpriteStrategy.update`

```python
update() -> pygame.surface.Surface
```


### `AnimatorStrategy`

```python
AnimatorStrategy(imgs_dict: Dict[str, List[Any]], world: Optional[waligame.config.World] = None) -> None
```

状态动画策略：``{"状态名": [图片...]}``。

注意 ``state`` 的读写语义：setter 只记录"待切换"状态，属性读取的是"已生效"状态，
切换在**下一次** ``update()`` 时生效（这样本帧仍完整显示旧状态的画面）。
因此 ``strategy.state = "walk"`` 之后立刻读 ``state`` 仍是旧值，
需要 ``strategy.update()`` 之后才是 ``"walk"``。

方法：调用 update 方法来输出当前帧图片。

| 成员 | 类型 | 签名 |
|---|---|---|
| `frame` | property | — |
| `set_dt` | method | `(state: Optional[str], dt: float) -> None` |
| `set_end_func` | method | `(state: str, func: Any) -> None` |
| `set_next_state` | method | `(state: str, next_state: str) -> None` |
| `set_start_func` | method | `(state: str, func: Any) -> None` |
| `state` | property | — |
| `update` | method | `() -> pygame.surface.Surface` |

#### `AnimatorStrategy.frame`

属性（property）。

#### `AnimatorStrategy.set_dt`

```python
set_dt(state: Optional[str], dt: float) -> None
```

#### `AnimatorStrategy.set_end_func`

```python
set_end_func(state: str, func: Any) -> None
```

#### `AnimatorStrategy.set_next_state`

```python
set_next_state(state: str, next_state: str) -> None
```

#### `AnimatorStrategy.set_start_func`

```python
set_start_func(state: str, func: Any) -> None
```

#### `AnimatorStrategy.state`

属性（property）。

#### `AnimatorStrategy.update`

```python
update() -> pygame.surface.Surface
```


### `TiledMapStrategy`

```python
TiledMapStrategy(tiledmap: Any, world: Optional[waligame.config.World] = None) -> None
```

| 成员 | 类型 | 签名 |
|---|---|---|
| `update` | method | `()` |

#### `TiledMapStrategy.update`

```python
update()
```


## 物理与约束

### `Body`

```python
Body(body_type: Any, shape: str, size: Any, sensor: bool, world: Optional[waligame.config.World] = None) -> None
```

| 成员 | 类型 | 签名 |
|---|---|---|
| `angular_velocity` | property | — |
| `apply_impulse_at_local_point` | method | `(impulse)` |
| `collide` | method | `(other)` |
| `elasticity` | property | — |
| `friction` | property | — |
| `kill` | method | `()` |
| `mass` | property | — |
| `point_query` | method | `(p)` |
| `set_parent` | method | `(parent: Any) -> None` |
| `set_pos` | method | `(pos: Any) -> None` |
| `set_rot` | method | `(rot)` |
| `set_vertices` | method | `(vertices, transform)` |
| `update` | method | `()` |
| `velocity` | property | — |

#### `Body.angular_velocity`

属性（property）。

#### `Body.apply_impulse_at_local_point`

```python
apply_impulse_at_local_point(impulse)
```

#### `Body.collide`

```python
collide(other)
```

#### `Body.elasticity`

属性（property）。

#### `Body.friction`

属性（property）。

#### `Body.kill`

```python
kill()
```

#### `Body.mass`

属性（property）。

#### `Body.point_query`

```python
point_query(p)
```

#### `Body.set_parent`

```python
set_parent(parent: Any) -> None
```

#### `Body.set_pos`

```python
set_pos(pos: Any) -> None
```

#### `Body.set_rot`

```python
set_rot(rot)
```

#### `Body.set_vertices`

```python
set_vertices(vertices, transform)
```

#### `Body.update`

```python
update()
```

#### `Body.velocity`

属性（property）。


### `BodiesGroup`

```python
BodiesGroup() -> None
```

继承：`Group`

刚体更新组。

实现已统一到 :class:`waligame.config.Group`（带更新钩子），本类只是保留公共名字的
薄子类，行为与历史版本完全一致。


### `TiledMapBodies`

```python
TiledMapBodies(body_type: Any, objs: List[Any], sensor: bool, world: Optional[waligame.config.World] = None) -> None
```

继承：`list`

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.

| 成员 | 类型 | 签名 |
|---|---|---|
| `angular_velocity` | property | — |
| `apply_impulse_at_local_point` | method | `(pos)` |
| `collide` | method | `(other)` |
| `elasticity` | property | — |
| `friction` | property | — |
| `kill` | method | `()` |
| `mass` | property | — |
| `point_query` | method | `(p)` |
| `set_parent` | method | `(parent)` |
| `set_pos` | method | `(pos)` |
| `set_rot` | method | `(rot)` |
| `set_vertices` | method | `(scalex, scaley)` |
| `update` | method | `()` |
| `velocity` | property | — |

#### `TiledMapBodies.angular_velocity`

属性（property）。

#### `TiledMapBodies.apply_impulse_at_local_point`

```python
apply_impulse_at_local_point(pos)
```

#### `TiledMapBodies.collide`

```python
collide(other)
```

#### `TiledMapBodies.elasticity`

属性（property）。

#### `TiledMapBodies.friction`

属性（property）。

#### `TiledMapBodies.kill`

```python
kill()
```

#### `TiledMapBodies.mass`

属性（property）。

#### `TiledMapBodies.point_query`

```python
point_query(p)
```

#### `TiledMapBodies.set_parent`

```python
set_parent(parent)
```

#### `TiledMapBodies.set_pos`

```python
set_pos(pos)
```

#### `TiledMapBodies.set_rot`

```python
set_rot(rot)
```

#### `TiledMapBodies.set_vertices`

```python
set_vertices(scalex, scaley)
```

#### `TiledMapBodies.update`

```python
update()
```

#### `TiledMapBodies.velocity`

属性（property）。


### `TiledMapBodiesGroup`

```python
TiledMapBodiesGroup() -> None
```

继承：`Group`

瓦片地图刚体组（同样是 :class:`waligame.config.Group` 的薄子类）。


### `Connect`

```python
Connect(a: Any, b: Any, world: Any = None) -> None
```

继承：`PinJoint`

销钉关节：把两个物体连成一根刚性杆（长度 = 创建时两物体的距离）。


### `Spring`

```python
Spring(a: Any, b: Any, rest_length: Optional[float] = None, stiffness: float = 100.0, damping: float = 10.0, anchor_a: Tuple[float, float] = (0, 0), anchor_b: Tuple[float, float] = (0, 0), world: Any = None) -> None
```

继承：`DampedSpring`

弹簧关节：两物体之间按弹簧-阻尼关系连接。

:param rest_length: 自然长度；``None`` 表示取创建时两物体的实际距离
:param stiffness: 劲度系数（越大越硬）
:param damping: 阻尼（越大越快停下）
:param anchor_a: 连接点在 a 上的局部坐标（默认物体中心）
:param anchor_b: 连接点在 b 上的局部坐标（默认物体中心）
:param world: 加到哪个世界；默认跟随 a（或 b）所属的世界


### `connect`

```python
connect(a: Any, b: Any, world: Any = None) -> waligame.constraints.Connect
```

用刚性杆连接两个物体（等价于 ``Connect(a, b)``），返回该关节。

想要有弹性的连接请用 :class:`Spring`。


### `set_gravity`

```python
set_gravity(x, *y, world=None)
```


## 相机、世界与屏幕

### `World`

```python
World() -> None
```

一个游戏世界的全部可变状态。

目前 `global_var` 就是默认世界实例（保留该名字作为兼容别名）。把状态收进
实例是为了后续支持相互独立的世界（多场景切换、单元测试互不干扰）。

| 成员 | 类型 | 签名 |
|---|---|---|
| `get_value` | method | `(var: str) -> Any` |
| `set_value` | method | `(var: str, value: Any) -> None` |

#### `World.get_value`

```python
get_value(var: str) -> Any
```

#### `World.set_value`

```python
set_value(var: str, value: Any) -> None
```


### `Camera`

```python
Camera(size: Optional[Tuple[int, int]] = None, world: Optional[waligame.config.World] = None) -> None
```

相机：把某个世界的内容绘制到自己的 surface 上。

每个世界一个实例（由 `setup()` 创建并写入 `world.CAMERA`），**不再是全局单例**
—— 单例会让第二个世界共用同一个相机。`world=None` 表示使用默认世界 `global_var`。

不传 `size` 时按该世界的窗口尺寸创建；若世界还没 `setup()`（尺寸为 0）会给出可读的
中英双语报错，而不是留下一个半初始化的对象。

| 成员 | 类型 | 签名 |
|---|---|---|
| `follow` | method | `(subject: Any) -> None` |
| `offset` | property | — |
| `pos` | property | — |
| `scale` | method | `(s: float) -> None` |
| `shake` | method | `(amount: float = 8.0, duration: float = 0.3) -> None` |
| `size` | property | — |
| `stop_shake` | method | `() -> None` |
| `update` | method | `() -> bool` |
| `x` | property | — |
| `y` | property | — |
| `zoom_to` | method | `(scl: float, speed: float = 2.0) -> None` |

#### `Camera.follow`

```python
follow(subject: Any) -> None
```

#### `Camera.offset`

属性（property）。

#### `Camera.pos`

属性（property）。

#### `Camera.scale`

```python
scale(s: float) -> None
```

#### `Camera.shake`

```python
shake(amount: float = 8.0, duration: float = 0.3) -> None
```

屏幕抖动（被打中、爆炸等反馈）。

:param amount: 最大像素偏移
:param duration: 持续秒数（期间每帧随机偏移，结束后自动归位）

#### `Camera.size`

属性（property）。

#### `Camera.stop_shake`

```python
stop_shake() -> None
```

立即停止抖动。

#### `Camera.update`

```python
update() -> bool
```

重绘相机画面，返回本帧画面是否有变化。

#### `Camera.x`

属性（property）。

#### `Camera.y`

属性（property）。

#### `Camera.zoom_to`

```python
zoom_to(scl: float, speed: float = 2.0) -> None
```

平滑缩放到 ``scl``（每秒变化 ``speed`` 个缩放单位）。


### `Screen`

```python
Screen(size: Tuple[int, int], world: Optional[waligame.config.World] = None) -> None
```

| 成员 | 类型 | 签名 |
|---|---|---|
| `draw` | method | `() -> None` |
| `update` | method | `() -> None` |

#### `Screen.draw`

```python
draw() -> None
```

#### `Screen.update`

```python
update() -> None
```


### `Group`

```python
Group(update_hook: Optional[Any] = None) -> None
```

一组需要按帧更新的对象（框架内唯一的“更新容器”实现）。

两种用法：

* ``Group()``：按游戏对象协议更新——先 ``obj._update()``，仍存活再 ``obj.update()``
  （``World.GROUP`` 用的就是这种）；
* ``Group(hook)``：只调用 ``hook(obj)``，例如物理层 ``Group(lambda body: body.update())``。

物理侧的 ``BodiesGroup`` / ``TiledMapBodiesGroup`` 现在只是本类的兼容薄子类。
绘制用的精灵层由 pygame 的 ``LayeredDirty``（见 ``screen.FullRedrawLayeredDirty``）负责，
因为绘制与图层操作是它自带的能力，不并入本类。

| 成员 | 类型 | 签名 |
|---|---|---|
| `add` | method | `(obj: Any) -> None` |
| `find` | method | `(tag: Any)` |
| `find_all` | method | `(tag: Any) -> list` |
| `remove` | method | `(obj: Any) -> None` |
| `update` | method | `() -> None` |

#### `Group.add`

```python
add(obj: Any) -> None
```

#### `Group.find`

```python
find(tag: Any)
```

#### `Group.find_all`

```python
find_all(tag: Any) -> list
```

按 tag 找所有还活着的对象（不依赖额外索引，tag 改了也不会失效）。

#### `Group.remove`

```python
remove(obj: Any) -> None
```

#### `Group.update`

```python
update() -> None
```


### `ResourceManager`

```python
ResourceManager(max_cache_size: int = 1000)
```

资源管理器，对图片/字体/音效/mask 分别维护独立的 LRU 缓存（单例）

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_cache` | method | `(cache_type: Optional[str] = None)` |
| `get_cache_info` | method | `() -> Dict[str, Dict[str, int]]` |
| `get_instance` | classmethod | `()` |
| `get_mask` | method | `(surface: pygame.surface.Surface, threshold: int = 0) -> pygame.mask.Mask` |
| `load_font` | method | `(path: Optional[str] = None, size: int = 25) -> pygame.font.Font` |
| `load_image` | method | `(path: str) -> pygame.surface.Surface` |
| `load_sound` | method | `(path: str) -> Optional[pygame.mixer.Sound]` |
| `preload` | method | `(assets: waligame.resource_manager.PreloadAssets)` |
| `reset` | classmethod | `()` |
| `unload` | method | `(path: str)` |

#### `ResourceManager.clear_cache`

```python
clear_cache(cache_type: Optional[str] = None)
```

清空缓存。
cache_type: 'image' | 'font' | 'sound' | 'mask' | None（全部）

#### `ResourceManager.get_cache_info`

```python
get_cache_info() -> Dict[str, Dict[str, int]]
```

获取各缓存当前状态

#### `ResourceManager.get_instance`

```python
get_instance()
```

#### `ResourceManager.get_mask`

```python
get_mask(surface: pygame.surface.Surface, threshold: int = 0) -> pygame.mask.Mask
```

获取 Surface 的碰撞 mask（按 Surface 弱引用缓存）。

同一 Surface + 同一 threshold 只会构建一次（`mask.from_surface` 在大贴图上很贵）；
Surface 被回收后缓存条目自动消失——缓存本身不持有 Surface。

#### `ResourceManager.load_font`

```python
load_font(path: Optional[str] = None, size: int = 25) -> pygame.font.Font
```

加载字体（带 LRU 缓存）。

path 的解析顺序见 :mod:`waligame.fonts`：
显式路径 → 环境变量 WALIGAME_FONT → 包内 static/ → 系统中文字体
→ pygame 默认字体。

与早期版本的区别：字体文件缺失时**不再抛异常**，而是发出一次警告
并使用可用的替代字体，因此在没有装中文字体的 Linux/CI 上也不会崩。
只有“显式指定的字体文件存在但已损坏”才会抛出 RuntimeError。

#### `ResourceManager.load_image`

```python
load_image(path: str) -> pygame.surface.Surface
```

加载图片（带 LRU 缓存）。
若传入的已经是 Surface，则直接返回，不缓存。

PNG / JPEG / TIFF 在解析时如果遇到有问题的 ``iCCP`` / ``sRGB`` chunk，
libpng / libjpeg / libtiff 会直接把警告写到 stderr（典型表现是终端里
出现一串 ``libpng warning: iCCP: known incorrect sRGB profile``），
Python 的 ``warnings.catch_warnings()`` 抓不住这种 C 库输出。本方法
在加载瞬间临时重定向 fd 2，屏蔽这一类无意义警告；其它 stderr 输出不受
影响（窗口只有微秒级）。

#### `ResourceManager.load_sound`

```python
load_sound(path: str) -> Optional[pygame.mixer.Sound]
```

加载音效（带 LRU 缓存）。

没有可用音频设备时返回 None（游戏静音继续），不抛异常。

#### `ResourceManager.preload`

```python
preload(assets: waligame.resource_manager.PreloadAssets)
```

批量预加载资源。
格式：{
    'images': ['a.png', 'b.png'],
    'fonts':  [('font.ttf', 24), (None, 32)],
    'sounds': ['snd.wav']
}

#### `ResourceManager.reset`

```python
reset()
```

重置单例（仅用于测试）

#### `ResourceManager.unload`

```python
unload(path: str)
```

手动卸载单个图片/音效资源


## 地图

### `TiledMap`

```python
TiledMap(tilemap: str) -> None
```

| 成员 | 类型 | 签名 |
|---|---|---|
| `create_objects` | method | `(name: Optional[str] = None, body_type: Any = 'STATIC', sensor: bool = False, images: Optional[Dict[str, Any]] = None, world: Any = None) -> List[Any]` |
| `get_objects` | method | `(name: Optional[str] = None) -> List[Any]` |
| `make_map` | method | `() -> pygame.surface.Surface` |
| `objects` | property | — |
| `render` | method | `(surface: pygame.surface.Surface) -> None` |

#### `TiledMap.create_objects`

```python
create_objects(name: Optional[str] = None, body_type: Any = 'STATIC', sensor: bool = False, images: Optional[Dict[str, Any]] = None, world: Any = None) -> List[Any]
```

把对象层的对象实例化为**游戏对象**（返回列表）。

做三件事：

1. 每个 TMX 对象按其顶点生成一个 POLY 刚体，因此可直接参与碰撞检测（`obj.collide(...)`）
   与物理；
2. TMX **图块对象**（object 带 ``gid``）会自动带上贴图；也可以用
   ``images={"对象名": "图片路径"}`` 给任意对象指定贴图；
3. 把 TMX 的名字 / 自定义属性 / 原始对象挂到游戏对象上
   （``.name``、``.properties``、``.tmx_object``），方便按名字取用。

注意：`objects` / `get_objects()` 返回的是 **pytmx 的解析结果**（几何+属性），
本方法才把它们变成能放进世界的游戏对象。

#### `TiledMap.get_objects`

```python
get_objects(name: Optional[str] = None) -> List[Any]
```

#### `TiledMap.make_map`

```python
make_map() -> pygame.surface.Surface
```

#### `TiledMap.objects`

属性（property）。

对象层列表（坐标已换算到游戏坐标系；多次访问结果一致）。

#### `TiledMap.render`

```python
render(surface: pygame.surface.Surface) -> None
```


## 文字与 HUD

### `TextBox`

```python
TextBox(size: int, font: Optional[str] = None, bgfill: Any = None, font_color: Any = (0, 0, 0), world: Optional[waligame.config.World] = None) -> None
```

继承：`DirtySprite`

a more featureful subclass of Sprite with more attributes

pygame.sprite.DirtySprite(*groups): return DirtySprite

Extra DirtySprite attributes with their default values:

dirty = 1
    If set to 1, it is repainted and then set to 0 again.
    If set to 2, it is always dirty (repainted each frame;
    flag is not reset).
    If set to 0, it is not dirty and therefore not repainted again.

blendmode = 0
    It's the special_flags argument of Surface.blit; see the blendmodes in
    the Surface.blit documentation

source_rect = None
    This is the source rect to use. Remember that it is relative to the top
    left corner (0, 0) of self.image.

visible = 1
    Normally this is 1. If set to 0, it will not be repainted. (If you
    change visible to 1, you must set dirty to 1 for it to be erased from
    the screen.)

_layer = 0
    0 is the default value but this is able to be set differently
    when subclassing.

| 成员 | 类型 | 签名 |
|---|---|---|
| `color` | property | — |
| `goto` | method | `(x, *y)` |
| `pos` | property | — |
| `print` | method | `(text: Any = None) -> None` |
| `update` | method | `()` |
| `write` | method | `(text: Any = None) -> None` |

#### `TextBox.color`

属性（property）。

#### `TextBox.goto`

```python
goto(x, *y)
```

#### `TextBox.pos`

属性（property）。

#### `TextBox.print`

```python
print(text: Any = None) -> None
```

设置文本框内容（下一次 update 时重新渲染）。

#### `TextBox.update`

```python
update()
```

method to control sprite behavior

Sprite.update(*args, **kwargs):

The default implementation of this method does nothing; it's just a
convenient "hook" that you can override. This method is called by
Group.update() with whatever arguments you give it.

There is no need to use this method if not using the convenience
method by the same name in the Group class.

#### `TextBox.write`

```python
write(text: Any = None) -> None
```

设置文本框内容（下一次 update 时重新渲染）。


### `DialogBox`

```python
DialogBox(parent: Any, DialogBox_img: str, DialogBox_font: Optional[str], world: Optional[waligame.config.World] = None) -> None
```

继承：`DirtySprite`

a more featureful subclass of Sprite with more attributes

pygame.sprite.DirtySprite(*groups): return DirtySprite

Extra DirtySprite attributes with their default values:

dirty = 1
    If set to 1, it is repainted and then set to 0 again.
    If set to 2, it is always dirty (repainted each frame;
    flag is not reset).
    If set to 0, it is not dirty and therefore not repainted again.

blendmode = 0
    It's the special_flags argument of Surface.blit; see the blendmodes in
    the Surface.blit documentation

source_rect = None
    This is the source rect to use. Remember that it is relative to the top
    left corner (0, 0) of self.image.

visible = 1
    Normally this is 1. If set to 0, it will not be repainted. (If you
    change visible to 1, you must set dirty to 1 for it to be erased from
    the screen.)

_layer = 0
    0 is the default value but this is able to be set differently
    when subclassing.

| 成员 | 类型 | 签名 |
|---|---|---|
| `hide` | method | `() -> None` |
| `say` | method | `(text: Any = None, textColor: Any = None) -> None` |
| `show` | method | `() -> None` |
| `update` | method | `() -> None` |

#### `DialogBox.hide`

```python
hide() -> None
```

#### `DialogBox.say`

```python
say(text: Any = None, textColor: Any = None) -> None
```

#### `DialogBox.show`

```python
show() -> None
```

#### `DialogBox.update`

```python
update() -> None
```

method to control sprite behavior

Sprite.update(*args, **kwargs):

The default implementation of this method does nothing; it's just a
convenient "hook" that you can override. This method is called by
Group.update() with whatever arguments you give it.

There is no need to use this method if not using the convenience
method by the same name in the Group class.


### `Label`

```python
Label(text: Any = '', size: int = 30, color=(0, 0, 0), x: int = 10, y: int = 10, font: Optional[str] = None, world: Optional[waligame.config.World] = None) -> None
```

屏幕空间文字（不受摄像机影响），默认左上角。

和 TextBox 的区别：TextBox 放在世界坐标里，会跟着镜头移动；Label 固定在屏幕上，
适合分数、金币、提示语。文字只在内容/颜色变化时重新渲染。

| 成员 | 类型 | 签名 |
|---|---|---|
| `color` | property | — |
| `draw` | method | `(screen) -> None` |
| `goto` | method | `(x: int, y: int) -> None` |
| `hide` | method | `() -> None` |
| `kill` | method | `() -> None` |
| `print` | method | `(text: Any) -> None` |
| `show` | method | `() -> None` |
| `text` | property | — |
| `visible` | property | — |
| `write` | method | `(text: Any) -> None` |

#### `Label.color`

属性（property）。

#### `Label.draw`

```python
draw(screen) -> None
```

#### `Label.goto`

```python
goto(x: int, y: int) -> None
```

#### `Label.hide`

```python
hide() -> None
```

#### `Label.kill`

```python
kill() -> None
```

#### `Label.print`

```python
print(text: Any) -> None
```

#### `Label.show`

```python
show() -> None
```

#### `Label.text`

属性（property）。

#### `Label.visible`

属性（property）。

#### `Label.write`

```python
write(text: Any) -> None
```


### `Score`

```python
Score(size: int = 30, color=(0, 0, 0), x: int = 10, y: int = 10, prefix: str = '分数: ', font: Optional[str] = None, world: Optional[waligame.config.World] = None) -> None
```

继承：`Label`

屏幕左上角的分数：score.add(10) / score.set(0)。

| 成员 | 类型 | 签名 |
|---|---|---|
| `add` | method | `(n=1)` |
| `set` | method | `(n)` |
| `text` | property | — |
| `value` | property | — |

#### `Score.add`

```python
add(n=1)
```

#### `Score.set`

```python
set(n)
```

#### `Score.text`

属性（property）。

#### `Score.value`

属性（property）。


## 输入

### `get_mouse_pos`

```python
get_mouse_pos(world: Optional[waligame.config.World] = None) -> Tuple[float, float]
```

获得鼠标坐标（同一世界同一帧内只查询一次；元组不可变，直接复用是安全的）。


### `get_mouse_rel`

```python
get_mouse_rel(world: Optional[waligame.config.World] = None) -> 'pygame.math.Vector2'
```

x, y = pygame.mouse.get_rel()
return vec(x, -y)


### `get_mouse_clicked`

```python
get_mouse_clicked(b: Union[int, str] = 'all', world: Optional[waligame.config.World] = None) -> bool
```


### `get_mouse_just_clicked`

```python
get_mouse_just_clicked(b: Union[int, str] = 'all', world: Optional[waligame.config.World] = None) -> bool
```


### `get_mouse_just_released`

```python
get_mouse_just_released(b: Union[int, str] = 'all', world: Optional[waligame.config.World] = None) -> bool
```


### `mouse_button_down`

```python
mouse_button_down(which='all', world: Optional[ForwardRef('World')] = None) -> bool
```

鼠标键当前是否按下：1 左键 / 2 中键 / 3 右键 / "all" 任意一个。

由 Screen.update() 每帧维护，不依赖某个对象这一帧是否查询鼠标。


### `key_pressed`

```python
key_pressed(key: Optional[int] = None) -> bool
```

按键是否被按住。

``key=None`` 表示"是否有任意键被按下"。这里用 ``any()`` 表达该语义：
旧写法 ``1 in pygame.key.get_pressed()`` 效果虽然相同（序列里存的是布尔），
但读起来像是在判断"键码 1"，而且把 ``get_pressed()`` 调了两次。


### `key_just_pressed`

```python
key_just_pressed(*keys: int, world: Optional[waligame.config.World] = None, require_all: bool = False) -> Union[bool, List[int]]
```

本帧刚按下的键。

默认“任意一个”满足即可（孩子更直觉）；要“全部按下”传 ``require_all=True``。
不传 keys 时返回本帧所有按下的键列表（兼容旧行为）。


### `key_just_released`

```python
key_just_released(*keys: int, world: Optional[waligame.config.World] = None, require_all: bool = False) -> Union[bool, List[int]]
```

本帧刚松开的键；默认任意一个，``require_all=True`` 为全部。


### `key_input`

```python
key_input(world: Optional[waligame.config.World] = None) -> str
```


### `set_mouse_visible`

```python
set_mouse_visible(visible: bool) -> None
```

显示 / 隐藏鼠标光标。


## 音频

### `bgmusic`

```python
bgmusic(bgm: str, loops: int = -1, start: float = 0.0) -> bool
```

播放背景音乐；没有音频设备时静音返回 False，不抛异常。


### `set_volume`

```python
set_volume(vol: float) -> None
```


### `music_load`

```python
music_load(bgm: str) -> None
```


### `music_play`

```python
music_play(loops: int = -1, start: float = 0.0) -> None
```


### `music_rewind`

```python
music_rewind() -> None
```


### `music_stop`

```python
music_stop() -> None
```


### `music_pause`

```python
music_pause() -> None
```


### `music_unpause`

```python
music_unpause() -> None
```


### `music_fadeout`

```python
music_fadeout(ms: int = 1000) -> None
```


### `music_set_volume`

```python
music_set_volume(vol: float) -> None
```


### `music_get_volume`

```python
music_get_volume() -> float
```


### `music_get_busy`

```python
music_get_busy() -> bool
```


### `music_set_pos`

```python
music_set_pos(pos: float) -> None
```


### `music_get_pos`

```python
music_get_pos() -> int
```


### `music_queue`

```python
music_queue(bgm: str) -> None
```


### `music_set_endevent`

```python
music_set_endevent(event_id: Optional[int] = None) -> None
```


### `music_get_endevent`

```python
music_get_endevent() -> int
```


### `init`

```python
init() -> None
```

初始化 pygame / mixer / font（可重复调用，幂等）。

历史上这段初始化写在模块顶层：`import waligame` 就会打开音频与视频子系统，
在没有声卡的 CI/服务器上会直接抛 pygame.error。现在改为由 setup() 显式调用，
导入本包不再有任何副作用。


### `ensure_audio`

```python
ensure_audio() -> bool
```

确保 mixer 可用；没有音频设备时返回 False，不抛异常。


### `audio_info`

```python
audio_info() -> dict
```

返回当前音频状态，方便排查（不会抛异常）。


## 资源、调试与工具

### `draw_line`

```python
draw_line(p1: Any, p2: Any, color: Any, width: float, world: Optional[waligame.config.World] = None) -> None
```

压一条待绘制线段（在下一个 update 的 draw 阶段画出）。


### `load_image`

```python
load_image(img, world=None)
```

加载图片，使用资源管理器进行缓存


### `preload`

```python
preload(assets, world=None)
```

批量预加载资源，避免游戏中第一次使用时的卡顿。

``assets`` 形如::

    preload({
        "images": ["player.png", "enemy.png"],
        "fonts":  [(None, 24), (None, 36)],     # (字体路径或 None 表示自动, 字号)
        "sounds": ["jump.wav"],
    })


### `set_dpi_awareness`

```python
set_dpi_awareness() -> bool
```

让 Windows 按物理像素创建窗口，避免不同 DPI 缩放下大小不一致。

必须在创建窗口（setup）之前调用；非 Windows、或进程已经设置过 DPI 时返回 False。


### `random_pos`

```python
random_pos(world=None)
```

在世界范围内取一个随机坐标。


### `sign`

```python
sign(n: float) -> int
```

返回 n 的符号：1 / -1 / 0（对象移动与旋转方向判定共用）。


### `tracer`

```python
tracer(f, world=None)
```

打开/关闭自动刷新（每个 update 结束时自动 update 一次）。


### `speed`

```python
speed(s, world=None)
```

设置每步位移上限。


### `Cartesian2pygame`

```python
Cartesian2pygame(x: Any, *y: Any, world: Optional[ForwardRef('World')] = None) -> Tuple[float, float]
```

世界坐标 -> 窗口坐标；world 缺省为默认世界。


### `pygame2Cartesian`

```python
pygame2Cartesian(x: Any, *y: Any, world: Optional[ForwardRef('World')] = None) -> Tuple[float, float]
```

窗口坐标 -> 世界坐标；world 缺省为默认世界。


### `to_cp`

```python
to_cp(value: Any) -> Any
```

把坐标转换成 pymunk(cffi) 可接受的 (x, y) 元组。

pymunk 底层通过 cffi 调用 Chipmunk，只接受 list / tuple / dict /
struct-cdata；直接传入 pygame.math.Vector2（即本模块的 vec）会抛出
TypeError: initializer for ctype 'struct cpVect' must be a list or
tuple or dict or struct-cdata。因此所有把坐标交给 pymunk 的地方都先
经过本函数转换一次。


### `install_error_help`

```python
install_error_help()
```

安装中文报错助手（重复调用安全）。


### `uninstall_error_help`

```python
uninstall_error_help()
```

卸载中文报错助手，恢复原有 excepthook。


### `set_error_help`

```python
set_error_help(enabled)
```

开 / 关中文报错助手（等价于 install_error_help / uninstall_error_help）。


### `is_error_help_enabled`

```python
is_error_help_enabled()
```


### `explain_exception`

```python
explain_exception(exc, tb=None)
```

在 except 块里使用：print(explain_exception(e))。


## 联机

### `LanGame`

```python
LanGame(game_name: str = '我的游戏', 最多人数: int = 4, 最少人数: int = 2, 允许中途加入: bool = False)
```

孩子用的联机房间入口。

net = 联机("我的游戏", 最多人数=4)
if not net.大厅():
    raise SystemExit
net.发送({...})
for msg in net.收到(): ...
net.关闭()

| 成员 | 类型 | 签名 |
|---|---|---|
| `create_room` | method | `(player_name: str, room_name: str, max_players: int, password: str = '') -> None` |
| `join_room` | method | `(room: Dict[str, Any], player_name: str, password: str = '') -> None` |
| `leave_room` | method | `() -> None` |
| `start` | method | `() -> bool` |
| `关闭` | method | `() -> None` |
| `发送` | method | `(data: Any) -> bool` |
| `大厅` | method | `() -> bool` |
| `我的编号` | property | — |
| `收到` | method | `() -> List[Dict[str, Any]]` |
| `是房主` | property | — |
| `玩家列表` | property | — |

#### `LanGame.create_room`

```python
create_room(player_name: str, room_name: str, max_players: int, password: str = '') -> None
```

#### `LanGame.join_room`

```python
join_room(room: Dict[str, Any], player_name: str, password: str = '') -> None
```

#### `LanGame.leave_room`

```python
leave_room() -> None
```

#### `LanGame.start`

```python
start() -> bool
```

#### `LanGame.关闭`

```python
关闭() -> None
```

#### `LanGame.发送`

```python
发送(data: Any) -> bool
```

#### `LanGame.大厅`

```python
大厅() -> bool
```

#### `LanGame.我的编号`

属性（property）。

#### `LanGame.收到`

```python
收到() -> List[Dict[str, Any]]
```

#### `LanGame.是房主`

属性（property）。

#### `LanGame.玩家列表`

属性（property）。


### `联机`

```python
联机(game_name: str = '我的游戏', 最多人数: int = 4, 最少人数: int = 2, 允许中途加入: bool = False)
```

孩子用的联机房间入口。

net = 联机("我的游戏", 最多人数=4)
if not net.大厅():
    raise SystemExit
net.发送({...})
for msg in net.收到(): ...
net.关闭()

| 成员 | 类型 | 签名 |
|---|---|---|
| `create_room` | method | `(player_name: str, room_name: str, max_players: int, password: str = '') -> None` |
| `join_room` | method | `(room: Dict[str, Any], player_name: str, password: str = '') -> None` |
| `leave_room` | method | `() -> None` |
| `start` | method | `() -> bool` |
| `关闭` | method | `() -> None` |
| `发送` | method | `(data: Any) -> bool` |
| `大厅` | method | `() -> bool` |
| `我的编号` | property | — |
| `收到` | method | `() -> List[Dict[str, Any]]` |
| `是房主` | property | — |
| `玩家列表` | property | — |

#### `联机.create_room`

```python
create_room(player_name: str, room_name: str, max_players: int, password: str = '') -> None
```

#### `联机.join_room`

```python
join_room(room: Dict[str, Any], player_name: str, password: str = '') -> None
```

#### `联机.leave_room`

```python
leave_room() -> None
```

#### `联机.start`

```python
start() -> bool
```

#### `联机.关闭`

```python
关闭() -> None
```

#### `联机.发送`

```python
发送(data: Any) -> bool
```

#### `联机.大厅`

```python
大厅() -> bool
```

#### `联机.我的编号`

属性（property）。

#### `联机.收到`

```python
收到() -> List[Dict[str, Any]]
```

#### `联机.是房主`

属性（property）。

#### `联机.玩家列表`

属性（property）。


## 其他公开类型

### `vec`

外部类型别名：`pygame.math.Vector2`


### `Color`

外部类型别名：`pygame.color.Color`


### `Rect`

外部类型别名：`pygame.rect.Rect`


### 公开变量

| 名称 | 类型 |
|---|---|
| `global_var` | `World` |
| `audio_available` | `_AudioState` |
| `cwd` | `str` |
| `__version__` | `str` |

<!-- API_REFERENCE_END -->
