Commit bd0a6f4b by BellCodeEditor

auto save

parent 92662126
Showing with 61 additions and 16 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import json
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -41,6 +42,9 @@ hero = [pygame.image.load('hero1.png'), ...@@ -41,6 +42,9 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
a_font=pygame.font.Font('STKAITI.TTF',18)
s_v=pygame.mixer.Sound('score.wav')
index = 0 index = 0
G=40 G=40
y=400 y=400
...@@ -55,8 +59,11 @@ PS=60 ...@@ -55,8 +59,11 @@ PS=60
gametate=True gametate=True
yy=0 yy=0
yyy=8 yyy=8
clock=1
l=0 l=0
score=0
speed=8
os=score
killer=False
class Rsc(pygame.sprite.Sprite): class Rsc(pygame.sprite.Sprite):
def __init__(self,im1,im2,im3): def __init__(self,im1,im2,im3):
...@@ -65,6 +72,7 @@ class Rsc(pygame.sprite.Sprite): ...@@ -65,6 +72,7 @@ class Rsc(pygame.sprite.Sprite):
self.rect=self.image.get_rect() self.rect=self.image.get_rect()
self.rect.x=1000 self.rect.x=1000
self.rect.y=500-self.rect.height self.rect.y=500-self.rect.height
self.score=1
class heros(pygame.sprite.Sprite): class heros(pygame.sprite.Sprite):
def __init__(self,hero): def __init__(self,hero):
super().__init__() super().__init__()
...@@ -77,15 +85,23 @@ wukong=heros(hero[index]) ...@@ -77,15 +85,23 @@ wukong=heros(hero[index])
blist=pygame.sprite.Group() blist=pygame.sprite.Group()
while True: while True:
with open('record.txt','r',encoding='utf-8') as f:
cont=f.read()
text=json.loads(cont)
print(cont)
one=text['第1名']
two=text['第2名']
three=text['第3名']
wukong=heros(hero[index]) wukong=heros(hero[index])
print(clock) if gametate==True:
time+=0.5*clock time+=1
if time>=60: if time>=60:
a=randint(1,60) a=randint(0,65)
if a>=20: if a>=20:
obg=Rsc(stone,cacti,apple) obg=Rsc(stone,cacti,apple)
blist.add(obg) blist.add(obg)
time=0 time=10
speed=8+score//3
if IM=='running': if IM=='running':
ind+=1 ind+=1
if ind>=5: if ind>=5:
...@@ -107,6 +123,14 @@ while True: ...@@ -107,6 +123,14 @@ while True:
if IM!='running' and I_M>=1: if IM!='running' and I_M>=1:
if event.key == locals.K_w: if event.key == locals.K_w:
IM='dup' IM='dup'
if event.key == locals.K_s:
gametate=True
if event.key == locals.K_q:
killer=True
if event.key == locals.K_e:
killer=False
if event.key == locals.K_p:
speed+=10
if gametate==True: if gametate==True:
if IM=='up': if IM=='up':
y-=G y-=G
...@@ -134,11 +158,11 @@ while True: ...@@ -134,11 +158,11 @@ while True:
herorun=hero[index] herorun=hero[index]
# 将背景图画上去 # 将背景图画上去
bg_x-=(2+0.25*clock) bg_x-=2
if bg_x<=-1000: if bg_x<=-1000:
bg_x=0 bg_x=0
screen.blit(bg, (bg_x, 0)) screen.blit(bg, (bg_x, 0))
rond_x-=(8+0.5*clock) rond_x-=speed
if rond_x<= -1000: if rond_x<= -1000:
rond_x=0 rond_x=0
screen.blit(road, (rond_x, 500)) screen.blit(road, (rond_x, 500))
...@@ -146,14 +170,35 @@ while True: ...@@ -146,14 +170,35 @@ while True:
# if obg.rect.x<0-obg.rect.height: # if obg.rect.x<0-obg.rect.height:
# obg=Rsc(stone,cacti,apple) # obg=Rsc(stone,cacti,apple)
for pop in blist: for pop in blist:
pop.rect.x-=(8+clock) pop.rect.x-=speed
screen.blit(pop.image,(pop.rect.x,pop.rect.y)) screen.blit(pop.image,(pop.rect.x,pop.rect.y))
if pop.rect.x<=0-pop.rect.width:
pop.kill()
if pygame.sprite.collide_rect(wukong,pop): if pygame.sprite.collide_rect(wukong,pop):
screen.blit(go,(400,200)) if killer==True:
gametate=False pop.kill()
score+=pop.score
speed+=pop.score
pop.score=0
else:
screen.blit(go,(400,200))
gametate=False
else: else:
if (pop.rect.x+pop.rect.y)<wukong.rect.x-wukong.rect.height: if (pop.rect.x+pop.rect.width)<=wukong.rect.x:
clock+=0.1 score+=pop.score
speed+=pop.score
pop.score=0
if os<score:
s_v.play()
os=score
sF=a_font.render("分数"+str(score),True,(255,255,255))
screen.blit(sF,(880,20))
sF=a_font.render("第一名"+str(one),True,(255,255,255))
screen.blit(sF,(880,40))
sF=a_font.render("第二名"+str(two),True,(255,255,255))
screen.blit(sF,(880,60))
sF=a_font.render("第三名"+str(three),True,(255,255,255))
screen.blit(sF,(880,80))
# 刷新画面 # 刷新画面
......
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