diff --git a/gamedata/assets/cursor.png b/gamedata/assets/cursor.png new file mode 100644 index 0000000..36d3014 Binary files /dev/null and b/gamedata/assets/cursor.png differ diff --git a/gamedata/game.py b/gamedata/game.py index 2b04d55..ef45d44 100644 --- a/gamedata/game.py +++ b/gamedata/game.py @@ -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 diff --git a/gamedata/objects/base.py b/gamedata/objects/base.py index 1bb1b63..9624535 100644 --- a/gamedata/objects/base.py +++ b/gamedata/objects/base.py @@ -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 diff --git a/gamedata/objects/gameloop.py b/gamedata/objects/gameloop.py index a005996..26d033d 100644 --- a/gamedata/objects/gameloop.py +++ b/gamedata/objects/gameloop.py @@ -40,7 +40,8 @@ class GameLoop(): objs = list(self.objects.values()) for i in objs: - i.step() + if not game.globals["pause"] or not i.ispaused: + i.step() def draw(self,game): #Je secoue ma caméra diff --git a/gamedata/objects/ingame/pause.py b/gamedata/objects/ingame/pause.py new file mode 100644 index 0000000..e592330 --- /dev/null +++ b/gamedata/objects/ingame/pause.py @@ -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) diff --git a/gamedata/objects/ingame/player.py b/gamedata/objects/ingame/player.py index 783ea84..550348c 100644 --- a/gamedata/objects/ingame/player.py +++ b/gamedata/objects/ingame/player.py @@ -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 diff --git a/gamedata/objects/transition.py b/gamedata/objects/transition.py index 15f83d6..ed4ae52 100644 --- a/gamedata/objects/transition.py +++ b/gamedata/objects/transition.py @@ -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) + self.game.scenes.ingame(self.game,level = self.level) else: self.game.scenes.overworld(self.game) + self.game.globals["pause"] = False + def draw(self): self.surface.set_alpha(self.alpha)