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))
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()
def submergeMood(self): p = engine.player yield self.submergeState() yield self.idleState(150) while True: dist = math.hypot(p.x - self.x, p.y - self.y) if dist > 100: yield self.growState() self.mood = self.attackMood break elif dist < 20: d = max(1, self.stats.att - p.stats.pres) p.hurt(d, self.recoil, self.direction) yield self.growState() self.mood = self.attackMood yield self.idleState() break else: engine.addEntity( ManeaterSpear( ika.Entity(p.x - 8, p.y - 8, self.layer, 'plant_tentacle.ika-sprite'), self)) yield self.idleState(60) yield self.idleState()
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
def spawnTentacleState(self): p = engine.player engine.addEntity( Tentacle( ika.Entity(p.x, p.y, self.layer, 'plant_tentacle.ika-sprite'), self)) yield None self.stop()
def spawnSporeState(self): x = self.x + self.ent.hotwidth / 2 - 4 y = self.y + self.ent.hotheight / 2 - 4 engine.addEntity( Spore( ika.Entity(x, y, ika.Map.layercount - 1, 'plant_spore.ika-sprite'))) yield None self.stop()
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
def spawnState(self): if self.beeCount < self.MAX_BEES: bee_ent = ika.Entity(self.ent.x, self.ent.y, self.ent.layer, "bee.ika-sprite") engine.addEntity(createBee(bee_ent, self)) self.beeCount += 1 yield None self.stop()
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)
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()
def defaultState(self): p = system.engine.player destY = self.y self.y -= 300 engine.addEntity( SporeShadow( ika.Entity(self.x, destY, p.ent.layer, 'maneater_shadow.ika-sprite'), self)) self.move(dir.DOWN, 100000) while self.y < destY: yield None self.stop() if self.play: sound.sporeHit.Play() self.speed = 0 self.ent.spritename = 'maneater_explode.ika-sprite' self.anim = 'explode' self.x -= 12 self.y -= 12 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
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()
def grappleState(self, me): sound.grapple1.Play() direction = dir.straighten[me.direction] x = me.x y = me.y # HACK: work around rectangular hotspot junk. dx, dy = dir.delta[direction] if dx > 0: x += 16 if dy > 0: y += 16 if me.direction in (dir.UP, dir.DOWN): x += 7 if me.direction in (dir.LEFT, dir.RIGHT): y += 2 me.anim = 'grapplethrow' me.invincible = True grapple = _GrappleEntity(x, y, me.layer, direction) engine.addEntity(grapple) yield None # needed to give the grapple a moment to start moving while grapple.isMoving(): yield None dx, dy = dir.delta[grapple.direction] tx = grapple.x / ika.Tileset.width + dx ty = grapple.y / ika.Tileset.height + dy tile = ika.Map.GetTile(tx, ty, grapple.layer) grippableTiles = self.GRIPPABLE_TILES.get(ika.Map.tilesetname, ()) if tile in grippableTiles: me.state = self.pullState(me, grapple) else: me.invincible = False me.state = me.defaultState() engine.destroyEntity(grapple) yield None
def update(self): if not self.subject: boss = Maneater( ika.Entity(136, 96, engine.player.ent.layer, "maneater.ika-sprite")) engine.addEntity(boss) self.subject = boss # Close the way in ika.Map.SetTile(9, 16, engine.player.ent.layer, 182) ika.Map.SetTile(9, 17, engine.player.ent.layer, 190) ika.Map.SetTile(16, 8, engine.player.ent.layer, 167) ika.Map.SetTile(16, 9, engine.player.ent.layer, 175) ika.Map.SetObs(16, 9, engine.player.ent.layer, True) ika.Map.SetObs(9, 17, engine.player.ent.layer, True) if self.subject not in engine.entities: self.bossDied() engine.saveData['maneater'] = True return True
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()
def firstConvo(): #if 'firstconvo' not in engine.saveData: if False: xwin = ika.Map.xwin ywin = ika.Map.ywin stone = ika.Entity(110, 60, 1, 'artifact.ika-sprite') fish = Fish(ika.Entity(110, 60, 2, 'fish.ika-sprite')) fish.ent.mapobs = fish.ent.entobs = fish.ent.isobs = False fish.ent.speed = 300 engine.addEntity(fish) fried = Friedrich(ika.Entity(176, 60, 1, 'friedrich.ika-sprite')) fried.ent.speed = 120 fried.ent.mapobs = fried.ent.entobs = fried.ent.isobs = False fried.anim = 'fly' engine.addEntity(fried) engine.player.stop() engine.saveData['firstconvo'] = True engine.beginCutScene() ana = engine.player.ent ana.specframe = 0 engine.synchTime() text( "left", "anastasia3", "Pfft! I can't believe I came away empty handed today! If it wasn't for that flock of gulls I'd still have that seventy-pounder." ) delay(33) ana.specframe = 24 text("left", "anastasia3", "You hear me?! Give me back my fish!") sound.fall.Play() delay(75) fish.x, fish.y, fish.layer = (110, -20, ana.layer + 1) fish.move(dir.DOWN, 200) tick() while fish.isMoving(): tick() draw() engine.things.append(Quake(20)) ana.specframe = 23 apos = (ana.x, ana.y + 16 - ywin) text(apos, "anastasia2", "left", "Ouch!!!") delay(80) fried.x, fried.y = 176, 60 fried.move(dir.DOWN, 70) delay(1) while fried.isMoving(): delay(1) fpos = (160, fried.y + 24 - ywin) text(fpos, "Dropped something?") delay(100) text((ana.x - 8, ana.y + 24 - ywin), '...') delay(50) text((ana.x - 8, ana.y + 24 - ywin), 'Mmph..') ana.specframe = 1 fish.move(dir.DOWN, 32) fried.move(dir.DOWN, 70) delay(1) while fried.isMoving(): delay(1) ana.specframe = 3 text("left", "anastasia3", "That thing is heavy.. ") text( "left", "anastasia", "Oh, Friedrich! Did you scare that fish out of the gulls? It's good to see you, it's been almost a week!" ) text( "right", "friedrich", "Indeed! It has been quite some time. Oh, but I've got some stories for you!" ) text("left", "anastasia", "Yeah? Did you find any new treasure on that deserted island?") text( "right", "friedrich", "It was a very enlightening experience. I shall have to take you there someday. We'll plan a trip!" ) text("left", "anastasia", "Ooooh! Sounds like fun!") text( "right", "friedrich", "As a matter of fact, there is something I found that I'd like to show you at my shop. Swing by when you get a chance." ) text("left", "anastasia", "Sure! I need to get this fish down to Yolander anyway.") text("right", "friedrich", "Oh do take your time, dear.") engine.destroyEntity(fish) fried.move(dir.UP, 160) fried.anim = 'fly' tick() while fried.isMoving(): tick() draw() engine.destroyEntity(fried) engine.endCutScene() engine.synchTime() engine.things.append(Caption("Anastasia's House", font=engine.font2))
def spawnSporeState(self, freq=7): cx = 9.5 * ika.Tileset.width cy = 10.5 * ika.Tileset.height rad = ika.Tileset.width * 7 cosDeg = lambda n: math.cos(n * math.pi / 180.0) sinDeg = lambda n: math.sin(n * math.pi / 180.0) forRange = lambda: range(0, 360, 90 / (rad / ika.Tileset.width)) backRange = lambda: range(360, 0, -90 / (rad / ika.Tileset.width)) ranges = [forRange, backRange] pos = 0 mode = ika.Random(0, 2) # 2 different modes # MODE 1 - closing circles if mode == 0: while rad > 0: cnt = 0 sound.fall.Play() play = True rng = ranges[pos]() for deg in rng: x = cx + cosDeg(deg) * rad - 4 y = cy + sinDeg(deg) * rad - 4 engine.addEntity( ManeaterSpore(ika.Entity(x, y, ika.Map.layercount - 1, 'maneater_spore.ika-sprite'), play=play)) for time in range(2): yield None if play: play = False elif cnt < 4: cnt += 1 else: cnt = 0 play = True pos ^= 1 for time in range(40): yield None rad -= ika.Tileset.width * 2 engine.addThing(Quake(duration=25, x=10, y=10)) # MODE 2 - random bombardment elif mode == 1: rng = ranges[0]() sound.fall.Play() play = True while rad > 0: for deg in rng: if not ika.Random( 0, freq): # half chance of bombarding this one x = cx + cosDeg(deg) * rad - 4 y = cy + sinDeg(deg) * rad - 4 engine.addEntity( ManeaterSpore(ika.Entity( x, y, ika.Map.layercount - 1, 'maneater_spore.ika-sprite'), play=play)) play = False rad -= ika.Tileset.width yield None