Better Fastfall
This commit is contained in:
parent
b6af2d4287
commit
33f9bc62a4
Binary file not shown.
Before Width: | Height: | Size: 815 B After Width: | Height: | Size: 9.9 KiB |
@ -16,7 +16,7 @@ class Player(Movable):
|
||||
self.spritehurt = game.sprite_lib["player/hurt.png"] # Being hurted
|
||||
self.spritelanding = game.sprite_lib["player/landing.png"]
|
||||
self.landingtimer = 0
|
||||
self.maxlandtime = 0.2
|
||||
self.maxlandtime = 0.15
|
||||
self.spriteindex = 0
|
||||
self.flipx = False
|
||||
self.animationspeed = 2.5
|
||||
@ -61,13 +61,12 @@ class Player(Movable):
|
||||
|
||||
self.candash = False
|
||||
self.canfastfall = False
|
||||
self.fastfall = False
|
||||
self.fastfall = 0
|
||||
|
||||
# Small leap in order to get out of the water
|
||||
self.leaptimer = 1
|
||||
self.leapmaxtimer = 0.5
|
||||
self.leapmargin = 30 # Vertical margin for the leap
|
||||
|
||||
self.gravityway = 1
|
||||
|
||||
def step(self):
|
||||
@ -78,22 +77,25 @@ class Player(Movable):
|
||||
if self.gravityway == 1:
|
||||
self.gravityway = -1
|
||||
# Décellerer
|
||||
self.canfastfall = False
|
||||
self.verspd *= 0.9
|
||||
# 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.right+5,self.water.rect.top-5,flipx=True,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=12)
|
||||
else:
|
||||
if self.gravityway == -1:
|
||||
self.gravityway = 1
|
||||
# Décellerer
|
||||
self.canfastfall = False
|
||||
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:
|
||||
self.leaptimer-=self.game.dt # Inside the margin
|
||||
else:
|
||||
self.leaptimer = self.leapmaxtimer # Outside, reset the timer
|
||||
if self.leaptimer<0:
|
||||
self.canfastfall = True
|
||||
|
||||
if not self.game.globals["hitpose"]:
|
||||
|
||||
@ -121,13 +123,16 @@ class Player(Movable):
|
||||
self.attackstate(self) # Si je suis sur le sol
|
||||
self.onground = False
|
||||
self.onceilling = False
|
||||
# Cancel fastfall if not enough speed
|
||||
if abs(self.verspd)<5:
|
||||
self.fastfall = 0
|
||||
if self.checkcollisions(0,self.gravityway):
|
||||
self.onground = True
|
||||
self.leaptimer = self.leapmaxtimer
|
||||
self.candash = True
|
||||
self.canfastfall = True
|
||||
if self.fastfall:
|
||||
self.fastfall = False
|
||||
self.fastfall = 0
|
||||
# Spawns dust
|
||||
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:
|
||||
@ -154,10 +159,13 @@ class Player(Movable):
|
||||
if canmove and not self.onground:
|
||||
verdir = self.verspd>0
|
||||
gravdir = self.gravityway>0
|
||||
if not self.fastfall:
|
||||
if verdir != gravdir:
|
||||
self.sprite=self.spritejumping
|
||||
else:
|
||||
self.sprite=self.spritefalling
|
||||
else:
|
||||
self.sprite = self.spritelanding
|
||||
|
||||
# Adding knockback
|
||||
self.horspd+=self.horkb
|
||||
@ -203,9 +211,11 @@ class Player(Movable):
|
||||
falled = True
|
||||
if not falled: # Check for fastfall
|
||||
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.fastfall = True
|
||||
self.fastfall = self.gravityway
|
||||
else:
|
||||
self.fastfall = False
|
||||
|
||||
@ -217,5 +227,8 @@ class Player(Movable):
|
||||
self.game.globals["cameray"] = self.rect.center[1]-self.game.globals["camerah"]/2
|
||||
|
||||
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"]])
|
||||
|
Loading…
Reference in New Issue
Block a user