Commit b9e693ee by BellCodeEditor

save project

parent c1849fb7
Showing with 63 additions and 52 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,59 +57,71 @@ while True: ...@@ -58,59 +57,71 @@ 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 state == 'running' : if gamestate == True:
wukong = hero[index] if state == 'running' :
index+=1 wukong = hero[index]
if index>4: index+=1
index=0 if index>4:
index=0
# 跳跃 wukong3 = Player(wukong)
if state == 'jumping' : # 跳跃
if y > 150 : if state == 'jumping' :
y-=t if y > 150 :
t-=1.8 y-=t
t-=1.8
wukong3.rect_y = y
else:
state = 'downing'
# 下落
if state == 'downing' :
if y < 400:
y+=t
t+=1.8
wukong3.rect_y = y
else:
state = 'running'
t=30
y=400
wukong3.rect_y = y
# 障碍物移动
# if obstacle.rect.x <= 0 - obstacle.rect.width:
# obstacle = Block(bush,stone,cacti)
# obstacle.rect.x = obstacle.rect.x -10
# 路
if road_x >-1000:
road_x = road_x - 10
else: else:
state = 'downing' road_x = 0
# 下落 # 背景
if state == 'downing' : if background_x > -1000 :
if y < 400: background_x = background_x - 0.3
y+=t
t+=1.8
else: else:
state = 'running' background_x = 0
t=30
y=400 # 将背景图画上去
# 障碍物移动 screen.blit(background, (background_x, 0))
# if obstacle.rect.x <= 0 - obstacle.rect.width: screen.blit(road, (road_x, 500))
# obstacle = Block(bush,stone,cacti) screen.blit(wukong,(150,y))
# obstacle.rect.x = obstacle.rect.x -10
# 路 time+=1
if road_x >-1000: if time >= 60 :
road_x = road_x - 10 r = random.randint(0,5)
else: if r > 2:
road_x = 0 obstacle = Block(bush,stone,cacti)
# 背景 group_list.add(obstacle)
if background_x > -1000 : time = 0
background_x = background_x - 0.3 for sprite in group_list:
else: sprite.rect.x-=10
background_x = 0 screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
# 将背景图画上去 if sprite.rect.x <= 0 - sprite.rect.width:
screen.blit(background, (background_x, 0)) sprite.kill()
screen.blit(road, (road_x, 500)) if pygame.sprite.collide_rect(wukong3,sprite) == True:
screen.blit(wukong, (150, y)) gameover = pygame.image.load('gameover.png')
time+=1 screen.blit(gameover,(400,200))
if time >= 60 : gamestate = False
r = random.randint(0,5)
if r > 2:
obstacle = Block(bush,stone,cacti)
group_list.add(obstacle)
time = 0
for sprite in group_list:
sprite.rect.x-=10
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0 - sprite.rect.width:
sprite.kill()
# 刷新画面 # 刷新画面
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