Commit b0c1e74b by BellCodeEditor

save project

parent f5d37d85
Showing with 27 additions and 13 deletions
......@@ -3,6 +3,14 @@ from pygame import locals
import random
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))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -23,10 +31,10 @@ index = 0
y=400
jumpSatate="running"
t=30
obstacle=random.choice([bush,stone,cacti])
rect = obstacle.get_rect()
rect.x=1000
rect.y=500-rect.height
rode_x=0
background_x=0
block_list=pygame.sprite.Group()
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -56,16 +64,21 @@ while True:
if index==5:
index=0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
if rode_x<=-1000:
rode_x=0
if background_x<=-1000:
background_x=0
background_x-=0.5
screen.blit(background, (background_x, 0))
rode_x-=8
screen.blit(road, (rode_x, 500))
screen.blit(wukong, (150, y))
# 刷新画面
if rect.x <= 0-rect.width:
obstacle = choice([bush,stone,cacti])
rect=obstacle.get_rect()
rect.x=1000
rect.y=500-rect.height
rect.x-=8
screen.blit(obstacle,(rect.x,rect.y))
obstacle=Block(bush,cacti,stone)
block_list.add(obstacle)
for sprite in block_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
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