Commit 8d4faccb by BellCodeEditor

save project

parent ef4c6a53
Showing with 37 additions and 20 deletions
......@@ -10,6 +10,15 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height # 初始化
class Player(pygame.sprite.Sprite):
def_init_(self,image):
super()._init_()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -32,6 +41,7 @@ t = 30
bg_x=0
road_x=0
time=0
gamestate=True
#obstacle=Block(bush,cacti,stone)
block_list=pygame.sprite.Group()
while True:
......@@ -43,13 +53,19 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
if gamestate == True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
wukong.rect.y=y
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
......@@ -59,11 +75,11 @@ while True:
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
#wukong = Player(hero[index])
#if jumpState == "runing": # 跑步状态下
# index += 1
#if index >= 5:
# index = 0
# 将背景图画上去
bg_x -=1
if bg_x <=-1000:
......@@ -82,16 +98,17 @@ while True:
time+=1
if time>=60:
r=random.randint(0,100)
if r >40:
time=0
num=random.randint(0,100)
if num >20:
obstacle=Block(bush,cacti,stone)
block_list.add(obstacle)
time=0
for prop in block_list:
prop.rect.x-=8
screen.blit(prop.image,(prop.rect.x, prop.rect.y))
if prop.rect.x<=0-prop.rect.width:
prop.kill()
for sprite in block_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x, sprite.rect.y))
if sprite.rect.x<=0-sprite.rect.width:
sprite.kill()
#print(len(block_list))
# 刷新画面
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