Commit b9e693ee by BellCodeEditor

save project

parent c1849fb7
Showing with 15 additions and 4 deletions
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
gamestate = True
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -48,7 +48,6 @@ class Player(pygame.sprite.Sprite): ...@@ -48,7 +48,6 @@ class Player(pygame.sprite.Sprite):
self.rect.x = 150 self.rect.x = 150
self.rect.y = 400 self.rect.y = 400
group_list=pygame.sprite.Group() group_list=pygame.sprite.Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -58,18 +57,21 @@ while True: ...@@ -58,18 +57,21 @@ while True:
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE and state == 'running' : if event.key == locals.K_SPACE and state == 'running' :
state = 'jumping' state = 'jumping'
# 切换跑步动作 # 切换跑步动作
if gamestate == True:
if state == 'running' : if state == 'running' :
wukong = hero[index] wukong = hero[index]
index+=1 index+=1
if index>4: if index>4:
index=0 index=0
wukong3 = Player(wukong)
# 跳跃 # 跳跃
if state == 'jumping' : if state == 'jumping' :
if y > 150 : if y > 150 :
y-=t y-=t
t-=1.8 t-=1.8
wukong3.rect_y = y
else: else:
state = 'downing' state = 'downing'
# 下落 # 下落
...@@ -77,10 +79,12 @@ while True: ...@@ -77,10 +79,12 @@ while True:
if y < 400: if y < 400:
y+=t y+=t
t+=1.8 t+=1.8
wukong3.rect_y = y
else: else:
state = 'running' state = 'running'
t=30 t=30
y=400 y=400
wukong3.rect_y = y
# 障碍物移动 # 障碍物移动
# if obstacle.rect.x <= 0 - obstacle.rect.width: # if obstacle.rect.x <= 0 - obstacle.rect.width:
# obstacle = Block(bush,stone,cacti) # obstacle = Block(bush,stone,cacti)
...@@ -95,10 +99,12 @@ while True: ...@@ -95,10 +99,12 @@ while True:
background_x = background_x - 0.3 background_x = background_x - 0.3
else: else:
background_x = 0 background_x = 0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (background_x, 0)) screen.blit(background, (background_x, 0))
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y)) screen.blit(wukong,(150,y))
time+=1 time+=1
if time >= 60 : if time >= 60 :
r = random.randint(0,5) r = random.randint(0,5)
...@@ -111,6 +117,11 @@ while True: ...@@ -111,6 +117,11 @@ while True:
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y)) screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0 - sprite.rect.width: if sprite.rect.x <= 0 - sprite.rect.width:
sprite.kill() sprite.kill()
if pygame.sprite.collide_rect(wukong3,sprite) == True:
gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate = False
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(50) FPS.tick(50)
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