Commit 1908703f by BellCodeEditor

save project

parent db637887
Showing with 22 additions and 9 deletions
...@@ -3,8 +3,16 @@ from pygame import locals ...@@ -3,8 +3,16 @@ from pygame import locals
import random import random
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
self.image=random.choice([image1,image2,image3])
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
...@@ -20,12 +28,14 @@ index = 0 ...@@ -20,12 +28,14 @@ index = 0
pygame.display.set_caption('悟空酷跑') pygame.display.set_caption('悟空酷跑')
a=0 a=0
t=30 t=30
zaw=Block(stone,cacti,apple)
wukong_1=hero[0] wukong_1=hero[0]
wukong='running' wukong='running'
y=400 y=400
z=random.choice([stone,cacti,apple]) #z=random.choice([stone,cacti,apple])
rect=stone.get_rect() #rect=stone.get_rect()
z_x=1000 #z_x=1000
road_x=0 road_x=0
bg_x=0 bg_x=0
while True: while True:
...@@ -60,14 +70,17 @@ while True: ...@@ -60,14 +70,17 @@ while True:
screen.blit(background, (bg_x, 0)) screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
screen.blit(wukong_1, (150, y)) screen.blit(wukong_1, (150, y))
screen.blit(z, (z_x, 500-rect.height))
z_x-=8 #z_x-=8
road_x-=8 road_x-=8
bg_x-=1 bg_x-=1
if z_x <= 0-rect.width: if zaw.rect.x<= 0-zaw.rect.width:
z=random.choice([stone,cacti,apple]) zaw=Block(stone,cacti,apple)
rect=stone.get_rect() screen.blit(zaw.image, (zaw.rect.x, 500-zaw.rect.height))
z_x=1000 zaw.rect.x-=8
#z=random.choice([stone,cacti,apple])
#rect=stone.get_rect()
#z_x=1000
if road_x<-1000: if road_x<-1000:
road_x=0 road_x=0
......
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