Overflown/gamedata/objects/ingame/pause.py

88 lines
3.0 KiB
Python
Raw Normal View History

2021-11-25 13:41:38 +01:00
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)
2021-11-26 16:28:28 +01:00
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"]
2021-11-26 16:10:58 +01:00
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)
2021-11-25 13:41:38 +01:00
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)
2021-11-26 16:28:28 +01:00
self.resumesfx.play()
2021-11-25 13:41:38 +01:00
def quit(self):
2021-11-26 15:10:29 +01:00
tileset = self.game.gameloop.findname("TilesetRenderer")[0]
tileset.bgm.stop()
2021-11-26 16:28:28 +01:00
self.backsfx.play()
2021-11-25 13:41:38 +01:00
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
2021-11-26 16:28:28 +01:00
self.sfx.play()
2021-11-25 13:41:38 +01:00
if self.game.inputs["keys"]["left"]["timer"]==1:
self.cursor-=1
2021-11-26 16:28:28 +01:00
self.sfx.play()
2021-11-25 13:41:38 +01:00
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])
2021-11-26 16:10:58 +01:00
# 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)
2021-11-25 13:41:38 +01:00
# 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)