Commit 6789bb63 by BellCodeEditor

auto save

parent 04afadc7
Showing with 16 additions and 21 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
#设计标题
pygame.display.set_caption("齐天大圣")
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入图片
background = pygame.image.load('bg.png') # 背景
......@@ -18,13 +15,11 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
#列表索引
pygame.image.load('hero5.png')]
index = 0
#跳远状态
jumpState="runing"
y=400
#重力参数
jumpstate="runing"
t=30
ob=random.choice([stone,cacti,bush])
rect=ob.get_rect()
......@@ -36,28 +31,28 @@ while True:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if jumpState=="runing":
if jumpstate=="runing":
if event.key == locals.K_SPACE:
jumpState="up"
if jumpState=="up":
jumpstate="up"
if jumpstate=="up":
if t>0:
y -= t
t -= 2
y-=t
t-=2
else:
jumpState="down"
if jumpState=="down":
jumpstate="down"
if jumpstate=="down":
if t<=30:
y += t
t += 2
y+=t
t+=2
else:
jumpState="runing"
jumpstate="runing"
t=30
if jumpState=="runing":
if jumpstate=="runing":
index += 1
if index>4:
index=0
wukong=hero[index]
rect.x -= 8
wukong=hero[index]
rect.x -= 8
if rect.x<0-rect.width:
ob=random.choice([stone,cacti,bush])
rect=ob.get_rect()
......
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