Commit 5580f037 by BellCodeEditor

save project

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