Commit 45278929 by BellCodeEditor

save project

parent 7d0e0fc8
Showing with 33 additions and 14 deletions
......@@ -3,6 +3,16 @@ 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时钟,控制游戏速度(帧数)
......@@ -22,12 +32,10 @@ index = 0
jumpState="runing"
t=30
y=400
road_x=0
background_x=0
A=random.choice([stone,apple,cacti])
rect=A.get_rect()
rect.x=1000
rect.y=500-rect.height
A=Block(apple,cacti,stone)
while True:
for event in pygame.event.get():
......@@ -58,18 +66,29 @@ while True:
if jumpState=="runing":
index += 1
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
background_x-=1
if background_x<=-1000:
background_x=0
screen.blit(background, (background_x, 0))
road_x-=8
if road_x<=-1000:
road_x=0
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
if rect.x<=0-rect.width:
A=random.choice([stone,apple,cacti])
rect=A.get_rect()
rect.x=1000
rect.y=500-rect.height
if A.rect.x<=0-A.rect.width:
A = Block(apple,cacti,stone)
#A=random.choice([stone,apple,cacti])
#rect=A.get_rect()
#rect.x=1000
#rect.y=500-rect.height
rect.x-=8
screen.blit(A,(rect.x,rect.y))
A.rect.x-=8
screen.blit(A.image,(A.rect.x,A.rect.y))
# 刷新画面
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