Commit a7a6a291 by BellCodeEditor

auto save

parent 588ad444
Showing with 8 additions and 25 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
......@@ -18,22 +18,16 @@ hero2 = pygame.image.load('hero3.png')
hero3 = pygame.image.load('hero4.png')
hero4 = pygame.image.load('hero5.png')
modelist=[hero,hero1,hero2,hero3,hero4]
randomNum=random.choice([stone,cacti,apple])
randomRect=randomNum.get_rect()
randomRect.x=1000
randomRect.y=500-randomRect.height
index = 0
y=400
status="runing"
t=30
while True:
wukong=modelist[index]
if status=="runing":
index+=2
if index>=5:
index=0
index+=2
if index>=5:
index=0
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -42,8 +36,7 @@ while True:
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
if status=="runing":
status="up"
status="up"
if status=="up":
if t>0:
y-=t
......@@ -51,12 +44,10 @@ while True:
else:
status="down"
if status=="down":
if t<=30:
y+=t
t+=2
if t<400:
y+=5
else:
status="runing"
t=30
......@@ -64,13 +55,6 @@ while True:
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150, y))
if randomRect.x<0-randomRect.width:
randomNum=random.choice([stone,cacti,apple])
randomRect=randomNum.get_rect()
randomRect.x=1000
randomRect.y=500-randomRect.height
randomRect.x-=8
screen.blit(randomNum,(randomRect.x,randomRect.y))
# 刷新画面
pygame.display.update()
FPS.tick(90)
\ 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