Transition between levels
This commit is contained in:
parent
109e84dfbb
commit
1a92f04c6b
@ -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)]
|
||||
|
@ -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)
|
||||
|
||||
|
30
gamedata/objects/transition.py
Normal file
30
gamedata/objects/transition.py
Normal file
@ -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])
|
Loading…
Reference in New Issue
Block a user