Exemple #1
0
    def detectCollision(self, rect):
        '''
        Returns a list of entities that are within the rect.
        The rect's position is taken as being relative to the
        entity's position.  This is useful for attacks and such.
        '''
        '''
        entsat = []
        for i in range(ika.Map.layercount): #hack to be able to attack other enemies on other layers
            rect = (
                rect[0] + self.x,
                rect[1] + self.y,
                rect[2], rect[3],
                i)
            entsat += [system.engine.entFromEnt[e] for e in
            ika.EntitiesAt(*rect) if e in system.engine.entFromEnt]    
        
        return entsat   
        '''
        rect = (rect[0] + self.x, rect[1] + self.y, rect[2], rect[3],
                self.layer)

        return [
            system.engine.entFromEnt[e] for e in ika.EntitiesAt(*rect)
            if e in system.engine.entFromEnt
        ]
Exemple #2
0
    def backSlashState(self):
        self.stop()
        self.anim = 'backslash'
        r = backSlashRange[self.direction]

        # when we hit an entity, we append it here so that
        # we know not to hurt it again.
        hitList = []

        sound.slash2.Play()

        while not self._animator.kill:
            rect = list(r[self._animator.index]) + [self.layer]
            rect[0] += self.x
            rect[1] += self.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                x = system.engine.entFromEnt[e]
                if isinstance(x, Enemy) and not x.invincible and x not in hitList:
                    hitList.append(x)
                    x.hurt(int(self.stats.att + ika.Random(0, 3) * 1.25 ), 130, self.direction)
                    self.giveMPforHit()

            yield None

        # Stall:
        count = 10
        while count > 0:
            count -= 1
            if controls.rend() or controls.joy_rend():
                self.state = self.hearthRendState()
            elif self.stats.level >= THRUST_LEVEL and (controls.attack() or controls.joy_attack()):
                self.state = self.thrustState()
            yield None
Exemple #3
0
    def backSlashState(self, me):
        me.stop()
        me.anim = 'backslash'
        r = backSlashRange[me.direction]
        # when we hit an entity, we append it here so that
        # we know not to hurt it again.
        hitList = []
        sound.sword2.Play()
        while not me._animator.kill:
            rect = list(r[me._animator.index]) + [me.layer]
            rect[0] += me.x
            rect[1] += me.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                if e is me.overlay: continue
                if e in engine.entFromEnt:
                    x = engine.entFromEnt[e]
                    if isinstance(
                            x,
                            Enemy) and not x.invincible and x not in hitList:
                        hitList.append(x)
                        x.hurt(int(me.stats.att), 140, me.direction)
                        me.giveMPforHit()
                    elif isinstance(e, _Powerup):
                        e.touch()
            self.cutBush(me, rect)
            yield None

        # Stall:
        count = 20
        while count > 0:
            count -= 1
            yield None
Exemple #4
0
    def detectCollision(self, rect):
        '''Returns a list of entities that are within the rect.
           The rect's position is taken as being relative to the
           entity's position.  This is useful for attacks and such.
        '''
        rect = (rect[0] + self.x, rect[1] + self.y, rect[2], rect[3],
                self.layer)

        return [
            engine.entFromEnt[e] for e in ika.EntitiesAt(*rect)
            if e in engine.entFromEnt
        ]
Exemple #5
0
    def die(self, *args):
        # When one dies, the others scatter

        ents = [system.engine.entFromEnt[x] for x in
            ika.EntitiesAt(self.x - 50, self.y - 50, 100, 100, self.layer)
            if x in system.engine.entFromEnt]
        allies = filter(lambda e: isinstance(e, AnkleBiter) and e.stats.hp > 0, ents)

        for a in allies:
            a.mood = a.fleeMood
            a.state = a.idleState()

        super(AnkleBiter, self).die(*args)
Exemple #6
0
    def slashState(self):
        self.stop()
        self.anim = 'slash'
        r = slashRange[self.direction]
        backslash = False
        backthrust = False

        # when we hit an entity, we append it here so that
        # we know not to hurt it again.
        hitList = []

        sound.slash1.Play()

        while not self._animator.kill:
            rect = list(r[self._animator.index]) + [self.layer]
            rect[0] += self.x
            rect[1] += self.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                x = system.engine.entFromEnt[e]
                if isinstance(x, Enemy) and not x.invincible and x not in hitList:
                    hitList.append(x)
                    x.hurt( int(self.stats.att + ika.Random(0, 3)), 120, self.direction)
                    self.giveMPforHit()
            if self.stats.level >= BACK_LEVEL: 
                if (controls.up() or controls.joy_up()) and self.direction == dir.DOWN:  backthrust = True
                elif (controls.down()  or controls.joy_down()) and self.direction == dir.UP:  backthrust = True
                elif (controls.left() or controls.joy_left()) and self.direction in [dir.RIGHT, dir.UPRIGHT, dir.DOWNRIGHT]:  backthrust = True
                elif (controls.right() or controls.joy_right()) and self.direction in [dir.LEFT, dir.UPLEFT, dir.DOWNLEFT]:  backthrust = True

            if (controls.attack() or controls.joy_attack()) and self.stats.level >= SLASH_LEVEL: 
                backslash = True

            yield None

        if backthrust:
            self.state = self.backThrustState()
            yield None
        elif backslash:
            self.state = self.backSlashState()
            yield None
        else:
            # Stall:
            count = 10
            while count > 0:
                count -= 1
                if self.stats.level >= THRUST_LEVEL and (controls.attack() or controls.joy_attack()):
                    self.state = self.thrustState()
                yield None
Exemple #7
0
    def die(self, *args):
        # When one dies, the others scatter

        ents = [system.engine.entFromEnt[x] for x in
            ika.EntitiesAt(self.x - 60, self.y - 60, 120, 120, self.layer)
            if x in system.engine.entFromEnt]
        allies = filter(lambda e: isinstance(e, RazorMane) and e.stats.hp > 0, ents)

        for a in allies:
            if ika.Random(0, 2) > 0:
                a.mood = a.fleeMood
            else:
                a.mood = a.attackMood #50% chance of more random aggression!
            a.state = a.idleState()

        super(RazorMane, self).die(*args)
Exemple #8
0
    def die(self, *args):
        """When one dies, the others come after the player."""

        ents = [
            system.engine.entFromEnt[x]
            for x in ika.EntitiesAt(self.x - 50, self.y -
                                    50, 100, 100, self.layer)
            if x in system.engine.entFromEnt
        ]

        for a in ents:
            if not isinstance(a, Goblin) or a.stats.hp <= 0: continue

            a.mood = a.attackMood
            a.state = a.idleState()

        super(Goblin, self).die(*args)
Exemple #9
0
        def thing():
            i = 8
            while i > 0:
                i -= 1
                self.speed -= (12 - i) * 10

                rect[0] = r[0] + self.x
                rect[1] = r[1] + self.y
                ents = ika.EntitiesAt(*rect)
                for e in ents:
                    x = system.engine.entFromEnt[e]
                    if isinstance(x, Enemy) and not x.invincible:
                        x.hurt(int(self.stats.att * 1.5) + ika.Random(0, 4), 300, self.direction)
                        self.giveMPforHit()
                        self.stop()
                        return

                yield None
Exemple #10
0
    def roarState(self):
        # spawn one to five Carnivores to irritate the shit out of the player
        self.anim = 'roar'
        s = False

        sound.serpentRoar.Play()

        for wait in range(200):

            n = self._animator.curFrame - 12  # Yet another hack.
            ika.Map.xwin += ika.Random(-n, n + 1)
            ika.Map.ywin += ika.Random(-n, n + 1)
            yield None

        # need to destroy old corpses (a first!)
        for e in system.engine.entities:
            if e.stats.hp == 0 and isinstance(e, Enemy):
                system.engine.destroyEntity(e)

        for q in range(ika.Random(1, 4)):
            x, y = 320 + (q * 60), 588
            n = ika.EntitiesAt(x, y, x + 16, y + 16, self.layer)

            if not n:
                if self.stats.hp > self.stats.maxhp / 2:  #normal
                    if ika.Random(0, 2):
                        e = Carnivore(
                            ika.Entity(x, y, self.layer,
                                       'carnivore.ika-sprite'))
                    else:
                        e = AnkleBiter(
                            ika.Entity(x, y, self.layer,
                                       'anklebiter.ika-sprite'))
                else:  #half dead, stronger spawns
                    if ika.Random(0, 2):
                        e = Devourer(
                            ika.Entity(x, y, self.layer,
                                       'devourer.ika-sprite'))
                    else:
                        e = Carnivore(
                            ika.Entity(x, y, self.layer,
                                       'carnivore.ika-sprite'))
                system.engine.addEntity(e)
                e.mood = e.attackMood
Exemple #11
0
    def splitState(self):
            
        x = self.ent.x
        y = self.ent.y
        tw = ika.Tileset.width
        th = ika.Tileset.height
        
        pos = [(x-tw, y), (x, y-th), (x+tw, y), (x, y+th)]
        positions = []
        
        for n in pos:
            add = True
            for p in [(n[0], n[1]), (n[0]+tw-1, n[1]), (n[0], n[1]+th-1), (n[0]+tw-1, n[1]+th-1)]:
                if ika.Map.GetObs(p[0] / tw, p[1] / th, self.ent.layer):
                    add = False
                    break
            if add:
                positions.append(n)
        
        if positions:
            
            num = ika.Random(0, len(positions))
            p = positions[num]
            timer = 300
            
            while len(ika.EntitiesAt(p[0], p[1], tw, th, self.ent.layer)) > 1 and timer > 0:
                num = ika.Random(0, len(positions))
                p = positions[num]
                timer -= 1
                yield None
    
            if timer:
                jelly_ent = ika.Entity(p[0], p[1], self.ent.layer, "jelly.ika-sprite")
                new_jelly = createJelly(jelly_ent)
                new_jelly.splitTimes = self.splitTimes + 1
                new_jelly.stats.maxhp = self.stats.hp
                new_jelly.stats.hp = self.stats.hp
                engine.addEntity(new_jelly)
                
            self.split = True
        
        yield None

        self.stop()
Exemple #12
0
        def hurt():
            rect[0] = r[0] + me.x
            rect[1] = r[1] + me.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                if e in hitlist: continue

                hitlist.add(e)

                x = engine.entFromEnt[e]
                if isinstance(x, Enemy) and not x.invincible:
                    x.hurt(int(me.stats.att * 1.5), 150, me.direction)
                    me.giveMPforHit()
                    #me.stop()
                    return False
                elif isinstance(e, _Powerup):
                    e.touch()

            return False
Exemple #13
0
    def spawnState(self):

        if self.jellyCount < self.MAX_JELLIES:
            
            x = self.ent.x
            y = self.ent.y
            tw = ika.Tileset.width
            th = ika.Tileset.height
    
            pos = [(x-tw, y), (x, y-th), (x+tw, y), (x, y+th)]
            positions = []
            
            for n in pos:
                add = True
                for p in [(n[0], n[1]), (n[0]+tw-1, n[1]), (n[0], n[1]+th-1), (n[0]+tw-1, n[1]+th-1)]:
                    if ika.Map.GetObs(p[0] / tw, p[1] / th, self.ent.layer):
                        add = False
                        break
                if add:
                    positions.append(n)
            
            if positions:
                
                num = ika.Random(0, len(positions))
                p = positions[num]
                
                while len(ika.EntitiesAt(p[0], p[1], tw, th, self.ent.layer)) > 1:
                    num = ika.Random(0, len(positions))
                    p = positions[num]
                    yield None
        
                jelly_ent = ika.Entity(p[0], p[1], self.ent.layer, "jelly.ika-sprite")
        
                engine.addEntity(createJelly(jelly_ent, self))
                self.jellyCount += 1
        
        yield None

        self.stop()
Exemple #14
0
    def slashState(self, me):
        if 0: me.overlay.renderscript = self.drawRect

        me.stop()
        me.anim = 'slash'
        r = slashRange[me.direction]
        thrust = False
        backslash = False
        backthrust = False
        # when we hit an entity, we append it here so that
        # we know not to hurt it again.
        hitList = set([])
        sound.sword1.Play()
        while not me._animator.kill:
            rect = list(r[me._animator.index]) + [me.layer]
            rect[0] += me.x
            rect[1] += me.y
            ents = ika.EntitiesAt(*rect)
            for e in ents:
                if e is me.overlay or e in hitList: continue
                if e in engine.entFromEnt:
                    x = engine.entFromEnt[e]

                    if isinstance(
                            x,
                            Enemy) and not x.invincible and x not in hitList:
                        hitList.add(x)
                        x.hurt(int(me.stats.att), 120, me.direction)
                        me.giveMPforHit()

                    elif isinstance(x, Arrow):
                        hitList.add(x)
                        sound.deflect.Play()
                        engine.destroyEntity(x)

                    elif isinstance(x, _Powerup):
                        x.touch()

            self.cutBush(me, rect)

            if (controls.up()
                    or controls.joy_up()) and me.direction == dir.DOWN:
                backthrust = True
            elif (controls.down()
                  or controls.joy_down()) and me.direction == dir.UP:
                backthrust = True
            elif (controls.left() or controls.joy_left()) and me.direction in [
                    dir.RIGHT, dir.UPRIGHT, dir.DOWNRIGHT
            ]:
                backthrust = True
            elif (controls.right()
                  or controls.joy_right()) and me.direction in [
                      dir.LEFT, dir.UPLEFT, dir.DOWNLEFT
                  ]:
                backthrust = True
            elif (controls.attack1() or controls.joy_attack1()) and not thrust:
                backslash = True
            elif (controls.attack2()
                  or controls.joy_attack2()) and not backslash:
                thrust = True
            yield None

        if 0: me.overlay.renderscript = None

        if thrust:
            me.state = self.thrustState(me)
        elif backslash:
            me.state = self.backSlashState(me)
        else:
            # Stall:
            count = 8
            while count > 0:
                count -= 1
                #if controls.attack2():
                #    me.state = me.thrustState()
                yield None

        yield None