Commit 3bb0855a by BellCodeEditor

save project

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