Commit 8c20b511 by BellCodeEditor

auto save

parent e9520799
Showing with 16 additions and 15 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random from random import *
class Block(pygame.sprite.Sprite): class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
...@@ -14,7 +14,7 @@ Block=pygame.sprite.Group() # 初始化 ...@@ -14,7 +14,7 @@ Block=pygame.sprite.Group() # 初始化
# 创建一个窗口 # 创建一个窗口
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') # 路
...@@ -28,12 +28,12 @@ hero = [pygame.image.load('hero1.png'), ...@@ -28,12 +28,12 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
lu_x=0 lu_x=0
shan_x=0 shan_x=0
index = 0 index = 0
t=30
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
time=0
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:
...@@ -47,17 +47,17 @@ while True: ...@@ -47,17 +47,17 @@ while True:
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
t -= 1 t -= 2
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 30:
y += t y += t
t += 1 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
time=0
# 悟空造型 # 悟空造型
wukong = hero[index] wukong = hero[index]
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
...@@ -78,17 +78,18 @@ time=0 ...@@ -78,17 +78,18 @@ time=0
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失 if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
# 创建障碍物对象 # 创建障碍物对象
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
for sprite in Block:
aa.rect.x -= 8 aa.rect.x -= 8
screen.blit(aa.image, (aa.rect.x, aa.rect.y)) screen.blit(aa.image, (aa.rect.x, aa.rect.y))
time+=1 time+=1
if time >60: if time >=60:
t=0 t=0
Block.random.randint(0,50) num=random.randint(0,50)
else: else:
time>20 num>20
aa.add(pygame.sprite.Sprite) aa.add(pygame.sprite.Sprite)
aa.Sprite.kill(pygame.sprite.Sprite) # 刷新画面 aa.Sprite.kill(pygame.sprite.Sprite)
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)#帧数
\ 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