def update(self): engine = system.engine p = engine.player p.direction=dir.UP p.state = p.cutsceneWalkState() engine.draw() ika.Video.ShowPage() for i in range(21 * 16 +8): ika.ProcessEntities() p.update() engine.camera.update() engine.draw() ika.Video.ShowPage() ika.Delay(1) p.direction=dir.LEFT p.stop() p.state = p.cutsceneStandState() p.update() y=float(ika.Map.ywin) for i in range(550): if y>100: y-=0.25 ika.Map.ywin=int(y) ika.ProcessEntities() p.update() engine.draw() ika.Video.ShowPage() ika.Delay(1) engine.synchTime() xi.effects.fadeOut(200, draw=system.engine.draw) cabin.scene('epilogue') ending.credits()
def fall(numtiles): controls.DisableInput() engine = system.engine p = engine.player p.stop() p.ent.specframe = 91 p._state = lambda: None # keep the player from moving engine.draw() ika.Video.ShowPage() ika.Delay(2) for y in range(numtiles * 8 + 2): p.y += 2 #ika.ProcessEntities() engine.camera.update() engine.draw() ika.Video.ShowPage() ika.Delay(1) p.ent.specframe = 92 t = ika.GetTime() + 80 while t > ika.GetTime(): #ika.ProcessEntities() engine.camera.update() engine.draw() ika.Video.ShowPage() ika.Delay(1) engine.synchTime() p.state = p.standState() controls.EnableInput()
def animate(ent, frames, delay, thing=None, loop=True, text=None): class AnimException(Exception): pass # frames should be a list of (frame, delay) pairs. if thing is not None: crap.append(thing) if text is not None: text = textBox(ent, text) crap.append(text) try: while True: for frame in frames: ent.specframe = frame d = delay while d > 0: d -= 1 draw() ika.Video.ShowPage() ika.Delay(1) ika.Input.Update() if controls.attack() or controls.ui_accept( ) or controls.joy_attack(): loop = False raise AnimException if not loop: raise AnimException except: #except what? if thing: crap.remove(thing) if text: crap.remove(text) ent.specframe = 0
def gameOver(self): c = Caption('G A M E O V E R', duration=1000000, y=(ika.Video.yres - self.font.height) / 2) t = 80 i = 0 self.fields = [] while True: i = min(i + 1, t) c.update() self.tick() self.draw() # darken the screen, draw the game over message: o = i * 255 / t ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, o), True) c.draw() ika.Video.ShowPage() ika.Delay(4) if i == t and (controls.attack() or controls.joy_attack() or controls.ui_accept() or controls.ui_cancel() or controls.cancel() or controls.joy_cancel()): break
def blurIn(wasteOfMemory): for img in wasteOfMemory[::-1]: ika.Video.ScaleBlit(img, 0, 0, ika.Video.xres, ika.Video.yres, ika.Opaque) ika.Video.ShowPage() ika.Input.Update() ika.Delay(3)
def regulateTiming(): '''TODO: make this not actually draw. Make it yield a value that the caller can use to decide how to draw and delay? ''' global nextFrameTime skipCount = 0 nextFrameTime = ika.GetTime() + ticksPerFrame while True: t = ika.GetTime() # if we're ahead, delay if t < nextFrameTime: ika.Delay(int(nextFrameTime - t)) # Do some thinking yield 'think' # if we're behind, and can, skip the frame. else draw if t > nextFrameTime and skipCount < config.MAX_SKIP_COUNT: skipCount += 1 else: skipCount = 0 #draw() yield 'draw' #ika.Video.ShowPage() #ika.Input.Update() nextFrameTime += ticksPerFrame
def run(self): try: skipCount = 0 controls.UnpressAllKeys() self.nextFrameTime = ika.GetTime() + self.ticksPerFrame while True: t = ika.GetTime() # if we're ahead, delay if t < self.nextFrameTime: ika.Delay(int(self.nextFrameTime - t)) automap.map.update() if controls.cancel() or controls.ui_cancel( ) or controls.joy_cancel(): self.pause() #if controls.savestate(): # self.SaveState() #if ika.Input.keyboard['F1'].Pressed(): # automap.map.debugrooms() #if controls.loadstate(): # self.LoadState() if controls.showmap() or controls.joy_showmap(): self.ShowMap() #if controls.speedhack(): # if self.framerate == 100: # self.SetFrameRate(200) # else: # self.SetFrameRate(100) # Do some thinking self.tick() # if we're behind, and can, skip the frame. else draw if t > self.nextFrameTime and skipCount < MAX_SKIP_COUNT: skipCount += 1 else: skipCount = 0 self.draw() ika.Video.ShowPage() ika.Input.Update() self.nextFrameTime += self.ticksPerFrame except GameOverException: self.gameOver() self.killList = self.entities[:] self.clearKillQueue() except LoadStateException, l: self.killList = self.entities[:] self.clearKillQueue() saveload.quicksave = l.s #assign quicksave to be loaded, to be interpreted back in system.py
def render(self, func): self.count += 1 # What we wish the time was t = ika.GetTime() if t > self.count: # behind schedule return if t == self.count: # ahead of schedule. Wait a second. ika.Delay(1) func() ika.Video.ShowPage()
def update(self): p = system.engine.player p.stop() p._state = lambda: None # keep the player from moving p.ent.specframe = 74 #laying in the snow system.engine.camera.update() for i in range(200): ika.Input.Update() ika.ProcessEntities() for t in (system.engine.mapThings): t.update() #hack to keep snow moving system.engine.draw() ika.Video.ShowPage() ika.Delay(1) p.ent.specframe = 73 #gettin up! for i in range(50): ika.Input.Update() ika.ProcessEntities() for t in (system.engine.mapThings): t.update() system.engine.draw() ika.Video.ShowPage() ika.Delay(1) p.ent.specframe = 72 #gettin up! for i in range(50): ika.Input.Update() ika.ProcessEntities() for t in (system.engine.mapThings): t.update() system.engine.draw() ika.Video.ShowPage() ika.Delay(1) p.state = p.standState() system.engine.synchTime() return True
def delay(draw, count, snow): while count > 0: draw() snow.update() snow.draw() ika.Delay(1) count -= 1 ika.Video.ShowPage() ika.Input.Update() if controls.attack() or controls.ui_accept( ) or controls.cancel() or controls.ui_cancel() or controls.joy_cancel( ) or controls.joy_attack(): raise _DoneException()
def render(self, func): now = ika.GetTime() # ahead. Pause a moment if now < self._nextTimeFrame: ika.Delay(int(self._nextTimeFrame - now)) # behind, skip if now > self._nextTimeFrame and self._skipCount < MAX_SKIP: self._skipCount += 1 else: self._skipCount = 0 func() ika.Video.ShowPage() self._nextTimeFrame += self._ticksPerFrame
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 blurOut(): wasteOfMemory = [] i = 1.0 while i < 2: img = blurScreen(1.0 / i) wasteOfMemory.append(img) ika.Video.ScaleBlit(img, 0, 0, ika.Video.xres, ika.Video.yres, ika.Opaque) ika.Video.ShowPage() ika.Input.Update() ika.Delay(3) BLEH = 1 ika.Video.ScaleBlit(img, -BLEH, -BLEH, ika.Video.xres + BLEH * 2, ika.Video.yres + BLEH * 2) ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, 2), True) i += 0.1 return wasteOfMemory
def bridge_break(): if 'bridge_broken' not in savedata.__dict__: sound.playMusic('music/Competative.xm') savedata.bridge_broken = 'True' bridge = ((366, 0, 367), (372, 0, 373), (378, 0, 379)) for x in range(3): ika.Map.SetTile(x + 19, 28, 4, bridge[0][x]) ika.Map.SetTile(x + 19, 29, 4, bridge[1][x]) ika.Map.SetTile(x + 19, 30, 4, bridge[2][x]) ika.Map.entities['break_gap'].x = 320 # This is really cheap. Probably fragile too. I'm stepping beyond # the game engine and directly twiddling with ika. engine = system.engine p = engine.player p.stop() p.layer = 3 p.ent.specframe = 91 p._state = lambda: None # keep the player from moving engine.draw() ika.Video.ShowPage() ika.Delay(8) for y in range(32): p.y += 1 #ika.ProcessEntities() engine.camera.update() engine.draw() ika.Video.ShowPage() ika.Delay(1) p.layer = 2 for y in range(32): p.y += 1 #ika.ProcessEntities() engine.camera.update() engine.draw() ika.Video.ShowPage() ika.Delay(1) p.ent.specframe = 92 t = ika.GetTime() + 80 while t > ika.GetTime(): engine.draw() ika.Video.ShowPage() #ika.Input.Update() p.state = p.standState() y = Yeti(ika.Entity(304, 64, 2, 'yeti.ika-sprite')) # UBER-YETI y.stats.maxhp = 400 y.stats.hp = y.stats.maxhp y.stats.att += 10 engine.addEntity(y) engine.mapThings.append(DeathListener(y)) engine.synchTime()
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 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