Commit 6b26f75f by BellCodeEditor

save project

parent 8a521983
Showing with 22 additions and 8 deletions
import pygame
import pygame,random
from pygame import locals
pygame.init() # 初始化
......@@ -16,19 +16,20 @@ index = 0
y=400
jump="running"
t=30
obstacle=random.choice([apple,cacti,stone])
rest=obstacle.get_rect()
rest.x=1000
rest.y=500-rest.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
pio=hero[index]
if index<4:
index+=1
else:
index=0
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
jump="up"
if jump=="running":
if event.key == locals.K_SPACE:
jump="up"
if jump=="up":
if t>0:
y-=t
......@@ -42,9 +43,22 @@ while True:
else:
jump="running"
t=30
if jump=="running":
pio=hero[index]
if index<4:
index+=1
else:
index=0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
if rest.x<=0-rest.width:
obstacle=random.choice([apple,cacti,stone])
rest=obstacle.get_rect()
rest.x=1000
rest.y=500-rest.height
rest.x-=8
screen.blit(obstacle, (rest.x, rest.y))
screen.blit(pio, (150, y))
pygame.display.set_caption("悟空酷跑")
# 刷新画面
......
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