Commit 7ce2dc6b by BellCodeEditor

save project

parent 0245f4e3
Showing with 20 additions and 14 deletions
......@@ -3,11 +3,25 @@ import random
from pygame import locals
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
class Player(pygame.sprite.Sprite):
def __init__(self,image):
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时钟,控制游戏速度(帧数)
pygame.display.set_caption('悟空酷跑')
class Block(pygame.sprite.Sprite):
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
......@@ -26,10 +40,7 @@ y = 400
bg_x = 0
road_x = 0
time = 0
obstable = random.choice([apple,stone,cacti])
rect = obstable.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
block_list = pygame.sprite.Group()
while True:
......@@ -77,7 +88,7 @@ while True:
if time >= 60:
r = random.randint(0,100)
if r > 40:
obstable = Block(bush,cacti,stone)
obstable = Block(apple,cacti,stone)
block_list.add(obstable)
time = 0
for prop in block_list:
......@@ -85,13 +96,8 @@ while True:
screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if prop.rect.x < 0 - prop.rect.width:
prop.kill()
if rect.x <= 0-rect.width:
obstable = random.choice([apple,stone,cacti])
rect = obstable.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
rect.x -= 10
screen.blit(obstable,(rect.x,rect.y))
# 刷新画面
......
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