def intro(): ikalogo = ika.Image('%s/ika.png' % config.IMAGE_PATH) gbabg = ika.Image('%s/sky_bg.png' % config.IMAGE_PATH) gba = ika.Image('%s/gba.png' % config.IMAGE_PATH) yourmom = ika.Image('%s/yourmother.png' % config.IMAGE_PATH) isabitch = ika.Image('%s/yourmother2.png' % config.IMAGE_PATH) controls.attack1() # unpress controls.joy_attack1() # unpress controls.ui_accept() # unpress v = ika.Video d = 40 def stub(): clearScreen() def showGba(): gbabg.Blit(0, 0) v.Blit(gba, (v.xres - gba.width) / 2, (v.yres - gba.height) / 2) clouds.update() clouds.draw() try: delay(stub, 10) delay(showGba, 440) delay(lambda: v.Blit(ikalogo, 0, 0, ika.Opaque), 440) delay(lambda: v.Blit(yourmom, 0, 0, ika.Opaque), 450) delay(lambda: v.Blit(isabitch, 0, 0, ika.Opaque), 1) except _DoneException: return
def standState(self): self.stop() self.anim = 'stand' while True: if controls.attack1() or controls.joy_attack1(): self.state = self.weapon.attack1(self) elif controls.attack2() or controls.joy_attack2(): self.state = self.weapon.attack2(self) elif (controls.tool1() or controls.joy_tool1()) and 'grapple' in engine.saveData: self.state = self.grapple.activate(self) elif (controls.left() or controls.right() or controls.up() or controls.down() or controls.joy_left() or controls.joy_right() or controls.joy_up() or controls.joy_down()): self.state = self.walkState() #elif (controls.left() or controls.right() or # controls.up() or controls.down() #): # self.state = self.walkState() # self._state() # get the walk state started right now. if not self.stats.mp: self.invincible = False self.ent.visible = 1 self.speed = 100 yield None
def chargeState(self, me): me.anim = 'charge' me.stop() sound.spear2.Play() power = 1.25 animcount = 0 charged = False while controls.attack2.position or controls.joy_attack2.position: power = min(3, power + 0.0125) # speed up the animation animcount += 25 * power while animcount > 100: me.animate() animcount -= 100 if power > 2.0 and not charged: sound.spearCharged.Play() charged = True if controls.attack1() or controls.joy_attack1(): if charged: me.state = self.powerLungeState(me, power) else: me.state = self.lungeState(me) yield None
def text(where, *args): """Displays a text frame. Where can be either a point or an entity. TODO: update Things while the textbox is visible """ portrait, text, side = None, '', '' if len(args) == 1: text = args[0] elif len(args) == 2: portrait, text = args elif len(args) == 3: portrait, side, text = args else: assert False, 'text recieves 1 or two arguments.' textBox = TextBox(where, portrait, side, text) engine.things.append(textBox) try: engine.beginCutScene() while not (controls.attack1() or controls.joy_attack1() or controls.ui_accept()): engine.tick() engine.draw() finally: engine.endCutScene() engine.things.remove(textBox)
def update(self): '''Performs one tick of menu input. This includes scrolling things around, and updating the position of the cursor, based on user interaction. If the user has selected an option, then the return value is the index of that option. If the user hit the cancel (ESC) key, the Cancel object is returned. Else, None is returned, to signify that nothing has happened yet. ''' ika.Input.Update() cy = self.cursorY unpress = False # lame unpress faking # TODO: handle it the manly way, by making the cursor repeat after a moment # update the cursor ymax = max(0, len(self.Text) * self.Font.height - self.textCtrl.Height) assert (0 <= self.cursorPos <= len(self.Text), 'cursorPos out of range 0 <= %i <= %i' % (self.cursorPos, len(self.Text))) delta = self.cursorPos * self.Font.height - self.textCtrl.YWin - cy if delta > 0: if cy < self.textCtrl.Height - self.Font.height: self.cursorY += self.cursorSpeed else: self.textCtrl.YWin += self.cursorSpeed elif delta < 0: if cy > 0: self.cursorY -= self.cursorSpeed elif self.textCtrl.YWin > 0: self.textCtrl.YWin -= self.cursorSpeed else: # Maybe this isn't a good idea. Maybe it is. # only move the cursor if delta is zero # that way movement doesn't get bogged # down by a cursor that moves too slowly if (controls.up.pressed or controls.ui_up.pressed or controls.joy_up.pressed) and self.cursorPos > 0: if not unpress: self.cursorPos -= 1 sound.menuMove.Play() unpress = True elif (controls.down.pressed or controls.ui_down.pressed or controls.joy_down.pressed ) and self.cursorPos < len(self.Text) - 1: if not unpress: self.cursorPos += 1 sound.menuMove.Play() unpress = True elif (controls.attack1() or controls.joy_attack1() or controls.ui_accept()): sound.menuSelect.Play() return self.cursorPos elif (controls.cancel() or controls.joy_cancel() or controls.ui_cancel()): return Cancel else: unpress = False
def update(self): super(Npc, self).update() if self.touches(engine.player): if not self.__touching and ( controls.attack1() or controls.joy_attack1() ): #feels dirty to be checking controls here, but... self.__touching = True self.__activate() else: self.__touching = False
def delay(draw, count): scr = effects.grabScreen() draw() effects.crossFade(30, scr) while count > 0: draw() ika.Delay(1) count -= 1 ika.Video.ShowPage() ika.Input.Update() if controls.attack1() or controls.joy_attack1() or controls.ui_accept( ): raise _DoneException() draw()
def walkState(self): oldDir = self.direction self.anim = 'walk' while True: if controls.attack1() or controls.joy_attack1(): self.state = self.weapon.attack1(self) yield None elif controls.attack2() or controls.joy_attack2(): self.state = self.weapon.attack2(self) yield None elif controls.left() or controls.joy_left(): if controls.up() or controls.joy_up(): d = dir.UPLEFT elif controls.down() or controls.joy_down(): d = dir.DOWNLEFT else: d = dir.LEFT elif controls.right() or controls.joy_right(): if controls.up() or controls.joy_up(): d = dir.UPRIGHT elif controls.down() or controls.joy_down(): d = dir.DOWNRIGHT else: d = dir.RIGHT elif controls.up() or controls.joy_up(): d = dir.UP elif controls.down() or controls.joy_down(): d = dir.DOWN else: self.state = self.standState() yield None self.move(d) # handle animation and junk if d != oldDir: self.anim = 'walk' self.direction = d oldDir = d yield None
def gameOver(): global fields c = Caption( 'G A M E O V E R', duration=1000000, y=(ika.Video.yres - font.height) / 2 ) t = 80 i = 0 fields = [] while True: i = min(i + 1, t) c.update() tick() raw_draw() # darken the screen, draw the game over message: ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, i * 255 / t), True) c.draw() ika.Video.ShowPage() ika.Delay(4) if i == t and (controls.attack1() or controls.joy_attack1() or controls.ui_accept() or controls.ui_cancel()): break
def update(self): assert (len(self.layout.children), 'There should be at least one frame in here. (Either ' 'indicating no saves, or to create a new save.)') ika.Input.Update() if self.curY < self.oldY: self.oldY -= 2 elif self.curY > self.oldY: self.oldY += 2 elif (controls.up.pressed or controls.ui_up.pressed or controls.joy_up.pressed) and self.cursorPos > 0: sound.menuMove.Play() self.cursorPos -= 1 self.curY = self.cursorPos * self.wndHeight elif (controls.down.pressed or controls.ui_down.pressed or controls.joy_down.pressed) and \ self.cursorPos < len(self.layout.children) - 1: sound.menuMove.Play() self.cursorPos += 1 self.curY = self.cursorPos * self.wndHeight elif (controls.attack1() or controls.joy_attack1() or controls.ui_accept()): sound.menuSelect.Play() return self.cursorPos elif (controls.cancel() or controls.joy_cancel() or controls.ui_cancel()): return Cancel
def menu(): clouds.speed = (1.0, .75) bg = ika.Image('%s/title_bg.png' % config.IMAGE_PATH) logo = ika.Image('%s/title_logo.png' % config.IMAGE_PATH) cursor = ika.Image('%s/ui/pointer.png' % config.IMAGE_PATH) result = None cursorPos = 0 menuTop = 175 menuLeft = 120 secrat = 0 menuItems = ("New Game", "Load Game", "Quit Game") wnd = subscreen.Window('gfx/ui/win_%s.png') FADE_TIME = 60 opacity = 0 opacity2 = 0 opacity3 = 0 def draw(): ika.Video.Blit(bg, 0, 0, ika.Opaque) clouds.update() clouds.draw() font.Print(2, 2, "v.1/05") ika.Video.TintBlit(logo, 0, 0, ika.RGB(255, 255, 255, opacity)) wnd.draw(menuLeft - 5, menuTop - 5, ika.Video.xres - (menuLeft * 2), (len(menuItems) * font.height) + 10, ika.RGB(255, 255, 255, opacity3)) y = 0 for i in menuItems: font.Print(menuLeft, menuTop + y, '#[%02XFFFFFF]%s' % (opacity2, i)) y += font.height ika.Video.TintBlit(cursor, menuLeft - cursor.width - 2, menuTop + cursorPos * font.height + 2, ika.RGB(255, 255, 255, opacity2)) for i in range(FADE_TIME - 1, -1, -1): draw() ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(255, 255, 255, i * 255 / FADE_TIME), True) ika.Video.ShowPage() ika.Input.Update() ika.Delay(1) u = 0 # unpress hack while result == None: opacity = min(255, opacity + 2) opacity2 = min(255, opacity2 + (opacity >= 128) * 2) opacity3 = min(255, opacity2 * 3) draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1) if opacity2 == 255: if controls.up.pressed or controls.ui_up.pressed or controls.joy_up.pressed: sound.menuMove.Play() if cursorPos > 0: cursorPos -= 1 else: secrat += 1 if (secrat == 6): menuItems = ("New Game", "Load Game", "Quit Game", "New Game +") cursorPos = 3 elif (controls.down.pressed or controls.ui_down.pressed or controls.joy_down.pressed ) and cursorPos < (len(menuItems) - 1): sound.menuMove.Play() cursorPos += 1 elif controls.attack1() or controls.joy_attack1( ) or controls.ui_accept(): result = cursorPos if result in (0, 3): sound.newGame.Play() else: sound.menuSelect.Play() return result
def thrustState(self, me): if me.direction == dir.UPLEFT or me.direction == dir.DOWNLEFT: me.direction = dir.LEFT elif me.direction == dir.UPRIGHT or me.direction == dir.DOWNRIGHT: me.direction = dir.RIGHT class SpeedSaver(object): def __init__(_self): _self.s = me.speed def __del__(_self): me.speed = _self.s ss = SpeedSaver() me.anim = 'thrust' me.speed += 200 me.move(me.direction, 1000) r = thrustRange[me.direction] + (me.layer, ) rect = list(r) sound.sword3.Play() hitlist = set() 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 i = 8 while i > 0: i -= 1 me.speed -= (8 - i) * 5 self.cutBush(me, rect) result = hurt() if result: break yield None spin = None i = 50 while i > 0: i -= 1 if controls.attack1() and spin is None: # tiny window: press the slash button just as the thrust finishes to do uber-attack! if i > 40: spin = False else: spin = True me.speed = max(10, me.speed - 10) yield None me.stop() if spin: print 'Spin!!! NYI omfg'
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