Ejemplo n.º 1
0
    def watchMood(self):
        '''
        Go left to right, try to vertically align with the player,
        then try to bite or fire beam.
        Roar every now and again.
        '''
        p = system.engine.player

        while True:
            # why is this necessary? O_o
            #self.interruptable = True
            #self._state = None
            s = 0  #used to increase stare chance
            for n in range(ika.Random(
                    6, 12)):  #min 6 attacks before next roar state
                if s >= 20:
                    s -= 10

                c = ika.Random(0, 100) + s
                if c < 75:
                    s = 0
                    x = self.x + self.ent.hotwidth / 2
                    d = dir.fromDelta(p.x - x, 0)
                    yield self.moveState(d, abs(p.x - x))
                    if c > 30:
                        yield self.biteState()
                else:
                    s = 40  #increase chance of staring again if just stared for multiple shots
                    yield self.stareState()
                    if ika.Random(0, 100) > 40:  #extra stare state!
                        yield self.stareState()

            yield self.roarState()
Ejemplo n.º 2
0
    def spawnSpearState(self, mode=0):

        p = engine.player

        # MODE 1 -- random spears
        if mode == 0:

            rngX = range(3, 15, 4)
            rngY = range(4, 16, 4)

            for rx in rngX:
                for ry in rngY:
                    x = rx * ika.Tileset.width + ika.Random(
                        0, ika.Tileset.width * 4)
                    y = ry * ika.Tileset.height + ika.Random(
                        0, ika.Tileset.height * 4)
                    engine.addEntity(
                        ManeaterSpear(
                            ika.Entity(x, y, self.layer,
                                       'plant_tentacle.ika-sprite'), self))

            engine.addEntity(
                ManeaterSpear(
                    ika.Entity(p.x, p.y, self.layer,
                               'plant_tentacle.ika-sprite'), self))

        yield None
Ejemplo n.º 3
0
 def cutBush(self, me, rect):
     tiles = tilesAt(*rect)
     #ika.Log(str(tiles))
     for t in tiles:
         if t[2] in [78, 368, 369, 370]:  #bush!
             ika.Map.SetTile(t[0], t[1], me.layer, 0)
             ika.Map.SetObs(t[0], t[1], me.layer, 0)
             flower = Leaf(
                 ika.Entity(t[0] * 16 + 2, t[1] * 16 + 4, me.layer,
                            'flowercenter.ika-sprite'))
             engine.addEntity(flower)
             for i in range(5 + ika.Random(0, 3)):
                 lx = t[0] * 16 + ika.Random(-4, 12)
                 ly = t[1] * 16 + ika.Random(0, 7)
                 leaf = Leaf(
                     ika.Entity(lx, ly, me.layer, 'flowerleaf.ika-sprite'))
                 engine.addEntity(leaf)
             chance = ika.Random(0, 100)
             if chance > 90:
                 shell = powerup.createShell(
                     ika.Entity(t[0] * 16 + 4, t[1] * 16 + 4, me.layer,
                                'seashell.ika-sprite'))
                 engine.addEntity(shell)
             elif chance > 80:
                 berry = powerup.createRedBerry(
                     ika.Entity(t[0] * 16 + 4, t[1] * 16 + 4, me.layer,
                                'berry.ika-sprite'))
                 engine.addEntity(berry)
Ejemplo n.º 4
0
    def stalkMood(self):
        DIST = 0
        p = system.engine.player
        # be DIST away, if at all possible
        while True:
            d = self.playerDir()
            dist = self.playerDist()
            self.direction=d

            if dist - DIST > 48:
                # get closer
                n = int(dist - DIST - 1)
                r= ika.Random(0,8)
                if r>=6:                                        
                    yield self.walkState(dir.rotateCounterCW45[d], ika.Random(int(n / 2), n))                    
                elif r>=4:                    
                    yield self.walkState(dir.rotateCW45[d], ika.Random(int(n / 2), n))                                                        
                yield self.walkState(d, ika.Random(int(n / 2), n))

                yield self.idleState(30)
            elif dist < DIST:
                # fall back
                yield self.walkState(dir.invert[d], min(80, DIST - dist))
                self.direction = dir.invert[d]
                yield self.idleState(30)
            else:
                self.mood = self.attackMood
                yield self.idleState(1)
Ejemplo n.º 5
0
def finalBattle():
    if 'finalbattle' in savedata:
        pass
        # make the river passable
    else:
        savedata['finalbattle'] = 'True'

        p = system.engine.player

        def walkUp():
            p.move(dir.UP, 96)
            p.anim = 'walk'
            for n in range(96):
                yield None

        p.state = walkUp()

        for n in range(96):
            system.engine.tick()
            system.engine.draw()
            ika.Video.ShowPage()
            ika.Input.Update()

        def noOp():
            while True:
                yield None

        p.anim = 'stand'
        p.state = noOp()

        for n in range(256):
            # teh earthquake
            ika.Map.xwin += ika.Random(-4, 5)
            ika.Map.ywin += ika.Random(-4, 5)
            system.engine.tick()
            system.engine.draw()
            ika.Video.ShowPage()
            ika.Input.Update()

        s = Serpent(ika.Entity(25 * 16, 24 * 16, p.layer,
                               'serpent.ika-sprite'))
        s.anim = 'appear'
        system.engine.addEntity(s)

        for n in range(19, 32):
            # close off the way back
            ika.Map.SetTile(n, 38, p.layer, 26)
            ika.Map.SetTile(n, 39, p.layer, 32)
            ika.Map.SetObs(n, 38, p.layer, True)
            system.engine.tick()
            system.engine.draw()
            ika.Video.ShowPage()
            ika.Input.Update()

        p.state = p.defaultState()

        s.state = s.roarState()
        system.engine.synchTime()
        system.engine.mapThings.append(DeathListener(s))
Ejemplo n.º 6
0
    def hearthRendState(self):
        if self.direction == dir.UPLEFT or self.direction == dir.DOWNLEFT:
            self.direction = dir.LEFT
        elif self.direction == dir.UPRIGHT or self.direction == dir.DOWNRIGHT:
            self.direction = dir.RIGHT

        self.stop()
        self.anim = 'rend'
        r = rendRange[self.direction]

        if self.stats.mp < 10 or not self.stats.rend:
            sound.menuBuzz.Play()
            return

        self.stats.mp -= 10

        # charge
        # TODO: sound/particle effect here
        while self._animator.index == 0:
            yield None

        fire = ika.Entity(self.x, self.y, self.layer, 'rend.ika-sprite')
        f = self.direction * 5 # hack.

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

        sound.hearthRend.Play()
        
        self.invincible = True #invincible while swinging, why not!
        while not self._animator.kill:
            ents = self.detectCollision(r[self._animator.index] + (self.layer,))
            fire.specframe = f + self._animator.index

            for e in ents:
                if isinstance(e, Enemy) and not e.invincible and e not in hitList:
                    hitList.append(e)
                    if(isinstance(e, Serpent)): #he resists, no extra 1.5!
                        e.hurt( int( ((self.stats.att + self.stats.mag) + ika.Random(-3, 3))), 300, self.direction)
                    else: 
                        e.hurt(int((self.stats.att + self.stats.mag) * 1.5) + ika.Random(-3, 3), 300, self.direction)
                elif isinstance(e, IceWall):
                    # TODO: some sort of nice animation.
                    setattr(savedata, e.flagName, 'True')

                    system.engine.destroyEntity(e)
                    #system.engine.things.append(Caption('The ice melted!'))

            yield None
        self.invincible = False #no longer invincible during stall period

        del fire

        # stall period:
        for i in range(30):
            yield None
Ejemplo n.º 7
0
def addEntity():
    min = 0
    max = 10000
    if ika.Random(min, max) < 100:
        if ika.Random(1, 3) < 2:
            lane = lane1
        else:
            lane = lane2
        Entities.append(Car(lane, 0))
Ejemplo n.º 8
0
def MakeTile():
    structure = ika.Random(1, 6) + ika.Random(1, 6) + ika.Random(1, 6)  #3d5
    a = ika.Random(1, 4)
    rarity = "N"
    mineral = "Nothing"
    item = None
    if a == 1:
        b = ika.Random(1, 10)
        if b in [1, 2, 3, 4]:
            c = ika.Random(0, len(common))
            mineral = common[c]
            rarity = "C"
        elif b in [4, 5, 6]:
            c = ika.Random(0, len(semi))
            mineral = semi[c]
            rarity = "S"
        elif b in [7, 8]:
            c = ika.Random(0, len(rare))
            mineral = rare[c]
            rarity = "R"
        elif b in [9]:
            c = ika.Random(0, len(special))
            mineral = special[c]
            rarity = "X"
            item = True

    return Tile(structure, mineral, rarity, item)
Ejemplo n.º 9
0
    def passiveMood(self):

        p = system.engine.player
        self._animator.kill = True
        while True:
            yield self.walkState(ika.Random(0,8), ika.Random(24,64))
            yield self.idleState(ika.Random(0,20))
            if self.stats.hp <= self.stats.maxhp / 2 and self.splitTimes < self.MAX_SPLITS and not self.split:
                yield self.submergeState()
                yield self.splitState()
                yield self.growState()
Ejemplo n.º 10
0
 def passiveMood(self):
     p = system.engine.player
     self._animator.kill = True
     while True:
         yield self.walkState(ika.Random(0, 8), ika.Random(16, 64))
         yield self.idleState(ika.Random(0, 75))
         dist = math.hypot(p.x - self.x, p.y - self.y)
         if dist < 100:
             self.mood = self.summonMood
             yield self.idleState()
             break
Ejemplo n.º 11
0
    def update(self):

        if ika.GetTime() > self.time:
            engine.camera.locked = self.wasLocked
            sound.earthquake.Pause()
            return True
        else:
            engine.camera.locked = False
            engine.camera.center()

            ika.Map.xwin += ika.Random(-self.x, self.x)
            ika.Map.ywin += ika.Random(-self.y, self.y)
Ejemplo n.º 12
0
 def summonState(self):
     self.anim = 'glow'
     p = engine.player
     for b in range(6):
         xr = ika.Random(-24, 24)
         yr = ika.Random(-24, 24)
         engine.addEntity(
             Bone(
                 ika.Entity(p.x + xr, p.y + yr - 300,
                            ika.Map.layercount - 1,
                            'frankenhead_bone.ika-sprite')))
         for x in range(15):
             yield None
     yield None
     self.stop()
Ejemplo n.º 13
0
 def attackMood(self):
     for q in range(ika.Random(3, 6)):
         d = self.playerDir()
         dist = self.playerDist()
         if dist <= 48:
             yield self.attackState(d)
             yield self.idleState(20)
         else:
             r= ika.Random(0,8)
             if r>=6:                     
                 yield self.walkState(dir.rotateCounterCW[d], min(30, dist))                    
             elif r>=4:
                 yield self.walkState(dir.rotateCW[d], min(30, dist))                        
             else:                       
                 yield self.walkState(d, min(30, dist))
Ejemplo n.º 14
0
    def hurtState(self, dist, dir):
        if self.stats.hp > 0:
            i = ika.Random(0, len(sound.yetiHurt[self.stats.ind]))
            sound.yetiHurt[self.stats.ind][i].Play()

        self.mood = self.attackMood
        return super(Yeti, self).hurtState(dist * 2 / 3, dir)
Ejemplo n.º 15
0
    def spawnTentacleState(self):

        p = engine.player

        yp = [7.5, 10.5, 13.5]
        xp = [4.5, 12.5]
        comb = []

        order = []

        for y in yp:
            for x in xp:
                comb.append((x, y))

        for n in range(len(comb)):
            a = ika.Random(0, len(comb))
            order.append(comb[a])
            comb.pop(a)

        for x, y in order:
            t = ManeaterTentacle(
                ika.Entity(int(x * ika.Tileset.width),
                           int(y * ika.Tileset.height), self.layer,
                           'maneater_tentacle.ika-sprite'), self)
            t.direction = [dir.RIGHT, dir.LEFT][int(x) / 10]
            engine.addEntity(t)
            sound.maneaterTentacle.Play()

            for time in range(25):
                yield None

        yield None
        self.stop()
Ejemplo n.º 16
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
Ejemplo n.º 17
0
    def generatePowerup(self, enemy):

        drop = None
        chance = ika.Random(0, 100)
        kwargs = {}

        if enemy.powerup:

            drop = enemy.powerup

        elif chance > 50:

            #if chance > 98:
            #    drop = Skull
            #elif chance > 95:
            #    drop = GoldenEgg
            #elif chance > 92:
            #    drop = BlackPearl

            if chance > 93:
                drop = GreenBerry
            elif chance > 75:
                drop = RedBerry
            else:
                drop = Seashell
                kwargs['money'] = self.ent.stats.money

        if drop:
            x = self.x + self.w / 2 - 8
            y = self.y + self.h / 2 - 8
            ent = ika.Entity(x, y, self.ent.layer, drop.SPRITE)
            engine.addEntity(drop(ent, **kwargs))
Ejemplo n.º 18
0
 def chooseMood(self):
     """Weighted random pick."""
     n = ika.Random(0, sum([x.desirability for x in self.moods]))
     for p in self.moods:
         if n <= p.desirability:
             return p
         n -= p.desirability
Ejemplo n.º 19
0
def intro():
    snow = Snow(velocity=(0, 0.5))

    i = ika.Random(0, 7)
    gba = ika.Image('gfx/gba' + str(i) + '.png')
    ikalogo = ika.Image('gfx/ika.png')
    hatchlogo = ika.Image('gfx/HatchetLogo2.png')

    v = ika.Video
    d = 50

    def showGba():
        v.ClearScreen()
        v.Blit(gba, (v.xres - gba.width) / 2, (v.yres - gba.height) / 2)

    try:
        delay(lambda: v.Blit(ikalogo, 0, 0, ika.Opaque), 200, snow)
        delay(lambda: v.ClearScreen(), d, snow)
        delay(lambda: v.Blit(hatchlogo, 0, 0, ika.Opaque), 200, snow)
        delay(lambda: v.ClearScreen(), d, snow)
        delay(showGba, 200, snow)
        delay(lambda: v.ClearScreen(), d, snow)

    except _DoneException:
        return
Ejemplo n.º 20
0
    def passiveMood(self):

        p = system.engine.player
        self._animator.kill = True
        while True:
            yield self.walkState(ika.Random(0, 8), ika.Random(8, 32))

            tx = (self.ent.x + self.ent.hotwidth) / ika.Tileset.width
            ty = (self.ent.y + self.ent.hotheight) / ika.Tileset.height

            # if on a flower, sit there
            if ika.Map.GetTile(
                    tx, ty, self.ent.layer) in [356, 357, 358, 364, 365, 366]:
                yield self.idleState(400)
            else:
                yield self.idleState(ika.Random(0, 10))
Ejemplo n.º 21
0
 def enemydead(self, enemy):
     self.effects.append(
         effects.Explosion(enemy.center.x, enemy.center.y, enemy.r / 2))
     #10% chance
     num = ika.Random(0, 10)
     if num == 1:
         pass
         '''turn into giving power-up'''
Ejemplo n.º 22
0
    def __call__(self, ent):
        if self.state == self.WAIT:
            self.state = self.MOVE
            ent.Wait(self.delay)

        elif self.state == self.MOVE:
            self.state = self.WAIT
            dir = ika.Random(0, 4)  # pick a direction (just cardinal for now)
            dist = ika.Random(self.steps / 2, self.steps)  # pick a distance

            if dir == 0:  # left
                ent.MoveTo(ent.x - dist, ent.y)
            elif dir == 1:  # right
                ent.MoveTo(ent.x + dist, ent.y)
            elif dir == 2:  # up
                ent.MoveTo(ent.x, ent.y - dist)
            elif dir == 3:  # down
                ent.MoveTo(ent.x, ent.y + dist)
Ejemplo n.º 23
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
Ejemplo n.º 24
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()
Ejemplo n.º 25
0
    def defaultState(self):

        p = system.engine.player

        self.move(dir.UP, 100000)
        while self.y > -10:
            yield None
        self.stop()

        for x in range(100):
            yield None

        self.x = p.x + p.ent.hotwidth / 2 - 4
        destY = p.y + p.ent.hotheight / 2 - 4

        self.y = p.y - 300

        engine.addEntity(
            SporeShadow(
                ika.Entity(self.x, destY, p.ent.layer,
                           'plant_shadow.ika-sprite'), self))

        self.move(dir.DOWN, 100000)
        sound.fall.Play()
        while self.y < destY:
            yield None
        self.stop()

        sound.sporeHit.Play()

        self.speed = 0

        self.ent.spritename = 'plant_explode.ika-sprite'
        self.anim = 'explode'
        self.x -= 12
        self.y -= 12

        sound.sporeHit.Play()

        oldLayer = self.ent.layer
        self.ent.layer = p.ent.layer
        ents = self.detectCollision(
            (0, 0, self.ent.hotwidth, self.ent.hotheight))
        self.ent.layer = oldLayer

        for e in ents:
            if e is p:
                p.hurt(self.damage, self.recoil, ika.Random(0, 8))

        while not self._animator.kill:
            yield None

        engine.destroyEntity(self)

        while True:
            yield None
Ejemplo n.º 26
0
def cloudMove(cloud):
    xw, yw = ika.Map.xwin, ika.Map.ywin
    x2 = xw + ika.Video.xres
    y2 = yw + ika.Video.yres

    if ((not (xw - cloud.hotwidth < cloud.x < x2)
         or not (yw - cloud.hotheight < cloud.y < y2))
            and (ika.Random(0, 100) > 70)):  # :(
        cloudReset(cloud)

    cloud.MoveTo(cloud.x - 16, cloud.y + 1)
Ejemplo n.º 27
0
    def __init__(self, x, y, special):

        self.x = x
        self.y = y
        self.w = engine.TILE_SIZE  #for collission detection
        self.h = engine.TILE_SIZE

        self.alive = True
        self.dead = False  #for rendering
        self.pregnant = 0
        self.birth_time = 0

        self.special = special

        self.sex = ika.Random(0, 2)  #male: 0;   female: 1

        self.waterlvl = self.max_waterlvl  #   (-1) will be used for grey frogs--might be a mistake for future updates

        self.movenum = ika.Random(
            0, 9)  #direction from top left clockwise, 0 is center
Ejemplo n.º 28
0
 def __init__(self, x, y, endx, endy, color):
     self.x=x
     self.y=y
     self.endx=endx
     self.endy=endy
     self.duration=0
     self.maxduration=50
     self.opacity=200               
     self.r, self.g, self.b, self.a = ika.GetRGB(color)        
     self.color=color        
     self.points=self.generatePoints(ika.Random(6, 12))                        
     self.update = self._update().next 
Ejemplo n.º 29
0
def startgame(difficulty):
    global rungame

    numstalac = 5  #numstalac not presently used

    if difficulty == 0:  #current all-encompasing difficulty: ie. random.
        MINFROGS = 3
        MAXFROGS = 7
        numfrogs = ika.Random(MINFROGS, MAXFROGS)

        game.generatefrogs(numfrogs)
        game.generatestalactites(numstalac)
Ejemplo n.º 30
0
    def chooseMood(self):
        # weighted random pick:

        N = sum([x.desirability for x in self.moods])
        n = ika.Random(0, N)

        for p in self.moods:
            if n < p.desirability:
                return p
            else:
                n -= p.desirability

        return None