Commit e215fc89 by BellCodeEditor

save project

parent c6fdc21c
Showing with 15 additions and 13 deletions
import pygame
from pygame import locals
import random
pyame.int()
class Block(pygame.sprite.sprite):
def_int_(self,image1,imge2,imge3):
super()._init_()
self.image = random.choice([image1,image2,image3])
self.rect = self.image.get_rect()
self.rect.x = 1000
self.rest.y = 500 - self.rest.height
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
# 载入图片
background = pygame.image.load('bg.png') # 背景
......@@ -71,7 +62,7 @@ while True:
road_x -= 8
if road_x <= -1000:
road_x = 0 # 远处背景
screen.blit(road, (road_x, 500)) # 路
screen.blit(road, (0, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
if rect.x <= 0-rect.width: # 障碍物消失
......@@ -82,6 +73,17 @@ while True:
rect.y = 500 - rect.height
rect.x -= 8
screen.blit(obstacle, (rect.x, rect.y))
# 刷新画面
time += 1
if time >= 60:
time = 0
num = random.randint(0,50)
if num > 20:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
for sprite in block_list:
sprite.rest.x -= 8
screen.blit(sprite.image,(sprite.rect.x,sprite.rest.y))
if sprite.rect.x <= 0-sprite.rect.width:
sprite.ki11() # 刷新画面
pygame.display.update()
FPS.tick(30)
\ No newline at end of file
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