Commit b206a469 by BellCodeEditor

save project

parent 04f6112b
Showing with 5 additions and 18 deletions
......@@ -4,8 +4,8 @@ import random
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def _init_(self,image1,image2,image3):
super()._init_()
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
......@@ -32,10 +32,6 @@ t = 30
bg_x=0
road_x=0
obstacle = Block(bush,cacti,stone)
obstacle = random.choice([bush, stone, cacti])
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
while True:
for event in pygame.event.get():
......@@ -75,21 +71,11 @@ while True:
if road_x<=-1000:
road_x=0
screen.blit(road,(road_x,500))
screen.blit(wukong, (150, y)) # 悟空
if obstacle.rect.x <=0-obstacle.rect.width:
if obstacle.rect.x <= 0-obstacle.rect.width:
obstacle=Block(bush,cacti,stone)
obstacle.rect.x-=8
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
if rect.x <= 0-rect.width: # 障碍物消失
# 创建障碍物对象
obstacle = random.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))
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