Commit b9e693ee by BellCodeEditor

save project

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