🎮 WaliGame 2026.11.17
面向少儿编程与课堂教学的 2D 游戏引擎。 基座来自 Walimaker 4.0.2(MIT),在保留旧课件写法的同时,提供更完整的对象模型、物理、相机、中文报错、局域网联机和开箱即用的默认素材。
📖 目录
- ✨ 特性亮点 | 🚀 快速开始 | 📦 安装
- 🧑🎓 默认角色 | 🎞️ GIF 与帧范围 | 🪟 窗口放大
- 🏫 局域网联机 | ⏱️ 教学便利 API | 🩺 中文报错与字体
- 🔁 旧写法兼容 | 🧭 与 Walimaker 4.3.5 的关系 | 📚 完整 API
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) 只是 4.3.5 风格的辅助入口,不是主功能,也不应替代 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
python -m pip install WaliGame
本地 wheel
python -m pip install "waligame-2026.11.17-py3-none-any.whl"
依赖
Python >= 3.8.1
pygame >= 2.5.0
pymunk >= 6.5.0
pytmx >= 3.32
Pillow >= 9.0
GIF 需要 Pillow;其余功能只需要 pygame/pymunk。
Windows 用户也可以使用安装器:
双击我安装(2026.11.17).bat
双击我安装(2026.11.17-网络版).bat
安装器会先检测 Walimaker / WalimakerPythonGameEngine 旧包,避免两套引擎混装。
Quickstart
🚀 第一个游戏
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) 是兼容 4.3.5 的辅助写法,不是 WaliGame 的主功能,普通游戏不需要使用。
Character
🧑🎓 默认角色
不传图片也能创建角色:
Character(size=40) # 内置白色圆形
Character(size=40, shape="square") # 内置白色方形
颜色可以直接改:
player = Character(size=40)
player.color = (255, 80, 80, 255)
Animation
🎞️ GIF 与帧范围
GIF 会按每帧自带时长自动播放:
player = Character("walk.gif", size=48)
player.play_anim()
player.stop_anim()
player.frame = 2
12 帧 GIF 可以拆成四个动作:
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
🪟 窗口放大
setup(1400, 600, dpi_aware=True, scale=1.5)
- 逻辑坐标仍然是
1400 × 600 - 实际窗口为
2100 × 900 - 鼠标坐标自动换算回逻辑坐标
- HUD、角色、相机统一放大
- 默认
scale=1.0,不开启时没有额外缩放成本
LAN
🏫 局域网联机
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 返回大厅
Helpers
⏱️ 教学便利 API
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 常量、路径错误等常见问题
开关:
set_error_help(False)
或:
WALIGAME_ERROR_HELP=0
内置字体:
waligame/static/NotoSansSC-Regular.otf
默认优先使用包内中文字体,找不到才回退系统字体,避免另一台电脑上因缺少微软雅黑/黑体而显示方框或报错。
字体许可:SIL Open Font License 1.1,详见包内 NotoSansSC-OFL.txt。
Compatibility
🔁 旧写法兼容
from Walimaker import *
等价于:
from waligame import *
旧的 random / time / os / math / sys / pygame 星号导入也保留,旧课件通常不用改。
Upstream
🧭 与 Walimaker 4.3.5 的关系
WaliGame 的基座是 Walimaker 4.0.2,并在此之上加入:
- 联机大厅与网络层
- 默认圆形/方形角色
- GIF 与帧范围
- 窗口
scale - 安装器与旧包迁移
- 更完整的中文文档
Walimaker 4.3.5 的网页版打包依赖 pygbag、WebAssembly、pymunk 6.4.0 和浏览器专用的资源/网络适配,和桌面版不是同一套运行方式;WaliGame 当前仍以桌面和局域网为主,不对“直接 --web”作承诺。
API
📚 完整 API
下面是根据 waligame.__all__ 自动生成的完整 API 参考,包含所有公开函数、类、方法和属性。
WaliGame 完整 API 参考
版本:
2026.11.17
由tools/generate_api_reference.py从waligame.__all__自动生成。
使用方式
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
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
update(world: Optional[waligame.config.World] = None) -> None
推进一个世界一帧(默认世界可省略参数)。
title
title(title: str) -> None
done
done(world: Optional[waligame.config.World] = None) -> None
save_screen
save_screen(name: str, world: Optional[waligame.config.World] = None) -> None
bgpic
bgpic(img, world=None)
把一张图片 / Surface / TileMap 作为背景铺上,并把相机尺寸设成它的大小。
- 传
TiledMap:用TiledMapStrategy把整张地图渲染成一个精灵。 历史实现只改相机尺寸、并不会渲染地图(想显示必须绕道Character(tiledmap)),现已修正。 - 传图片路径 /
Surface:按普通精灵渲染。
返回背景对象,便于后续移动或销毁(例如 bgpic("bg.png").kill())。
debug
debug(world=None)
set_depth
set_depth(i: int = 1) -> str
返回向上 i 级的相对路径字符串(例如 set_depth(2) -> "../../")。
行为变更:历史版本会直接 os.chdir()——库函数擅自改变调用进程的工作目录,
之后所有相对路径(含资源加载)都会跟着漂移,极难排查。现在只返回路径字符串,
并发出一次 DeprecationWarning;确实需要切换目录时请在自己的代码里显式:
.. code-block:: python
import os
os.chdir(set_depth(2))
对象与角色
Object
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
apply_force(x, *y)
Object.blue
属性(property)。
Object.body
属性(property)。
Object.body_scale
body_scale(scalex, scaley)
Object.color
属性(property)。
Object.elasticity
属性(property)。
Object.flipx
flipx(h)
Object.flipy
flipy(v)
Object.friction
属性(property)。
Object.green
属性(property)。
Object.height
属性(property)。
Object.hide
hide()
Object.kill
kill()
销毁对象:销毁三个组件、清空槽位、置 alive = False,最后回调 :meth:_on_kill。
Object.layer
属性(property)。
Object.mass
属性(property)。
Object.move_to_back
move_to_back()
Object.move_to_front
move_to_front()
Object.pos
属性(property)。
Object.red
属性(property)。
Object.rot
属性(property)。
Object.scale
scale(scalex, scaley=None)
Object.scl
属性(property)。
Object.set_body
set_body(body)
Object.set_sprite
set_sprite(sprite)
Object.set_tiledmap_bodies
set_tiledmap_bodies(tiledmap_bodies)
Object.shift_by
shift_by(delta)
按增量直接位移,不改变速度(这是它与 pos setter 的区别)。
内部按键位移 / 滑行动画用它:只挪位置,重力等已有速度继续生效。
直接写 obj.pos = ... / goto() 则视为瞬移,会清零速度。
Object.show
show()
Object.sprite
属性(property)。
Object.sync_pos
sync_pos(pos)
由物理层同步显示坐标(只改缓存)。
物理每帧把刚体位置回写自身会触发无意义的 reindex_shapes_for_body(宽相重排), 因此这里既不写回刚体、也不清速度,只更新缓存坐标。
Object.sync_rot
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
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) -> 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
backward(d: float) -> None
GameObject.clear_frame_range
clear_frame_range()
恢复完整帧范围。
GameObject.clone
clone()
复制一个自己(图片/大小/位置/缩放/旋转/颜色/tag/物理属性)。
兼容自定义子类:例如 class Plant(Sensor): def __init__(self): ...。
会按子类真实构造签名选择参数,而不是假定它接受 imgs/size/world/tag。
GameObject.collide
collide(other: Any) -> Any
GameObject.collide_tag
collide_tag(tag)
和某个 tag 的任意对象碰撞,返回碰到的对象(没有就返回 None)。
GameObject.dir
属性(property)。
GameObject.distance
distance(other: Any) -> float
GameObject.dt
属性(property)。
GameObject.face_to
face_to(x, *y, VEC=False)
GameObject.follow
follow(target, speed=2, stop=0)
每帧朝 target(对象或坐标)移动 speed,距离小于 stop 时停下。
GameObject.forward
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
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
GameObject.get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
GameObject.get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
GameObject.get_mouse_upon
get_mouse_upon() -> bool
GameObject.goto
goto(x: Any, *y: Any) -> None
GameObject.left
left(a)
GameObject.on_screen
属性(property)。
是否在摄像机可见范围内(用来清理飞出屏幕的子弹)。
GameObject.play_anim
play_anim() -> None
GameObject.play_frames
play_frames(start, end=None, loop=True)
播放 start-end 帧(包含首尾),并开始播放。
list / GIF / 字典状态动画都支持;字典只作用于当前 state。
GameObject.play_snd
play_snd(snd=None, volume=None)
GameObject.right
right(a)
GameObject.rotate_direction
rotate_direction(rot)
GameObject.rotate_image
rotate_image(rot)
GameObject.say
say(text: Any = None, textColor: Any = (0, 0, 0)) -> None
GameObject.separate
separate(other: Any) -> bool
GameObject.set_angle
set_angle(angle)
GameObject.set_dt
set_dt(*args: Any) -> None
GameObject.set_end_func
set_end_func(state, func)
GameObject.set_frame_range
set_frame_range(start, end=None, loop=True)
只设置帧范围,不改变当前播放/暂停状态。
GameObject.set_next_state
set_next_state(state: str, next_state: str) -> None
GameObject.set_start_func
set_start_func(state, func)
GameObject.set_volume
set_volume(volume)
GameObject.slide_to
slide_to(pos, v=1)
GameObject.state
属性(property)。
GameObject.stop_anim
stop_anim() -> None
GameObject.stop_follow
stop_follow()
GameObject.update
update()
GameObject.播放帧
播放帧(start, end=None, loop=True)
GameObject.清除帧范围
清除帧范围()
GameObject.设置帧范围
设置帧范围(start, end=None, loop=True)
NewGameObject
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) -> 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
backward(d: float) -> None
NewGameObject.clear_frame_range
clear_frame_range()
恢复完整帧范围。
NewGameObject.clone
clone()
复制一个自己(图片/大小/位置/缩放/旋转/颜色/tag/物理属性)。
兼容自定义子类:例如 class Plant(Sensor): def __init__(self): ...。
会按子类真实构造签名选择参数,而不是假定它接受 imgs/size/world/tag。
NewGameObject.collide
collide(other: Any) -> Any
NewGameObject.collide_tag
collide_tag(tag)
和某个 tag 的任意对象碰撞,返回碰到的对象(没有就返回 None)。
NewGameObject.dir
属性(property)。
NewGameObject.distance
distance(other: Any) -> float
NewGameObject.dt
属性(property)。
NewGameObject.face_to
face_to(x, *y, VEC=False)
NewGameObject.follow
follow(target, speed=2, stop=0)
每帧朝 target(对象或坐标)移动 speed,距离小于 stop 时停下。
NewGameObject.forward
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
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
NewGameObject.get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
NewGameObject.get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
NewGameObject.get_mouse_upon
get_mouse_upon() -> bool
NewGameObject.goto
goto(x: Any, *y: Any) -> None
NewGameObject.left
left(a)
NewGameObject.on_screen
属性(property)。
是否在摄像机可见范围内(用来清理飞出屏幕的子弹)。
NewGameObject.play_anim
play_anim() -> None
NewGameObject.play_frames
play_frames(start, end=None, loop=True)
播放 start-end 帧(包含首尾),并开始播放。
list / GIF / 字典状态动画都支持;字典只作用于当前 state。
NewGameObject.play_snd
play_snd(snd=None, volume=None)
NewGameObject.right
right(a)
NewGameObject.rotate_direction
rotate_direction(rot)
NewGameObject.rotate_image
rotate_image(rot)
NewGameObject.say
say(text: Any = None, textColor: Any = (0, 0, 0)) -> None
NewGameObject.separate
separate(other: Any) -> bool
NewGameObject.set_angle
set_angle(angle)
NewGameObject.set_dt
set_dt(*args: Any) -> None
NewGameObject.set_end_func
set_end_func(state, func)
NewGameObject.set_frame_range
set_frame_range(start, end=None, loop=True)
只设置帧范围,不改变当前播放/暂停状态。
NewGameObject.set_next_state
set_next_state(state: str, next_state: str) -> None
NewGameObject.set_start_func
set_start_func(state, func)
NewGameObject.set_volume
set_volume(volume)
NewGameObject.slide_to
slide_to(pos, v=1)
NewGameObject.state
属性(property)。
NewGameObject.stop_anim
stop_anim() -> None
NewGameObject.stop_follow
stop_follow()
NewGameObject.update
update()
NewGameObject.播放帧
播放帧(start, end=None, loop=True)
NewGameObject.清除帧范围
清除帧范围()
NewGameObject.设置帧范围
设置帧范围(start, end=None, loop=True)
Character
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) -> 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
clear_frame_range()
恢复完整帧范围。
Character.collide
collide(other: Any) -> Any
Character.distance
distance(other: Any) -> float
Character.dt
属性(property)。
Character.frame
属性(property)。
Character.frame_count
属性(property)。
当前动画的帧数。
Character.frame_range
属性(property)。
当前播放范围 (start, end),包含首尾。
Character.get_mouse_clicked
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
Character.get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
Character.get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
Character.get_mouse_upon
get_mouse_upon() -> bool
Character.play_anim
play_anim() -> None
Character.play_frames
play_frames(start, end=None, loop=True)
播放 start-end 帧(包含首尾),并开始播放。
list / GIF / 字典状态动画都支持;字典只作用于当前 state。
Character.separate
separate(other: Any) -> bool
Character.set_dt
set_dt(*args: Any) -> None
Character.set_end_func
set_end_func(state, func)
Character.set_frame_range
set_frame_range(start, end=None, loop=True)
只设置帧范围,不改变当前播放/暂停状态。
Character.set_next_state
set_next_state(state: str, next_state: str) -> None
Character.set_start_func
set_start_func(state, func)
Character.state
属性(property)。
Character.stop_anim
stop_anim() -> None
Character.播放帧
播放帧(start, end=None, loop=True)
Character.清除帧范围
清除帧范围()
Character.设置帧范围
设置帧范围(start, end=None, loop=True)
Sensor
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) -> 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
clear_frame_range()
恢复完整帧范围。
Sensor.collide
collide(other: Any) -> Any
Sensor.distance
distance(other: Any) -> float
Sensor.dt
属性(property)。
Sensor.frame
属性(property)。
Sensor.frame_count
属性(property)。
当前动画的帧数。
Sensor.frame_range
属性(property)。
当前播放范围 (start, end),包含首尾。
Sensor.get_mouse_clicked
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
Sensor.get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
Sensor.get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
Sensor.get_mouse_upon
get_mouse_upon() -> bool
Sensor.play_anim
play_anim() -> None
Sensor.play_frames
play_frames(start, end=None, loop=True)
播放 start-end 帧(包含首尾),并开始播放。
list / GIF / 字典状态动画都支持;字典只作用于当前 state。
Sensor.separate
separate(other: Any) -> bool
Sensor.set_dt
set_dt(*args: Any) -> None
Sensor.set_end_func
set_end_func(state, func)
Sensor.set_frame_range
set_frame_range(start, end=None, loop=True)
只设置帧范围,不改变当前播放/暂停状态。
Sensor.set_next_state
set_next_state(state: str, next_state: str) -> None
Sensor.set_start_func
set_start_func(state, func)
Sensor.state
属性(property)。
Sensor.stop_anim
stop_anim() -> None
Sensor.播放帧
播放帧(start, end=None, loop=True)
Sensor.清除帧范围
清除帧范围()
Sensor.设置帧范围
设置帧范围(start, end=None, loop=True)
Wall
Wall(imgs=None, size=None, world=None, tag=None)
继承:GameObject
墙壁,无法运动的物体
| 成员 | 类型 | 签名 |
|---|---|---|
clear_frame_range |
method (mixin) | () |
collide |
method (mixin) | (other: Any) -> 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
clear_frame_range()
恢复完整帧范围。
Wall.collide
collide(other: Any) -> Any
Wall.distance
distance(other: Any) -> float
Wall.dt
属性(property)。
Wall.frame
属性(property)。
Wall.frame_count
属性(property)。
当前动画的帧数。
Wall.frame_range
属性(property)。
当前播放范围 (start, end),包含首尾。
Wall.get_mouse_clicked
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
Wall.get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
Wall.get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
Wall.get_mouse_upon
get_mouse_upon() -> bool
Wall.play_anim
play_anim() -> None
Wall.play_frames
play_frames(start, end=None, loop=True)
播放 start-end 帧(包含首尾),并开始播放。
list / GIF / 字典状态动画都支持;字典只作用于当前 state。
Wall.separate
separate(other: Any) -> bool
Wall.set_dt
set_dt(*args: Any) -> None
Wall.set_end_func
set_end_func(state, func)
Wall.set_frame_range
set_frame_range(start, end=None, loop=True)
只设置帧范围,不改变当前播放/暂停状态。
Wall.set_next_state
set_next_state(state: str, next_state: str) -> None
Wall.set_start_func
set_start_func(state, func)
Wall.state
属性(property)。
Wall.stop_anim
stop_anim() -> None
Wall.velocity
属性(property)。
Wall.播放帧
播放帧(start, end=None, loop=True)
Wall.清除帧范围
清除帧范围()
Wall.设置帧范围
设置帧范围(start, end=None, loop=True)
Mouse
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) -> 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
body_scale(scalex, scaley=None)
Mouse.clear_frame_range
clear_frame_range()
恢复完整帧范围。
Mouse.collide
collide(other: Any) -> Any
Mouse.distance
distance(other: Any) -> float
Mouse.dt
属性(property)。
Mouse.frame
属性(property)。
Mouse.frame_count
属性(property)。
当前动画的帧数。
Mouse.frame_range
属性(property)。
当前播放范围 (start, end),包含首尾。
Mouse.get_clicked
get_clicked()
Mouse.get_just_clicked
get_just_clicked()
Mouse.get_just_released
get_just_released()
Mouse.get_mouse_clicked
get_mouse_clicked(b: Union[int, str] = 'all') -> bool
Mouse.get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all') -> bool
Mouse.get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all') -> bool
Mouse.get_mouse_upon
get_mouse_upon() -> bool
Mouse.get_pos
get_pos()
Mouse.get_rel
get_rel()
Mouse.play_anim
play_anim() -> None
Mouse.play_frames
play_frames(start, end=None, loop=True)
播放 start-end 帧(包含首尾),并开始播放。
list / GIF / 字典状态动画都支持;字典只作用于当前 state。
Mouse.separate
separate(other: Any) -> bool
Mouse.set_dt
set_dt(*args: Any) -> None
Mouse.set_end_func
set_end_func(state, func)
Mouse.set_frame_range
set_frame_range(start, end=None, loop=True)
只设置帧范围,不改变当前播放/暂停状态。
Mouse.set_next_state
set_next_state(state: str, next_state: str) -> None
Mouse.set_start_func
set_start_func(state, func)
Mouse.state
属性(property)。
Mouse.stop_anim
stop_anim() -> None
Mouse.update
update()
Mouse.播放帧
播放帧(start, end=None, loop=True)
Mouse.清除帧范围
清除帧范围()
Mouse.设置帧范围
设置帧范围(start, end=None, loop=True)
find_all
find_all(tag, world=None)
返回所有 tag 相同的、还活着的对象。
find
find(tag, world=None)
返回第一个 tag 相同的、还活着的对象;没有则返回 None。
every
every(seconds: float, func, *args, world: Optional[waligame.config.World] = None, **kwargs)
每隔 seconds 秒执行一次 func(第一次在 seconds 秒后),返回可 cancel() 的 timer。
after
after(seconds: float, func, *args, world: Optional[waligame.config.World] = None, **kwargs)
seconds 秒后执行一次 func。
clear_timers
clear_timers(world: Optional[waligame.config.World] = None) -> None
精灵与动画
Sprite
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
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
set_parent(parent: Any) -> None
Sprite.sprite_strategy
属性(property)。
Sprite.update
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
SpriteSheet(sheet: Any, w: int, h: int, world: Optional[waligame.config.World] = None) -> None
EasySpriteStrategy
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
clear_frame_range()
EasySpriteStrategy.frame
属性(property)。
EasySpriteStrategy.frame_count
属性(property)。
EasySpriteStrategy.frame_range
属性(property)。
EasySpriteStrategy.set_frame_range
set_frame_range(start, end=None, loop=True)
EasySpriteStrategy.update
update() -> pygame.surface.Surface
ListSpriteStrategy
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
clear_frame_range()
ListSpriteStrategy.frame
属性(property)。
ListSpriteStrategy.frame_count
属性(property)。
ListSpriteStrategy.frame_range
属性(property)。
ListSpriteStrategy.set_dt
set_dt(dt: float) -> None
ListSpriteStrategy.set_frame_range
set_frame_range(start, end=None, loop=True)
ListSpriteStrategy.update
update() -> pygame.surface.Surface
AnimatorStrategy
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
clear_frame_range()
AnimatorStrategy.frame
属性(property)。
AnimatorStrategy.frame_count
属性(property)。
AnimatorStrategy.frame_range
属性(property)。
AnimatorStrategy.set_dt
set_dt(state: Optional[str], dt: float) -> None
AnimatorStrategy.set_end_func
set_end_func(state: str, func: Any) -> None
AnimatorStrategy.set_frame_range
set_frame_range(start, end=None, loop=True)
AnimatorStrategy.set_next_state
set_next_state(state: str, next_state: str) -> None
AnimatorStrategy.set_start_func
set_start_func(state: str, func: Any) -> None
AnimatorStrategy.state
属性(property)。
AnimatorStrategy.update
update() -> pygame.surface.Surface
TiledMapStrategy
TiledMapStrategy(tiledmap: Any, world: Optional[waligame.config.World] = None) -> None
| 成员 | 类型 | 签名 |
|---|---|---|
update |
method | () |
TiledMapStrategy.update
update()
物理与约束
Body
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
apply_impulse_at_local_point(impulse)
Body.collide
collide(other)
Body.elasticity
属性(property)。
Body.friction
属性(property)。
Body.kill
kill()
Body.mass
属性(property)。
Body.point_query
point_query(p)
Body.set_parent
set_parent(parent: Any) -> None
Body.set_pos
set_pos(pos: Any) -> None
Body.set_rot
set_rot(rot)
Body.set_vertices
set_vertices(vertices, transform)
Body.update
update()
Body.velocity
属性(property)。
BodiesGroup
BodiesGroup() -> None
继承:Group
刚体更新组。
实现已统一到 :class:waligame.config.Group(带更新钩子),本类只是保留公共名字的
薄子类,行为与历史版本完全一致。
TiledMapBodies
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
apply_impulse_at_local_point(pos)
TiledMapBodies.collide
collide(other)
TiledMapBodies.elasticity
属性(property)。
TiledMapBodies.friction
属性(property)。
TiledMapBodies.kill
kill()
TiledMapBodies.mass
属性(property)。
TiledMapBodies.point_query
point_query(p)
TiledMapBodies.set_parent
set_parent(parent)
TiledMapBodies.set_pos
set_pos(pos)
TiledMapBodies.set_rot
set_rot(rot)
TiledMapBodies.set_vertices
set_vertices(scalex, scaley)
TiledMapBodies.update
update()
TiledMapBodies.velocity
属性(property)。
TiledMapBodiesGroup
TiledMapBodiesGroup() -> None
继承:Group
瓦片地图刚体组(同样是 :class:waligame.config.Group 的薄子类)。
Connect
Connect(a: Any, b: Any, world: Any = None) -> None
继承:PinJoint
销钉关节:把两个物体连成一根刚性杆(长度 = 创建时两物体的距离)。
Spring
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
connect(a: Any, b: Any, world: Any = None) -> waligame.constraints.Connect
用刚性杆连接两个物体(等价于 Connect(a, b)),返回该关节。
想要有弹性的连接请用 :class:Spring。
set_gravity
set_gravity(x, *y, world=None)
相机、世界与屏幕
World
World() -> None
一个游戏世界的全部可变状态。
目前 global_var 就是默认世界实例(保留该名字作为兼容别名)。把状态收进
实例是为了后续支持相互独立的世界(多场景切换、单元测试互不干扰)。
| 成员 | 类型 | 签名 |
|---|---|---|
get_value |
method | (var: str) -> Any |
set_value |
method | (var: str, value: Any) -> None |
World.get_value
get_value(var: str) -> Any
World.set_value
set_value(var: str, value: Any) -> None
Camera
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
follow(subject: Any) -> None
Camera.offset
属性(property)。
Camera.pos
属性(property)。
Camera.scale
scale(s: float) -> None
Camera.shake
shake(amount: float = 8.0, duration: float = 0.3) -> None
屏幕抖动(被打中、爆炸等反馈)。
:param amount: 最大像素偏移 :param duration: 持续秒数(期间每帧随机偏移,结束后自动归位)
Camera.size
属性(property)。
Camera.stop_shake
stop_shake() -> None
立即停止抖动。
Camera.update
update() -> bool
重绘相机画面,返回本帧画面是否有变化。
Camera.x
属性(property)。
Camera.y
属性(property)。
Camera.zoom_to
zoom_to(scl: float, speed: float = 2.0) -> None
平滑缩放到 scl(每秒变化 speed 个缩放单位)。
Screen
Screen(size: Tuple[int, int], world: Optional[waligame.config.World] = None, scale: float = 1.0) -> None
| 成员 | 类型 | 签名 |
|---|---|---|
draw |
method | () -> None |
update |
method | () -> None |
Screen.draw
draw() -> None
Screen.update
update() -> None
Group
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
add(obj: Any) -> None
Group.find
find(tag: Any)
Group.find_all
find_all(tag: Any) -> list
按 tag 找所有还活着的对象(不依赖额外索引,tag 改了也不会失效)。
Group.remove
remove(obj: Any) -> None
Group.update
update() -> None
ResourceManager
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
clear_cache(cache_type: Optional[str] = None)
清空缓存。 cache_type: 'image' | 'font' | 'sound' | 'mask' | None(全部)
ResourceManager.get_cache_info
get_cache_info() -> Dict[str, Dict[str, int]]
获取各缓存当前状态
ResourceManager.get_instance
get_instance()
ResourceManager.get_mask
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
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
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
load_sound(path: str) -> Optional[pygame.mixer.Sound]
加载音效(带 LRU 缓存)。
没有可用音频设备时返回 None(游戏静音继续),不抛异常。
ResourceManager.preload
preload(assets: waligame.resource_manager.PreloadAssets)
批量预加载资源。 格式:{ 'images': ['a.png', 'b.png'], 'fonts': [('font.ttf', 24), (None, 32)], 'sounds': ['snd.wav'] }
ResourceManager.reset
reset()
重置单例(仅用于测试)
ResourceManager.unload
unload(path: str)
手动卸载单个图片/音效资源
地图
TiledMap
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
create_objects(name: Optional[str] = None, body_type: Any = 'STATIC', sensor: bool = False, images: Optional[Dict[str, Any]] = None, world: Any = None) -> List[Any]
把对象层的对象实例化为游戏对象(返回列表)。
做三件事:
- 每个 TMX 对象按其顶点生成一个 POLY 刚体,因此可直接参与碰撞检测(
obj.collide(...)) 与物理; - TMX 图块对象(object 带
gid)会自动带上贴图;也可以用images={"对象名": "图片路径"}给任意对象指定贴图; - 把 TMX 的名字 / 自定义属性 / 原始对象挂到游戏对象上
(
.name、.properties、.tmx_object),方便按名字取用。
注意:objects / get_objects() 返回的是 pytmx 的解析结果(几何+属性),
本方法才把它们变成能放进世界的游戏对象。
TiledMap.get_objects
get_objects(name: Optional[str] = None) -> List[Any]
TiledMap.make_map
make_map() -> pygame.surface.Surface
TiledMap.objects
属性(property)。
对象层列表(坐标已换算到游戏坐标系;多次访问结果一致)。
TiledMap.render
render(surface: pygame.surface.Surface) -> None
文字与 HUD
TextBox
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
goto(x, *y)
TextBox.pos
属性(property)。
TextBox.print
print(text: Any = None) -> None
设置文本框内容(下一次 update 时重新渲染)。
TextBox.update
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
write(text: Any = None) -> None
设置文本框内容(下一次 update 时重新渲染)。
DialogBox
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
hide() -> None
DialogBox.say
say(text: Any = None, textColor: Any = None) -> None
DialogBox.show
show() -> None
DialogBox.update
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
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
draw(screen) -> None
Label.goto
goto(x: int, y: int) -> None
Label.hide
hide() -> None
Label.kill
kill() -> None
Label.print
print(text: Any) -> None
Label.show
show() -> None
Label.text
属性(property)。
Label.visible
属性(property)。
Label.write
write(text: Any) -> None
Score
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
add(n=1)
Score.set
set(n)
Score.text
属性(property)。
Score.value
属性(property)。
输入
get_mouse_pos
get_mouse_pos(world: Optional[waligame.config.World] = None) -> Tuple[float, float]
获得鼠标坐标(同一世界同一帧内只查询一次;元组不可变,直接复用是安全的)。
get_mouse_rel
get_mouse_rel(world: Optional[waligame.config.World] = None) -> 'pygame.math.Vector2'
获得鼠标相对移动;窗口放大时自动换算回逻辑坐标。
get_mouse_clicked
get_mouse_clicked(b: Union[int, str] = 'all', world: Optional[waligame.config.World] = None) -> bool
get_mouse_just_clicked
get_mouse_just_clicked(b: Union[int, str] = 'all', world: Optional[waligame.config.World] = None) -> bool
get_mouse_just_released
get_mouse_just_released(b: Union[int, str] = 'all', world: Optional[waligame.config.World] = None) -> bool
mouse_button_down
mouse_button_down(which='all', world: Optional[ForwardRef('World')] = None) -> bool
鼠标键当前是否按下:1 左键 / 2 中键 / 3 右键 / "all" 任意一个。
由 Screen.update() 每帧维护,不依赖某个对象这一帧是否查询鼠标。
key_pressed
key_pressed(key: Optional[int] = None) -> bool
按键是否被按住。
key=None 表示"是否有任意键被按下"。这里用 any() 表达该语义:
旧写法 1 in pygame.key.get_pressed() 效果虽然相同(序列里存的是布尔),
但读起来像是在判断"键码 1",而且把 get_pressed() 调了两次。
key_just_pressed
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
key_just_released(*keys: int, world: Optional[waligame.config.World] = None, require_all: bool = False) -> Union[bool, List[int]]
本帧刚松开的键;默认任意一个,require_all=True 为全部。
key_input
key_input(world: Optional[waligame.config.World] = None) -> str
set_mouse_visible
set_mouse_visible(visible: bool) -> None
显示 / 隐藏鼠标光标。
音频
bgmusic
bgmusic(bgm: str, loops: int = -1, start: float = 0.0) -> bool
播放背景音乐;没有音频设备时静音返回 False,不抛异常。
set_volume
set_volume(vol: float) -> None
music_load
music_load(bgm: str) -> None
music_play
music_play(loops: int = -1, start: float = 0.0) -> None
music_rewind
music_rewind() -> None
music_stop
music_stop() -> None
music_pause
music_pause() -> None
music_unpause
music_unpause() -> None
music_fadeout
music_fadeout(ms: int = 1000) -> None
music_set_volume
music_set_volume(vol: float) -> None
music_get_volume
music_get_volume() -> float
music_get_busy
music_get_busy() -> bool
music_set_pos
music_set_pos(pos: float) -> None
music_get_pos
music_get_pos() -> int
music_queue
music_queue(bgm: str) -> None
music_set_endevent
music_set_endevent(event_id: Optional[int] = None) -> None
music_get_endevent
music_get_endevent() -> int
init
init() -> None
初始化 pygame / mixer / font(可重复调用,幂等)。
历史上这段初始化写在模块顶层:import waligame 就会打开音频与视频子系统,
在没有声卡的 CI/服务器上会直接抛 pygame.error。现在改为由 setup() 显式调用,
导入本包不再有任何副作用。
ensure_audio
ensure_audio() -> bool
确保 mixer 可用;没有音频设备时返回 False,不抛异常。
audio_info
audio_info() -> dict
返回当前音频状态,方便排查(不会抛异常)。
资源、调试与工具
draw_line
draw_line(p1: Any, p2: Any, color: Any, width: float, world: Optional[waligame.config.World] = None) -> None
压一条待绘制线段(在下一个 update 的 draw 阶段画出)。
load_image
load_image(img, world=None)
加载图片,使用资源管理器进行缓存
preload
preload(assets, world=None)
批量预加载资源,避免游戏中第一次使用时的卡顿。
assets 形如::
preload({
"images": ["player.png", "enemy.png"],
"fonts": [(None, 24), (None, 36)], # (字体路径或 None 表示自动, 字号)
"sounds": ["jump.wav"],
})
set_dpi_awareness
set_dpi_awareness() -> bool
让 Windows 按物理像素创建窗口,避免不同 DPI 缩放下大小不一致。
必须在创建窗口(setup)之前调用;非 Windows、或进程已经设置过 DPI 时返回 False。
random_pos
random_pos(world=None)
在世界范围内取一个随机坐标。
sign
sign(n: float) -> int
返回 n 的符号:1 / -1 / 0(对象移动与旋转方向判定共用)。
tracer
tracer(f, world=None)
打开/关闭自动刷新(每个 update 结束时自动 update 一次)。
speed
speed(s, world=None)
设置每步位移上限。
Cartesian2pygame
Cartesian2pygame(x: Any, *y: Any, world: Optional[ForwardRef('World')] = None) -> Tuple[float, float]
世界坐标 -> 窗口坐标;world 缺省为默认世界。
pygame2Cartesian
pygame2Cartesian(x: Any, *y: Any, world: Optional[ForwardRef('World')] = None) -> Tuple[float, float]
窗口坐标 -> 世界坐标;world 缺省为默认世界。
to_cp
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
install_error_help()
安装中文报错助手(重复调用安全)。
uninstall_error_help
uninstall_error_help()
卸载中文报错助手,恢复原有 excepthook。
set_error_help
set_error_help(enabled)
开 / 关中文报错助手(等价于 install_error_help / uninstall_error_help)。
is_error_help_enabled
is_error_help_enabled()
explain_exception
explain_exception(exc, tb=None)
在 except 块里使用:print(explain_exception(e))。
联机
LanGame
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
create_room(player_name: str, room_name: str, max_players: int, password: str = '') -> None
LanGame.join_room
join_room(room: Dict[str, Any], player_name: str, password: str = '') -> None
LanGame.leave_room
leave_room() -> None
LanGame.start
start() -> bool
LanGame.关闭
关闭() -> None
LanGame.发送
发送(data: Any) -> bool
LanGame.大厅
大厅() -> bool
LanGame.我的编号
属性(property)。
LanGame.收到
收到() -> List[Dict[str, Any]]
LanGame.是房主
属性(property)。
LanGame.玩家列表
属性(property)。
联机
联机(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
create_room(player_name: str, room_name: str, max_players: int, password: str = '') -> None
联机.join_room
join_room(room: Dict[str, Any], player_name: str, password: str = '') -> None
联机.leave_room
leave_room() -> None
联机.start
start() -> bool
联机.关闭
关闭() -> None
联机.发送
发送(data: Any) -> bool
联机.大厅
大厅() -> bool
联机.我的编号
属性(property)。
联机.收到
收到() -> List[Dict[str, Any]]
联机.是房主
属性(property)。
联机.玩家列表
属性(property)。
其他公开类型
run
run(loop: Any, world: Optional[waligame.config.World] = None) -> None
可选的辅助主循环,兼容 4.3.5 的 run(game) 写法。
WaliGame 桌面版的标准写法仍然是::
while True:
...
update()
run(game) 每帧调用一次 game() 后自动 update();
game 里不要再调用 update()。它不是桌面版的主功能,
也不应替代 while True: update()。
vec
外部类型别名:pygame.math.Vector2
Color
外部类型别名:pygame.color.Color
Rect
外部类型别名:pygame.rect.Rect
公开变量
| 名称 | 类型 |
|---|---|
global_var |
World |
audio_available |
_AudioState |
cwd |
str |
__version__ |
str |
Metadata
Release files for WaliGame 2026.11.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| waligame-2026.11.17.tar.gz | 2.0 MB | Without provenance | Details for waligame-2026.11.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| waligame-2026.11.17-py3-none-any.whl | Python 3 | none | any | Details for waligame-2026.11.17-py3-none-any.whl |
Total release size: 4.0 MB
Release files / waligame-2026.11.17.tar.gz
| Download URL | waligame-2026.11.17.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e194fd1d3441f73d4e36b55932f309d1f27c897d6fb872e8fdd554431511f14d
|
|
BLAKE2b-256 checksum How to use checksums |
a04a8a65ccadda1ea303b7494923ad8ddb580c59ad7ed9885028a18b98cad0a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Release files / waligame-2026.11.17-py3-none-any.whl
| Download URL | waligame-2026.11.17-py3-none-any.whl |
|---|---|
| Size | 2.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d761b84cf3aa011fc5708b18df923dd5ec5841748fc101ca4279bac4bb7b4ac
|
|
BLAKE2b-256 checksum How to use checksums |
3fb674c2f93e54ce6478d031ff3fb8724529b0782b11e9f67f0a56816a8ba0b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Security for WaliGame 2026.11.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.