Commit 852b89f0 by BellCodeEditor

save project

parent 4fe2d97c
Showing with 20 additions and 7 deletions
...@@ -18,6 +18,11 @@ hero = [pygame.image.load('hero1.png'), ...@@ -18,6 +18,11 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
sj = random.choice([stone,cacti,apple])
rect = sj.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
index = 0 index = 0
y = 400 y = 400
state='runing' state='runing'
...@@ -28,9 +33,8 @@ while True: ...@@ -28,9 +33,8 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if state == "runing": if event.key == locals.K_SPACE:
if event.key == locals.K_SPACE: state = "up"
state = "up"
if state == "up": if state == "up":
if t >= 0: if t >= 0:
y-=t y-=t
...@@ -46,14 +50,22 @@ while True: ...@@ -46,14 +50,22 @@ while True:
t = 30 t = 30
wukong=hero[index] wukong=hero[index]
if state == "runing": index+=1
index+=1 if index==5:
if index==5: index=0
index=0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(wukong, (150, y)) screen.blit(wukong, (150, y))
if rect.x < 0 - rect.width:
sj = random.choice([stone,cacti,apple])
rect = sj.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
rect.x -= 8
screen.blit(sj,(rect.x,rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ 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