def MainLoop(self): while 1: if ika.GetTime() >= self.lastUpdate: self.lastUpdate = ika.GetTime() if self.lastFPS != ika.GetFrameRate(): self.lastFPS = ika.GetFrameRate() #ika.SetCaption(str(self.LastFPS)) ika.Input.Update() self.Update() self.currentFrame += 1 if self.currentFrame > 60: self.currentFrame = 0 self.lastUpdate = ika.GetTime() + 1 #print "%s - %s" %(ika.GetTime(), self.CurrentFrame) self.fpsManager.render(self.Draw)
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 mainloop(): last_update = 0 last_update2 = 0 while 1: if ika.GetTime() > last_update: global last_fps last_update = ika.GetTime() + 1 # from hawk's code if last_fps != ika.GetFrameRate(): ika.SetCaption("'Duo' (FPS: " + str(ika.GetFrameRate()) + ")") last_fps = ika.GetFrameRate() ika.Input.Update() manager.globalupdate() ika.ProcessEntities() #note: get rid of last_update2 and functionality for better performace (combine with last_update1 or drop if FPS low) if ika.GetTime() >= last_update2: ika.Render() manager.globalrender() ika.Video.ShowPage() last_update2 = ika.GetTime() + 1
def mainloop(): last_update = 0 last_update2 = 0 while 1: if ika.GetTime() > last_update: global last_fps last_update = ika.GetTime() + 10 """ from hawk's code""" if last_fps != ika.GetFrameRate(): ika.SetCaption("Tropfsteinhoehle (FPS: " + str(ika.GetFrameRate()) + ")") last_fps = ika.GetFrameRate() ika.Input.Update() manager.globalupdate() ika.ProcessEntities() if ika.GetTime() > last_update2: ika.Render() manager.globalrender() ika.Video.ShowPage() last_update2 = ika.GetTime() + 1
def RunGame(): global drawList global updateList last_update = 0 while 1: if ika.GetTime() > last_update: global last_fps last_update = ika.GetTime() + 1 if last_fps != ika.GetFrameRate(): ika.SetCaption("Bergbau (FPS: " + str(ika.GetFrameRate()) + ")") last_fps = ika.GetFrameRate() ika.Input.Update() #update shit for updateable in updateList: updateable.Update() #ika.ProcessEntities() ika.Render() #draw shit for drawable in drawList: drawable.Draw() ika.Video.ShowPage()
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 blurry(callback = lambda: None): global xres, yres startscale = 100 endscale = 500 scalestep = 1.5 scaleRange = endscale - startscale xres = ika.Video.xres yres = ika.Video.yres ika.Map.Render() scr = ika.Video.GrabImage(0, 0, ika.Video.xres, ika.Video.yres) t = ika.GetTime() i = 0 while i < scaleRange: x = xres * (i + startscale) / startscale y = yres * (i + startscale) / startscale Effect1(i, startscale, endscale, scr) scr = ika.Video.GrabImage(0, 0, ika.Video.xres, ika.Video.yres) ika.Video.ShowPage() ika.Input.Update() callback() i += (ika.GetTime() - t) * scalestep t = ika.GetTime()
def fade(time, startColour = ika.RGB(0, 0, 0, 0), endColour = ika.RGB(0, 0, 0, 255), draw = ika.Map.Render): startColour = ika.GetRGB(startColour) endColour = ika.GetRGB(endColour) deltaColour = [ s - e for e, s in zip(startColour, endColour) ] t = ika.GetTime() endtime = t + time saturation = 0.0 while t < endtime: i = ika.GetTime() - t t = ika.GetTime() saturation = min(saturation + float(i) / time, 1.0) draw() colour = [int(a + b * saturation) for a, b in zip(startColour, deltaColour)] ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(*colour), True) ika.Video.ShowPage() ika.Input.Update() while t == ika.GetTime(): ika.Input.Update()
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 wait(duration): t = ika.GetTime() d = t + duration while t < d: draw() ika.Video.ShowPage() ika.Input.Update() t = ika.GetTime()
def delay(duration, drawfunc=None): endTime = ika.GetTime() + duration while ika.GetTime() < endTime: tick() if not drawfunc: draw() elif drawfunc=='blank': pass else: drawfunc()
def increasewater(self, dif): self.water += dif if self.water > 32: self.water = 32 if self.notladen == True: self.next_update = ika.GetTime()+250 self.notladen = False if ika.GetTime() > self.next_update: self.dropwater() self.notladen = True
def execute(self): def draw(): ika.Map.Render() self.portraitWindow.draw() self.statWindow.draw() self.description.draw() self.equipMenu.draw() self.itemMenu.draw() self.state = self.updateEquipWindow time = ika.GetTime() fps = FPSManager() while True: result = self.state() if controls.cancel(): break if result is not None: break fps.render(draw) return True
def Reset(self): """ Resets the start and end times based on the original duration of the timer. """ self.startTime = ika.GetTime() self.endTime = self.startTime + self.duration
def __init__(self, duration, x=2, y=None): self.duration = duration self.x = x self.y = y or x self.time = ika.GetTime() + duration self.wasLocked = engine.camera.locked sound.earthquake.Play()
def credits(): m = sound.music.get('title', ika.Music('%s/title.ogg' % config.MUSIC_PATH)) m.loop = True sound.fader.kill() sound.fader.reset(m) bg = ika.Image('%s/sky_bg.png' % config.IMAGE_PATH) clouds = Clouds('%s/sky_clouds.png' % config.IMAGE_PATH, tint=ika.RGB(255, 255, 255, 128), speed=(0.1, 0.05)) y = -ika.Video.yres font = engine.font # stupid def draw(): ika.Video.Blit(bg, 0, 0, ika.Opaque) ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, 128), True) firstLine = int(y) / font.height adjust = int(y) % font.height length = (ika.Video.yres / font.height) + 1 print firstLine Y = -adjust while Y < ika.Video.yres and firstLine < len(_text): if firstLine >= 0: font.CenterPrint(160, Y, _text[firstLine]) Y += font.height firstLine += 1 ika.Video.DrawTriangle((0, 0, ika.RGB(0, 0, 0)), (ika.Video.xres, 0, ika.RGB(0, 0, 0, 0)), (0, 60, ika.RGB(0, 0, 0, 0))) ika.Video.DrawTriangle((ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0)), (0, ika.Video.yres, ika.RGB(0, 0, 0, 0)), (ika.Video.xres, ika.Video.yres - 60, ika.RGB(0, 0, 0, 0))) clouds.draw() now = ika.GetTime() while True: t = ika.GetTime() delta = (t - now) / 10.0 y += delta now = t clouds.update() draw() ika.Video.ShowPage() ika.Input.Update()
def Update(self): #print self ## #print 'hotspots', self.realX + self.hotX, self.realY + self.hotY ## oldRealX = self.realX oldRealY = self.realY print self print 'time', self.timeLastMoved, ika.GetTime() print 'old', oldRealX, oldRealY if self.timeLastMoved + 20 > ika.GetTime() or self.type is 'player': positionhandler.PositionHandler.Update(self) entity.Entity.Update(self) self.sprite.Update() print 'new', self.realX, self.realY if self.realX is not oldRealX or self.realY is not oldRealY: print 'bleh', self.timeLastMoved self.timeLastMoved = ika.GetTime()
def crossFade(time, startImage=None, endImage=None): """Crossfades! Set either startImage or endImage, or both.""" assert startImage or endImage if not startImage: startImage = grabScreen() if not endImage: endImage = grabScreen() endTime = ika.GetTime() + time now = ika.GetTime() while now < endTime: opacity = (endTime - now) * 255 / time ika.Video.ClearScreen() ika.Video.Blit(endImage, 0, 0) ika.Video.TintBlit(startImage, 0, 0, ika.RGB(255, 255, 255, opacity)) ika.Video.ShowPage() ika.Input.Update() now = ika.GetTime()
def __init__(self, duration): """ Starts the timer. Duration is the length it lasts in 1/100s of seconds. """ self.startTime = ika.GetTime() self.duration = duration self.endTime = self.startTime + duration self.Reset()
def IsDone(self): """ Returns true or false depending on whether the timer's designated end time has passed. """ if self.endTime <= ika.GetTime(): return True else: return False
def execute(self): now = ika.GetTime() done = False while not done: done = True ika.Input.Update() ika.Map.Render() t = ika.GetTime() delta = t - now now = t for child in self.children: if not child.isDone(): done = False child.update(delta) child.draw() ika.Video.ShowPage()
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)
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 crossFade(time, startImage = None, endImage = None): '''Crossfades! Set either startImage or endImage, or both.''' assert startImage or endImage, "Don't be a retard." if not startImage: startImage = ika.Video.GrabImage(0, 0, ika.Video.xres, ika.Video.yres) if not endImage: endImage = ika.Video.GrabImage(0, 0, ika.Video.xres, ika.Video.yres) endTime = ika.GetTime() + time now = ika.GetTime() while now < endTime: opacity = (endTime - now) * 255 / time ika.Video.ClearScreen() ika.Video.Blit(endImage, 0, 0) ika.Video.TintBlit(startImage, 0, 0, ika.RGB(255, 255, 255, opacity)) ika.Video.ShowPage() ika.Input.Update() now = ika.GetTime()
def __init__(self, x, y, type, direction = "right"): entity.Entity.__init__(self, x, y, type) positionhandler.PositionHandler.__init__(self) self.sprite = sprite.MakeSprite(self, type) self.type = type self.currentState = 'Wait' self.direction = direction #used to determine actions such as 'make block' or 'attack' #updates with 'left' or 'right' movement self.extraStates = [] self.falling = False self.timeLastMoved = ika.GetTime() + 20
def MainLoop(): last_update = 0 ika.SetCaption("Get the donkey to the end of the road") while 1: #If 1/100th of a second has passed since the last update. if ika.GetTime() > last_update: """ Updates ika's input functions with whatever the player is currently pressing. """ ika.Input.Update() """ Custom Update here. This is where your game's update code goes. """ MyUpdate() ika.ProcessEntities() #Processes the map entities. """ Sets the variable to the current time plus 1 so it knows what to check for the next update. """ last_update = ika.GetTime() + 1 ika.Render() #Draws the map to screen """ Custom Render Here. This is where things your game draws to screen go. """ MyRender() """ This is what actually puts all the new screen updates on the screen. """ ika.Video.ShowPage()
def drawCursor(self, active=False): pic = self.layout.children[self.cursorPos] WIDTH = 4 x = pic.x + self.x + self.layout.x - WIDTH y = pic.y + self.y + self.layout.y - WIDTH BLINK_RATE = 50 blink = (ika.GetTime() % BLINK_RATE) * 2 > BLINK_RATE if active and blink: ika.Video.Blit(self.cursor, x, y) else: ika.Video.TintBlit(self.cursor, x, y, ika.RGB(128, 128, 128))
def blurFade(time, startImages, endImages): startTime = ika.GetTime() endTime = ika.GetTime() + time now = startTime while now < endTime: imageIndex = (now - startTime) * len(startImages) / time opacity = (now - startTime) * 255 / time startfade = ika.RGB(255, 255, 255, 255 - opacity) endfade = ika.RGB(255, 255, 255, opacity) ika.Video.TintDistortBlit( startImages[imageIndex], (0, 0, startfade), (ika.Video.xres, 0, startfade), (ika.Video.xres, ika.Video.yres, startfade), (0, ika.Video.yres, startfade)) ika.Video.TintDistortBlit( endImages[-(imageIndex+1)], (0, 0, endfade), (ika.Video.xres, 0, endfade), (ika.Video.xres, ika.Video.yres, endfade), (0, ika.Video.yres, endfade)) ika.Video.ShowPage() ika.Input.Update() now = ika.GetTime()
def Execute(self): self.state = self.UpdateEquipWindow time = ika.GetTime() fps = FPSManager() while True: result = self.state() if cancel(): break if result is not None: break fps.Render(self.Draw) return True
def MainLoop(): last_update = 0 while 1: if ika.GetTime() > last_update + 1: last_update = ika.GetTime() global last_fps if last_fps != ika.GetFrameRate(): ika.SetCaption(str("Trauzl FPS(" + str(last_fps) + ")")) last_fps = ika.GetFrameRate() ika.Input.Update() manager.Update() last_update = ika.GetTime() + 1 ##will need to remove this when outputting map layer by layer in Manager ika.Render() #map #fpsManager.Render(manager.Render) manager.Render() ika.Video.ShowPage()