Commit 77387de3 by BellCodeEditor

save project

parent cca9d15a
Showing with 17 additions and 9 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -19,27 +20,34 @@ hero5 = pygame.image.load('hero5.png') ...@@ -19,27 +20,34 @@ hero5 = pygame.image.load('hero5.png')
heroo =[hero1,hero2,hero3,hero4,hero5] heroo =[hero1,hero2,hero3,hero4,hero5]
index = 0 index = 0
y = 400 y = 400
JS = "runing" jumpState = "runing"
t=30 t=30
obstacle=random.choice([stone,cacti,apple])
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
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:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if JS=="runing": if jumpState=="runing":
if event.type == locals.K_SPACE: if event.type == locals.K_SPACE:
JS = "UP" jumpState = "up"
if JS=="UP": if jumpState=="up":
if y > 150: if y > 150:
y-=5 y-=t
t-=2
else: else:
JS = "down" jumpState = "down"
if JS == "down": if jumpState == "down":
if y < 400: if y < 400:
y+= 5 y+= t
t+=2
else: else:
JS = "runing" jumpState = "runing"
t=30
herooo = heroo[index] herooo = heroo[index]
index += 1 index += 1
if index >= 5: if index >= 5:
......
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