Can actually die

This commit is contained in:
theo@manjaro 2021-11-23 18:53:48 +01:00
parent c5848a12ca
commit 01cfa1ddfc
5 changed files with 64 additions and 35 deletions

View File

@ -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

View File

@ -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,6 +286,7 @@ class Player(Movable):
self.combotimer = 1
def yeet(self,hor,ver,resetcombo=True):
if not self.dead:
self.verspd = 0
self.horkb = hor
self.verkb = ver
@ -285,10 +294,27 @@ class Player(Movable):
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):
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])

View File

@ -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)

View File

@ -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,14 +12,21 @@ 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):
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:

Binary file not shown.