Overflown/gamedata/objects/ingame/pause.py

69 lines
2.2 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)
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)
def quit(self):
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
if self.game.inputs["keys"]["left"]["timer"]==1:
self.cursor-=1
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 options
for i,v in enumerate(self.optionsorder):
x = self.game.globals["cameraw"]/2
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)