added walking animation

This commit is contained in:
MasterGordon 2023-01-02 18:42:25 +01:00
parent cf9e6eb072
commit 1bc8e5a56f
14 changed files with 63 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 812 B

After

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

View File

@ -52,6 +52,8 @@ public class PlayerEntity
}; };
player.Position += movement.CurrentVelocity; player.Position += movement.CurrentVelocity;
if (movement.CurrentVelocity.X != 0)
movement.MovingRight = movement.CurrentVelocity.X > 0;
} }
public static void Jump(Player player) public static void Jump(Player player)

View File

@ -6,6 +6,7 @@ public class Chunk
public int X { get; set; } public int X { get; set; }
public int Y { get; set; } public int Y { get; set; }
public List<Entity> Entities { get; set; } = new(); public List<Entity> Entities { get; set; } = new();
public Dictionary<(int, int), Entity> TileEntities { get; set; } = new();
public Chunk(int x, int y) public Chunk(int x, int y)
{ {

View File

@ -17,4 +17,5 @@ public enum ItemId
RawUranium = 116, RawUranium = 116,
Diamond = 117, Diamond = 117,
PickaxeBasic = 200, PickaxeBasic = 200,
PickaxeStone = 201,
} }

View File

@ -30,7 +30,8 @@ public class ItemRegistry
this.Register(ItemId.RawTungsten, new Item(ItemId.RawTungsten, "Raw Tungsten", "items.raw-tungsten" )); this.Register(ItemId.RawTungsten, new Item(ItemId.RawTungsten, "Raw Tungsten", "items.raw-tungsten" ));
this.Register(ItemId.RawUranium, new Item(ItemId.RawUranium, "Raw Uranium", "items.raw-uranium" )); this.Register(ItemId.RawUranium, new Item(ItemId.RawUranium, "Raw Uranium", "items.raw-uranium" ));
this.Register(ItemId.Diamond, new Item(ItemId.Diamond, "Diamond", "items.diamond" )); this.Register(ItemId.Diamond, new Item(ItemId.Diamond, "Diamond", "items.diamond" ));
this.Register(ItemId.PickaxeBasic, new PickaxeItem(ItemId.PickaxeBasic, "Basic Pickaxe", "items.pickaxe-basic")); this.Register(ItemId.PickaxeBasic, new PickaxeItem(ItemId.PickaxeBasic, "Basic Pickaxe", "items.pickaxe-basic", 15, 4));
this.Register(ItemId.PickaxeStone, new PickaxeItem(ItemId.PickaxeStone, "Stone Pickaxe", "items.pickaxe-stone", 25, 6));
} }
public void Register(ItemId id, Item item) public void Register(ItemId id, Item item)

View File

@ -8,12 +8,27 @@ namespace Mine2d.game.core.items;
public class PickaxeItem : Item public class PickaxeItem : Item
{ {
public PickaxeItem(ItemId id, string name, string textureName) : base(id, name, textureName) private readonly int miningSpeed;
private readonly int harvestLevel;
public PickaxeItem(ItemId id, string name, string textureName, int miningSpeed, int harvestLevel) : base(id, name, textureName)
{ {
this.miningSpeed = miningSpeed;
this.harvestLevel = harvestLevel;
} }
public override ItemKind GetKind() public override ItemKind GetKind()
{ {
return ItemKind.Pickaxe; return ItemKind.Pickaxe;
} }
public int GetMiningSpeed()
{
return this.miningSpeed;
}
public int GetHarvestLevel()
{
return this.harvestLevel;
}
} }

View File

@ -33,12 +33,30 @@ public class PlayerRenderer : IRenderer
// 14 * scale, // 14 * scale,
// 28 * scale // 28 * scale
// ); // );
var y = player.PlayerMovementState.MovingRight ? 32 * 3 : 32 * 1;
var moving = player.PlayerMovementState.CurrentVelocity.X != 0;
var dt = (DateTime.Now - DateTime.MinValue).TotalMilliseconds;
var x = 0;
if(moving)
{
x = (int)((dt / 100) % 6) * 16;
y += 32;
}
if(!player.PlayerMovementState.IsGrounded)
{
x = 0;
y = player.PlayerMovementState.MovingRight ? 32 * 6 : 32 * 5;
}
ctx.Renderer.DrawTexture( ctx.Renderer.DrawTexture(
this.playerTexture, this.playerTexture,
width / 2, width / 2,
(height / 2) - (31 * scale), (height / 2) - (32 * scale),
16 * scale, 16 * scale,
32 * scale 32 * scale,
x,
y,
16,
32
); );
} }
} }

View File

@ -1,3 +1,5 @@
using Mine2d.game.core.items;
namespace Mine2d.game.state; namespace Mine2d.game.state;
public class Player public class Player
@ -15,11 +17,24 @@ public class Player
return this.Position + new Vector2(7, -14); return this.Position + new Vector2(7, -14);
} }
public int GetMiningSpeed() { private PickaxeItem getPickaxe()
return 10; {
if (this.Inventory.Pickaxe == null)
{
return null;
} }
public int GetHarvestLevel() { var item = Context.Get().ItemRegistry.GetItem(this.Inventory.Pickaxe.Id);
return 1; return item as PickaxeItem;
}
public int GetMiningSpeed()
{
return this.getPickaxe() == null ? 1 : this.getPickaxe().GetMiningSpeed();
}
public int GetHarvestLevel()
{
return this.getPickaxe() == null ? 1 : this.getPickaxe().GetHarvestLevel();
} }
} }

View File

@ -11,4 +11,5 @@ public class PlayerMovementState
public bool IsGrounded { get; set; } = false; public bool IsGrounded { get; set; } = false;
public Vector2 CurrentVelocity { get; set; } = Vector2.Zero; public Vector2 CurrentVelocity { get; set; } = Vector2.Zero;
public Vector2 CurrentMovement { get; set; } = Vector2.Zero; public Vector2 CurrentMovement { get; set; } = Vector2.Zero;
public bool MovingRight { get; set; } = true;
} }