Commit 3d368eae by BellCodeEditor

save project

parent 4f53a136
Showing with 25 additions and 12 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,8 +9,7 @@ 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("悟空酷跑")
......@@ -31,7 +30,11 @@ index = 0
y = 400
jumpState = "runing"
t = 30
aa=Block(bush,cacti,stone)
#aa=Block(bush,cacti,stone)
bg_x = 0
road_x = 0
time = 0
block_list =pygame.sprite.Group()
while True:
for event in pygame.event.get():
......@@ -74,13 +77,23 @@ while True:
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
# 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))
# aa=Block(bush,cacti,stone)
# aa.rect.x -= 8
time += 1
if time >= 60 :
r = random.randint(0,100)
if r>40:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
time=0
for obs in block_list:
obs.rect.x-=8
screen.blit(obs.image,(obs.rect.x, obs.rect.y))
if obs.rect.x <= 0-obs.rect.width:
obs.kill()
print(len(block_list))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
FPS.tick(600)
\ 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