Ejemplo n.º 1
0
 def resetIcons():
     icons = []
     ups = inspect.getmembers(TowerUpgrades, inspect.isclass)
     for c, d in ups:
         if c != "Upgrade":
             try:
                 next = (c, eval("TowerUpgrades." + c + ".pos"),
                         imgLoad(os.path.join("upgradeicons", c + ".jpg")))
                 if (c in tower.upgrades):
                     temp = next[2].copy()
                     temp.fill((0, 150, 0))
                     temp.set_alpha(125)
                     next[2].blit(temp, (0, 0))
                 elif not eval("TowerUpgrades." + c + ".checkReq(tower)"):
                     temp = next[2].copy()
                     temp.fill((150, 0, 0))
                     temp.set_alpha(125)
                     next[2].blit(temp, (0, 0))
                 icons.append(next)
             except:
                 try:
                     next = (c, eval("TowerUpgrades." + c + ".pos"),
                             imgLoad(
                                 os.path.join("upgradeicons",
                                              c[:2] + ".jpg")))
                     if (c in tower.upgrades):
                         temp = next[2].copy()
                         temp.fill((0, 150, 0))
                         temp.set_alpha(125)
                         next[2].blit(temp, (0, 0))
                     elif not eval("TowerUpgrades." + c +
                                   ".checkReq(tower)"):
                         temp = next[2].copy()
                         temp.fill((150, 0, 0))
                         temp.set_alpha(125)
                         next[2].blit(temp, (0, 0))
                     icons.append(next)
                 except:
                     taimg = pygame.Surface((20, 20))
                     if (c in tower.upgrades):
                         taimg.fill((0, 150, 0))
                     elif not eval("TowerUpgrades." + c +
                                   ".checkReq(tower)"):
                         taimg.fill((150, 0, 0))
                     else:
                         taimg.fill((90, 90, 255))
                     icons.append(
                         (c, eval("TowerUpgrades." + c + ".pos"), taimg))
     return icons
 def resetIcons():
     icons = []
     ups = inspect.getmembers(TowerUpgrades,inspect.isclass)
     for c,d in ups:
         if c != "Upgrade":
             try:
                 next = (c,eval("TowerUpgrades."+c+".pos"),imgLoad(os.path.join("upgradeicons",c+".jpg")))
                 if (c in tower.upgrades):
                     temp = next[2].copy()
                     temp.fill((0,150,0))
                     temp.set_alpha(125)
                     next[2].blit(temp,(0,0))
                 elif not eval("TowerUpgrades."+c+".checkReq(tower)"):
                     temp = next[2].copy()
                     temp.fill((150,0,0))
                     temp.set_alpha(125)
                     next[2].blit(temp,(0,0))
                 icons.append(next)
             except:
                 try:
                     next = (c,eval("TowerUpgrades."+c+".pos"),imgLoad(os.path.join("upgradeicons",c[:2]+".jpg")))
                     if (c in tower.upgrades):
                         temp = next[2].copy()
                         temp.fill((0,150,0))
                         temp.set_alpha(125)
                         next[2].blit(temp,(0,0))
                     elif not eval("TowerUpgrades."+c+".checkReq(tower)"):
                         temp = next[2].copy()
                         temp.fill((150,0,0))
                         temp.set_alpha(125)
                         next[2].blit(temp,(0,0))
                     icons.append(next)
                 except:
                     taimg = pygame.Surface((20,20))
                     if (c in tower.upgrades):
                         taimg.fill((0,150,0))
                     elif not eval("TowerUpgrades."+c+".checkReq(tower)"):
                         taimg.fill((150,0,0))
                     else:
                         taimg.fill((90,90,255))
                     icons.append((c,eval("TowerUpgrades."+c+".pos"),taimg))
     return icons
Ejemplo n.º 3
0
def pickNewTowerImage(screen, clock, st):
    run = 1
    bg = pygame.Surface((localdefs.scrwid, localdefs.scrhei))
    bg.fill((255, 255, 255))
    font = pygame.font.Font(None, 20)
    fontBig = pygame.font.Font(None, 30)
    nametext = fontBig.render("Pick Tower %d's Image" % (st), 1, (0, 0, 0))
    nametextpos = nametext.get_rect(centerx=localdefs.scrwid / 2, top=10)
    ImageNames = ["Basic", "Archer", "Cleric", "ClericNegative", "Fighter", "Mage", "Node"]
    ImageFiles = dict()
    for n in ImageNames:
        ImageFiles[n] = localdefs.imgLoad(os.path.join("towerimgs", n + ".png"))
    while run:
        clock.tick(30)
        screen.blit(bg, (0, 0))

        screen.blit(nametext, nametextpos)

        textrectdict = dict()
        imgrectdict = dict()

        for i, key in enumerate(ImageFiles.keys()):
            text = font.render("%s" % (key), 1, (0, 0, 0))
            textpos = text.get_rect(
                centerx=(1 + i) * (localdefs.scrwid / (1 + len(ImageFiles))), centery=localdefs.scrhei / 2
            )
            textrectdict[key] = textpos
            imgrect = ImageFiles[key].get_rect(centerx=textpos.centerx, bottom=textpos.top - 2)
            imgrectdict[key] = imgrect
            screen.blit(text, textpos)
            screen.blit(ImageFiles[key], imgrect)

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit(0)
            elif event.type == MOUSEBUTTONUP:
                for key in textrectdict.keys():
                    if textrectdict[key].collidepoint(event.dict["pos"]) or imgrectdict[key].collidepoint(
                        event.dict["pos"]
                    ):
                        localdefs.player.modDict["tower"][st]["ImageName"] = key
                        localdefs.player.save()
                        localdefs.player.__init__()
                        return
            else:
                keyinput = pygame.key.get_pressed()
                if keyinput[K_ESCAPE] or keyinput[K_BACKSPACE]:
                    return
                elif keyinput[K_f]:
                    screen = pygame.display.set_mode((localdefs.scrwid, localdefs.scrhei), FULLSCREEN)
                elif keyinput[K_w]:
                    screen = pygame.display.set_mode((localdefs.scrwid, localdefs.scrhei))

        pygame.display.flip()
Ejemplo n.º 4
0
def pickNewTowerImage(screen,clock,st):
    run = 1
    bg = pygame.Surface((localdefs.scrwid,localdefs.scrhei))
    bg.fill((255,255,255))
    font = pygame.font.Font(None,20)
    fontBig = pygame.font.Font(None,30)
    nametext = fontBig.render("Pick Tower %d's Image" % (st),1,(0,0,0))
    nametextpos = nametext.get_rect(centerx=localdefs.scrwid/2,top=10)
    ImageNames = ["Basic","Archer","Cleric","ClericNegative","Fighter","Mage","Node"]
    ImageFiles = dict()
    for n in ImageNames:
        ImageFiles[n] = localdefs.imgLoad(os.path.join("towerimgs",n+".png"))
    while run:
        clock.tick(30)
        screen.blit(bg,(0,0))

        screen.blit(nametext,nametextpos)

        textrectdict = dict()
        imgrectdict = dict()

        for i,key in enumerate(ImageFiles.keys()):
            text = font.render("%s" % (key),1,(0,0,0))
            textpos = text.get_rect(centerx=(1+i)*(localdefs.scrwid/(1+len(ImageFiles))),centery=localdefs.scrhei/2)
            textrectdict[key] = textpos
            imgrect = ImageFiles[key].get_rect(centerx=textpos.centerx,bottom=textpos.top-2)
            imgrectdict[key] = imgrect
            screen.blit(text,textpos)
            screen.blit(ImageFiles[key],imgrect)

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit(0)
            elif event.type == MOUSEBUTTONUP:
                for key in textrectdict.keys():
                    if textrectdict[key].collidepoint(event.dict['pos']) or imgrectdict[key].collidepoint(event.dict['pos']):
                        localdefs.player.modDict['tower'][st]['ImageName'] = key
                        localdefs.player.save()
                        localdefs.player.__init__()
                        return
            else:
                keyinput = pygame.key.get_pressed()
                if keyinput[K_ESCAPE] or keyinput[K_BACKSPACE]:
                    return
                elif keyinput[K_f]:
                    screen = pygame.display.set_mode((localdefs.scrwid,localdefs.scrhei),FULLSCREEN)
                elif keyinput[K_w]:
                    screen = pygame.display.set_mode((localdefs.scrwid,localdefs.scrhei))

        pygame.display.flip()
Ejemplo n.º 5
0
def main(screen, clock):
    bg = pygame.Surface((localdefs.scrwid, localdefs.scrhei))
    bg.fill((255, 255, 255))
    run = 1
    imgs = dict()
    rects = dict()
    for num, i in enumerate(["playmap", "edittowers"]):
        imgs[i] = localdefs.imgLoad(os.path.join("menuimages", i + ".png"))
        rects[i] = imgs[i].get_rect(centerx=localdefs.scrwid / 2,
                                    centery=(num + 1) * localdefs.scrhei / 5)
    while run:
        clock.tick(30)
        screen.blit(bg, (0, 0))

        for key in imgs.keys():
            screen.blit(imgs[key], rects[key])

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
            elif event.type == MOUSEBUTTONUP:
                if rects["playmap"].collidepoint(event.dict['pos']):
                    map = pickMap(screen, clock)
                    if len(map) > 2:
                        return map
                elif rects["edittowers"].collidepoint(event.dict['pos']):
                    pickTower(screen, clock)
                elif rects["options"].collidepoint(event.dict['pos']):
                    print "Not Yet Implemented"
            else:
                keyinput = pygame.key.get_pressed()
                if keyinput[K_ESCAPE]:
                    sys.exit()
                elif keyinput[K_f]:
                    screen = pygame.display.set_mode(
                        (localdefs.scrwid, localdefs.scrhei), FULLSCREEN)
                elif keyinput[K_w]:
                    screen = pygame.display.set_mode(
                        (localdefs.scrwid, localdefs.scrhei))

        pygame.display.flip()
Ejemplo n.º 6
0
def main(screen, clock):
    bg = pygame.Surface((localdefs.scrwid, localdefs.scrhei))
    bg.fill((255, 255, 255))
    run = 1
    imgs = dict()
    rects = dict()
    for num, i in enumerate(["playmap", "edittowers", "options"]):
        imgs[i] = localdefs.imgLoad(os.path.join("menuimages", i + ".png"))
        rects[i] = imgs[i].get_rect(centerx=localdefs.scrwid / 2, centery=(num + 1) * localdefs.scrhei / 5)
    while run:
        clock.tick(30)
        screen.blit(bg, (0, 0))

        for key in imgs.keys():
            screen.blit(imgs[key], rects[key])

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
            elif event.type == MOUSEBUTTONUP:
                if rects["playmap"].collidepoint(event.dict["pos"]):
                    map = pickMap(screen, clock)
                    if len(map) > 2:
                        return map
                elif rects["edittowers"].collidepoint(event.dict["pos"]):
                    pickTower(screen, clock)
                elif rects["options"].collidepoint(event.dict["pos"]):
                    print "Not Yet Implemented"
            else:
                keyinput = pygame.key.get_pressed()
                if keyinput[K_ESCAPE]:
                    sys.exit()
                elif keyinput[K_f]:
                    screen = pygame.display.set_mode((localdefs.scrwid, localdefs.scrhei), FULLSCREEN)
                elif keyinput[K_w]:
                    screen = pygame.display.set_mode((localdefs.scrwid, localdefs.scrhei))

        pygame.display.flip()
Ejemplo n.º 7
0
def changeTowerAbilities(screen,clock):
    run = 1
    bg = pygame.Surface((localdefs.scrwid,localdefs.scrhei))
    bg.fill((255,255,255))
    font = pygame.font.Font(None,20)
    fontBig = pygame.font.Font(None,30)
    nametext = fontBig.render("Pick Tower Abilities",1,(0,0,0))
    nametextpos = nametext.get_rect(centerx=localdefs.scrwid/2,top=10)

    towerlist = list()

    for num in range(0,localdefs.player.modDict['towerNum']):
        towerlist.append(dict())
        try:
            towerlist[num]["image"] = localdefs.imgLoad(os.path.join('towerimgs',localdefs.player.modDict['tower'][num+1]['ImageName']+'.png'))
        except:
            towerlist[num]["image"] = localdefs.imgLoad(os.path.join('towerimgs','Fighter.png'))

        towerlist[num]["imagerect"] = towerlist[num]["image"].get_rect(left=20,centery=nametextpos.bottom+(num+1)*(localdefs.scrhei-nametextpos.bottom)/(localdefs.player.modDict['towerNum']+2))
        towerlist[num]["upgrades"] = list()
        towerlist[num]["num"] = num

    upslist = list()
    nondisups = list()

    if 'upgrades' in localdefs.player.loadarray.keys():
        for up in localdefs.player.loadarray['upgrades']:
            if len(up)>0:
                if eval("PlayerUpgrades."+up[:-1]+".selectTower"):
                    img = pygame.Surface((20,20))
                    img.fill((137,109,213))
                    upslist.append(dict())
                    upslist[-1]["class"] = eval("PlayerUpgrades."+up[:-1])
                    upslist[-1]["name"] = up[:-1]
                    upslist[-1]["curtower"] = int(up[-1])-1
                    upslist[-1]["img"] = img
                    upslist[-1]["rect"] = upslist[-1]["img"].get_rect(left=60+30*len(towerlist[int(up[-1])-1]["upgrades"]),centery=towerlist[int(up[-1])-1]["imagerect"].centery)
                    towerlist[int(up[-1])-1]["upgrades"].append(upslist[-1])
                else:
                    nondisups.append(dict())
                    nondisups[-1]["name"] = up[:-1]
                    nondisups[-1]["curtower"] = -1
    else:
        print "No Abilities To Assign"
        return

    selected = None

    while run:
        clock.tick(30)
        screen.blit(bg,(0,0))

        screen.blit(nametext,nametextpos)

        for up in upslist:
            screen.blit(up["img"],up["rect"])

        for tower in towerlist:
            screen.blit(tower["image"],tower["imagerect"])

        if selected:
            screen.blit(selected["img"],pygame.mouse.get_pos())
        else:
            for up in upslist:
                if up["rect"].collidepoint(pygame.mouse.get_pos()):
                    try:text = font.render("%s" % (up["class"].singlename),1,(0,0,0))
                    except:text = font.render("%s" % (up["class"].name),1,(0,0,0))
                    if pygame.mouse.get_pos()[0]>localdefs.scrwid/2:
                        screen.blit(text,text.get_rect(right=up["rect"].left-10,bottom=up["rect"].top))
                    else:
                        screen.blit(text,text.get_rect(left=up["rect"].right+10,bottom=up["rect"].top))

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit(0)
            elif event.type == MOUSEBUTTONDOWN:
                for up in upslist:
                    if up["rect"].collidepoint(event.dict["pos"]):
                        selected = up
            elif event.type == MOUSEBUTTONUP:
                if selected:
                    for tower in towerlist:
                        if tower["imagerect"].collidepoint(event.dict["pos"]):
                            selected["rect"] = selected["img"].get_rect(left=60+30*len(tower["upgrades"]),centery=tower["imagerect"].centery)
                            selected["curtower"] = tower["num"]
                            tower["upgrades"].append(selected)
                selected = None
            else:
                keyinput = pygame.key.get_pressed()
                if keyinput[K_ESCAPE] or keyinput[K_BACKSPACE]:
                    localdefs.player.upgrades = list()
                    for up in upslist+nondisups:
                        localdefs.player.upgrades.append(up["name"]+str(up["curtower"]+1))
                    localdefs.player.save()
                    localdefs.player.__init__()
                    return
                elif keyinput[K_f]:
                    screen = pygame.display.set_mode((localdefs.scrwid,localdefs.scrhei),FULLSCREEN)
                elif keyinput[K_w]:
                    screen = pygame.display.set_mode((localdefs.scrwid,localdefs.scrhei))

        pygame.display.flip()
Ejemplo n.º 8
0
def changeTowerAbilities(screen, clock):
    run = 1
    bg = pygame.Surface((localdefs.scrwid, localdefs.scrhei))
    bg.fill((255, 255, 255))
    font = pygame.font.Font(None, 20)
    fontBig = pygame.font.Font(None, 30)
    nametext = fontBig.render("Pick Tower Abilities", 1, (0, 0, 0))
    nametextpos = nametext.get_rect(centerx=localdefs.scrwid / 2, top=10)

    towerlist = list()

    for num in range(0, localdefs.player.modDict["towerNum"]):
        towerlist.append(dict())
        try:
            towerlist[num]["image"] = localdefs.imgLoad(
                os.path.join("towerimgs", localdefs.player.modDict["tower"][num + 1]["ImageName"] + ".png")
            )
        except:
            towerlist[num]["image"] = localdefs.imgLoad(os.path.join("towerimgs", "Fighter.png"))

        towerlist[num]["imagerect"] = towerlist[num]["image"].get_rect(
            left=20,
            centery=nametextpos.bottom
            + (num + 1) * (localdefs.scrhei - nametextpos.bottom) / (localdefs.player.modDict["towerNum"] + 2),
        )
        towerlist[num]["upgrades"] = list()
        towerlist[num]["num"] = num

    upslist = list()
    nondisups = list()

    if "upgrades" in localdefs.player.loadarray.keys():
        for up in localdefs.player.loadarray["upgrades"]:
            if len(up) > 0:
                if eval("PlayerUpgrades." + up[:-1] + ".selectTower"):
                    img = pygame.Surface((20, 20))
                    img.fill((137, 109, 213))
                    upslist.append(dict())
                    upslist[-1]["class"] = eval("PlayerUpgrades." + up[:-1])
                    upslist[-1]["name"] = up[:-1]
                    upslist[-1]["curtower"] = int(up[-1]) - 1
                    upslist[-1]["img"] = img
                    upslist[-1]["rect"] = upslist[-1]["img"].get_rect(
                        left=60 + 30 * len(towerlist[int(up[-1]) - 1]["upgrades"]),
                        centery=towerlist[int(up[-1]) - 1]["imagerect"].centery,
                    )
                    towerlist[int(up[-1]) - 1]["upgrades"].append(upslist[-1])
                else:
                    nondisups.append(dict())
                    nondisups[-1]["name"] = up[:-1]
                    nondisups[-1]["curtower"] = -1
    else:
        print "No Abilities To Assign"
        return

    selected = None

    while run:
        clock.tick(30)
        screen.blit(bg, (0, 0))

        screen.blit(nametext, nametextpos)

        for up in upslist:
            screen.blit(up["img"], up["rect"])

        for tower in towerlist:
            screen.blit(tower["image"], tower["imagerect"])

        if selected:
            screen.blit(selected["img"], pygame.mouse.get_pos())
        else:
            for up in upslist:
                if up["rect"].collidepoint(pygame.mouse.get_pos()):
                    try:
                        text = font.render("%s" % (up["class"].singlename), 1, (0, 0, 0))
                    except:
                        text = font.render("%s" % (up["class"].name), 1, (0, 0, 0))
                    if pygame.mouse.get_pos()[0] > localdefs.scrwid / 2:
                        screen.blit(text, text.get_rect(right=up["rect"].left - 10, bottom=up["rect"].top))
                    else:
                        screen.blit(text, text.get_rect(left=up["rect"].right + 10, bottom=up["rect"].top))

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit(0)
            elif event.type == MOUSEBUTTONDOWN:
                for up in upslist:
                    if up["rect"].collidepoint(event.dict["pos"]):
                        selected = up
            elif event.type == MOUSEBUTTONUP:
                if selected:
                    for tower in towerlist:
                        if tower["imagerect"].collidepoint(event.dict["pos"]):
                            selected["rect"] = selected["img"].get_rect(
                                left=60 + 30 * len(tower["upgrades"]), centery=tower["imagerect"].centery
                            )
                            selected["curtower"] = tower["num"]
                            tower["upgrades"].append(selected)
                selected = None
            else:
                keyinput = pygame.key.get_pressed()
                if keyinput[K_ESCAPE] or keyinput[K_BACKSPACE]:
                    localdefs.player.upgrades = list()
                    for up in upslist + nondisups:
                        localdefs.player.upgrades.append(up["name"] + str(up["curtower"] + 1))
                    localdefs.player.save()
                    localdefs.player.__init__()
                    return
                elif keyinput[K_f]:
                    screen = pygame.display.set_mode((localdefs.scrwid, localdefs.scrhei), FULLSCREEN)
                elif keyinput[K_w]:
                    screen = pygame.display.set_mode((localdefs.scrwid, localdefs.scrhei))

        pygame.display.flip()