Commit f46b8148 by BellCodeEditor

save project

parent 19a042df
Showing with 24 additions and 8 deletions
import pygame
import random
from pygame import locals
pygame.init() # 初始化
......@@ -18,7 +19,12 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png'),]
index = 0
y=400
t=30
x=150
obstacle=random.choice([apple,stone,cacti])
rect=obstacle.get_rect()
rect.x=1000
rect.y=500-rect.height
jumpState="runing"
pygame.display.set_caption("悟空快跑")
wkzx=['hero1.png','hero2.png','hero3.png','hero4.png','hero5.png']
......@@ -27,28 +33,38 @@ while True:
if event.type == locals.QUIT:
exit()# 接收到退出事件后退出程序
if event.type == locals.KEYDOWN:
if jumpState=="runing":
if event.key==locals.K_SPACE:
jumpState="up"
if jumpState=="up":
if y>150:
y-=5
x+=1
if t>0:
y-=t
t-=2
else:
jumpState="down"
if jumpState=="down":
if y<400:
y+=5
x-=1
if t<=30:
y+=t
t+=2
else:
jumpState="runing"
t=40
wukong=hero[index]
if jumpState=="runing":
index+=1
if index>=5:
index=0
if rect.x<=0-rect.width:
obstacle=random.choice([apple,stone,cacti])
rect=obstacle.get_rect()
rect.x=1000
rect.y=500-rect.height
rect.x-=12
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (x, y))
screen.blit(obstacle,(rect.x,rect.y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
FPS.tick(30)
\ No newline at end of file
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