diff --git a/gamedata/assets/player/0.png b/gamedata/assets/player/0.png deleted file mode 100644 index ef51f05..0000000 Binary files a/gamedata/assets/player/0.png and /dev/null differ diff --git a/gamedata/assets/player/falling.png b/gamedata/assets/player/falling.png new file mode 100644 index 0000000..713fdea Binary files /dev/null and b/gamedata/assets/player/falling.png differ diff --git a/gamedata/assets/player/hurt.png b/gamedata/assets/player/hurt.png new file mode 100644 index 0000000..5fe4f02 Binary files /dev/null and b/gamedata/assets/player/hurt.png differ diff --git a/gamedata/assets/player/jumping.png b/gamedata/assets/player/jumping.png new file mode 100644 index 0000000..5d89045 Binary files /dev/null and b/gamedata/assets/player/jumping.png differ diff --git a/gamedata/assets/player/landing.png b/gamedata/assets/player/landing.png new file mode 100644 index 0000000..83bf2e7 Binary files /dev/null and b/gamedata/assets/player/landing.png differ diff --git a/gamedata/assets/player/still.png b/gamedata/assets/player/still.png new file mode 100644 index 0000000..ec81efa Binary files /dev/null and b/gamedata/assets/player/still.png differ diff --git a/gamedata/assets/player/walking/0.png b/gamedata/assets/player/walking/0.png new file mode 100644 index 0000000..f810e68 Binary files /dev/null and b/gamedata/assets/player/walking/0.png differ diff --git a/gamedata/assets/player/walking/1.png b/gamedata/assets/player/walking/1.png new file mode 100644 index 0000000..8e2aba1 Binary files /dev/null and b/gamedata/assets/player/walking/1.png differ diff --git a/gamedata/assets/player/walking/2.png b/gamedata/assets/player/walking/2.png new file mode 100644 index 0000000..f810e68 Binary files /dev/null and b/gamedata/assets/player/walking/2.png differ diff --git a/gamedata/assets/player/walking/3.png b/gamedata/assets/player/walking/3.png new file mode 100644 index 0000000..d1e200b Binary files /dev/null and b/gamedata/assets/player/walking/3.png differ diff --git a/gamedata/objects/combat/player.py b/gamedata/objects/combat/player.py index aa82bdf..41964b6 100644 --- a/gamedata/objects/combat/player.py +++ b/gamedata/objects/combat/player.py @@ -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"]])