Commit 8c682624 by BellCodeEditor

save project

parent 12c5384b
Showing with 26 additions and 3 deletions
import pygame import pygame
from pygame import locals from pygame import locals
y=400
ddd="running"
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
...@@ -22,6 +23,21 @@ while True: ...@@ -22,6 +23,21 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE:
ddd="up"
if ddd=="up":
if y>150:
y-=5
else:
ddd="down"
if ddd=="down":
if y<400:
y+=5
else:
ddd="running"
index+=1 index+=1
if index>4: if index>4:
...@@ -31,11 +47,18 @@ while True: ...@@ -31,11 +47,18 @@ while True:
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(guku, (150, 400)) screen.blit(guku, (150, y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE:
ddd="up"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment