Commit 1b138e68 by BellCodeEditor

save project

parent 2742489a
Showing with 15 additions and 12 deletions
import pygame
from pygame import locals
import random
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -14,6 +13,7 @@ pygame.init() # 初始化
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
time=0
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
......@@ -32,7 +32,7 @@ y = 400
jumpState = "runing"
t = 30
aa=Block(bush,cacti,stone)
block_list=pygame.sprite.Group()
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -42,7 +42,6 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
......@@ -56,7 +55,6 @@ while True:
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
......@@ -73,14 +71,18 @@ 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=time+1
if time>=60:
r=random.randint(0,50)
if r>40:
ob=Block(bush,cacti,stone)
block_list.add(ob)
time=0
for prop in block_list:
prop.rect.x=prop.rect.x-8
screen.blit(prop.image,(prop.x,prop.y))
if prop.rect.x<=0-prop.rect.width:
prop.kill()
# 刷新画面
pygame.display.update()
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