用户:
胡桃,,查看:0 回复:1 评论:0 创建时间:2021-03-28T15:31:54
【作品展示】

【作品介绍】
小鸟伏特加
【作品源代码】
import pygame
pygame.init()
keep_going = True
cnt = 0
timer = pygame.time.Clock()
class Cat():
def __init__(self):
self.x = 100 # 设置x坐标初始值为100
self.y = 100 # 设置y坐标初始值为100
self.y_speed = 0 # 设置起跳初始度为0
self.jumpSpeed = -12 # 设置起跳速度为-12
self.gravity = 0.8 # 模似重力
def jump(self):
self.y_speed = self.jumpSpeed # 更新起跳速度
def get_position(self):
self.y += self.y_speed # 更新y坐标
self.y_speed += self.gravity # 重力作用下改变速度
return (self.x, self.y)
codemao = Cat() # 生成codemao对象
while keep_going:
screen = pygame.display.set_mode([1000,300])
bg_color = (255, 255, 255)
screen.fill(bg_color)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
print("编程猫跳")
codemao.jump()
screen.blit(codemao.pose_list[cnt % 29], (100, 100)) # 绑定图片到对应位置
pygame.display.update()
cnt += 1
timer.tick(70)
pygame.quit()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn