Commit 3bb0855a by BellCodeEditor

save project

parent 96e09b00
Showing with 8 additions and 6 deletions
import pygame,random
from pygame import locals
pygame.init() # 初始化
class Player(pygame.sprite.Sprite):
......@@ -10,7 +9,7 @@ class Player(pygame.sprite.Sprite):
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=500
self.rect.y=400 # 应该是400
......@@ -49,8 +48,9 @@ bg_x = 0
time=0
gamestate=True
obstacle = Block(bush,stone,cacti) # 障碍物列表, 随机一个对象
# obstacle = Block(bush,stone,cacti) # 障碍物列表, 随机一个对象
block_list=pygame.sprite.Group()
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -60,10 +60,11 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
wukong =Player( hero[index])
wukong =Player(hero[index])
if jumpState == "runing":
index += 1
if index == 5:
if index >= 5: # 出错 >= 不是 ==
index = 0
if gamestate==True:
......@@ -92,6 +93,7 @@ while True:
if bg_x <= -1000:
bg_x = 0
screen.blit(background, (bg_x, 0))
road_x -= 8 # 道路移动
if road_x <= -1000:
road_x = 0
......@@ -114,7 +116,7 @@ while True:
if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate=False
gamestate=False
# 刷新画面
pygame.display.update()
......
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