Metadata-Version: 2.4
Name: WaliGame
Version: 2026.11.21
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
Requires-Dist: Pillow>=9.0
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.21

> 面向少儿编程与课堂教学的 2D 游戏引擎。
> 基座来自 **Walimaker 4.0.2**（MIT），在保留旧课件写法的同时，提供更完整的对象模型、物理、相机、中文报错、局域网联机和开箱即用的默认素材。

[![PyPI](https://img.shields.io/pypi/v/WaliGame.svg)](https://pypi.org/project/WaliGame/)
[![Python](https://img.shields.io/pypi/pyversions/WaliGame.svg)](https://pypi.org/project/WaliGame/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

## 📖 目录

- ✨ [特性亮点](#features) ｜ 🚀 [快速开始](#quickstart) ｜ 📦 [安装](#install)
- 🧑‍🎓 [默认角色](#character) ｜ 🎞️ [GIF 与帧范围](#animation) ｜ 🪟 [窗口放大](#scale)
- 🏫 [局域网联机](#lan) ｜ 🧱 [图层遮挡](#layer-occlusion)
- ⏱️ [教学便利 API](#helpers)
- 🩺 [中文报错与字体](#fonts)
- 🔁 [旧写法兼容](#compatibility) ｜ 🧭 [与 Walimaker 4.3.5 的关系](#upstream) ｜ 📚 [完整 API](#api)

---

```python
from waligame import *

setup(800, 600)
player = Character("player.png", size=(40, 60), tag="player")

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

    update()
```

WaliGame 桌面版的主循环始终是 `while True: update()`。  
`run(game)` 是可选的桌面写法，和 `while True: update()` 等价。

---

## Features

**✨ 为什么用 WaliGame**

| 能力 | 说明 |
|---|---|
| 🧱 清晰的继承链 | `Object → GameObject → Character / Sensor / Wall / Mouse` |
| 🎞️ 多帧动画 | 图片列表、GIF、字典状态动画、SpriteSheet |
| 🎯 帧范围控制 | `play_frames(0, 2)` 把 12 帧 GIF 拆成多个动作 |
| 🧑‍🎓 默认角色 | `Character()` 不用图片也能直接创建圆形/方形角色 |
| 🌍 物理与相机 | pymunk 刚体、约束、弹簧、震屏、死区、平滑缩放 |
| 🖥️ 窗口缩放 | `setup(..., scale=1.5)` 逻辑尺寸不变，窗口整体放大 |
| 🏫 局域网联机 | 房间发现、最多 16 人、中途加入、主机权威 |
| 🧩 教学 API | `every` / `after` / `find_all` / `clone` / `follow` / `on_screen` |
| 🩺 中文报错助手 | 原始 traceback 保留，追加中文原因和修复建议 |
| 🔤 内置中文字体 | Noto Sans SC 子集，默认从包内加载，避免系统字体缺失 |
| 📦 旧课件兼容 | `from Walimaker import *`、`random` / `time` / `os` 星号导入 |
| 🪟 安装器 | Windows 本地/网络安装，检测旧 Walimaker 并清理 |

WaliGame 不是简单地“改个名字”：它把 Walimaker 的工程化结构、教学便利功能和完整中文文档合在了一起。

---

## Install

**📦 安装**

### PyPI

```bash
python -m pip install WaliGame
```

### 本地 wheel

```bash
python -m pip install "waligame-2026.11.21-py3-none-any.whl"
```

### 依赖

```text
Python >= 3.8.1
pygame >= 2.5.0
pymunk >= 6.5.0
pytmx >= 3.32
Pillow >= 9.0
```

GIF 需要 Pillow；其余功能只需要 pygame/pymunk。

Windows 用户也可以使用安装器：

```text
双击我安装(2026.11.21).bat
双击我安装(2026.11.21-网络版).bat
```

安装器会先检测 `Walimaker` / `WalimakerPythonGameEngine` 旧包，避免两套引擎混装。

---

## Quickstart

**🚀 第一个游戏**

```python
from waligame import *

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

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

score = Score()

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

    if key_just_pressed(K_SPACE):
        score.add(1)

    update()
```

这是 WaliGame 的标准桌面主循环：每帧处理输入，然后调用 `update()`。

`run(game)` 是可选的桌面写法，现有 `while True: update()` 不需要改。

---

## Character

**🧑‍🎓 默认角色**

不传图片也能创建角色：

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

颜色可以直接改：

```python
player = Character(size=40)
player.color = (255, 80, 80, 255)
```

---

## Animation

**🎞️ GIF 与帧范围**

GIF 会按每帧自带时长自动播放：

```python
player = Character("walk.gif", size=48)
player.play_anim()
player.stop_anim()
player.frame = 2
```

12 帧 GIF 可以拆成四个动作：

```python
player.play_frames(0, 2)    # 0、1、2
player.play_frames(3, 5)    # 3、4、5
player.play_frames(6, 8)    # 6、7、8
player.play_frames(9, 11)   # 9、10、11
```

规则：

- 范围包含首尾
- `play_frames` 会从 `start` 帧重新开始
- `loop=False` 播到 `end` 帧后停止
- 列表、GIF、字典当前 `state` 都支持
- `frame_count` / `frame_range` 可查询
- 中文别名：`播放帧` / `设置帧范围` / `清除帧范围`

---

## Scale

**🪟 窗口放大**

```python
setup(1400, 600, dpi_aware=True, scale=1.5)
```

- 逻辑坐标仍然是 `1400 × 600`
- 实际窗口为 `2100 × 900`
- 鼠标坐标自动换算回逻辑坐标
- HUD、角色、相机统一放大
- 默认 `scale=1.0`，不开启时没有额外缩放成本

---

## LAN

**🏫 局域网联机**

```python
from waligame import *

net = 联机("彩色食材大作战", 最多人数=16, 允许中途加入=True)

if not net.大厅():
    raise SystemExit

while True:
    net.发送({
        "pos": player.pos,
        "score": score.value,
    })

    for msg in net.收到():
        remote.goto(msg["pos"])

    update()
```

支持：

- UDP 房间发现
- 主机权威状态
- 客户端预测/插值
- 最多 16 人
- 中途加入
- Esc 返回大厅

---

## Layer Occlusion

**🧱 图层遮挡**

默认关闭，保持旧课件行为。开启后按 `layer` 决定谁能被碰撞/点击：

```python
set_layer_occlusion(1)   # 下层角色不再参与碰撞
set_layer_occlusion(2)   # 下层角色不碰撞，也不能被点击
set_layer_occlusion(0)   # 关闭
```

示例：

```python
background = Character("bg_obj.png")
background.layer = 1

button = Character("button.png")
button.layer = 2

set_layer_occlusion(2)
# 现在被 button 盖住的部分，点击不会再命中 background
```

规则：

- 只有 `layer` **更高**的对象才会遮挡
- 同层对象互不遮挡
- 1 级只影响碰撞，鼠标点击仍可命中
- 2 级同时影响碰撞和鼠标点击
- 支持 `collide()` / `collide_tag()` / `get_mouse_*`
- 中文别名：`设置图层遮挡` / `图层遮挡等级`

---

## Helpers

**⏱️ 教学便利 API**

```python
def shoot():
    bullet = template.clone()
    bullet.show()
    bullet.goto(player.pos)
    bullet.velocity = (400, 0)

every(1.2, shoot)       # 每 1.2 秒重复
after(3, spawn_boss)    # 3 秒后一次
clear_timers()          # 清空所有计时器
```

- `every` / `after` 由 `update()` 驱动，不是线程
- 计时器返回对象，可 `.cancel()`
- `clone()` 复制图片、大小、位置、缩放、旋转、颜色、tag、物理属性
- `find_all("bullet")` 找同类对象
- `bullet.collide_tag("zombie")` 找碰撞对象
- `follow(target)` / `stop_follow()`
- `on_screen` 判断是否在镜头内

---

## Fonts

**🩺 中文报错与字体**

WaliGame 默认安装中文报错助手：

- 原始英文 traceback 完整保留
- 后面追加中文解释
- 覆盖拼写错误、参数数量、类型错误、pygame 常量、路径错误等常见问题

开关：

```python
set_error_help(False)
```

或：

```text
WALIGAME_ERROR_HELP=0
```

内置字体：

```text
waligame/static/NotoSansSC-Regular.otf
```

默认优先使用包内中文字体，找不到才回退系统字体，避免另一台电脑上因缺少微软雅黑/黑体而显示方框或报错。

字体许可：SIL Open Font License 1.1，详见包内 `NotoSansSC-OFL.txt`。

---

## Compatibility

**🔁 旧写法兼容**

```python
from Walimaker import *
```

等价于：

```python
from waligame import *
```

旧的 `random` / `time` / `os` / `math` / `sys` / `pygame` 星号导入也保留，旧课件通常不用改。

---

## Upstream

**🧭 与 Walimaker 4.3.5 的关系**

WaliGame 的基座是 **Walimaker 4.0.2**，并在此之上加入：

- 联机大厅与网络层
- 默认圆形/方形角色
- GIF 与帧范围
- 窗口 `scale`
- 安装器与旧包迁移
- 更完整的中文文档

WaliGame 基于 Walimaker 4.0.2，包含字体、报错助手、图层遮挡和局域网联机等桌面功能；当前发布**不包含** 4.3.5 的 HTML5/Web 打包链路。

---

## Changelog

**📋 更新日志**

| 版本 | 主要变化 |
|---|---|
| 2026.11.21 | 新增 `set_layer_occlusion()` 图层遮挡：1 级下层不碰撞，2 级下层不碰撞且不可点击；安装包不再附带游戏 |
| 2026.11.17 | 内置 Noto Sans SC 中文字体，移植完整中文报错规则，可选 `run(game)` |
| 2026.11.16 | 修复圆形刚体 `scale(1,1)` 误报 |
| 2026.11.15 | 大厅字体改用 WaliGame 字体解析器，避免 SysFont 崩溃 |
| 2026.11.14 | `clone()` 兼容自定义子类构造函数 |
| 2026.11.13 | 新增 `setup(..., scale=...)` 窗口放大 |
| 2026.11.12 | GIF 动画、帧范围 `play_frames`、Pillow 依赖 |
| 2026.11.11 | 安装器、网络安装、DPI 适配 |
| 2026.11.11 | 联机大厅与中途加入 |
| 2026.11.9 | 首个 WaliGame 发布版 |

详细历史见安装包内的 `CHANGELOG.md` 和 `VERSION_LOG.md`。

---

## API

**📚 完整 API**

下面是根据 `waligame.__all__` 自动生成的完整 API 参考，包含所有公开函数、类、方法和属性。

---

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

> 版本：`2026.11.21`  
> 由 `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, scale: float = 1.0) -> 'Screen'
```

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

`world=None`（默认）初始化默认世界 `global_var`，保持既有用法不变；
传入自己创建的世界即可获得互不干扰的第二套状态：
`w2 = World(); setup(800, 600, world=w2)`。

`dpi_aware` 默认 False；需要 Windows 按物理像素显示时手动传 True。

`scale` 默认 1.0；大于 1 时按逻辑尺寸绘制后整体放大到窗口，例如
`setup(1400, 600, dpi_aware=True, scale=1.5)` 的逻辑坐标仍是
1400×600，实际窗口为 2100×900。


### `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` |
| `clear_frame_range` | method (mixin) | `()` |
| `clone` | method | `()` |
| `collide` | method (mixin) | `(other: Any, _ignore_occlusion: bool = False) -> 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) | — |
| `frame_count` | property (mixin) | — |
| `frame_range` | 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_frames` | method (mixin) | `(start, end=None, loop=True)` |
| `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_frame_range` | method (mixin) | `(start, end=None, loop=True)` |
| `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 | `()` |
| `播放帧` | method (mixin) | `(start, end=None, loop=True)` |
| `清除帧范围` | method (mixin) | `()` |
| `设置帧范围` | method (mixin) | `(start, end=None, loop=True)` |

#### `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.clear_frame_range`

```python
clear_frame_range()
```

恢复完整帧范围。

#### `GameObject.clone`

```python
clone()
```

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

兼容自定义子类：例如 ``class Plant(Sensor): def __init__(self): ...``。
会按子类真实构造签名选择参数，而不是假定它接受 imgs/size/world/tag。

#### `GameObject.collide`

```python
collide(other: Any, _ignore_occlusion: bool = False) -> 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.frame_count`

属性（property）。

当前动画的帧数。

#### `GameObject.frame_range`

属性（property）。

当前播放范围 (start, end)，包含首尾。

#### `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_frames`

```python
play_frames(start, end=None, loop=True)
```

播放 start-end 帧（包含首尾），并开始播放。

list / GIF / 字典状态动画都支持；字典只作用于当前 state。

#### `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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

只设置帧范围，不改变当前播放/暂停状态。

#### `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()
```

#### `GameObject.播放帧`

```python
播放帧(start, end=None, loop=True)
```

#### `GameObject.清除帧范围`

```python
清除帧范围()
```

#### `GameObject.设置帧范围`

```python
设置帧范围(start, end=None, loop=True)
```


### `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` |
| `clear_frame_range` | method (mixin) | `()` |
| `clone` | method | `()` |
| `collide` | method (mixin) | `(other: Any, _ignore_occlusion: bool = False) -> 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) | — |
| `frame_count` | property (mixin) | — |
| `frame_range` | 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_frames` | method (mixin) | `(start, end=None, loop=True)` |
| `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_frame_range` | method (mixin) | `(start, end=None, loop=True)` |
| `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 | `()` |
| `播放帧` | method (mixin) | `(start, end=None, loop=True)` |
| `清除帧范围` | method (mixin) | `()` |
| `设置帧范围` | method (mixin) | `(start, end=None, loop=True)` |

#### `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.clear_frame_range`

```python
clear_frame_range()
```

恢复完整帧范围。

#### `NewGameObject.clone`

```python
clone()
```

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

兼容自定义子类：例如 ``class Plant(Sensor): def __init__(self): ...``。
会按子类真实构造签名选择参数，而不是假定它接受 imgs/size/world/tag。

#### `NewGameObject.collide`

```python
collide(other: Any, _ignore_occlusion: bool = False) -> 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.frame_count`

属性（property）。

当前动画的帧数。

#### `NewGameObject.frame_range`

属性（property）。

当前播放范围 (start, end)，包含首尾。

#### `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_frames`

```python
play_frames(start, end=None, loop=True)
```

播放 start-end 帧（包含首尾），并开始播放。

list / GIF / 字典状态动画都支持；字典只作用于当前 state。

#### `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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

只设置帧范围，不改变当前播放/暂停状态。

#### `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()
```

#### `NewGameObject.播放帧`

```python
播放帧(start, end=None, loop=True)
```

#### `NewGameObject.清除帧范围`

```python
清除帧范围()
```

#### `NewGameObject.设置帧范围`

```python
设置帧范围(start, end=None, loop=True)
```


### `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")`` 使用内置方形贴图。
``Character("walk.gif")`` 会把 GIF 拆成多帧并按每帧 duration 自动循环。

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_frame_range` | method (mixin) | `()` |
| `collide` | method (mixin) | `(other: Any, _ignore_occlusion: bool = False) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `frame_count` | property (mixin) | — |
| `frame_range` | 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` |
| `play_frames` | method (mixin) | `(start, end=None, loop=True)` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_frame_range` | method (mixin) | `(start, end=None, loop=True)` |
| `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` |
| `播放帧` | method (mixin) | `(start, end=None, loop=True)` |
| `清除帧范围` | method (mixin) | `()` |
| `设置帧范围` | method (mixin) | `(start, end=None, loop=True)` |

#### `Character.clear_frame_range`

```python
clear_frame_range()
```

恢复完整帧范围。

#### `Character.collide`

```python
collide(other: Any, _ignore_occlusion: bool = False) -> Any
```

#### `Character.distance`

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

#### `Character.dt`

属性（property）。

#### `Character.frame`

属性（property）。

#### `Character.frame_count`

属性（property）。

当前动画的帧数。

#### `Character.frame_range`

属性（property）。

当前播放范围 (start, end)，包含首尾。

#### `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.play_frames`

```python
play_frames(start, end=None, loop=True)
```

播放 start-end 帧（包含首尾），并开始播放。

list / GIF / 字典状态动画都支持；字典只作用于当前 state。

#### `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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

只设置帧范围，不改变当前播放/暂停状态。

#### `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
```

#### `Character.播放帧`

```python
播放帧(start, end=None, loop=True)
```

#### `Character.清除帧范围`

```python
清除帧范围()
```

#### `Character.设置帧范围`

```python
设置帧范围(start, end=None, loop=True)
```


### `Sensor`

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

继承：`GameObject`

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

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

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_frame_range` | method (mixin) | `()` |
| `collide` | method (mixin) | `(other: Any, _ignore_occlusion: bool = False) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `frame_count` | property (mixin) | — |
| `frame_range` | 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` |
| `play_frames` | method (mixin) | `(start, end=None, loop=True)` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_frame_range` | method (mixin) | `(start, end=None, loop=True)` |
| `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` |
| `播放帧` | method (mixin) | `(start, end=None, loop=True)` |
| `清除帧范围` | method (mixin) | `()` |
| `设置帧范围` | method (mixin) | `(start, end=None, loop=True)` |

#### `Sensor.clear_frame_range`

```python
clear_frame_range()
```

恢复完整帧范围。

#### `Sensor.collide`

```python
collide(other: Any, _ignore_occlusion: bool = False) -> Any
```

#### `Sensor.distance`

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

#### `Sensor.dt`

属性（property）。

#### `Sensor.frame`

属性（property）。

#### `Sensor.frame_count`

属性（property）。

当前动画的帧数。

#### `Sensor.frame_range`

属性（property）。

当前播放范围 (start, end)，包含首尾。

#### `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.play_frames`

```python
play_frames(start, end=None, loop=True)
```

播放 start-end 帧（包含首尾），并开始播放。

list / GIF / 字典状态动画都支持；字典只作用于当前 state。

#### `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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

只设置帧范围，不改变当前播放/暂停状态。

#### `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
```

#### `Sensor.播放帧`

```python
播放帧(start, end=None, loop=True)
```

#### `Sensor.清除帧范围`

```python
清除帧范围()
```

#### `Sensor.设置帧范围`

```python
设置帧范围(start, end=None, loop=True)
```


### `Wall`

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

继承：`GameObject`

墙壁,无法运动的物体

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_frame_range` | method (mixin) | `()` |
| `collide` | method (mixin) | `(other: Any, _ignore_occlusion: bool = False) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `frame_count` | property (mixin) | — |
| `frame_range` | 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` |
| `play_frames` | method (mixin) | `(start, end=None, loop=True)` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_frame_range` | method (mixin) | `(start, end=None, loop=True)` |
| `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 | — |
| `播放帧` | method (mixin) | `(start, end=None, loop=True)` |
| `清除帧范围` | method (mixin) | `()` |
| `设置帧范围` | method (mixin) | `(start, end=None, loop=True)` |

#### `Wall.clear_frame_range`

```python
clear_frame_range()
```

恢复完整帧范围。

#### `Wall.collide`

```python
collide(other: Any, _ignore_occlusion: bool = False) -> Any
```

#### `Wall.distance`

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

#### `Wall.dt`

属性（property）。

#### `Wall.frame`

属性（property）。

#### `Wall.frame_count`

属性（property）。

当前动画的帧数。

#### `Wall.frame_range`

属性（property）。

当前播放范围 (start, end)，包含首尾。

#### `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.play_frames`

```python
play_frames(start, end=None, loop=True)
```

播放 start-end 帧（包含首尾），并开始播放。

list / GIF / 字典状态动画都支持；字典只作用于当前 state。

#### `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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

只设置帧范围，不改变当前播放/暂停状态。

#### `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）。

#### `Wall.播放帧`

```python
播放帧(start, end=None, loop=True)
```

#### `Wall.清除帧范围`

```python
清除帧范围()
```

#### `Wall.设置帧范围`

```python
设置帧范围(start, end=None, loop=True)
```


### `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")`` 使用内置方形贴图。
``Character("walk.gif")`` 会把 GIF 拆成多帧并按每帧 duration 自动循环。

| 成员 | 类型 | 签名 |
|---|---|---|
| `body_scale` | method | `(scalex, scaley=None)` |
| `clear_frame_range` | method (mixin) | `()` |
| `collide` | method (mixin) | `(other: Any, _ignore_occlusion: bool = False) -> Any` |
| `distance` | method (mixin) | `(other: Any) -> float` |
| `dt` | property (mixin) | — |
| `frame` | property (mixin) | — |
| `frame_count` | property (mixin) | — |
| `frame_range` | 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` |
| `play_frames` | method (mixin) | `(start, end=None, loop=True)` |
| `separate` | method (mixin) | `(other: Any) -> bool` |
| `set_dt` | method (mixin) | `(*args: Any) -> None` |
| `set_end_func` | method (mixin) | `(state, func)` |
| `set_frame_range` | method (mixin) | `(start, end=None, loop=True)` |
| `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 | `()` |
| `播放帧` | method (mixin) | `(start, end=None, loop=True)` |
| `清除帧范围` | method (mixin) | `()` |
| `设置帧范围` | method (mixin) | `(start, end=None, loop=True)` |

#### `Mouse.body_scale`

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

#### `Mouse.clear_frame_range`

```python
clear_frame_range()
```

恢复完整帧范围。

#### `Mouse.collide`

```python
collide(other: Any, _ignore_occlusion: bool = False) -> Any
```

#### `Mouse.distance`

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

#### `Mouse.dt`

属性（property）。

#### `Mouse.frame`

属性（property）。

#### `Mouse.frame_count`

属性（property）。

当前动画的帧数。

#### `Mouse.frame_range`

属性（property）。

当前播放范围 (start, end)，包含首尾。

#### `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.play_frames`

```python
play_frames(start, end=None, loop=True)
```

播放 start-end 帧（包含首尾），并开始播放。

list / GIF / 字典状态动画都支持；字典只作用于当前 state。

#### `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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

只设置帧范围，不改变当前播放/暂停状态。

#### `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()
```

#### `Mouse.播放帧`

```python
播放帧(start, end=None, loop=True)
```

#### `Mouse.清除帧范围`

```python
清除帧范围()
```

#### `Mouse.设置帧范围`

```python
设置帧范围(start, end=None, loop=True)
```


### `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方法来输出图片

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_frame_range` | method | `()` |
| `frame` | property | — |
| `frame_count` | property | — |
| `frame_range` | property | — |
| `set_frame_range` | method | `(start, end=None, loop=True)` |
| `update` | method | `() -> pygame.surface.Surface` |

#### `EasySpriteStrategy.clear_frame_range`

```python
clear_frame_range()
```

#### `EasySpriteStrategy.frame`

属性（property）。

#### `EasySpriteStrategy.frame_count`

属性（property）。

#### `EasySpriteStrategy.frame_range`

属性（property）。

#### `EasySpriteStrategy.set_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

#### `EasySpriteStrategy.update`

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


### `ListSpriteStrategy`

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

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

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_frame_range` | method | `()` |
| `frame` | property | — |
| `frame_count` | property | — |
| `frame_range` | property | — |
| `set_dt` | method | `(dt: float) -> None` |
| `set_frame_range` | method | `(start, end=None, loop=True)` |
| `update` | method | `() -> pygame.surface.Surface` |

#### `ListSpriteStrategy.clear_frame_range`

```python
clear_frame_range()
```

#### `ListSpriteStrategy.frame`

属性（property）。

#### `ListSpriteStrategy.frame_count`

属性（property）。

#### `ListSpriteStrategy.frame_range`

属性（property）。

#### `ListSpriteStrategy.set_dt`

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

#### `ListSpriteStrategy.set_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

#### `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 方法来输出当前帧图片。

| 成员 | 类型 | 签名 |
|---|---|---|
| `clear_frame_range` | method | `()` |
| `frame` | property | — |
| `frame_count` | property | — |
| `frame_range` | property | — |
| `set_dt` | method | `(state: Optional[str], dt: float) -> None` |
| `set_end_func` | method | `(state: str, func: Any) -> None` |
| `set_frame_range` | method | `(start, end=None, loop=True)` |
| `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.clear_frame_range`

```python
clear_frame_range()
```

#### `AnimatorStrategy.frame`

属性（property）。

#### `AnimatorStrategy.frame_count`

属性（property）。

#### `AnimatorStrategy.frame_range`

属性（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_frame_range`

```python
set_frame_range(start, end=None, loop=True)
```

#### `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, scale: float = 1.0) -> 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', 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'` |
| `load_sound` | method | `(path: 'str') -> 'Optional[pygame.mixer.Sound]'` |
| `preload` | method | `(assets: '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', threshold: 'int' = 0) -> 'pygame.mask.Mask'
```

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

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

如果运行环境没有加载 ``pygame.mask``，此时退化为矩形 mask，
保证碰撞检测仍能继续。

#### `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'
```

加载图片（带 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: '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'
```

获得鼠标相对移动；窗口放大时自动换算回逻辑坐标。


### `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）。


## 其他公开类型

### `run`

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

可选的桌面主循环：每帧调用一次 ``loop()``，然后自动 ``update()``。

等价于::

    while True:
        loop()
        update()

``loop`` 里不要再调用 ``update()``。


### `set_layer_occlusion`

```python
set_layer_occlusion(level: int = 1, world: Any = None) -> None
```

设置图层遮挡规则。

0 = 关闭；1 = 被更高 layer 压住的对象不参与碰撞；
2 = 在 1 的基础上，被压住的对象也不能被鼠标点击。


### `get_layer_occlusion`

```python
get_layer_occlusion(world: Any = None) -> int
```

返回当前图层遮挡等级。


### `设置图层遮挡`

```python
设置图层遮挡(level: int = 1, world: Any = None) -> None
```

设置图层遮挡规则。

0 = 关闭；1 = 被更高 layer 压住的对象不参与碰撞；
2 = 在 1 的基础上，被压住的对象也不能被鼠标点击。


### `图层遮挡等级`

```python
图层遮挡等级(world: Any = None) -> int
```

返回当前图层遮挡等级。


### `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 -->
