from gamedata.objects.base import BaseObject from gamedata.objects.transition import Transition class Pause(BaseObject): def __init__(self,game): super().__init__(0,0,game) self.depth = 3 self.fill = self.game.pygame.Surface((self.game.globals["cameraw"],self.game.globals["camerah"])) self.fill.fill([62,33,55]) self.fill.set_alpha(100) self.sfx = self.game.sound_lib["sfx/mapmove.wav"] self.resumesfx = self.game.sound_lib["sfx/select.wav"] self.backsfx = self.game.sound_lib["sfx/return.wav"] self.trash = game.sprite_lib["trash.png"] txt = "Cleared : "+str(self.game.globals["trashes"])+" / "+str(self.game.globals["totaltrashes"]) self.trashcounter = self.game.getchars(txt) self.cursor = 0 self.cursorsprite = self.game.sprite_lib["cursor.png"] self.ispaused = False self.options = {"Resume":self.resume,"Return to map":self.quit} self.optionsorder = ["Resume","Return to map"] self.sprites = self.genoptions(self.options) self.padding = 9 self.totalheight = len(self.optionsorder)*9+(len(self.optionsorder)-1)*self.padding self.offset = (self.game.globals["camerah"]-self.totalheight)/2 def genoptions(self,options): sprites = {} for i in options.keys(): sprites[i] = self.game.getchars(str(i)) return sprites def resume(self): self.game.globals["pause"] = False self.game.gameloop.delid(self.id) self.resumesfx.play() def quit(self): tileset = self.game.gameloop.findname("TilesetRenderer")[0] tileset.bgm.stop() self.backsfx.play() t = Transition(self.game,time=0.5) self.game.gameloop.summon(t) self.ispaused = True def step(self): if self.game.inputs["keys"]["right"]["timer"]==1: self.cursor+=1 self.sfx.play() if self.game.inputs["keys"]["left"]["timer"]==1: self.cursor-=1 self.sfx.play() self.cursor = self.cursor%len(self.optionsorder) if self.game.inputs["keys"]["up"]["timer"]==1: self.game.inputs["keys"]["up"]["timer"]=10 self.options[self.optionsorder[self.cursor]]() if self.game.inputs["keys"]["escape"]["timer"]==1: self.resume() def draw(self): self.game.window.blit(self.fill,[0,0]) # Draw clear counter x = self.game.globals["cameraw"]/2 self.game.lib.drawcenter(self.game,self.trashcounter,x,50) self.game.lib.drawcenter(self.game,self.trash,x-100,50) self.game.lib.drawcenter(self.game,self.trash,x+100,50) # Draw options for i,v in enumerate(self.optionsorder): y = self.offset+i*(9+self.padding) self.game.lib.drawcenter(self.game,self.sprites[v],x,y) # Draw cursor x = self.game.globals["cameraw"]/2-100 y = self.offset+self.cursor*(9+self.padding) self.game.lib.drawcenter(self.game,self.cursorsprite,x,y)