Commit f6f84259 by BellCodeEditor

auto save

parent d807163f
Showing with 58 additions and 37 deletions
......@@ -2,72 +2,92 @@ import pygame
from pygame import locals
import random
pygame.init() # 鍒濆鍖?
# 鍒涘缓涓€涓獥鍙?
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
# 鍔犺浇闅滅鐗╃殑鍥剧墖
self.image = random.choice([image1, image2, image3])
# 鏍规嵁闅滅鐗╀綅鍥剧殑瀹介珮璁剧疆鐭╁舰
self.rect = self.image.get_rect()
# 闅滅鐗╃粯鍒跺潗鏍?
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame鏃堕挓锛屾帶鍒舵父鎴忛€熷害锛堝抚鏁帮級
pygame.display.set_caption("悟空跑酷")
pygame.display.set_caption("鎮熺┖閰疯窇")
# 杞藉叆鍥剧墖
background = pygame.image.load('bg.png') # 鑳屾櫙
road = pygame.image.load('road.png') # 璺?
stone = pygame.image.load('stone.png') # 鐭冲ご
cacti = pygame.image.load('cacti.png') # 浠欎汉鎺?
apple = pygame.image.load('bush.png') # 鐏屾湪涓?
bush = pygame.image.load('bush.png') # 鐏屾湪涓L?
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
y=400
jump="runing"
t=30
obstacle = random.choice([bush, stone, cacti])
rect = obstacle.get_rect
rect.x = 1000
rect.y = 500-rect.height
y = 400
jumpState = "runing"
t = 30
bg_x _= 0
road_x = 0
time=0rreg6e64
# 鍒涘缓闅滅鐗?
Block_list=pygame.sprite.Group()
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 鎺ユ敹鍒伴€€鍑轰簨浠跺悗閫€鍑
exit()
if event.type == locals.KEYDOWN:
if jump =="runing":
if jumpState == "runing":
if event.key == locals.K_SPACE:
jump="up"
if jump=="up":
if t>0:
y-=t
t-=2
jumpState = "up"
if jumpState == "up": # 璧疯烦鐘舵€?
if t > 0:
y -= t
t -= 2
else:
jump="down"
if jump=="down":
if t<=30:
y+=t
t+=2
jumpState = "down"
if jumpState == "down": # 闄嶈惤鐘舵€?
if t <= 30:
y += t
t += 2
else:
jump="runing"
t=30
jumpState = "runing"
t =30
# 鎮熺┖閫犲瀷
wukong = hero[index]
if jump=="runing":
if jumpState == "runing": # 璺戞鐘舵€佷笅
index += 1
if index == 5:
if index >= 5:
index = 0
# 灏嗚儗鏅浘鐢讳笂鍘?
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150,y))
if rect.x<0-rect.width:
obstacle = random.choice([bush, stone, cacti])
rect = obstacle.get_rect
rect.x = 1000
rect.y = 500-rect.height
rect.x-=8
screen.blit(obstacle, (rect.x,rect.y))
bg_x -= 1
if bg_x<=-1000:
bg_x=0
screen.blit(background, (bg_x))
road_x -= 8
if road_x<=-1000:
road_x = 0
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y)) # 鎮熺┖
obstacle = Block(bush,cacti,stone)
Block_list.add(obstacle)
screen.blit(obstacle.image, (obstacle.rect.x, obstacle.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