🎮 WaliGame 2026.11.9
面向少儿编程的 2D 游戏引擎。基座来自 Walimaker 4.0.2(MIT), 在其工程化架构上合并了 2026.11.1 的教学功能,并重命名为 WaliGame。 游戏代码里使用
import waligame/from waligame import *。版本记录:
VERSION_LOG.md(每次更新必须升版本号并记录)。
完整 API 参考见 WaliGame API 文档.md(安装包内)。
安装
# 本地 wheel
python -m pip install "waligame-2026.11.6-py3-none-any.whl"
# 依赖
python -m pip install "pygame>=2.5.0" "pymunk>=6.5.0" "pytmx>=3.32"
pymunk必须 6.5+(4.0.2 的物理/类型基础);pygame2.5+。
2026.11.6 安装器会先检测旧包:
Walimaker(含 2026.11.1 / 上游 4.0.2) 和最早的WalimakerPythonGameEngine(2023.8.1)。 如果检测到,会询问是否卸载;选择“不卸载”会直接退出,不会安装 WaliGame。 选择“卸载”会先卸载旧包,再安装 WaliGame。
第一个游戏
import waligame
waligame.setup(800, 600)
waligame.title("我的第一个 WaliGame 游戏")
player = waligame.Character("player.png", size=(40, 60), tag="player")
player.goto(0, 0)
while True:
if waligame.key_pressed(waligame.K_RIGHT):
player.velocity = (250, player.velocity[1])
elif waligame.key_pressed(waligame.K_LEFT):
player.velocity = (-250, player.velocity[1])
else:
player.velocity = (0, player.velocity[1])
waligame.update()
也可以 from waligame import *,和旧版 Walimaker 的写法一致。
这一版保留/新增了什么
在 4.0.2 的底子上:
Object → GameObject → Character/Sensor/Wall/Mouse继承链- 多世界
World、setup(..., world=w2)、update(world=w2) ResourceManager:图片 LRU、弱引用 mask 缓存、preload()- 60 FPS + 固定物理步长累加器 + 防隧穿子步
- 相机
shake/deadzone/zoom_to/ 平滑缩放 - 约束
connect()/Spring()、TiledMap.create_objects() - 中文报错助手
error_help、字体回退fonts - 类型信息
py.typed、MIT 许可、src 布局
在 2026.11.1 的教学功能上:
-
兼容旧课件的星号导入:
from waligame import *也会带出random/time/os/math/sys/pygame(旧 Walimaker 课件常用random.randint而不写 import) -
主包内置
Walimaker别名:安装 WaliGame 后,from Walimaker import *等价于from waligame import *。 -
every(秒, 函数)/after(秒, 函数)/clear_timers()计时器 -
tag="zombie"+find_all()/find()/collide_tag() -
clone()复制对象(模板做子弹/僵尸) -
follow(目标, speed, stop)/stop_follow() -
on_screen判断是否在镜头内 -
Score/Label屏幕 HUD -
没有物理体的对象也支持
velocity(像素/帧) -
DPI 适配默认关闭:
setup(宽, 高);需要 Windows 物理像素时setup(..., dpi_aware=True) -
控制台:隐藏 pygame/pymunk 横幅、第一帧打印
【欢迎使用 WaliGame 2026.11.6】游戏启动成功! -
get_angle兼容别名(新代码用angle) -
鼠标“按住”状态每帧维护:松手发生在滑梯/动画等没有查询鼠标的状态里,也不会再卡住
-
音频失败只警告一次并静音继续:
bgmusic/play_snd/music_*不再因没有音频设备而崩溃 -
key_just_pressed/key_just_released默认“任意一个”,require_all=True恢复“全部按下”
典型用法
计时器 + 标签 + 碰撞
import waligame
from waligame import *
setup(900, 600)
player = Character("player.png", size=(40, 60), tag="player")
zombie = Character("zombie.png", size=(40, 80), tag="zombie")
score = Score()
def shoot():
bullet = Character("pea.png", tag="bullet")
bullet.goto(player.pos)
bullet.velocity = (8, 0)
every(1.2, shoot)
while True:
for bullet in find_all("bullet"):
hit = bullet.collide_tag("zombie")
if hit:
hit.kill()
bullet.kill()
score.add(10)
elif not bullet.on_screen:
bullet.kill()
update()
复制模板
template = Character("pea.png")
pea = template.clone()
pea.goto(player.pos)
pea.velocity = (8, 0)
没有物理体的角色
bullet = Character("pea.png") # 不传 size
bullet.velocity = (8, 0) # 每帧 8 像素,不受重力,不会被推
多世界
from waligame import World, setup, update
w2 = World()
setup(800, 600, world=w2)
update(world=w2)
通用联机房间
从 2026.11.6 起,WaliGame 提供通用局域网房间,不只为石头剪刀布写:
from waligame import *
net = 联机("我的游戏", 最多人数=4)
if not net.大厅():
raise SystemExit
setup(800, 600)
while True:
for msg in net.收到():
print(msg["玩家"], msg["内容"])
net.发送({"type": "操作", "data": ...})
update()
大厅():创建/查找房间、密码、玩家列表、房主开始;返回True表示开始。- 创建房间可设置:房间号/房间名、最多人数、玩家名、密码。
net.是房主、net.玩家列表、net.我的编号。net.发送()发给其他玩家;net.收到()返回{"玩家", "编号", "内容"}。大厅()要在setup()之前调用;大厅结束后再setup()。- 房主大厅会显示
房间地址:IP:端口,朋友找不到房间时用“直接输入 IP”。 - 只负责房间和消息转发;游戏规则由孩子写。
联机(..., 允许中途加入=True)支持游戏开始后加入;本版另附彩色食材大作战.py示例。
旧写法兼容
从 2026.11.6 起,Walimaker 别名直接内置在主 wheel 里:
from Walimaker import *
# 等价于 from waligame import *
安装 WaliGame 就同时有了 waligame 和 Walimaker,不需要再单独安装 compat 包。
注意:如果环境里还装着旧的 walimaker(2026.11.1 或 PyPI 4.0.2),它的
Walimaker/ 包目录会遮住别名;请先卸载旧包:
python -m pip uninstall -y walimaker
音频
setup()会尝试 48000/44100、2/1 声道打开 mixer;全部失败时只打印一次【WaliGame 音频提示】,游戏继续静音运行。bgmusic()返回True/False;play_snd()/music_*()在音频不可用时安全跳过。- 需要判断音频状态时用:
from waligame import audio_available, ensure_audio, audio_info if audio_available: # 动态反映当前 mixer 状态 bgmusic("bgm.mp3") ensure_audio() # 再尝试打开一次 print(audio_info()) # 诊断信息
- 安装包的
安装完在这里进行测试\音频诊断.py可打印 SDL 设备并尝试多种格式。
与 Walimaker 4.0.2 的差异
- 包名:
waligame;发行名:WaliGame;版本:2026.11.6 - 新增上面列出的计时器、tag、clone、follow、on_screen、Score/Label、 无物理体 velocity、DPI、欢迎语
get_angle保留为angle的兼容别名key_just_pressed默认改为“任意一个”- 控制台默认干净(pygame/pymunk 横幅、libpng 警告)
许可证与来源
WaliGame 基于 Walimaker 4.0.2(MIT,Copyright (c) 2026 Walimaker Project
Contributors)做了大幅修改与扩展。原始 MIT 许可证保留在 LICENSE,
来源说明见 NOTICE。4.0.2 的原始 README 保留为 README_4.0.2.md 供对照。
Metadata
Release files for WaliGame 2026.11.9
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.9.tar.gz | 270.0 kB | Without provenance | Details for waligame-2026.11.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| waligame-2026.11.9-py3-none-any.whl | Python 3 | none | any | Details for waligame-2026.11.9-py3-none-any.whl |
Total release size: 504.5 kB
Release files / waligame-2026.11.9.tar.gz
| Download URL | waligame-2026.11.9.tar.gz |
|---|---|
| Size | 270.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
93c25ebdf40fb1329611d90024e172924dc197dd3d323df9c96ea6e7768f24d2
|
|
BLAKE2b-256 checksum How to use checksums |
e25bf8e7e25c819f35955bf0e6c07d7506fa75bb15dfa00f2eb17aed812fe540
|
| 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.9-py3-none-any.whl
| Download URL | waligame-2026.11.9-py3-none-any.whl |
|---|---|
| Size | 234.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0e363f587d4aefab1f371f749e6c21e4bbfcfd35f890efd284b78bba1e16212
|
|
BLAKE2b-256 checksum How to use checksums |
359bc0d67f070da38e1d8865add9645d347a72536502f23172ee9fb3e1ddc88c
|
| 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.9
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.