From 1a92f04c6b4cc0bfe59bb6e295bce29a4f2f225a Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Tue, 23 Nov 2021 11:24:59 +0100 Subject: [PATCH] Transition between levels --- gamedata/objects/ingame/endflag.py | 6 ++++-- gamedata/objects/levels.py | 6 ++++-- gamedata/objects/transition.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gamedata/objects/transition.py diff --git a/gamedata/objects/ingame/endflag.py b/gamedata/objects/ingame/endflag.py index 7660c49..91af977 100644 --- a/gamedata/objects/ingame/endflag.py +++ b/gamedata/objects/ingame/endflag.py @@ -1,4 +1,5 @@ from gamedata.objects.ingame.ennemies.ennemy import Ennemy +from gamedata.objects.transition import Transition class EndFlag(Ennemy): @@ -25,7 +26,7 @@ class EndFlag(Ennemy): self.candie = False self.canhit = False - self.endtimer = self.game.lib.Timer(3) + self.endtimer = self.game.lib.Timer(0.5) self.ended = False def step(self): @@ -52,7 +53,8 @@ class EndFlag(Ennemy): if self.ended: if self.endtimer.tick(self.game.dt): - self.game.scene = self.game.scenes.overworld + t = Transition(self.game) + self.game.gameloop.summon(t) def draw(self): sprite = self.sprites[int(self.spriteindex)%len(self.sprites)] diff --git a/gamedata/objects/levels.py b/gamedata/objects/levels.py index b72d17e..297f21b 100644 --- a/gamedata/objects/levels.py +++ b/gamedata/objects/levels.py @@ -1,4 +1,5 @@ from gamedata.objects.base import BaseObject +from gamedata.objects.transition import Transition class Levels(BaseObject): @@ -64,9 +65,10 @@ class Levels(BaseObject): if self.game.inputs["keys"]["left"]["timer"]>0: self.cursor-=1 self.flip = True - if self.game.inputs["keys"]["up"]["timer"]>0: + if self.game.inputs["keys"]["up"]["timer"]==1: # Launch the level - self.game.scenes.ingame(self.game,level="Level "+str(self.cursor+1)) + t = Transition(self.game,level = "Level "+str(self.cursor+1)) + self.game.gameloop.summon(t) self.cursor = min(self.cursor,len(self.nodes)-1) self.cursor = max(0,self.cursor) diff --git a/gamedata/objects/transition.py b/gamedata/objects/transition.py new file mode 100644 index 0000000..81ddc60 --- /dev/null +++ b/gamedata/objects/transition.py @@ -0,0 +1,30 @@ +from gamedata.objects.base import BaseObject + +class Transition(BaseObject): + + def __init__(self,game,time=0.7,level=None): + + super().__init__(0,0,game) + + self.color = [31,14,28] + self.surface = game.pygame.Surface((game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT)) + self.surface.fill(self.color) + self.level = level + + self.timer = game.lib.Timer(time) + self.alpha = 0 + + self.depth = 4 + + def step(self): + + self.alpha = (1-self.timer.getratio())*255 + if self.timer.tick(self.game.dt): + if self.level: + self.game.scenes.ingame(self.game,level = self.level) + else: + self.game.scenes.overworld(self.game) + + def draw(self): + self.surface.set_alpha(self.alpha) + self.game.window.blit(self.surface,[0,0])