Can actually die
This commit is contained in:
parent
c5848a12ca
commit
01cfa1ddfc
@ -303,4 +303,8 @@ class Game():
|
|||||||
result = []
|
result = []
|
||||||
for i in chars:
|
for i in chars:
|
||||||
result.append(self.getchar(i))
|
result.append(self.getchar(i))
|
||||||
return result
|
surface = pygame.Surface((len(result)*9,9),flags=pygame.SRCALPHA)
|
||||||
|
for i in range(len(result)):
|
||||||
|
if result[i]:
|
||||||
|
surface.blit(result[i],(i*9,0))
|
||||||
|
return surface
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from gamedata.objects.ingame.movable import Movable
|
from gamedata.objects.ingame.movable import Movable
|
||||||
|
from gamedata.objects.transition import Transition
|
||||||
|
|
||||||
class Player(Movable):
|
class Player(Movable):
|
||||||
|
|
||||||
@ -22,6 +23,12 @@ class Player(Movable):
|
|||||||
self.animationspeed = 2.5
|
self.animationspeed = 2.5
|
||||||
self.canmove = True
|
self.canmove = True
|
||||||
|
|
||||||
|
self.hp = 2
|
||||||
|
self.dead = False
|
||||||
|
self.deathtimer = self.game.lib.Timer(0.5)
|
||||||
|
self.deadsfx = self.game.sound_lib["sfx/dead.wav"]
|
||||||
|
self.retrytext = self.game.getchars("Try again !")
|
||||||
|
|
||||||
self.maxwidth,self.maxheight = self.tileset.layers[0]["surface"].get_size()
|
self.maxwidth,self.maxheight = self.tileset.layers[0]["surface"].get_size()
|
||||||
if abs(self.maxheight-234)<16:
|
if abs(self.maxheight-234)<16:
|
||||||
self.maxheight = self.game.globals["camerah"]
|
self.maxheight = self.game.globals["camerah"]
|
||||||
@ -92,7 +99,7 @@ class Player(Movable):
|
|||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
|
|
||||||
if not self.hitpose:
|
if not self.dead:
|
||||||
if self.water and self.rect.center[1]>self.water.rect.y: # Reverse gravity underwater
|
if self.water and self.rect.center[1]>self.water.rect.y: # Reverse gravity underwater
|
||||||
if self.gravityway == 1:
|
if self.gravityway == 1:
|
||||||
self.gravityway = -1
|
self.gravityway = -1
|
||||||
@ -209,6 +216,8 @@ class Player(Movable):
|
|||||||
self.jumpsfx.play()
|
self.jumpsfx.play()
|
||||||
self.jumped = True
|
self.jumped = True
|
||||||
super().step() # Actually move
|
super().step() # Actually move
|
||||||
|
if self.rect.center[1]>self.game.globals["cameray"]+self.game.globals["camerah"]:
|
||||||
|
self.die()
|
||||||
# Updated hitrect
|
# Updated hitrect
|
||||||
self.hitrect[0] = self.rect.center[0]-self.hitrect[2]/2
|
self.hitrect[0] = self.rect.center[0]-self.hitrect[2]/2
|
||||||
offset = 0
|
offset = 0
|
||||||
@ -251,9 +260,8 @@ class Player(Movable):
|
|||||||
else:
|
else:
|
||||||
self.fastfall = False
|
self.fastfall = False
|
||||||
|
|
||||||
else: # If I'm in hitpose
|
else:
|
||||||
if self.hitposetimer.tick(self.game.dt):
|
self.deathtimer.tick(self.game.dt)
|
||||||
self.hitpose = False
|
|
||||||
|
|
||||||
self.game.globals["camerax"] = self.rect.center[0]-self.game.globals["cameraw"]/2
|
self.game.globals["camerax"] = self.rect.center[0]-self.game.globals["cameraw"]/2
|
||||||
self.game.globals["cameray"] = self.rect.center[1]-self.game.globals["camerah"]/2
|
self.game.globals["cameray"] = self.rect.center[1]-self.game.globals["camerah"]/2
|
||||||
@ -278,17 +286,35 @@ class Player(Movable):
|
|||||||
self.combotimer = 1
|
self.combotimer = 1
|
||||||
|
|
||||||
def yeet(self,hor,ver,resetcombo=True):
|
def yeet(self,hor,ver,resetcombo=True):
|
||||||
self.verspd = 0
|
if not self.dead:
|
||||||
self.horkb = hor
|
self.verspd = 0
|
||||||
self.verkb = ver
|
self.horkb = hor
|
||||||
self.canfastfall = True
|
self.verkb = ver
|
||||||
if resetcombo:
|
self.canfastfall = True
|
||||||
self.combo = 0
|
if resetcombo:
|
||||||
self.hurtsfx.play()
|
self.combo = 0
|
||||||
|
self.hurtsfx.play()
|
||||||
|
self.hp-=1
|
||||||
|
if self.hp<=0:
|
||||||
|
self.die()
|
||||||
|
|
||||||
|
def die(self):
|
||||||
|
if not self.dead:
|
||||||
|
self.deadsfx.play()
|
||||||
|
self.depth = 5
|
||||||
|
self.rect[2],self.rect[3] = 0,0
|
||||||
|
self.dead = True
|
||||||
|
|
||||||
|
t = Transition(self.game,time=1,holdtime=0.5,level=self.game.globals["levelname"])
|
||||||
|
self.game.gameloop.summon(t)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
flipy = (self.gravityway<0 and not self.leaptimer<0)
|
if not self.dead:
|
||||||
if self.fastfall:
|
flipy = (self.gravityway<0 and not self.leaptimer<0)
|
||||||
flipy = self.fastfall<0
|
if self.fastfall:
|
||||||
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,flipy)
|
flipy = self.fastfall<0
|
||||||
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"]-self.spriteoffset,self.rect[1]-self.game.globals["cameray"]])
|
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,flipy)
|
||||||
|
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"]-self.spriteoffset,self.rect[1]-self.game.globals["cameray"]])
|
||||||
|
else:
|
||||||
|
if self.deathtimer.getloops()%2==0:
|
||||||
|
self.game.window.blit(self.retrytext,[self.game.globals["cameraw"]/2-self.retrytext.get_width()/2,self.game.globals["camerah"]/2-self.retrytext.get_height()/2])
|
||||||
|
@ -30,21 +30,13 @@ class Levels(BaseObject):
|
|||||||
self.flagsindex.append(self.game.lib.randint(1,3))
|
self.flagsindex.append(self.game.lib.randint(1,3))
|
||||||
|
|
||||||
# Get sprites for "Level N"
|
# Get sprites for "Level N"
|
||||||
sprites = self.game.getchars("Level "+str(i+1))
|
sprite = self.game.getchars("Level "+str(i+1))
|
||||||
text = self.game.pygame.Surface((len(sprites)*9,9),flags=self.game.pygame.SRCALPHA)
|
self.textnumbers.append(sprite)
|
||||||
for j,s in enumerate(sprites):
|
|
||||||
if s:
|
|
||||||
text.blit(s,[j*9,0])
|
|
||||||
self.textnumbers.append(text)
|
|
||||||
|
|
||||||
# Get sprites for the level's name
|
# Get sprites for the level's name
|
||||||
if str(i) in customvalues.keys():
|
if str(i) in customvalues.keys():
|
||||||
sprites = self.game.getchars(customvalues[str(i)])
|
sprites = self.game.getchars(customvalues[str(i)])
|
||||||
text = self.game.pygame.Surface((len(sprites)*9,9),flags=self.game.pygame.SRCALPHA)
|
self.names.append(sprites)
|
||||||
for i,v in enumerate(sprites):
|
|
||||||
if v:
|
|
||||||
text.blit(v,[i*9,0])
|
|
||||||
self.names.append(text)
|
|
||||||
else:
|
else:
|
||||||
self.names.append(None)
|
self.names.append(None)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from gamedata.objects.base import BaseObject
|
|||||||
|
|
||||||
class Transition(BaseObject):
|
class Transition(BaseObject):
|
||||||
|
|
||||||
def __init__(self,game,time=0.7,level=None):
|
def __init__(self,game,time=0.7,holdtime=0,level=None):
|
||||||
|
|
||||||
super().__init__(0,0,game)
|
super().__init__(0,0,game)
|
||||||
|
|
||||||
@ -12,18 +12,25 @@ class Transition(BaseObject):
|
|||||||
self.level = level
|
self.level = level
|
||||||
|
|
||||||
self.timer = game.lib.Timer(time)
|
self.timer = game.lib.Timer(time)
|
||||||
|
self.holdtimer = game.lib.Timer(holdtime)
|
||||||
|
self.hold = False
|
||||||
self.alpha = 0
|
self.alpha = 0
|
||||||
|
|
||||||
self.depth = 4
|
self.depth = 4
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
|
|
||||||
self.alpha = (1-self.timer.getratio())*255
|
if not self.hold:
|
||||||
if self.timer.tick(self.game.dt):
|
self.alpha = (1-self.timer.getratio())*255
|
||||||
if self.level:
|
if self.timer.tick(self.game.dt):
|
||||||
self.game.scenes.ingame(self.game,level = self.level)
|
self.hold = True
|
||||||
else:
|
self.alpha = 255
|
||||||
self.game.scenes.overworld(self.game)
|
else:
|
||||||
|
if self.holdtimer.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):
|
def draw(self):
|
||||||
self.surface.set_alpha(self.alpha)
|
self.surface.set_alpha(self.alpha)
|
||||||
|
BIN
gamedata/sounds/sfx/dead.wav
Normal file
BIN
gamedata/sounds/sfx/dead.wav
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user