def handleiconclick(self, vicon): if vicon == "trash": if panels.selectedtile is not None: panels.claimtile() self.clearselections() elif vicon == "zoomin": vista.zoomin() elif vicon == "zoomout": vista.zoomout() elif vicon == "menu": game.save() context.push(menu.Menu()) elif vicon == "music": noise.nexttrack() elif vicon == "heal": game.state.body.core.setbranchstatus() if self.healmode: self.clearselections() else: self.clearselections() if vista.icons["heal"].active: self.healmode = True elif vicon == "cut": if self.cutmode: self.clearselections() else: self.clearselections() if vista.icons["cut"].active: self.cutmode = True
def main(): vista.init() vista.addsplash() pygame.display.set_caption(_("Obb is loading.... Please wait")) noise.nexttrack() if settings.restart: game.restart() else: game.load() context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = clock.tick(settings.maxfps) * 0.001 * settings.gamespeed dt = min(dt, 1.0 / settings.minfps) con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: game.save() settings.save() savetime = settings.savetimer for event in events: if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): if settings.saveonquit: settings.save() game.save() pygame.quit() return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F3: settings.showfps = not settings.showfps con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: t = pygame.time.get_ticks() * 0.001 if int(t / 5.0) != int((t - dt) / 5.0): # Update once every 5 seconds fpsstring = "%.1ffps" % clock.get_fps() try: mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss // 1024 fpsstring += " %sMB" % mem except: pass pygame.display.set_caption("Obb - %s" % fpsstring) if settings.fullscreen: print(fpsstring) else: pygame.display.set_caption("Obb")
def main(): vista.init() pygame.display.set_caption("Obb is loading.... Please wait") savefile = data.filepath("savegame.pkl") noise.nexttrack() if settings.restart: context.push(play.Play()) else: try: context.push(cPickle.load(open(savefile, "rb"))) except: context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = min(clock.tick(settings.maxfps) * 0.001, 1./settings.minfps) if settings.fast: dt *= 2 con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: cPickle.dump(con, open(savefile, "wb")) savetime = settings.savetimer for event in events: if event.type == QUIT: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_ESCAPE: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F9: # Manual save cPickle.dump(con, open(savefile, "wb")) con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: pygame.display.set_caption("Obb - %.1ffps" % clock.get_fps()) if settings.fullscreen: print clock.get_fps() else: pygame.display.set_caption("Obb")
def main(): vista.init() pygame.display.set_caption("Obb is loading.... Please wait") savefile = data.filepath("savegame.pkl") noise.nexttrack() if settings.restart: context.push(play.Play()) else: try: context.push(cPickle.load(open(savefile, "rb"))) except: context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = min(clock.tick(settings.maxfps) * 0.001, 1. / settings.minfps) if settings.fast: dt *= 2 con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: cPickle.dump(con, open(savefile, "wb")) savetime = settings.savetimer for event in events: if event.type == QUIT: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_ESCAPE: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F9: # Manual save cPickle.dump(con, open(savefile, "wb")) con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: pygame.display.set_caption("Obb - %.1ffps" % clock.get_fps()) if settings.fullscreen: print clock.get_fps() else: pygame.display.set_caption("Obb")
def handleleftclick(self, mousepos): if self.clickat is None: # It's a drag return (x0, y0), (x1, y1) = self.clickat, mousepos if abs(x0-x1) + abs(y0-y1) > 25: return bicon = self.status.iconpoint(mousepos) # Any build icons pointed to vicon = vista.iconhit(mousepos) # Any vista icons pointed to if vicon == "trash": if self.panel.selected is not None: self.panel.claimtile() noise.play("trash") self.clearselections() elif vicon == "zoomin": vista.zoomin() elif vicon == "zoomout": vista.zoomout() elif vicon == "pause": self.pause() elif vicon == "music": noise.nexttrack() elif vicon == "heal": self.body.core.setbranchstatus() if self.healmode: self.clearselections() else: self.clearselections() if vista.icons["heal"].active: self.healmode = True elif vicon == "cut": if self.cutmode: self.clearselections() else: self.clearselections() if vista.icons["cut"].active: self.cutmode = True elif vista.prect.collidepoint(mousepos): # Click on panel self.clearselections(clearpanel = False) jtile = self.panel.iconp(mousepos) if jtile in (None, 0, 1, 2, 3, 4, 5): self.panel.selecttile(jtile) elif bicon is not None: self.clearselections(clearstatus = False) self.status.select(bicon.name) elif vista.vrect.collidepoint(mousepos): if self.cutmode and self.target is not None: self.target.die() self.clearselections() elif self.healmode and self.target is not None: self.target.autoheal = not self.target.autoheal elif self.parttobuild is not None and self.canbuild and self.body.canaddpart(self.parttobuild): if self.panel.selected is not None: self.panel.claimtile() if self.status.selected is not None: self.status.build() self.body.addpart(self.parttobuild) self.clearselections() else: worldpos = vista.screentoworld(mousepos) if vista.HexGrid.nearesttile(worldpos) == (0,0): settings.showtips = not settings.showtips noise.play("addpart")
def handleleftclick(self, mousepos): if self.clickat is None: # It's a drag return (x0, y0), (x1, y1) = self.clickat, mousepos if abs(x0 - x1) + abs(y0 - y1) > 25: return bicon = self.status.iconpoint(mousepos) # Any build icons pointed to vicon = vista.iconhit(mousepos) # Any vista icons pointed to if vicon == "trash": if self.panel.selected is not None: self.panel.claimtile() noise.play("trash") self.clearselections() elif vicon == "zoomin": vista.zoomin() elif vicon == "zoomout": vista.zoomout() elif vicon == "pause": self.pause() elif vicon == "music": noise.nexttrack() elif vicon == "heal": self.body.core.setbranchstatus() if self.healmode: self.clearselections() else: self.clearselections() if vista.icons["heal"].active: self.healmode = True elif vicon == "cut": if self.cutmode: self.clearselections() else: self.clearselections() if vista.icons["cut"].active: self.cutmode = True elif vista.prect.collidepoint(mousepos): # Click on panel self.clearselections(clearpanel=False) jtile = self.panel.iconp(mousepos) if jtile in (None, 0, 1, 2, 3, 4, 5): self.panel.selecttile(jtile) elif bicon is not None: self.clearselections(clearstatus=False) self.status.select(bicon.name) elif vista.vrect.collidepoint(mousepos): if self.cutmode and self.target is not None: self.target.die() self.clearselections() elif self.healmode and self.target is not None: self.target.autoheal = not self.target.autoheal elif self.parttobuild is not None and self.canbuild and self.body.canaddpart( self.parttobuild): if self.panel.selected is not None: self.panel.claimtile() if self.status.selected is not None: self.status.build() self.body.addpart(self.parttobuild) self.clearselections() else: worldpos = vista.screentoworld(mousepos) if vista.HexGrid.nearesttile(worldpos) == (0, 0): settings.showtips = not settings.showtips noise.play("addpart")