Better Fastfall

This commit is contained in:
theo@manjaro 2021-11-18 08:26:30 +01:00
parent b6af2d4287
commit 33f9bc62a4
2 changed files with 27 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 815 B

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@ -16,7 +16,7 @@ class Player(Movable):
self.spritehurt = game.sprite_lib["player/hurt.png"] # Being hurted self.spritehurt = game.sprite_lib["player/hurt.png"] # Being hurted
self.spritelanding = game.sprite_lib["player/landing.png"] self.spritelanding = game.sprite_lib["player/landing.png"]
self.landingtimer = 0 self.landingtimer = 0
self.maxlandtime = 0.2 self.maxlandtime = 0.15
self.spriteindex = 0 self.spriteindex = 0
self.flipx = False self.flipx = False
self.animationspeed = 2.5 self.animationspeed = 2.5
@ -61,13 +61,12 @@ class Player(Movable):
self.candash = False self.candash = False
self.canfastfall = False self.canfastfall = False
self.fastfall = False self.fastfall = 0
# Small leap in order to get out of the water # Small leap in order to get out of the water
self.leaptimer = 1 self.leaptimer = 1
self.leapmaxtimer = 0.5 self.leapmaxtimer = 0.5
self.leapmargin = 30 # Vertical margin for the leap self.leapmargin = 30 # Vertical margin for the leap
self.gravityway = 1 self.gravityway = 1
def step(self): def step(self):
@ -78,22 +77,25 @@ class Player(Movable):
if self.gravityway == 1: if self.gravityway == 1:
self.gravityway = -1 self.gravityway = -1
# Décellerer # Décellerer
self.canfastfall = False
self.verspd *= 0.9 self.verspd *= 0.9
# Spawn splash particles # Spawn splash particles
self.game.addParticle(self.splashparticles,self.rect.left-5,self.water.rect.top-5,fps=8) self.game.addParticle(self.splashparticles,self.rect.left-5,self.water.rect.top-5,fps=12)
self.game.addParticle(self.splashparticles,self.rect.right+5,self.water.rect.top-5,flipx=True,fps=8) self.game.addParticle(self.splashparticles,self.rect.right+5,self.water.rect.top-5,flipx=True,fps=12)
else: else:
if self.gravityway == -1: if self.gravityway == -1:
self.gravityway = 1 self.gravityway = 1
# Décellerer # Décellerer
self.canfastfall = False
self.verspd *= 0.9 self.verspd *= 0.9
# Spawn splash particles
self.game.addParticle(self.splashparticles,self.rect.left-5,self.water.rect.top-5,fps=12)
self.game.addParticle(self.splashparticles,self.rect.right+5,self.water.rect.top-5,flipx=True,fps=12)
if self.water and self.water.rect.y-self.leapmargin<=self.rect.y<=self.water.rect.y+self.leapmargin: if self.water and self.water.rect.y-self.leapmargin<=self.rect.y<=self.water.rect.y+self.leapmargin:
self.leaptimer-=self.game.dt # Inside the margin self.leaptimer-=self.game.dt # Inside the margin
else: else:
self.leaptimer = self.leapmaxtimer # Outside, reset the timer self.leaptimer = self.leapmaxtimer # Outside, reset the timer
if self.leaptimer<0:
self.canfastfall = True
if not self.game.globals["hitpose"]: if not self.game.globals["hitpose"]:
@ -121,13 +123,16 @@ class Player(Movable):
self.attackstate(self) # Si je suis sur le sol self.attackstate(self) # Si je suis sur le sol
self.onground = False self.onground = False
self.onceilling = False self.onceilling = False
# Cancel fastfall if not enough speed
if abs(self.verspd)<5:
self.fastfall = 0
if self.checkcollisions(0,self.gravityway): if self.checkcollisions(0,self.gravityway):
self.onground = True self.onground = True
self.leaptimer = self.leapmaxtimer self.leaptimer = self.leapmaxtimer
self.candash = True self.candash = True
self.canfastfall = True self.canfastfall = True
if self.fastfall: if self.fastfall:
self.fastfall = False self.fastfall = 0
# Spawns dust # Spawns dust
self.game.addParticle(self.dustparticles,self.rect.center[0],self.rect.center[1]+self.rect[3]/2*self.gravityway,fps=25) self.game.addParticle(self.dustparticles,self.rect.center[0],self.rect.center[1]+self.rect[3]/2*self.gravityway,fps=25)
if self.verspd!=0: if self.verspd!=0:
@ -154,10 +159,13 @@ class Player(Movable):
if canmove and not self.onground: if canmove and not self.onground:
verdir = self.verspd>0 verdir = self.verspd>0
gravdir = self.gravityway>0 gravdir = self.gravityway>0
if verdir != gravdir: if not self.fastfall:
self.sprite=self.spritejumping if verdir != gravdir:
self.sprite=self.spritejumping
else:
self.sprite=self.spritefalling
else: else:
self.sprite=self.spritefalling self.sprite = self.spritelanding
# Adding knockback # Adding knockback
self.horspd+=self.horkb self.horspd+=self.horkb
@ -203,9 +211,11 @@ class Player(Movable):
falled = True falled = True
if not falled: # Check for fastfall if not falled: # Check for fastfall
if self.canfastfall and not self.onground: if self.canfastfall and not self.onground:
self.verspd = self.maxgravity/5*self.gravityway self.verspd = self.maxgravity/5
if self.leaptimer>0:
self.verspd*=self.gravityway
self.canfastfall = False self.canfastfall = False
self.fastfall = True self.fastfall = self.gravityway
else: else:
self.fastfall = False self.fastfall = False
@ -217,5 +227,8 @@ class Player(Movable):
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
def draw(self): def draw(self):
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,self.gravityway<0 and not self.leaptimer<0) 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.rect[1]-self.game.globals["cameray"]]) self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])