Commit 2d9a1e42 by BellCodeEditor

save project

parent 5e677b7c
Showing with 35 additions and 7 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
......@@ -19,27 +19,41 @@ hero = [pygame.image.load('hero1.png'),
index = 0
jumpState = "runing"
y =400
t = 30
roadx = 0
obstale = random.choice([stone,cacti,apple])
rect = obstale.get_rect() # 获取当前的x,y 宽高
print(rect.height,"ssssssssssssssssssssssss")
rect.x = 1000
rect.y = 500-rect.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN: #获取是否是按键模块信息
if jumpState == "runing":
if event.key == locals.K_SPACE: #获取是否的空格的key值
jumpState = "up"
if jumpState == "up": #起跳
if y >150:
y -=5
if t >0:
y -=t
t -=2
else:
jumpState = "down"
if jumpState == "down":
if y <400:
y +=5
if t<=30:
y +=t
t +=2
else:
jumpState = "runing"
t =30
if jumpState == "runing":
wukong = hero[index]
index += 1
if index>=5:
......@@ -47,8 +61,21 @@ while True:
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
if roadx<=-1000:
roadx = 0
road.x -=8
screen.blit(road, (road.x, 500))
screen.blit(wukong, (150, y))
if rect.x < 0-rect.width:
obstale = random.choice([stone,cacti,apple])
rect = obstale.get_rect() # 获取当前的x,y 宽高
rect.x = 1000
rect.y = 500-rect.height
rect.x -=8
screen.blit(obstale,(rect.x,rect.y))
# 刷新画面
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