Commit 5580f037 by BellCodeEditor

save project

parent 86f01323
Showing with 18 additions and 15 deletions
import pygame
from pygame import locals
import random
pygame.init()
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -9,11 +9,10 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
pygame.display.set_caption("闪电猴")
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
......@@ -31,7 +30,8 @@ index = 0
y = 400
jumpState = "runing"
t = 30
aa=Block(bush,cacti,stone)
time=0
block_list=pygame.sprite.Group()
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -72,14 +72,17 @@ while True:
lu_x=0
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
# 创建障碍物对象
aa=Block(bush,cacti,stone)
aa.rect.x -= 8
screen.blit(aa.image, (aa.rect.x, aa.rect.y))
# 刷新画面
time +=1
if time >=60:
time=0
num=random.randint(0,50)
if num > 20:
aa=Block(bush,cacti,stone)
block_list.add(aa)
for sprist in block_list:
sprist.rest.x -=8
screen.blit(sprist.image,(sprist.rest.x,sprist.rect.y))
if sprist.rect.x<=0-sprist.rect.width:
sprist.kill()
pygame.display.update()
FPS.tick(50)
\ No newline at end of file
FPS.tick(120)
\ 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