Commit 7c60890a by BellCodeEditor

save project

parent 022ec8df

48.6 KB | W: | H:

52.6 KB | W: | H:

gameover.png
gameover.png
gameover.png
gameover.png
  • 2-up
  • Swipe
  • Onion skin
hole.png

248 Bytes

import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 import json
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) pygame.init()
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) screen = pygame.display.set_mode((1000, 600))
# 载入图片 FPS = pygame.time.Clock()
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 background = pygame.image.load('bg.png')
stone = pygame.image.load('stone.png') # 石头 road = pygame.image.load('road.png')
cacti = pygame.image.load('cacti.png') # 仙人掌 stone = pygame.image.load('stone.png')
apple = pygame.image.load('bush.png') # 灌木丛 cacti = pygame.image.load('cacti.png')
hero = pygame.image.load('hero1.png') bush = pygame.image.load('bush.png')
index = 0 hole = pygame.image.load('hole.png')
GG = pygame.image.load('gameover.png')
while True: GGG = pygame.image.load('gameover_.png')
for event in pygame.event.get(): heroes = [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'),]
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit() ##流程
with open("record.txt","r",encoding="utf-8") as file:
# 将背景图画上去 data=file.read()
screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) if data.startswith(u'\ufeff'):
screen.blit(hero, (150, 400)) data = data.encode('utf8')[3:].decode('utf8')
# 刷新画面 broad=json.loads(data)
pygame.display.update() first="一:"+str(broad["第1名"])
FPS.tick(60) second="二:"+str(broad["第2名"])
\ No newline at end of file third="三:"+str(broad["第3名"])
state = "moving"
i=0
y=400
t=30
road_x=0
bg_x=0
time=0
shadow_x=-200
score=0
die = False
speed=20
score_=0
die_purpose=1
font = pygame.font.Font("STKAITI.TTF",50)
score__=pygame.mixer.Sound("score.wav")
shadow=1
class Block(pygame.sprite.Sprite):
def __init__(self,img1,img2,img3,img4):
super().__init__()
self.image = random.choice([img1,img2,img3,img4])
self.rect=self.image.get_rect()
self.rect.x=1000+self.rect.width
self.rect.y=500-self.rect.height
self.price=1
blocks=Block(hole,stone,bush,cacti)
group=pygame.sprite.Group()
class Player(pygame.sprite.Sprite):
def __init__(self,img):
super().__init__()
self.image = img
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
while True:
##Shadow
if shadow_x<30*speed-20 and shadow_x>200 and state == "moving" and die_purpose == 1:
state="up"
shadow=0
##Events
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN :
if event.key==locals.K_DOWN :##and die
if die :
die = False
for block in group:
block.kill()
score-=1
elif state != "moving":
state = "fls"
if shadow == 0:
die_purpose=0
##
if state=="moving" and event.key==locals.K_UP and shadow==1:
state = "up"
##Action
if not die:
print(state)
monkey=Player(heroes[i])
speed=30+score
if state=="up":
if t>0:
y-=t
monkey.rect.y=y
t-=2
else:
state="down"
if state=="down":
if t<=30:
y+=t
monkey.rect.y=y
t+=2
else:
state="moving"
t-=2
if state == "fls" and monkey.rect.y<591:
y=400
t=30
state = "moving"
bg_x-=10
if bg_x<-1000:
bg_x=0
road_x-=speed
if road_x<-1000:
road_x=0
if i<4 and state == "moving":
i+=1
else:
i=0
##Play
screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(monkey.image, (150, y))
time+=1
if time > 30:
time = 0
seed=random.randint(0,50)
if seed > 20:
blocks=Block(hole,bush,cacti,stone)
group.add(blocks)
for block in group:
block.rect.x -= speed
shadow_x-=speed
'''print('self:'+str(block.rect.x))
print('shadow:'+str(shadow_x))'''
if block.rect.x+block.rect.width < monkey.rect.x:
score=score+block.price
block.price=0
if score>score_:
score__.play()
score_=score
if block.rect.x<0-block.rect.width:
block.kill()
if len(group)==1:
shadow_x=block.rect.x
screen.blit(block.image,(block.rect.x,block.rect.y))
if pygame.sprite.collide_rect(block,monkey):
shadow_x = -200
die_purpose=1
for block in group:
block.rect.x = -200
screen.blit(GGG,(0,0))
die = True
text = font.render("Score:"+str(score)+"|"+first+"|"+second+"|"+third,True,(1,2,3))
screen.blit(text,(random.randint(20,30),random.randint(20,30)))
pygame.display.update()
FPS.tick(30)
\ No newline at end of file
{"第1名": 9, "第2名": 0, "第3名": 0}
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0}
\ No newline at end of file
File added
思路是
思路是
增加快速下落(飞雷神即可)
在这个的基础上,把shadow检测做成列表从而实现大于二的()
bugs
not die 之后灵异检测
您record呢
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