Skip to main content

🎮 WaliGame 2026.11.16

面向少儿编程的 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 的物理/类型基础);pygame 2.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)

GIF 动画

Character 也支持 GIF,会把 GIF 拆成多帧并按每帧延迟循环播放:

player = Character("walk.gif", size=40)

player.stop_anim()   # 暂停
player.play_anim()   # 继续
player.frame = 0     # 跳到第 0 帧
  • GIF 默认自动播放
  • 保留原 GIF 的每帧 duration
  • 单图、图片列表、状态字典的用法不变
  • GIF 需要 Pillow,安装 WaliGame 时会自动安装

动画帧范围

列表、GIF、字典状态动画都可以只播放一段帧:

player = Character("actions.gif", size=40)

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 帧后自动停止
  • 字典动画只作用于当前 state
  • frame_count 查看总帧数,frame_range 查看当前范围
  • clear_frame_range() 恢复全部帧
images = Character(["a.png", "b.png", "c.png", "d.png"])
images.play_frames(1, 2)

states = Character({"idle": [...], "run": [...]})
states.state = "run"
states.play_frames(0, 2)

窗口放大 scale

setup 新增 scale 参数:

setup(1400, 600, dpi_aware=True, scale=1.5)
  • 逻辑坐标仍然是 1400 × 600
  • 实际窗口变成 2100 × 900
  • 鼠标坐标自动换算回逻辑坐标
  • HUD、角色、相机统一放大
  • 默认 scale=1.0,不开启时没有额外缩放成本
  • global_var.SCALE / global_var.SCREEN.window_size 可查询

没有图片也能创建角色

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

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

没有物理体的角色

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 供对照。

WaliGame 完整 API 参考

版本:2026.11.16
由 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]

把对象层的对象实例化为游戏对象(返回列表)。

做三件事:

  1. 每个 TMX 对象按其顶点生成一个 POLY 刚体,因此可直接参与碰撞检测(obj.collide(...)) 与物理;
  2. TMX 图块对象(object 带 gid)会自动带上贴图;也可以用 images={"对象名": "图片路径"} 给任意对象指定贴图;
  3. 把 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)。

其他公开类型

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.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for WaliGame 2026.11.16
File Size Uploaded Provenance Actions
waligame-2026.11.16.tar.gz 328.0 kB Without provenance Details for waligame-2026.11.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for WaliGame 2026.11.16
File Interpreter ABI Platform Actions
waligame-2026.11.16-py3-none-any.whl Python 3 none any Details for waligame-2026.11.16-py3-none-any.whl

Total release size: 584.0 kB

Release files / waligame-2026.11.16.tar.gz

Download URL waligame-2026.11.16.tar.gz
Size 328.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2a62de1cb514dd0dbf8b588d90bc4987bb3e4c2d410bedb2d981344cb5475716
BLAKE2b-256 checksum
How to use checksums
dba6b9f98d7e3e79df9bc260a39e7046390b1543f1902057641b9f13b42fad0d
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.16-py3-none-any.whl

Download URL waligame-2026.11.16-py3-none-any.whl
Size 256.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80959cc65956ed98ceadd0a9a1d7ca0d3ac1285642074685020d519541c3fc4a
BLAKE2b-256 checksum
How to use checksums
7e688c29a3b42c88fbf1cd99e8b0d5b1e0d9530757d2438dc684b14f4bb50bd6
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.16

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page