Commit 95c852c0 by BellCodeEditor

save project

parent acb06362
Showing with 26 additions and 5 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
......@@ -18,10 +19,16 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
index = 0
jumpState = "runing"
y = 400
t=30
x=1
a=random.choice([apple,cacti,stone])
rect=a.get_rect()
rect.x=1000
rect.y=500-rect.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -31,7 +38,8 @@ while True:
if jumpState=="runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if jumpState == "up": # 起跳
if t>0:
y -= t
......@@ -49,14 +57,26 @@ while True:
wukong = hero[index]
index += 1
if jumpState =="runing":
index += 1
else :
x+=1
if index == 5:
index = 0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150, y))
# 刷新画面
pygame.display.update()
rect.x -= 5
if rect.x>0-rect.width:
screen.blit(a,(rect.x,rect.y))
else:
a=random.choice([apple,cacti,stone])
rect=a.get_rect()
rect.x=1000
rect.y=500-rect.height
pygame.display.update()
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