def walkState(self): oldDir = self.direction self.anim = 'walk' while True: self.regenMP() if controls.attack() or controls.joy_attack(): self.state = self.slashState() elif controls.rend() or controls.joy_rend(): self.state = self.hearthRendState() yield None elif controls.gale() or controls.joy_gale(): self.state = self.crushingGaleState() yield None elif controls.heal() or controls.joy_heal(): self.state = self.healingRainState() yield None elif controls.bolt() or controls.joy_bolt(): self.state = self.boltState() 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 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 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 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() or controls.joy_up() or controls.ui_up()) and self.cursorPos > 0: if not self.unpress: self.cursorPos -= 1 sound.cursormove.Play() self.unpress = True elif (controls.down() or controls.joy_down() or controls.ui_down()) and self.cursorPos < len(self.Text) - 1: if not self.unpress: self.cursorPos += 1 sound.cursormove.Play() self.unpress = True elif controls.enter() or controls.joy_enter() or controls.ui_accept(): return self.cursorPos elif controls.cancel() or controls.joy_cancel() or controls.ui_cancel(): return Cancel else: self.unpress = False return None
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
def standState(self): self.stop() self.anim = 'stand' while True: self.regenMP() if controls.attack() or controls.joy_attack(): self.state = self.slashState() elif controls.rend() or controls.joy_rend(): self.state = self.hearthRendState() yield None elif controls.gale() or controls.joy_gale(): self.state = self.crushingGaleState() yield None elif controls.heal() or controls.joy_heal(): self.state = self.healingRainState() yield None elif controls.bolt() or controls.joy_bolt(): self.state = self.boltState() yield None 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() self._state() # get the walk state started right now. yield None
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 else: if (controls.up() or controls.ui_up() or controls.joy_up()) and self.cursorPos > 0: self.cursorPos -= 1 self.curY = self.cursorPos * self.wndHeight elif (controls.down() or controls.ui_down() or controls.joy_down()) and self.cursorPos < len(self.layout.children) - 1: self.cursorPos += 1 self.curY = self.cursorPos * self.wndHeight elif controls.attack() or controls.ui_accept() or controls.joy_attack(): if self.saving and self.cursorPos == len(self.layout.children) -1: #create new return New else: return self.cursorPos elif controls.cancel() or controls.ui_cancel() or controls.joy_cancel(): return Cancel return None
def menu(): bg = ika.Image('gfx/title.png') cursor = ika.Image('gfx/ui/pointer.png') snow = Snow(velocity=(0, 0.5)) snow.update() result = None cursorPos = 0 FADE_TIME = 60 font = ika.Font('system.fnt') def draw(): ika.Video.Blit(bg, 0, 0, ika.Opaque) ika.Video.Blit(cursor, 68, 128 + cursorPos * 26) txt = '(c) 2003, 2021' length = font.StringWidth(txt) font.Print(ika.Video.xres - length - 10, ika.Video.yres - 10, txt) txt = 'Version 1.02' length = font.StringWidth(txt) font.Print(ika.Video.xres - length - 10, ika.Video.yres - 20, txt) if controls.useGamePad: font.Print(10, ika.Video.yres - 10, 'Gamepad controls enabled.') for i in range(FADE_TIME - 1, -1, -1): draw() ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, i * 255 / FADE_TIME), True) snow.update() snow.draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1) u = 0 # gay unpress hack while result == None: draw() snow.update() snow.draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1) if (controls.up() or controls.ui_up() or controls.joy_up()) and cursorPos > 0: if not u: cursorPos -= 1 u = 1 elif (controls.down() or controls.ui_down() or controls.joy_down()) and cursorPos < 2: if not u: cursorPos += 1 u = 1 elif controls.attack() or controls.ui_accept() or controls.joy_attack( ): result = cursorPos else: u = 0 # one last draw. Later on, there's a blurfade that can take advantage of this: draw() snow.draw() return result for i in range(FADE_TIME): draw() ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, i * 255 / FADE_TIME), True) snow.update() snow.draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1)
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, Cancel is returned. Else, None is returned, to signify that nothing has happened yet. ''' ika.Input.Update() cy = self.cursorY # update the cursor ymax = max(0, len(self.text) * self.font.height - self._textCtrl.height) # Goofy, but kinda cool. # We figure out where the cursor should be given its logical position. # (ie the item it's supposed to point at) If it's different from its # actual position, we move it. This way, we get nice smooth cursor # movement. 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 += min(delta, self._cursorSpeed) elif delta < 0: if cy > 0: self._cursorY -= self._cursorSpeed elif self._textCtrl.ywin > 0: self._textCtrl.ywin -= min(-delta, self._cursorSpeed) else: # Only move the cursor if delta is zero. That way movement doesn't # get bogged down by a cursor that moves too slowly. # # The cursor delaying stuff mucks this up considerably. Basically, there's # a counter variable (_cursorCount) that is reset when no key is pressed. # When a key is pressed, the cursor is moved iff the count is maxed, or at 0. # when the counter goes below 0, it is set to the repeat count. if controls.up() and self.cursorPos > 0: if self._cursorCount == 0 or self._cursorCount == self._pauseDelay: self.cursorPos -= 1 sound.cursormove.Play() self._cursorCount -= 1 if self._cursorCount < 0: self._cursorCount = self._repeatDelay elif controls.down() and self.cursorPos < len(self.text) - 1: if self._cursorCount == 0 or self._cursorCount == self._pauseDelay: self.cursorPos += 1 sound.cursormove.Play() self._cursorCount -= 1 if self._cursorCount < 0: self._cursorCount = self._repeatDelay elif controls.enter(): return self.cursorPos elif controls.cancel(): return Cancel else: self._cursorCount = self._pauseDelay # execution reaches this point if enter or cancel is not pressed return None
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
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, Cancel is returned. Else, None is returned, to signify that nothing has happened yet. ''' ika.Input.Update() cy = self.cursorY # update the cursor ymax = max(0, len(self.text) * self.font.height - self._textCtrl.height) # Goofy, but kinda cool. # We figure out where the cursor should be given its logical position. # (ie the item it's supposed to point at) If it's different from its # actual position, we move it. This way, we get nice smooth cursor # movement. 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 += min(delta, self._cursorSpeed) elif delta < 0: if cy > 0: self._cursorY -= self._cursorSpeed elif self._textCtrl.ywin > 0: self._textCtrl.ywin -= min(-delta, self._cursorSpeed) else: # Only move the cursor if delta is zero. That way movement doesn't # get bogged down by a cursor that moves too slowly. # # The cursor delaying stuff mucks this up considerably. Basically, there's # a counter variable (_cursorCount) that is reset when no key is pressed. # When a key is pressed, the cursor is moved iff the count is maxed, or at 0. # when the counter goes below 0, it is set to the repeat count. if controls.up() and self.cursorPos > 0: if self._cursorCount == 0 or self._cursorCount == self._pauseDelay: self.cursorPos -= 1 sound.cursormove.Play() self._cursorCount -= 1 if self._cursorCount < 0: self._cursorCount = self._repeatDelay elif controls.down() and self.cursorPos < len(self.text) - 1: if self._cursorCount == 0 or self._cursorCount == self._pauseDelay: self.cursorPos += 1 sound.cursormove.Play() self._cursorCount -= 1 if self._cursorCount < 0: self._cursorCount = self._repeatDelay elif controls.enter(): return self.cursorPos elif controls.cancel(): return Cancel else: self._cursorCount = self._pauseDelay # execution reaches this point if enter or cancel is not pressed return None