Added pause menu
This commit is contained in:
parent
28515f6b77
commit
acb4ad11a3
BIN
gamedata/assets/cursor.png
Normal file
BIN
gamedata/assets/cursor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 684 B |
@ -96,6 +96,7 @@ class Game():
|
||||
self.globals["scameray"] = 0
|
||||
self.globals["players"] = []
|
||||
self.globals["hitpose"] = False
|
||||
self.globals["pause"] = False
|
||||
self.globals["finishedlevels"] = [] # Levels where the player went to the end
|
||||
self.globals["completedlevels"] = [] # Levels where the player kicked all non-respawnable ennemies
|
||||
self.globals["speedrunlevels"] = [] # Levels where the player finished fast enough
|
||||
|
@ -9,6 +9,8 @@ class BaseObject():
|
||||
self.spriteoffset = 0,0
|
||||
self.depth = 1 # Sa "profondeur", déterminera l'odre d'affichage des objets
|
||||
|
||||
self.ispaused = True
|
||||
|
||||
def step(self):
|
||||
pass
|
||||
|
||||
|
@ -40,6 +40,7 @@ class GameLoop():
|
||||
|
||||
objs = list(self.objects.values())
|
||||
for i in objs:
|
||||
if not game.globals["pause"] or not i.ispaused:
|
||||
i.step()
|
||||
|
||||
def draw(self,game):
|
||||
|
68
gamedata/objects/ingame/pause.py
Normal file
68
gamedata/objects/ingame/pause.py
Normal file
@ -0,0 +1,68 @@
|
||||
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)
|
@ -1,5 +1,6 @@
|
||||
from gamedata.objects.ingame.movable import Movable
|
||||
from gamedata.objects.transition import Transition
|
||||
from gamedata.objects.ingame.pause import Pause
|
||||
|
||||
class Player(Movable):
|
||||
|
||||
@ -125,6 +126,7 @@ class Player(Movable):
|
||||
if self.leaptimer<0:
|
||||
self.canfastfall = True
|
||||
|
||||
|
||||
if not self.game.globals["hitpose"]:
|
||||
|
||||
canmove = (abs(self.verkb)+1)*(abs(self.horkb)+1)<2
|
||||
@ -134,6 +136,10 @@ class Player(Movable):
|
||||
if self.canmove:
|
||||
self.horspd=(keys["right"]["pressed"]-keys["left"]["pressed"])*self.game.dt*self.speed
|
||||
self.game.globals["timer"]+=self.game.dt
|
||||
if self.game.inputs["keys"]["escape"]["timer"]==1:
|
||||
self.game.globals["pause"] = True
|
||||
p = Pause(self.game)
|
||||
self.game.gameloop.summon(p)
|
||||
|
||||
if self.landingtimer<=0:
|
||||
self.sprite = self.spritestill
|
||||
|
@ -16,6 +16,8 @@ class Transition(BaseObject):
|
||||
self.hold = False
|
||||
self.alpha = 0
|
||||
|
||||
self.ispaused = False
|
||||
|
||||
self.depth = 4
|
||||
|
||||
def step(self):
|
||||
@ -28,12 +30,11 @@ class Transition(BaseObject):
|
||||
else:
|
||||
if self.holdtimer.tick(self.game.dt):
|
||||
if self.level:
|
||||
if self.level!="END":
|
||||
self.game.scenes.ingame(self.game,level = self.level)
|
||||
else:
|
||||
self.game.scenes.end(self.game)
|
||||
else:
|
||||
self.game.scenes.overworld(self.game)
|
||||
self.game.globals["pause"] = False
|
||||
|
||||
|
||||
def draw(self):
|
||||
self.surface.set_alpha(self.alpha)
|
||||
|
Loading…
Reference in New Issue
Block a user