猫史档案馆


【Python作品分享】8-3

用户:黄金狒狒座黄金狒狒座查看:0 回复:0 评论:0 创建时间:2021-05-08T21:22:49


【作品展示】

center_image

 

【作品介绍】

 

【作品源代码】

import pgzrun  # 导入游戏库
WIDTH = 600
HEIGHE = 800  # 窗口的宽度和高度
playerSpeed = 5  # 玩家水平移动的速度
alien = Actor('alien')  # 导入角色(alien)
alien.x = WIDTH/2
alien.y = HEIGHE/2  # 设置角色的坐标
brick = Actor('brick')
brick.x= WIDTH/2
brick.y= 460
bricks = []
for i in range(5):
    brick = Actor('brick')
    brick.pos = 100*(i+1),150*(i+1)
    bricks.append(brick)



def draw():  # 绘制模块,每帧重复执行
    screen.clear()  # 清屏处理
    alien.draw()
    for brick in bricks:
        brick.draw()
def update():  # 更新模块,每帧重复执行
    if abs(alien.bottom - brick.top) < 5 and brick.left - alien.left < alien.width*2/3 and alien.right - brick.right < alien.width*2/3:
        if keyboard.left:  # 如果按下键盘左键
            alien.x = alien.x - playerSpeed  # 玩家左移
        if keyboard.right :  # 如果按下右键
            alien.x = alien.x + playerSpeed  # 玩家右移
    else:
        alien.y +=5

pgzrun.go()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页