You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
import pygame
|
|
import sys
|
|
|
|
# 初始化 Pygame
|
|
pygame.init()
|
|
|
|
# 定义窗口大小
|
|
WIDTH, HEIGHT = 600, 400
|
|
|
|
# 创建窗口
|
|
win = pygame.display.set_mode((WIDTH, HEIGHT))
|
|
pygame.display.set_caption("Flappy Bird Clone")
|
|
|
|
# 颜色定义
|
|
BACKGROUND_COLOR = (135, 206, 250)
|
|
BIRD_COLOR = (255, 255, 0)
|
|
|
|
# 初始化小鸟位置和速度
|
|
bird_x, bird_y = WIDTH // 2, HEIGHT // 2
|
|
# print(type(bird_x))
|
|
bird_vel_y = 0
|
|
|
|
# 游戏主循环
|
|
while True:
|
|
# 事件处理
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
pygame.quit()
|
|
sys.exit()
|
|
|
|
# 小鸟控制
|
|
keys = pygame.key.get_pressed()
|
|
if keys[pygame.K_SPACE]:
|
|
bird_vel_y = -1
|
|
|
|
# 小鸟移动
|
|
bird_y += bird_vel_y
|
|
bird_vel_y += 0.02 # 添加重力
|
|
|
|
# 绘制背景
|
|
win.fill(BACKGROUND_COLOR)
|
|
|
|
# 绘制小鸟
|
|
print(bird_x)
|
|
print(bird_y)
|
|
pygame.draw.circle(win, BIRD_COLOR, (bird_x, bird_y), 10)
|
|
|
|
# 更新窗口
|
|
pygame.display.update() |