天天看点

Python精灵模块:走来走去的小猫咪

"""
   本程序会实例化一只小猫,它会不断地在窗口中走来走去.
"""

from sprites import *         # 从精灵模块导入所有命令

frames = 'res/cat1.png','res/cat2.png'
cat = Sprite(frames)          # 新建精灵,造型帧序列为frames 
cat.rotatemode(1)             # 设置旋转模式为左右翻转

while True:
    cat.fd(10)                # 小猫前进10个单位
    cat.nextcostume()         # 小猫切换到下一个造型
    cat.bounce_on_edge()      # 小猫碰到边缘就反弹
    cat.wait(0.2)             # 小猫等待0.2秒