Added player's animations
Before Width: | Height: | Size: 14 KiB |
BIN
gamedata/assets/player/falling.png
Normal file
After Width: | Height: | Size: 849 B |
BIN
gamedata/assets/player/hurt.png
Normal file
After Width: | Height: | Size: 895 B |
BIN
gamedata/assets/player/jumping.png
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
gamedata/assets/player/landing.png
Normal file
After Width: | Height: | Size: 815 B |
BIN
gamedata/assets/player/still.png
Normal file
After Width: | Height: | Size: 850 B |
BIN
gamedata/assets/player/walking/0.png
Normal file
After Width: | Height: | Size: 841 B |
BIN
gamedata/assets/player/walking/1.png
Normal file
After Width: | Height: | Size: 865 B |
BIN
gamedata/assets/player/walking/2.png
Normal file
After Width: | Height: | Size: 841 B |
BIN
gamedata/assets/player/walking/3.png
Normal file
After Width: | Height: | Size: 837 B |
@ -9,12 +9,24 @@ class Player(Movable):
|
||||
spawnpoint = game.lib.choice(self.tileset.spawns)
|
||||
self.rect.move_ip(spawnpoint.center)
|
||||
|
||||
self.sprite = game.sprite_lib["player/0.png"]
|
||||
self.sprites = game.getSpriteDir("player/walking/") # Walking animation
|
||||
self.spritestill = game.sprite_lib["player/still.png"] # Standing still
|
||||
self.spritejumping = game.sprite_lib["player/jumping.png"] # Ascending
|
||||
self.spritefalling = game.sprite_lib["player/falling.png"] # Descending
|
||||
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.spriteindex = 0
|
||||
self.flipx = False
|
||||
self.animationspeed = 2.5
|
||||
|
||||
self.sprite = self.spritestill
|
||||
self.rect[2] = self.sprite.get_width()
|
||||
self.rect[3] = self.sprite.get_height()
|
||||
|
||||
self.water = self.game.gameloop.findname("Water")[0]
|
||||
|
||||
|
||||
self.hitrect = self.rect.copy()
|
||||
self.hitrect[2] = round(self.hitrect[2]*0.7)
|
||||
self.hitrect[3] = round(self.hitrect[3]*0.7)
|
||||
@ -23,7 +35,6 @@ class Player(Movable):
|
||||
self.dustparticles = game.getSpriteDir("particles/dust/")
|
||||
|
||||
self.speed = 200
|
||||
self.controlled = True
|
||||
|
||||
self.playerid = 0
|
||||
self.teamid = self.playerid
|
||||
@ -86,8 +97,23 @@ class Player(Movable):
|
||||
canmove = (abs(self.verkb)+1)*(abs(self.horkb)+1)<2
|
||||
keys = self.game.inputs["keys"]
|
||||
self.horspd = 0
|
||||
if self.controlled and canmove:
|
||||
if canmove:
|
||||
self.horspd=(keys["right"]["pressed"]-keys["left"]["pressed"])*self.game.dt*self.speed
|
||||
|
||||
if self.landingtimer<=0:
|
||||
self.sprite = self.spritestill
|
||||
else:
|
||||
self.landingtimer-=self.game.dt
|
||||
self.spriteindex = 0
|
||||
if self.horspd != 0:
|
||||
if self.landingtimer<=0:
|
||||
self.spriteindex+=self.horspd*self.animationspeed*self.game.dt
|
||||
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
|
||||
self.flipx = self.horspd<0
|
||||
else:
|
||||
# Beeing hurt
|
||||
self.sprite = self.spritehurt
|
||||
|
||||
if self.attackstate:
|
||||
self.attackstate(self) # Si je suis sur le sol
|
||||
self.onground = False
|
||||
@ -100,6 +126,9 @@ class Player(Movable):
|
||||
self.fastfall = False
|
||||
# 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:
|
||||
self.sprite=self.spritelanding
|
||||
self.landingtimer = self.maxlandtime
|
||||
if self.gravityway > 0:
|
||||
self.verspd=min(0,self.verspd)
|
||||
else:
|
||||
@ -117,6 +146,15 @@ class Player(Movable):
|
||||
else:
|
||||
self.verspd = min(0,self.verspd)
|
||||
|
||||
# Jumping and falling sprites
|
||||
if canmove and not self.onground:
|
||||
verdir = self.verspd>0
|
||||
gravdir = self.gravityway>0
|
||||
if verdir != gravdir:
|
||||
self.sprite=self.spritejumping
|
||||
else:
|
||||
self.sprite=self.spritefalling
|
||||
|
||||
# Adding knockback
|
||||
self.horspd+=self.horkb
|
||||
self.verspd+=self.verkb
|
||||
@ -175,4 +213,5 @@ class Player(Movable):
|
||||
self.game.globals["cameray"] = self.rect.center[1]-self.game.globals["camerah"]/2
|
||||
|
||||
def draw(self):
|
||||
self.game.window.blit(self.sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])
|
||||
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,False)
|
||||
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])
|
||||
|