Can actually die
This commit is contained in:
parent
c5848a12ca
commit
01cfa1ddfc
@ -303,4 +303,8 @@ class Game():
|
||||
result = []
|
||||
for i in chars:
|
||||
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.transition import Transition
|
||||
|
||||
class Player(Movable):
|
||||
|
||||
@ -22,6 +23,12 @@ class Player(Movable):
|
||||
self.animationspeed = 2.5
|
||||
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()
|
||||
if abs(self.maxheight-234)<16:
|
||||
self.maxheight = self.game.globals["camerah"]
|
||||
@ -92,7 +99,7 @@ class Player(Movable):
|
||||
|
||||
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.gravityway == 1:
|
||||
self.gravityway = -1
|
||||
@ -209,6 +216,8 @@ class Player(Movable):
|
||||
self.jumpsfx.play()
|
||||
self.jumped = True
|
||||
super().step() # Actually move
|
||||
if self.rect.center[1]>self.game.globals["cameray"]+self.game.globals["camerah"]:
|
||||
self.die()
|
||||
# Updated hitrect
|
||||
self.hitrect[0] = self.rect.center[0]-self.hitrect[2]/2
|
||||
offset = 0
|
||||
@ -251,9 +260,8 @@ class Player(Movable):
|
||||
else:
|
||||
self.fastfall = False
|
||||
|
||||
else: # If I'm in hitpose
|
||||
if self.hitposetimer.tick(self.game.dt):
|
||||
self.hitpose = False
|
||||
else:
|
||||
self.deathtimer.tick(self.game.dt)
|
||||
|
||||
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
|
||||
@ -278,17 +286,35 @@ class Player(Movable):
|
||||
self.combotimer = 1
|
||||
|
||||
def yeet(self,hor,ver,resetcombo=True):
|
||||
self.verspd = 0
|
||||
self.horkb = hor
|
||||
self.verkb = ver
|
||||
self.canfastfall = True
|
||||
if resetcombo:
|
||||
self.combo = 0
|
||||
self.hurtsfx.play()
|
||||
if not self.dead:
|
||||
self.verspd = 0
|
||||
self.horkb = hor
|
||||
self.verkb = ver
|
||||
self.canfastfall = True
|
||||
if resetcombo:
|
||||
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):
|
||||
flipy = (self.gravityway<0 and not self.leaptimer<0)
|
||||
if self.fastfall:
|
||||
flipy = self.fastfall<0
|
||||
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"]])
|
||||
if not self.dead:
|
||||
flipy = (self.gravityway<0 and not self.leaptimer<0)
|
||||
if self.fastfall:
|
||||
flipy = self.fastfall<0
|
||||
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))
|
||||
|
||||
# Get sprites for "Level N"
|
||||
sprites = self.game.getchars("Level "+str(i+1))
|
||||
text = self.game.pygame.Surface((len(sprites)*9,9),flags=self.game.pygame.SRCALPHA)
|
||||
for j,s in enumerate(sprites):
|
||||
if s:
|
||||
text.blit(s,[j*9,0])
|
||||
self.textnumbers.append(text)
|
||||
sprite = self.game.getchars("Level "+str(i+1))
|
||||
self.textnumbers.append(sprite)
|
||||
|
||||
# Get sprites for the level's name
|
||||
if str(i) in customvalues.keys():
|
||||
sprites = self.game.getchars(customvalues[str(i)])
|
||||
text = self.game.pygame.Surface((len(sprites)*9,9),flags=self.game.pygame.SRCALPHA)
|
||||
for i,v in enumerate(sprites):
|
||||
if v:
|
||||
text.blit(v,[i*9,0])
|
||||
self.names.append(text)
|
||||
self.names.append(sprites)
|
||||
else:
|
||||
self.names.append(None)
|
||||
|
||||
|
@ -2,7 +2,7 @@ from gamedata.objects.base import 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)
|
||||
|
||||
@ -12,18 +12,25 @@ class Transition(BaseObject):
|
||||
self.level = level
|
||||
|
||||
self.timer = game.lib.Timer(time)
|
||||
self.holdtimer = game.lib.Timer(holdtime)
|
||||
self.hold = False
|
||||
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)
|
||||
if not self.hold:
|
||||
self.alpha = (1-self.timer.getratio())*255
|
||||
if self.timer.tick(self.game.dt):
|
||||
self.hold = True
|
||||
self.alpha = 255
|
||||
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):
|
||||
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