Added falling (& jumping) animation for lion.

Added some grass tiles.
This commit is contained in:
Sander Schobers 2023-06-05 01:31:14 +02:00
parent ced8a1994f
commit 61d024b56d
4 changed files with 17 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -20,6 +20,7 @@ pub const Game = struct {
health: i64 = 4,
playerPosition: engine.PointF,
playerFallingAnimation: Animation,
playerIdleAnimation: Animation,
playerWalkingAnimation: Animation,
playerDirection: Direction,
@ -37,6 +38,7 @@ pub const Game = struct {
return Game{
.level = level,
.playerPosition = playerPosition,
.playerFallingAnimation = Animation.initPartialLoop(renderer.sprites.get("character_lion_48").?, 0.2, 8, 12),
.playerIdleAnimation = Animation.initPartialLoop(renderer.sprites.get("character_lion_48").?, 0.25, 0, 4),
.playerWalkingAnimation = Animation.initPartialLoop(renderer.sprites.get("character_lion_48").?, 0.125, 4, 8),
.playerDirection = Direction.Right,

View File

@ -51,11 +51,17 @@ pub const GameScene = struct {
}
// self.game.playerVelocity.y = std.math.min(maxFallVelocity, self.game.playerVelocity.y + self.game.playerAcceleration.y * dt);
if (self.game.playerVelocity.x != 0 and self.game.playerVelocity.y == 0) {
if (self.game.playerVelocity.y != 0) {
self.game.playerFallingAnimation.tick(t);
self.game.playerIdleAnimation.reset();
self.game.playerWalkingAnimation.reset();
} else if (self.game.playerVelocity.x != 0 and self.game.playerVelocity.y == 0) {
self.game.playerWalkingAnimation.tick(t);
self.game.playerFallingAnimation.tick(t);
self.game.playerIdleAnimation.reset();
} else if (self.game.playerVelocity.x == 0) {
self.game.playerIdleAnimation.tick(t);
self.game.playerFallingAnimation.tick(t);
self.game.playerWalkingAnimation.reset();
}
self.game.movePlayer(dt);
@ -101,10 +107,14 @@ pub const GameScene = struct {
1 => {
if (ordinals.right) offset = 0;
if (ordinals.left) offset = 3;
if (ordinals.top) offset = 15;
if (ordinals.bottom) offset = 14;
},
2 => {
if (ordinals.right and ordinals.left) offset = 1 + self.game.randomTileOffset(x, y, 2);
if (ordinals.top and ordinals.bottom) offset = 12;
if (ordinals.top and ordinals.left) offset = 9;
if (ordinals.top and ordinals.right) offset = 8;
if (ordinals.right and ordinals.bottom) offset = 4;
if (ordinals.left and ordinals.bottom) offset = 5;
},
@ -131,8 +141,10 @@ pub const GameScene = struct {
}
}
const playerDirectionFrameOffset: usize = if (self.game.playerDirection == game.Game.Direction.Left) 0 else 8;
if (self.game.playerVelocity.x != 0 and self.game.playerVelocity.y == 0) {
const playerDirectionFrameOffset: usize = if (self.game.playerDirection == game.Game.Direction.Left) 0 else 12;
if (self.game.playerVelocity.y != 0) {
self.game.drawSpriteFrameP("character_lion_48", self.game.playerFallingAnimation.current + playerDirectionFrameOffset, self.game.playerPosition.add(engine.PointF.init(-0.25, -0.25)));
} else if (self.game.playerVelocity.x != 0 and self.game.playerVelocity.y == 0) {
self.game.drawSpriteFrameP("character_lion_48", self.game.playerWalkingAnimation.current + playerDirectionFrameOffset, self.game.playerPosition.add(engine.PointF.init(-0.25, -0.25)));
} else {
self.game.drawSpriteFrameP("character_lion_48", self.game.playerIdleAnimation.current + playerDirectionFrameOffset, self.game.playerPosition.add(engine.PointF.init(-0.25, -0.25)));