added walking animation
|
Before Width: | Height: | Size: 720 B After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 812 B After Width: | Height: | Size: 822 B |
|
Before Width: | Height: | Size: 263 B |
|
Before Width: | Height: | Size: 252 B After Width: | Height: | Size: 263 B |
|
After Width: | Height: | Size: 249 B |
|
|
@ -52,6 +52,8 @@ public class PlayerEntity
|
|||
};
|
||||
|
||||
player.Position += movement.CurrentVelocity;
|
||||
if (movement.CurrentVelocity.X != 0)
|
||||
movement.MovingRight = movement.CurrentVelocity.X > 0;
|
||||
}
|
||||
|
||||
public static void Jump(Player player)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ public class Chunk
|
|||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public List<Entity> Entities { get; set; } = new();
|
||||
public Dictionary<(int, int), Entity> TileEntities { get; set; } = new();
|
||||
|
||||
public Chunk(int x, int y)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ public enum ItemId
|
|||
RawUranium = 116,
|
||||
Diamond = 117,
|
||||
PickaxeBasic = 200,
|
||||
PickaxeStone = 201,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ public class ItemRegistry
|
|||
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.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)
|
||||
|
|
|
|||
|
|
@ -8,12 +8,27 @@ namespace Mine2d.game.core.items;
|
|||
|
||||
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()
|
||||
{
|
||||
return ItemKind.Pickaxe;
|
||||
}
|
||||
|
||||
public int GetMiningSpeed()
|
||||
{
|
||||
return this.miningSpeed;
|
||||
}
|
||||
|
||||
public int GetHarvestLevel()
|
||||
{
|
||||
return this.harvestLevel;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ public class PlayerRenderer : IRenderer
|
|||
|
||||
public void Render()
|
||||
{
|
||||
if(this.playerTexture == IntPtr.Zero)
|
||||
if (this.playerTexture == IntPtr.Zero)
|
||||
{
|
||||
this.playerTexture = Context.Get().TextureFactory.LoadTexture("character.character");
|
||||
}
|
||||
|
|
@ -33,12 +33,30 @@ public class PlayerRenderer : IRenderer
|
|||
// 14 * 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(
|
||||
this.playerTexture,
|
||||
width / 2,
|
||||
(height / 2) - (31 * scale),
|
||||
(height / 2) - (32 * scale),
|
||||
16 * scale,
|
||||
32 * scale
|
||||
32 * scale,
|
||||
x,
|
||||
y,
|
||||
16,
|
||||
32
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using Mine2d.game.core.items;
|
||||
|
||||
namespace Mine2d.game.state;
|
||||
|
||||
public class Player
|
||||
|
|
@ -15,11 +17,24 @@ public class Player
|
|||
return this.Position + new Vector2(7, -14);
|
||||
}
|
||||
|
||||
public int GetMiningSpeed() {
|
||||
return 10;
|
||||
private PickaxeItem getPickaxe()
|
||||
{
|
||||
if (this.Inventory.Pickaxe == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public int GetHarvestLevel() {
|
||||
return 1;
|
||||
var item = Context.Get().ItemRegistry.GetItem(this.Inventory.Pickaxe.Id);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ public class PlayerMovementState
|
|||
public bool IsGrounded { get; set; } = false;
|
||||
public Vector2 CurrentVelocity { get; set; } = Vector2.Zero;
|
||||
public Vector2 CurrentMovement { get; set; } = Vector2.Zero;
|
||||
public bool MovingRight { get; set; } = true;
|
||||
}
|
||||