Commit a7a6a291 by BellCodeEditor

auto save

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