Commit 5f94e006 by BellCodeEditor

save project

parent 30be87bf
File added
bg.png

200 KB

bush.png

14.5 KB

cacti.png

5.58 KB

hero1.png

12.4 KB

hero2.png

10.9 KB

hero3.png

11.3 KB

hero4.png

11.5 KB

hero5.png

11.9 KB

import pygame
from pygame import locals
import random
screen = pygame.display.set_mode((1000,600))
pygame.display.set_caption("悟空酷跑")
fps = pygame.time.Clock()
bg = pygame.image.load("bg.png")
bush = pygame.image.load("bush.png")
cacti = pygame.image.load("cacti.png")
stone = pygame.image.load("stone.png")
road = pygame.image.load("road.png")
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")]
index = 0
jumpState="runing"
y=400
t=30
zhangaiwu=random.choice((cacti,bush,stone))
rect=zhangaiwu.get_rect()
rect.x=1000
rect.y=500-rect.height
wukong = hero[index]
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:
jumpState="up"
if jumpState=="up":
if t>0:
y-=t
t-=2
else:
jumpState="dowe"
if jumpState=="dowe":
if t<=30:
y+=t
t+=2
else:
jumpState="runing"
t=30
if jumpState=="runing":
index += 1
if index > 4:
index = 0
wukong = hero[index]
screen.blit(bg,(0,0))
screen.blit(road,(0,500))
screen.blit(wukong,(150,y))
rect.x-=9
if rect.x<=0-rect.width:
zhangaiwu=random.choice((cacti,bush,stone))
rect=zhangaiwu.get_rect()
rect.x=1000
rect.y=500-rect.height
screen.blit(zhangaiwu,(rect.x,rect.y))
pygame.display.update()
fps.tick(60)
\ No newline at end of file
road.png

34.7 KB

stone.png

11.3 KB

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