Commit 95c852c0 by BellCodeEditor

save project

parent acb06362
Showing with 22 additions and 1 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -18,10 +19,16 @@ hero = [pygame.image.load('hero1.png'), ...@@ -18,10 +19,16 @@ 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')]
index = 0 index = 0
jumpState = "runing" jumpState = "runing"
y = 400 y = 400
t=30 t=30
x=1
a=random.choice([apple,cacti,stone])
rect=a.get_rect()
rect.x=1000
rect.y=500-rect.height
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -32,6 +39,7 @@ while True: ...@@ -32,6 +39,7 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if jumpState == "up": # 起跳 if jumpState == "up": # 起跳
if t>0: if t>0:
y -= t y -= t
...@@ -49,14 +57,26 @@ while True: ...@@ -49,14 +57,26 @@ while True:
wukong = hero[index] wukong = hero[index]
if jumpState =="runing":
index += 1 index += 1
else :
x+=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))
# 刷新画面 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() pygame.display.update()
FPS.tick(30) 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