Commit 4d817209 by BellCodeEditor

save project

parent 022ec8df
Showing with 43 additions and 6 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
FPS = pygame.time.Clock()
pygame.display.set_caption("悟空酷跑")
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
# pygame时钟,控制游戏速度(帧数)
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛
bush = pygame.image.load('bush.png') # 灌木丛
hero = pygame.image.load('hero1.png')
index = 0
index = 0
jumpsrate="runing"
t=30
road_x=0
bg_x=0
block_list=pygame.sprite.Group()
time=0
for sprite in block_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.x))
while True:
for event in pygame.event.get():
......@@ -24,6 +48,19 @@ while True:
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(hero, (150, 400))
time+=1
if time<=60:
time>20
mun=random.randint(0,50)
if mun>20:
obstcle=Block(bush,cacti,stone)
block_list.add(obstcle)
for sprite in block_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.x))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ 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