你是否还记得有一款游戏叫做“魔塔”?(三)

简介: 你是否还记得有一款游戏叫做“魔塔”?

3.24 开始画地图


for i in ground_L:
    screen.blit(ground,i)
for j in wall_L:
    screen.blit(wall,j)
for k in List_temp1:
    screen.blit(yellow_door,k)
for k in List_temp2:
    screen.blit(upstair,k)
for k in List_temp3:
    screen.blit(rbottle,k)
for k in List_temp4:
    screen.blit(bbottle,k)
for k in List_temp5:
    screen.blit(rgem,k)
for k in List_temp6:
    screen.blit(bgem,k)
for k in List_temp7:
    screen.blit(ykey,k)
for k in List_temp8:
    screen.blit(blue_door,k)
for k in List_temp9:
    screen.blit(bkey,k)
for k in List_temp10:
    screen.blit(red_door,k)
for k in List_temp11:
    screen.blit(rkey,k)
for k in list_molocation:
    n=list_molocation.index(k)
    k_name=list_moname[n]
    screen.blit(eval(k_name),k)
screen.blit(lift,Lift[0])
screen.blit(guide,Guide[0])

3.25 对于列表中碰撞以后的元素


for y_door in ydoorL[:]:
    if CAIXUKUN.image_rect.colliderect(y_door):
        if CAIXUKUN.property["Yellow_key"]>0:
            i=ydoorL.index(y_door)
            ydoorL.remove(y_door)
            CAIXUKUN.property["Yellow_key"]-=1
            del List_temp1[i]
        else:
            pass
for b_door in bdoorL[:]:
    if CAIXUKUN.image_rect.colliderect(b_door):
        if CAIXUKUN.property["Blue_key"]>0:
            i=bdoorL.index(b_door)
            bdoorL.remove(b_door)
            CAIXUKUN.property["Blue_key"]-=1
            del List_temp8[i]
        else:
            pass
for r_door in rdoorL[:]:
    if CAIXUKUN.image_rect.colliderect(r_door):
        if CAIXUKUN.property["Red_key"]>0:
            i=rdoorL.index(r_door)
            rdoorL.remove(r_door)
            CAIXUKUN.property["Red_key"]-=1
            del List_temp10[i]
        else:
            pass

3.26 红血瓶

for r_bottle in rbottleL[:]:
    if CAIXUKUN.image_rect.colliderect(r_bottle):
        sound1.play()
        i=rbottleL.index(r_bottle)
        rbottleL.remove(r_bottle)
        CAIXUKUN.life+=20
        del List_temp3[i]

3.27 蓝血瓶

for b_bottle in bbottleL[:]:
    if CAIXUKUN.image_rect.colliderect(b_bottle):
        sound1.play()
        i=bbottleL.index(b_bottle)
        bbottleL.remove(b_bottle)
        CAIXUKUN.life+=10
        del List_temp4[i]

3.28 战斗事件

for monster_ in list_morect[:]:
    if CAIXUKUN.image_rect.colliderect(monster_):
        x=list_morect.index(monster_)
        oops=eval(list_moname[x]+'_')
        if(fight(CAIXUKUN,oops)!=[0]):
            sound2.play()
            list_morect[x]=pygame.Rect(-100,-100,50,50)
            list_molocation[x]=(-100,-100)
        else:
            pass

3.29 侧边栏背景

screen.fill((191,191,191),rect=att_rect1,special_flags=0)
screen.fill((191,191,191),rect=att_rect2,special_flags=0)
screen.fill((191,191,191),rect=att_rect3,special_flags=0)
screen.fill((191,191,191),rect=att_rect4,special_flags=0)

3.30 任务栏

1. screen.blit(ykey,(0,400))
2. screen.blit(bkey,(0,450))
3. screen.blit(rkey,(0,500))

3.31 属性栏

text_surface1=my_FontCHs.render("第%s层"%str(CAIXUKUN.floor),True,(0,0,0),(191,191,191))
text_surface2=my_FontCHs.render("攻击力:%s"%str(CAIXUKUN.attack),True,(0,0,0),(191,191,191))
text_surface3=my_FontCHs.render("防御力:%s"%str(CAIXUKUN.defend),True,(0,0,0),(191,191,191))
text_surface4=my_FontCHs.render("生命值:%s"%str(CAIXUKUN.life),True,(0,0,0),(191,191,191))
text_surface5=my_FontCHs.render("金币:%s"%str(CAIXUKUN.gold),True,(0,0,0),(191,191,191))

3.32 钥匙数量

Yellow_key=CAIXUKUN.property['Yellow_key']
Blue_key=CAIXUKUN.property['Blue_key']
Red_key=CAIXUKUN.property['Red_key']

3.33 物品栏

text_surface6=my_FontCHs.render("%s把"%str(Yellow_key),True,(0,0,0),(191,191,191))
text_surface7=my_FontCHs.render("%s把"%str(Blue_key),True,(0,0,0),(191,191,191))
text_surface8=my_FontCHs.render("%s把"%str(Red_key),True,(0,0,0),(191,191,191))
text_surface9=my_FontCHs.render("永久使用宝物",True,(0,0,0),(191,191,191))
text_surface10=my_FontCHs.render("一次使用宝物",True,(0,0,0),(191,191,191))
text_surface11=my_FontCHs.render("自动使用宝物",True,(0,0,0),(191,191,191))

3.34 如果获得则在右侧边栏加上该宝物

1. if get_lift:
2.     screen.blit(pygame.transform.scale(pygame.image.load('life.png').convert_alpha(),(40,40)),(770,100))

3.35 属性栏

screen.blit(text_surface0,(280,0))
screen.blit(text_surface1,(0,100))
screen.blit(text_surface2,(0,150))
screen.blit(text_surface3,(0,200))
screen.blit(text_surface4,(0,250))
screen.blit(text_surface5,(0,300))
screen.blit(text_surface6,(100,400))
screen.blit(text_surface7,(100,450))
screen.blit(text_surface8,(100,500))
screen.blit(text_surface9,(758,50))
screen.blit(text_surface10,(758,280))
screen.blit(text_surface11,(758,510))

代码参考

fight.py

def fight(A,B,cancel=0):
    a=A.attack-B.defend
    b=B.attack-A.defend
    alife=A.life
    blife=B.life
    if a<=0:
        return [0]
    if a>0 and b<=0:
        if(cancel==0):
            A.gold+=B.gold
        if(cancel!=0):
            A.life=alife
            B.life=blife
        return 0
    else:
        for i in range(1,100):
            B.life=B.life-a
            if B.life<0:
                if(cancel==0):
                    B.life=blife
                    A.gold+=B.gold
                if(cancel!=0):
                    A.life=alife
                    B.life=blife
                return alife-A.life
            A.life=A.life-b
            if A.life<0:
                A.life=alife
                B.life=blife
                return [0]
if __name__=="__main__":
    class character:
        def __init__(self,tuple):
            self.attack=tuple[0]
            self.defend=tuple[1]
            self.life=tuple[2]
            self.gold=0
        def __str__(self):
            return u"攻击力:%d ,防御力:%d, 生命值:%d,金币:  %d"%(self.attack,self.defend,self.life,self.gold)
    class monster:
        def __init__(self,tuple):
            self.attack=tuple[0]
            self.defend=tuple[1]
            self.life=tuple[2]
            self.gold=tuple[3]
        def __str__(self):
            return u"攻击力:%d ,防御力:%d, 生命值:%d,"%(self.attack,self.defend,self.life)
    CAIXUKUN=character((10,10,100))
    gSlime_=monster((11,5,10,1))
    rSlime_=monster((12,5,10,2))
    sBat_=monster((13,5,10,3))
    bWizard_=monster((15,5,10,5))
    Skeleton_=monster((18,5,10,8))
    scSkeleton_=monster((25,5,10,10))
    BOSS=monster((100,5,10,10))
    fight(CAIXUKUN,gSlime_)
    print(CAIXUKUN)
    fight(CAIXUKUN,gSlime_,cancel=1)
    print(CAIXUKUN,rSlime_)
    print(CAIXUKUN)
    if (fight(CAIXUKUN,BOSS)==0):
        print(CAIXUKUN)
        print(BOSS)

TowerTest.py

import pygame,sys
from Fight import fight
pygame.init()
pygame.mixer.init()
size=width,height=950,650
screen=pygame.display.set_mode(size)
pygame.display.set_caption('Tower')
#环境
wall=pygame.transform.scale(pygame.image.load('w1.png').convert_alpha(),(50,50))
ground=pygame.transform.scale(pygame.image.load('w2.png').convert_alpha(),(50,50))
yellow_door=pygame.transform.scale(pygame.image.load('d1.png').convert_alpha(),(50,50))
blue_door=pygame.transform.scale(pygame.image.load('d2.png').convert_alpha(),(50,50))
red_door=pygame.transform.scale(pygame.image.load('d3.png').convert_alpha(),(50,50))
special_door=pygame.transform.scale(pygame.image.load('d4.png').convert_alpha(),(50,50))
ykey=pygame.transform.scale(pygame.image.load('ykey.png').convert_alpha(),(50,50))
bkey=pygame.transform.scale(pygame.image.load('bkey.png').convert_alpha(),(50,50))
rkey=pygame.transform.scale(pygame.image.load('rkey.png').convert_alpha(),(50,50))
rbottle=pygame.transform.scale(pygame.image.load('rbottle.png').convert_alpha(),(50,50))
bbottle=pygame.transform.scale(pygame.image.load('bbottle.png').convert_alpha(),(50,50))
rgem=pygame.transform.scale(pygame.image.load('rgem.png').convert_alpha(),(50,50))
bgem=pygame.transform.scale(pygame.image.load('bgem.png').convert_alpha(),(50,50))
upstair=pygame.transform.scale(pygame.image.load('upstair.png').convert_alpha(),(50,50))
downstair=pygame.transform.scale(pygame.image.load('downstair.png').convert_alpha(),(50,50))
#怪物
rSlime=pygame.transform.scale(pygame.image.load('rSlime.png').convert_alpha(),(50,50))
gSlime=pygame.transform.scale(pygame.image.load('gSlime.png').convert_alpha(),(50,50))
bSlime=pygame.transform.scale(pygame.image.load('bSlime.png').convert_alpha(),(50,50))
kSlime=pygame.transform.scale(pygame.image.load('kSlime.png').convert_alpha(),(50,50))
sBat=pygame.transform.scale(pygame.image.load('sBat.png').convert_alpha(),(50,50))
bBat=pygame.transform.scale(pygame.image.load('bBat.png').convert_alpha(),(50,50))
rBat=pygame.transform.scale(pygame.image.load('rBat.png').convert_alpha(),(50,50))
bWizard=pygame.transform.scale(pygame.image.load('bWizard.png').convert_alpha(),(50,50))
rWizard=pygame.transform.scale(pygame.image.load('rWizard.png').convert_alpha(),(50,50))
Skeleton=pygame.transform.scale(pygame.image.load('Skeleton.png').convert_alpha(),(50,50))
scSkeleton=pygame.transform.scale(pygame.image.load('scSkeleton.png').convert_alpha(),(50,50))
bcSkeleton=pygame.transform.scale(pygame.image.load('bcSkeleton.png').convert_alpha(),(50,50))
ghost=pygame.transform.scale(pygame.image.load('ghost.png').convert_alpha(),(50,50))
lGuard=pygame.transform.scale(pygame.image.load('lGuard.png').convert_alpha(),(50,50))
mGuard=pygame.transform.scale(pygame.image.load('mGuard.png').convert_alpha(),(50,50))
hGuard=pygame.transform.scale(pygame.image.load('hGuard.png').convert_alpha(),(50,50))
lWitch=pygame.transform.scale(pygame.image.load('lWitch.png').convert_alpha(),(50,50))
hWitch=pygame.transform.scale(pygame.image.load('hWitch.png').convert_alpha(),(50,50))
Orc=pygame.transform.scale(pygame.image.load('Orc.png').convert_alpha(),(50,50))
wOrc=pygame.transform.scale(pygame.image.load('wOrc.png').convert_alpha(),(50,50))
Stone=pygame.transform.scale(pygame.image.load('Stone.png').convert_alpha(),(50,50))
Swordsman=pygame.transform.scale(pygame.image.load('Swordsman.png').convert_alpha(),(50,50))
wGhost=pygame.transform.scale(pygame.image.load('wGhost.png').convert_alpha(),(50,50))
Vampier=pygame.transform.scale(pygame.image.load('Vampier.png').convert_alpha(),(50,50))
#神秘人和宝物
guide=pygame.transform.scale(pygame.image.load('guide.png').convert_alpha(),(50,50))
merchant=pygame.transform.scale(pygame.image.load('merchant.png').convert_alpha(),(50,50))
princess=pygame.transform.scale(pygame.image.load('princess.png').convert_alpha(),(50,50))
lift=pygame.transform.scale(pygame.image.load('lift.png').convert_alpha(),(50,50))
#商店
shop=pygame.transform.scale(pygame.image.load('shop.png').convert_alpha(),(150,50))
#背景音乐
pygame.mixer.music.load('background.mp3')
pygame.mixer.music.play()
musicPlaying=False
sound0=pygame.mixer.Sound('0.wav')
sound1=pygame.mixer.Sound('1.wav')
sound2=pygame.mixer.Sound('2.wav')
#sound3=pygame.mixer.Sound('3.wav')
sound4=pygame.mixer.Sound('4.wav')
sound5=pygame.mixer.Sound('5.wav')
sound6=pygame.mixer.Sound('6.wav')
pygame.time.delay(1000)
sound0.play()
#加载字体
my_FontCH=pygame.font.Font('【春田】小火锅安卓.ttf',30)
my_FontCHs=pygame.font.Font('方正正中黑简体.TTF',30)
my_FontEN=pygame.font.Font('KeeponTruckin.ttf',30)
#最上面一格
text_surface0=my_FontCH.render('小游戏',True,(0,0,0),(191,191,191))
#矩形的四个值
att_rect1=pygame.Rect(0,50,200,600)
att_rect2=pygame.Rect(750,50,200,600)
att_rect3=pygame.Rect(200,600,550,50)
att_rect4=pygame.Rect(0,0,950,50)
#获取钥匙图片所在的位置
ykey_rect=ykey.get_rect()
ykey_rect.left,ykey_rect.top=0,400
bkey_rect=bkey.get_rect()
bkey_rect.left,bkey_rect.top=0,450
rkey_rect=rkey.get_rect()
rkey_rect.left,rkey_rect.top=0,500
#电梯位置
up_lift_rect=pygame.Rect(770,100,40,20)
down_lift_rect=pygame.Rect(770,120,40,20)
#人物类
class character:
    def __init__(self,tuple):
        self.floor=1
        self.attack=tuple[0]
        self.defend=tuple[1]
        self.life=tuple[2]
        self.gold=0
        #物品栏
        self.property={'Yellow_key':0,'Blue_key':0,'Red_key':0}
        #图像
        self.image=pygame.transform.scale(pygame.image.load('character.png').convert_alpha(),(50,50))
        self.bg=pygame.transform.scale(pygame.image.load('w2.png').convert_alpha(),(50,50))
        self.image_rect=self.image.get_rect()
        self.image_rect.left=450
        self.image_rect.top=550
    def move(self,str):
        if str=="UP":
            FORBID=0
            rect_new=self.image_rect.copy()
            rect_new.move_ip(0,-50)
            for wall_ in wallL[:]:
                if rect_new.colliderect(wall_):
                    FORBID=1
            for y_door in ydoorL[:]:
                if rect_new.colliderect(y_door) and self.property["Yellow_key"]==0:
                    FORBID=1
            for b_door in bdoorL[:]:
                if rect_new.colliderect(b_door) and self.property["Blue_key"]==0:
                    FORBID=1
            for r_door in rdoorL[:]:
                if rect_new.colliderect(r_door) and self.property["Red_key"]==0:
                    FORBID=1
            for monster_ in list_morect[:]:
                if rect_new.colliderect(monster_):
                    x=list_morect.index(monster_)
                    if(fight(CAIXUKUN,eval(list_moname[x]+"_"),1))==[0]:
                        sound5.play()
                        FORBID=1
            if FORBID==1:
                pass
            else:
                if self.image_rect.top<100:
                    pass
                else:
                    self.image_rect.move_ip(0,-50)
        if str=="DOWN":
            FORBID=0
            rect_new=self.image_rect.copy()
            rect_new.move_ip(0,50)
            for wall_ in wallL[:]:
                if rect_new.colliderect(wall_):
                    FORBID=1
            for y_door in ydoorL[:]:
                if rect_new.colliderect(y_door)and self.property["Yellow_key"]==0:
                    FORBID=1
            for b_door in bdoorL[:]:
                if rect_new.colliderect(b_door) and self.property["Blue_key"]==0:
                    FORBID=1
            for r_door in rdoorL[:]:
                if rect_new.colliderect(r_door) and self.property["Red_key"]==0:
                    FORBID=1
            for monster_ in list_morect[:]:
                if rect_new.colliderect(monster_):
                     x = list_morect.index(monster_)
                     if (fight(CAIXUKUN, eval(list_moname[x] + "_"), 1)) == [0]:
                         sound5.play()
                         FORBID = 1
            if FORBID == 1:
                pass
            else:
                if self.image_rect.bottom>550:
                    pass
                else:
                    self.image_rect.move_ip(0, 50)
        if str == "LEFT":
            FORBID = 0
            rect_new = self.image_rect.copy()
            rect_new.move_ip(-50, 0)
            for wall_ in wallL[:]:
                if rect_new.colliderect(wall_):
                    FORBID = 1
            for y_door in ydoorL[:]:
                if rect_new.colliderect(y_door) and self.property["Yellow_key"] == 0:
                    FORBID = 1
            for b_door in bdoorL[:]:
                if rect_new.colliderect(b_door) and self.property["Blue_key"]==0:
                    FORBID=1
            for r_door in rdoorL[:]:
                if rect_new.colliderect(r_door) and self.property["Red_key"]==0:
                    FORBID=1
            for monster_ in list_morect[:]:
                if rect_new.colliderect(monster_):
                    x = list_morect.index(monster_)
                    if (fight(CAIXUKUN, eval(list_moname[x] + "_"), 1)) == [0]:
                        sound5.play()
                        FORBID = 1
            if FORBID == 1:
                pass
            else:
                if self.image_rect.left< 250:
                    pass
                else:
                    self.image_rect.move_ip(-50,0)
        if str == "RIGHT":
            FORBID = 0
            rect_new = self.image_rect.copy()
            rect_new.move_ip(50, 0)
            for wall_ in wallL[:]:
                if rect_new.colliderect(wall_):
                    FORBID = 1
            for y_door in ydoorL[:]:
                if rect_new.colliderect(y_door) and self.property["Yellow_key"] == 0:
                    FORBID = 1
            for b_door in bdoorL[:]:
                if rect_new.colliderect(b_door) and self.property["Blue_key"]==0:
                    FORBID=1
            for r_door in rdoorL[:]:
                if rect_new.colliderect(r_door) and self.property["Red_key"]==0:
                    FORBID=1
            for monster_ in list_morect[:]:
                if rect_new.colliderect(monster_):
                    x = list_morect.index(monster_)
                    if (fight(CAIXUKUN, eval(list_moname[x] + "_"), 1)) == [0]:
                        sound5.play()
                        FORBID = 1
            if FORBID == 1:
                pass
            else:
                if self.image_rect.right > 700:
                    pass
                else:
                    self.image_rect.move_ip(50, 0)
class monster:
    def __init__(self,tuple):
        self.attack=tuple[0]
        self.defend=tuple[1]
        self.life=tuple[2]
        self.gold=tuple[3]
CAIXUKUN=character((10,10,100))
gSlime_=monster((11,5,10,1))
rSlime_=monster((12,5,10,2))
sBat_=monster((13,5,10,3))
ghost_=monster((14,5,10,4))
hWitch_=monster((15,5,10,5))
Skeleton_=monster((20,11,10,8))
scSkeleton_=monster((25,11,10,10))
ground_L=[]
for i in range(4,14+1):
    for j in range(1,11+1):
        ground_L.append((50*i,50*j))
wall_L=[(200,100),(250,100),(300,100),(350,100),(400,100),(450,100),(500,100),(550,100),(600,100),(650,100),(450,150),(450,200),(450,250),(450,350),
        (500,250),(550,250),(650,250),(650,150),(650,200),(600,350),(550,350),(500,350),(650,350),(650,300),(350,200),(350,250),(350,300),(350,350),
        (350,400),(350,450),(350,500),(350,550),(300,250),(200,250),(300,400),(200,400),(400,450),(550,450),(600,450),
        (500,450),(550,500),(550,550),(700,450)]
#门
dict_door={(350,150):'yellow',(250,250):'blue',(600,250):'yellow',(450,300):'yellow',(250,400):'yellow',(450,450):'yellow',(450,450):'yellow',
           (650,450):'red',(600,250):'red'}
#宝物
dict_trea={(550,150):'ykey',(200,350):'ykey',(300,500):'ykey',(400,500):'ykey',(400,550):'bkey',(400,250):'rkey',(600,150):'rkey',(400,200):'ykey',(200,150):'ykey',(300,550):'ykey',(200,150):'rbottle',(100,350):'rbottle',(500,150):'rgem',(500,200):'bgem',(550,200):'rbottle',(200,550):'rbottle',(200,500):'bbottle',(650,550):'bbottle',(650,500):'bgem',}
#楼梯
dict_stair={(200,50):'up'}
#怪物
dict_monster={(300,50):'gSlime',(400,50):'gSlime',(600,550):'sBat',(700,550):'sBat',(350,50):'gSlime',(500,300):'rSlime',(500,300):'rSlime',
(250,300):'hWitch',(250,450):'ghost',(550,300):'ghost',(600,300):'rSlime'}
#神秘人
Guide=[(500,500)]
Lift=[(250,550)]
get_lift=0
List_temp1=[k for k,v in dict_door.items() if v=='yellow']
List_temp2=[k for k,v in dict_stair.items() if v=='up']
List_temp3=[k for k,v in dict_trea.items() if v=='rbottle']
List_temp4=[k for k,v in dict_trea.items() if v=='bbottle']
List_temp5=[k for k,v in dict_trea.items() if v=='rgem']
List_temp6=[k for k,v in dict_trea.items() if v=='bgem']
List_temp7=[k for k,v in dict_trea.items() if v=='ykey']
List_temp8=[k for k,v in dict_door.items() if v=='blue']
List_temp9=[k for k,v in dict_trea.items() if v=='bkey']
List_temp10=[k for k,v in dict_door.items() if v=='red']
List_temp11=[k for k,v in dict_trea.items() if v=='rkey']
def build_List(LIST1,LIST2):
    for i in range(1,len(LIST2)+1):
        LIST1.append(pygame.Rect(LIST2[i-1][0],LIST2[i-1][1],50,50))
wallL=[]
build_List(wallL,wall_L)
ydoorL=[]
build_List(ydoorL,List_temp1)
bdoorL=[]
build_List(bdoorL,List_temp2)
rdoorL=[]
build_List(rdoorL,List_temp3)
stairupL=[]
build_List(stairupL,List_temp4)
rbottleL=[]
build_List(rbottleL,List_temp5)
bbottleL=[]
build_List(bbottleL,List_temp6)
rgemL=[]
build_List(rgemL,List_temp7)
bgemL=[]
build_List(bgemL,List_temp8)
ykeyL=[]
build_List(ykeyL,List_temp9)
bkeyL=[]
build_List(bkeyL,List_temp10)
rkeyL=[]
build_List(rkeyL,List_temp11)
list_molocation=list(dict_monster)
list_moname=list(dict_monster.values())
list_morect=[]
build_List(list_morect,list_molocation)
guideL=[]
guideL.append(pygame.Rect(Guide[0][0],Guide[0][1],50,50))
liftL=[]
liftL.append(pygame.Rect(Lift[0][0],Lift[0][1],50,50))
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()
        elif event.type==pygame.KEYDOWN:
            if event.key==pygame.K_w:
                CAIXUKUN.move("UP")
            if event.key == pygame.K_s:
                CAIXUKUN.move("DOWN")
            if event.key==pygame.K_a:
                CAIXUKUN.move("LEFT")
            if event.key==pygame.K_d:
                CAIXUKUN.move("RIGHT")
            if event.key==pygame.K_p:
                if musicPlaying:
                    pygame.mixer.music.stop()
                else:
                    pygame.mixer.music.play(-1)
                musicPlaying=not musicPlaying
            if event.key==pygame.K_1:
                sound0.play()
        elif event.type==pygame.MOUSEBUTTONDOWN:
            if ykey_rect.collidepoint(event.pos):
                if event.button==1:
                    CAIXUKUN.property["Yellow_key"]+=1
                    sound4.play()
                elif event.button==2:
                    CAIXUKUN.property["Yellow_key"]=0
                elif event.button==3:
                    CAIXUKUN.property["Yellow_key"]-=1
            elif bkey_rect.collidepoint(event.pos):
                if event.button==1:
                    CAIXUKUN.property["Blue_key"]+=1
                    sound4.play()
                elif event.button==2:
                    CAIXUKUN.property["Blue_key"]=0
                elif event.button==3:
                    CAIXUKUN.property["Blue_key"]-=1
            elif rkey_rect.collidepoint(event.pos):
                if event.button==1:
                    CAIXUKUN.property["Red_key"]+=1
                    sound4.play()
                elif event.button==2:
                    CAIXUKUN.property["Red_key"]=0
                elif event.button==3:
                    CAIXUKUN.property["Red_key"]-=1
            elif up_lift_rect.collidepoint(event.pos):
                if event.button==1 and get_lift and CAIXUKUN.floor<66 and CAIXUKUN.floor!=42:
                    CAIXUKUN.floor+=1
            elif down_lift_rect.collidepoint(event.pos):
                if event.button==1 and get_lift and CAIXUKUN.floor>1 and CAIXUKUN.floor!=44:
                    CAIXUKUN.floor-=1
    for i in ground_L:
        screen.blit(ground,i)
    for j in wall_L:
        screen.blit(wall,j)
    for k in List_temp1:
        screen.blit(yellow_door,k)
    for k in List_temp8:
        screen.blit(blue_door,k)
    for k in List_temp10:
        screen.blit(red_door,k)
    for k in List_temp2:
        screen.blit(upstair,k)
    for k in List_temp3:
        screen.blit(rbottle,k)
    for k in List_temp4:
        screen.blit(bbottle,k)
    for k in List_temp5:
        screen.blit(rgem,k)
    for k in List_temp6:
        screen.blit(bgem,k)
    for k in List_temp7:
        screen.blit(ykey,k)
    for k in List_temp9:
        screen.blit(bkey,k)
    for k in List_temp11:
        screen.blit(rkey,k)
    for k in list_molocation:
        n=list_molocation.index(k)
        k_name=list_moname[n]
        screen.blit(eval(k_name),k)
    screen.blit(lift,Lift[0])
    screen.blit(guide,Guide[0])
    #黄门
    for y_door in ydoorL[:]:
        if CAIXUKUN.image_rect.colliderect(y_door):
            if CAIXUKUN.property["Yellow_key"]>0:
                i=ydoorL.index(y_door)
                ydoorL.remove(y_door)
                CAIXUKUN.property["Yellow_key"]-=1
                del List_temp1[i]
            else:
                pass
    for b_door in bdoorL[:]:
        if CAIXUKUN.image_rect.colliderect(b_door):
            if CAIXUKUN.property["Blue_key"]>0:
                i=bdoorL.index(b_door)
                bdoorL.remove(b_door)
                CAIXUKUN.property["Blue_key"]-=1
                del List_temp8[i]
            else:
                pass
    for r_door in rdoorL[:]:
        if CAIXUKUN.image_rect.colliderect(r_door):
            if CAIXUKUN.property["Red_key"]>0:
                i=rdoorL.index(r_door)
                rdoorL.remove(r_door)
                CAIXUKUN.property["Red_key"]-=1
                del List_temp10[i]
            else:
                pass
    #红血瓶
    for r_bottle in rbottleL[:]:
        if CAIXUKUN.image_rect.colliderect(r_bottle):
            sound1.play()
            i=rbottleL.index(r_bottle)
            rbottleL.remove(r_bottle)
            CAIXUKUN.life+=20
            del List_temp3[i]
    #蓝血瓶
    for b_bottle in bbottleL[:]:
        if CAIXUKUN.image_rect.colliderect(b_bottle):
            sound1.play()
            i=bbottleL.index(b_bottle)
            bbottleL.remove(b_bottle)
            CAIXUKUN.life+=10
            del List_temp4[i]
    for r_gem in rgemL[:]:
        if CAIXUKUN.image_rect.colliderect(r_gem):
            sound1.play()
            i=rgemL.index(r_gem)
            rgemL.remove(r_gem)
            CAIXUKUN.attack +=2
            del List_temp5[i]
    for b_gem in bgemL[:]:
        if CAIXUKUN.image_rect.colliderect(b_gem):
            sound1.play()
            i=bgemL.index(b_gem)
            bgemL.remove(b_gem)
            CAIXUKUN.defend +=2
            del List_temp6[i]
    for y_key in ykeyL[:]:
        if CAIXUKUN.image_rect.colliderect(y_key):
            i=ykeyL.index(y_key)
            ykeyL.remove(y_key)
            CAIXUKUN.property['Yellow_key']+=1
            del List_temp7[i]
    for b_key in bkeyL[:]:
        if CAIXUKUN.image_rect.colliderect(b_key):
            i=bkeyL.index(b_key)
            bkeyL.remove(b_key)
            CAIXUKUN.property['Blue_key']+=1
            del List_temp9[i]
    for r_key in rkeyL[:]:
        if CAIXUKUN.image_rect.colliderect(r_key):
            i=rkeyL.index(r_key)
            rkeyL.remove(r_key)
            CAIXUKUN.property['Red_key']+=1
            del List_temp11[i]
    #战斗事件
    for monster_ in list_morect[:]:
        if CAIXUKUN.image_rect.colliderect(monster_):
            x=list_morect.index(monster_)
            oops=eval(list_moname[x]+'_')
            if(fight(CAIXUKUN,oops)!=[0]):
                sound2.play()
                list_morect[x]=pygame.Rect(-100,-100,50,50)
                list_molocation[x]=(-100,-100)
            else:
                pass
    for lift_ in liftL[:]:
        if CAIXUKUN.image_rect.colliderect(lift_):
            sound6.play()
            liftL.remove(lift_)
            get_lift=1
            Lift[0]=(-100,-100)
    #侧边栏背景
    screen.fill((191,191,191),rect=att_rect1,special_flags=0)
    screen.fill((191,191,191),rect=att_rect2,special_flags=0)
    screen.fill((191,191,191),rect=att_rect3,special_flags=0)
    screen.fill((191,191,191),rect=att_rect4,special_flags=0)
    #任务栏
    screen.blit(ykey,(0,400))
    screen.blit(bkey,(0,450))
    screen.blit(rkey,(0,500))
    #属性栏
    text_surface1=my_FontCHs.render("第%s层"%str(CAIXUKUN.floor),True,(0,0,0),(191,191,191))
    text_surface2=my_FontCHs.render("攻击力:%s"%str(CAIXUKUN.attack),True,(0,0,0),(191,191,191))
    text_surface3=my_FontCHs.render("防御力:%s"%str(CAIXUKUN.defend),True,(0,0,0),(191,191,191))
    text_surface4=my_FontCHs.render("生命值:%s"%str(CAIXUKUN.life),True,(0,0,0),(191,191,191))
    text_surface5=my_FontCHs.render("金币:%s"%str(CAIXUKUN.gold),True,(0,0,0),(191,191,191))
    #钥匙数量
    Yellow_key=CAIXUKUN.property['Yellow_key']
    Blue_key=CAIXUKUN.property['Blue_key']
    Red_key=CAIXUKUN.property['Red_key']
    text_surface6=my_FontCHs.render("%s把"%str(Yellow_key),True,(0,0,0),(191,191,191))
    text_surface7=my_FontCHs.render("%s把"%str(Blue_key),True,(0,0,0),(191,191,191))
    text_surface8=my_FontCHs.render("%s把"%str(Red_key),True,(0,0,0),(191,191,191))
    text_surface9=my_FontCHs.render("永久使用宝物",True,(0,0,0),(191,191,191))
    text_surface10=my_FontCHs.render("一次使用宝物",True,(0,0,0),(191,191,191))
    text_surface11=my_FontCHs.render("自动使用宝物",True,(0,0,0),(191,191,191))
    if get_lift:
        screen.blit(pygame.transform.scale(pygame.image.load('life.png').convert_alpha(),(40,40)),(770,100))
    screen.blit(CAIXUKUN.image,CAIXUKUN.image_rect)
    #属性栏
    screen.blit(text_surface0,(280,0))
    screen.blit(text_surface1,(0,100))
    screen.blit(text_surface2,(0,150))
    screen.blit(text_surface3,(0,200))
    screen.blit(text_surface4,(0,250))
    screen.blit(text_surface5,(0,300))
    screen.blit(text_surface6,(100,400))
    screen.blit(text_surface7,(100,450))
    screen.blit(text_surface8,(100,500))
    screen.blit(text_surface9,(758,50))
    screen.blit(text_surface10,(758,280))
    screen.blit(text_surface11,(758,510))
    pygame.display.update()

总结

一点回忆

       不知道大家是否还记得原版的一个场景——当你历经千辛万苦、突破重重阻碍来到塔顶,大魔法师奇诺对你说:

"You villain. Little did I expect to be beaten. But I would never die in such a way. I'll be looking forward to fighting with you again!"


“你这个恶棍!我从未想过会被击败。但我不会就此死去。我很期待再和你打上一场!”

       魔王依旧不会死,勇者依旧会回到里魔塔的第一层。魔王继续变强。整个魔塔没有尽头,无论你打通多少周目,那个不可能击倒的魔王还是在塔顶等着你。


image.png

目录
相关文章
|
2月前
|
移动开发 JavaScript C#
总有一个是你想要的分享31个游戏源代码
该资源分享了31款游戏源代码,包括C#版植物大战僵尸、HTML5版五子棋等,均经过亲测可运行。下载链接中还包含13款游戏源码,适合游戏开发者和爱好者学习参考。作者辛苦整理,希望得到您的点赞与关注作为支持。
80 1
|
4月前
|
网络安全 Python
我不善言辞,但还是想教你做个没用的东西
一个可以禁用任意程序的上下行网络的小工具,有倒计时功能
|
6月前
|
移动开发 JavaScript C#
分享31个游戏源代码总有一个是你想要的
分享31个游戏源代码总有一个是你想要的
182 0
|
图形学 数据安全/隐私保护
还在用Unity开发游戏?那你就out了,试试用Unity做一个答题系统吧
大家都支持Unity是用来做游戏开发,比如说做2D游戏、3D游戏,或者工业虚拟仿真软件的开发。 其他Unity可以做的有很多,比如答题系统。 本篇就介绍答题系统的开发 这个答题系统,可以从文本文档中提取题目和分数,然后绑定到UI上,在答题的过程中,自动判断分数,自动判断正确率。 目的是实现一个可快速导入到项目中使用的小模块。
小白的第二个项目--扫雷游戏
小白的第二个项目--扫雷游戏
87 0
|
C语言
C/关于N子棋小游戏的创建
C/关于N子棋小游戏的创建
|
开发者
你应该试着独自做个游戏
对于大部分从事游戏开发行业的人,其实并没有机会能够完整的去掌控一个游戏制作的全过程。开发的只负责开发工作,美术的只负责美术工作,大概只有策划能够有机会从整体上了解一个游戏,可能在很多公司中,对于策划也分为很多种,如果只是其中的一种策划,也是没有机会的,唯一一个能够从始至终掌控一个游戏的大概叫做总策划或者叫产品经理。
92 0
|
人工智能 移动开发 数据可视化
不会写代码,想要做游戏
嗨!大家好,我是小蚂蚁。 “我不会写代码,还能做游戏吗?”不少想做游戏的朋友可能都会有这个疑问,答案当然是“能”。 即使不会代码,也并不影响你做游戏。会不会写代码,并不是做游戏的必要条件。 感谢工具的力量,是先进的工具让做游戏这件事对很多人来说成为了可能,下面我就为大家介绍几个不需要写代码,也能够做游戏的工具。
182 0
|
开发工具
为什么不要通过去找游戏源码的方式来做游戏
一个来自游戏开发新手朋友的问题: 蚂蚁老师,我从小就很喜欢玩游戏,玩得多了渐渐就有一些自己的想法,没事无聊的时候就会把这些想法写下来,写得多了就有自己做游戏的想法,因为自己什么都不会,所以一直都没能付诸行动,直到有天在抖音刷到您的教学视频,又燃起我做游戏的热情。现在我最想做的是一款类似《植物大战僵尸》类的休闲塔防游戏。
230 0
|
Python 内存技术
你是否还记得有一款游戏叫做“魔塔”?(一)
你是否还记得有一款游戏叫做“魔塔”?
397 0
你是否还记得有一款游戏叫做“魔塔”?(一)