Exemple #1
0
 def fire(self, direction, what=None):
     weapon = what
     if what is None:
         if self.rangedpreference is None:
             if self.player:
                 weapon = self.getbestrangedforplayer()
             else:
                 weapon = self.getbestranged()
         else:
             weapon = self.rangedpreference
     if weapon is None:
         return None
     weapon.setposition(self.getposition())
     weapon = self.throwaway(weapon)
     weapon.setlastuser(self)
     weapon.fired = True
     # set fuse for fused weapons
     if weapon.getparam("defaultFuse") is not None and weapon.getparam("fuse") is not None:
         weapon.setparam("fuse", int(weapon.getparam("defaultFuse")))
     self.gameengine.mapfield.items.append(weapon)
     if weapon.getparam("range") is not None:
         wrange = weapon.getparam("range")
     else:  # weapon not meant as ranged
         wrange = 0
     for i in range(0, wrange):
         if weapon.getflag("beam"):
             if weapon.geteffect() is not None:
                 newposition = pathfinder.alterposition(weapon.getposition(), direction)
                 # if weapon hits obstacle
                 if not self.gameengine.mapfield.isnonsolid(newposition):
                     break
                 weapon.setposition(newposition)
                 neweffect = effect.Effect(self.gameengine.effinfo[weapon.geteffect()], self.gameengine)
                 neweffect.setposition(weapon.getposition())
                 neweffect.setowner(self)
                 self.gameengine.mapfield.effects.append(neweffect)
         else:
             newposition = pathfinder.alterposition(weapon.getposition(), direction)
             monsterat = self.gameengine.mapfield.getoccupants(newposition)
             # if weapon hits any monster
             if monsterat is not None:
                 monsterat.rangedcombat(weapon, self)
                 break
             # if weapon hits obstacle
             elif not self.gameengine.mapfield.ispassable(newposition):
                 break
             # if not, it flies to its maximum range
             else:
                 weapon.setposition(newposition)
                 if weapon.geteffect() is not None:
                     neweffect = effect.Effect(self.gameengine.effinfo[weapon.geteffect()], self.gameengine)
                     neweffect.setposition(weapon.getposition())
                     neweffect.setowner(self)
                     self.gameengine.mapfield.effects.append(neweffect)
     if weapon.getflag("nodrop"):
         self.gameengine.mapfield.items.remove(weapon)
Exemple #2
0
    def large(self):
        neighbors = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        for n in neighbors:
            ncoord = pathfinder.alterposition(self.getposition(), n)
            protoeffect = copy.copy(self.gameengine.effinfo[self.getname()])
            # remove large to prevent flood
            # copy because we don't want to change the flags in global effects library
            flags = copy.copy(protoeffect["flags"])
            for f in flags:
                if f == "large":
                    flags.remove(f)
                    break
            protoeffect["flags"] = flags
            neweffect = Effect(protoeffect, self.gameengine)
            neweffect.setposition(ncoord)
            neweffect.setowner(self.owner)
            neweffect.ttl = self.ttl

            neweffect.setparam("flags", flags)
            self.gameengine.mapfield.effects.append(neweffect)
            neweffect.update()
Exemple #3
0
    def large(self):
        neighbors = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1),
                     (-1, 1), (-1, -1)]
        for n in neighbors:
            ncoord = pathfinder.alterposition(self.getposition(), n)
            protoeffect = copy.copy(self.gameengine.effinfo[self.getname()])
            # remove large to prevent flood
            # copy because we don't want to change the flags in global effects library
            flags = copy.copy(protoeffect["flags"])
            for f in flags:
                if f == "large":
                    flags.remove(f)
                    break
            protoeffect["flags"] = flags
            neweffect = Effect(protoeffect, self.gameengine)
            neweffect.setposition(ncoord)
            neweffect.setowner(self.owner)
            neweffect.ttl = self.ttl

            neweffect.setparam("flags", flags)
            self.gameengine.mapfield.effects.append(neweffect)
            neweffect.update()
Exemple #4
0
    def drawboard(self, arenamap):
        self.maplayer = self.maptileeng.getmapsurface(arenamap)
        self.screen.fill(pygame.Color('black'))
        self.screen.blit(self.maplayer, (MAPPOSX, MAPPOSY))

        # display all items
        for item in self.gameengine.mapfield.items:
            itemimage = self.itetileeng.gettile(item.parameters["id"])
            self.screen.blit(itemimage, c(item.getvisualpos(TILESIZE)))

        # display all monsters
        for monster in self.gameengine.mapfield.monsters:
            # huge monsters has another tileset and are huge
            if monster.getflag("huge"):
                monsterimage = self.bigmontileeng.gettile(monster.parameters["id"])
                position = c(monster.getvisualpos(TILESIZE))
                position = (position[0] - bigtilestep / 2, position[1] - bigtilestep / 2)
                self.screen.blit(monsterimage, position)
            else:
                monsterimage = self.montileeng.gettile(monster.parameters["id"])
                self.screen.blit(monsterimage, c(monster.getvisualpos(TILESIZE)))

        # display all effects
        for effect in self.gameengine.mapfield.effects:
            effectimage = self.efftileeng.gettile(effect.parameters["id"])
            self.screen.blit(effectimage, c(effect.getvisualpos(TILESIZE)))

        # Events
        for key in self.eventstack:
            self.screen.blit(self.eventstack[key], key)

        # Special effects
        if self.gameengine.deepblue == 1:
            alpha = 0
            fcolor = (0, 36, 56)
            # if self.gameengine.noscore:
            #     fcolor = (255, 0, 0)
            for y in range(self.maplayer.get_height()):
                s = pygame.Surface((self.maplayer.get_width(), 1))
                s.set_alpha(int(alpha))
                s.fill(fcolor)
                self.screen.blit(s, (MAPPOSX, MAPPOSY + y))
                alpha += 0.2


        # Log
        logposadd = 0
        logbackgr = pygame.Surface(LOGWINDOWSIZE)
        logbackgr = logbackgr.convert()
        logbackgr.fill(pygame.Color("black"))
        for line in self.loglines:
            text = self.logfont.render(line, 1, (120+logposadd, 120+logposadd, 120+logposadd))
            logbackgr.blit(text, (10, 0+logposadd))
            logposadd += 20
        self.screen.blit(logbackgr, LOGWINDOWPOS)

        if self.gameengine.state == "help":
            self.displayhelpscreen()
            self.finalscreen.blit(pygame.transform.smoothscale(self.screen, self.correctratio(self.size)), (0, 0))
            pygame.display.flip()
            return

        if self.gameengine.state == "win":
            player = self.gameengine.mapfield.getplayer()
            self.displaywin(player.score, player.killslist)
            pygame.display.flip()
            return

        if self.gameengine.state == "reset":
            player = self.gameengine.mapfield.getplayer()
            if player is not None and int(player.getparam("level")) >= self.gameengine.LASTLEVEL:
                self.displaywin(player.score, player.killslist)
            else:
                self.displaydeath(str(self.gameengine.lastscore), self.gameengine.lastplayer.killslist)
            self.finalscreen.blit(pygame.transform.smoothscale(self.screen, self.correctratio(self.size)), (0, 0))
            pygame.display.flip()
            return

        if self.gameengine.mapfield.getplayer() is not None:
            # Status
            self.displayhelp()

            watchimage = self.uiparttileeng.getcustomtile(0, 0, 168, 315)

            player = self.gameengine.mapfield.getplayer()
            maxhp = str(player.getparam("maxhp"))
            curhp = str(player.getparam("hp"))
            score = str(player.score)
            level = str(player.getparam("level"))
            combo = str(player.combo)

            maxweight = str(player.getparam("weight limit"))
            weight = str(player.gettotalweight())

            tcolor = "green"
            if (int(curhp) - int(maxhp) / 5) <= 0:
                tcolor = "red"
            text = self.statusfont.render("H "+curhp+" / "+maxhp, 1, (pygame.Color(tcolor)))
            watchimage.blit(text, (40, 113))
            text = self.statusfont.render("S "+score, 1, (pygame.Color("green")))
            watchimage.blit(text, (40, 133))

            tcolor = "green"
            if (self.gameengine.getrequiredkillcount() - player.killcount) <= 0:
                tcolor = "red"
            text = self.statusfont.render("L " + level + " / " +
                                    str(self.gameengine.getrequiredkillcount() - player.killcount),
                                    1, (pygame.Color(tcolor)))
            watchimage.blit(text, (40, 153))

            tcolor = "green"
            if int(weight) > int(maxweight):
                tcolor = "red"
            text = self.statusfont.render("W " + weight + " / " + maxweight, 1, (pygame.Color(tcolor)))
            watchimage.blit(text, (40, 173))

            tcolor = "green"
            if int(combo) >= self.gameengine.COMBO_ITEM:
                tcolor = "red"
            text = self.statusfont.render("C " + combo, 1, (pygame.Color(tcolor)))
            watchimage.blit(text, (64, 193))

            self.screen.blit(watchimage, WATCHPOS)

            # Special modes
            if self.gameengine.state == "fire":
                statusbackgr = pygame.Surface((100, 20))
                statusbackgr = statusbackgr.convert()
                text = self.statusfont.render("Firing", 1, (pygame.Color("grey70")))
                # display fire range
                pointerimage = self.uitileeng.getcustomtile(32, 0, 32, 32)
                weapon = self.gameengine.mapfield.getplayer().rangedpreference
                wrange = None
                if weapon is not None:
                    wrange = self.gameengine.mapfield.getplayer().rangedpreference.getparam("range")
                possible = []
                if wrange is not None:
                    for direction in pathfinder.neighbors:
                        temppos = self.gameengine.mapfield.getplayer().getposition()
                        for i in range(0, wrange):
                            if weapon.getflag("beam"):
                                if weapon.geteffect() is not None:
                                    temppos = pathfinder.alterposition(temppos, direction)
                                    # if weapon hits obstacle
                                    if not self.gameengine.mapfield.isnonsolid(temppos):
                                        break
                                    possible.append(temppos)
                            else:
                                oldpos = temppos
                                temppos = pathfinder.alterposition(temppos, direction)
                                monsterat = self.gameengine.mapfield.getoccupants(temppos)
                                if not self.gameengine.mapfield.isnonsolid(temppos):
                                    possible.append(oldpos)
                                    break
                                # if weapon hits any monster
                                if monsterat is not None:
                                    possible.append(temppos)
                                    break
                                # if weapon hits obstacle
                                elif not self.gameengine.mapfield.ispassable(temppos):
                                    break
                                # if not, it flies to its maximum range
                                else:
                                    if i == wrange-1:
                                        possible.append(temppos)
                for location in possible:
                    self.screen.blit(pointerimage, (location[0]*TILESIZE+MAPPOSX,
                                                    location[1]*TILESIZE+MAPPOSY))
                statusbackgr.blit(text, (1, 1))
                self.screen.blit(statusbackgr, (830, 20))
            if self.gameengine.state == "look":
                statusbackgr = pygame.Surface((100, 20))
                statusbackgr = statusbackgr.convert()
                text = self.statusfont.render("Looking", 1, (pygame.Color("grey70")))
                statusbackgr.blit(text, (1, 1))
                self.screen.blit(statusbackgr, (830, 20))
                cursorimage = self.uitileeng.getcustomtile(0, 0, 32, 32)
                self.screen.blit(cursorimage, (self.gameengine.cursorcoord[0]*TILESIZE+MAPPOSX,
                                               self.gameengine.cursorcoord[1]*TILESIZE+MAPPOSY))
                infotext = self.infoview(self.gameengine.cursorcoord)
                if infotext is not None:
                    self.drawwindow(infotext, self.gameengine.cursorcoord)
            else:
                if self.mousetile is not None:
                    infotext = self.infoview(self.mousetile)
                    if infotext is not None:
                        self.drawwindow(infotext, self.mousetile)
            self.displaypops()
        self.finalscreen.blit(pygame.transform.smoothscale(self.screen, self.correctratio(self.size)), (0, 0))
        pygame.display.flip()
Exemple #5
0
 def fire(self, direction, what=None):
     weapon = what
     if what is None:
         if self.rangedpreference is None:
             if self.player:
                 weapon = self.getbestrangedforplayer()
             else:
                 weapon = self.getbestranged()
         else:
             weapon = self.rangedpreference
     if weapon is None:
         return None
     weapon.setposition(self.getposition())
     weapon = self.throwaway(weapon)
     weapon.setlastuser(self)
     weapon.fired = True
     # set fuse for fused weapons
     if weapon.getparam("defaultFuse") is not None and weapon.getparam(
             "fuse") is not None:
         weapon.setparam("fuse", int(weapon.getparam("defaultFuse")))
     self.gameengine.mapfield.items.append(weapon)
     if weapon.getparam("range") is not None:
         wrange = weapon.getparam("range")
     else:  # weapon not meant as ranged
         wrange = 0
     for i in range(0, wrange):
         if weapon.getflag("beam"):
             if weapon.geteffect() is not None:
                 newposition = pathfinder.alterposition(
                     weapon.getposition(), direction)
                 # if weapon hits obstacle
                 if not self.gameengine.mapfield.isnonsolid(newposition):
                     break
                 weapon.setposition(newposition)
                 neweffect = effect.Effect(
                     self.gameengine.effinfo[weapon.geteffect()],
                     self.gameengine)
                 neweffect.setposition(weapon.getposition())
                 neweffect.setowner(self)
                 self.gameengine.mapfield.effects.append(neweffect)
         else:
             newposition = pathfinder.alterposition(weapon.getposition(),
                                                    direction)
             monsterat = self.gameengine.mapfield.getoccupants(newposition)
             # if weapon hits any monster
             if monsterat is not None:
                 monsterat.rangedcombat(weapon, self)
                 break
             # if weapon hits obstacle
             elif not self.gameengine.mapfield.ispassable(newposition):
                 break
             # if not, it flies to its maximum range
             else:
                 weapon.setposition(newposition)
                 if weapon.geteffect() is not None:
                     neweffect = effect.Effect(
                         self.gameengine.effinfo[weapon.geteffect()],
                         self.gameengine)
                     neweffect.setposition(weapon.getposition())
                     neweffect.setowner(self)
                     self.gameengine.mapfield.effects.append(neweffect)
     if weapon.getflag("nodrop"):
         self.gameengine.mapfield.items.remove(weapon)