Compare commits

..

No commits in common. "main" and "v0.1" have entirely different histories.
main ... v0.1

53 changed files with 80 additions and 339 deletions

View File

@ -22,18 +22,11 @@ jobs:
- name: Build - name: Build
run: dotnet build --no-restore run: dotnet build --no-restore
- name: Publish - name: Publish
run: cd Mine2d && make run: dotnet publish -r linux-x64 --self-contained
- name: Upload a Build Artifact - name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.0 uses: actions/upload-artifact@v3.1.0
with: with:
# Artifact name # Artifact name
name: Linux build name: Linux build
# A file, directory or wildcard pattern that describes what to upload # A file, directory or wildcard pattern that describes what to upload
path: Mine2d/build/linux-64.zip path: Mine2d/bin/Debug/net6.0/linux-x64/publish/Mine2d
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.0
with:
# Artifact name
name: Windows build
# A file, directory or wildcard pattern that describes what to upload
path: Mine2d/build/win-64.zip

1
Mine2d/.gitignore vendored
View File

@ -1 +0,0 @@
build/

View File

@ -1,14 +0,0 @@
all: win-64 linux-64
win-64:
dotnet publish --runtime win-x64 --output build/win-64
cp credits.md build/win-64
zip -r build/win-64.zip build/win-64
linux-64:
dotnet publish --runtime linux-x64 --output build/linux-64
cp credits.md build/linux-64
zip -r build/linux-64.zip build/linux-64
clean:
rm -rf build

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

View File

@ -1,17 +0,0 @@
# Credits of used assets and Libraries
## Assets
* Character - [CutieCatTv](https://github.com/CutieCatTv)
* Nova Mono Font - Open Font License
* audio/block_break.wav - dxeyes - CC BY 4.0
* audio/block_hit.wav - MattRuthSound - CC BY 4.0
* audio/block_hit_alt.wav - MattRuthSound - CC BY 4.0
* audio/music-loop.wav - [Chris aka el3usis](https://www.youtube.com/@Eleusis/featured)
## Libraries
* SDL2# - zlib
* SDL2 - zlib
* Newtonsoft.Json - MIT
* WatsonTcp - MIT

View File

@ -5,13 +5,6 @@ public enum Sound
BlockHit, BlockHit,
BlockBreak, BlockBreak,
ItemPickup, ItemPickup,
MusicLoop,
Step0,
Step1,
Step2,
Step3,
Step4,
Step5,
} }
public class AudioPlayer public class AudioPlayer

View File

@ -11,7 +11,7 @@ public class ResourceLoader
this.assemblyName = this.GetType().Assembly.GetName().Name!; this.assemblyName = this.GetType().Assembly.GetName().Name!;
} }
public string LoadString(string resourceName) public static string LoadString(string resourceName)
{ {
#if DEBUG #if DEBUG
Console.WriteLine("Loading resource: " + resourceName); Console.WriteLine("Loading resource: " + resourceName);

View File

@ -14,10 +14,6 @@ public class Window
h, h,
SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_RESIZABLE SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_RESIZABLE
); );
var (ptr, size) = new ResourceLoader().LoadToIntPtr("assets.icon.png");
var sdlBuffer = SDL_RWFromMem(ptr, size);
var surface = IMG_Load_RW(sdlBuffer, 1);
SDL_SetWindowIcon(this.window, surface);
} }
public Window(string title, int x, int y, int w, int h, SDL_WindowFlags flags) public Window(string title, int x, int y, int w, int h, SDL_WindowFlags flags)

View File

@ -1,7 +1,6 @@
using Mine2d.engine; using Mine2d.engine;
using Mine2d.engine.system.annotations; using Mine2d.engine.system.annotations;
using Mine2d.game.backend.network.packets; using Mine2d.game.backend.network.packets;
using Mine2d.game.core;
namespace Mine2d.game.backend.interactor; namespace Mine2d.game.backend.interactor;
@ -14,35 +13,4 @@ public class Audio
var ctx = Context.Get(); var ctx = Context.Get();
ctx.GameAudio.Play(Sound.BlockBreak); ctx.GameAudio.Play(Sound.BlockBreak);
} }
[Interaction(InteractorKind.Client, PacketType.Tick)]
public static void Tick()
{
var ctx = Context.Get();
if (ctx.FrontendGameState.NextMusicPlay < DateTime.Now)
{
ctx.GameAudio.Play(Sound.MusicLoop);
ctx.FrontendGameState.NextMusicPlay = DateTime.Now.AddSeconds(130);
}
if (false && ctx.FrontendGameState.NextStepPlay < DateTime.Now && PlayerEntity.GetSelf().PlayerMovementState.CurrentVelocity != Vector2.Zero)
{
ctx.GameAudio.Play(GetRandomStepSound());
ctx.FrontendGameState.NextStepPlay = DateTime.Now.AddSeconds(0.2);
}
}
private static Sound GetRandomStepSound()
{
var sound = new Random().NextInt64(0, 6);
return sound switch
{
0 => Sound.Step0,
1 => Sound.Step1,
2 => Sound.Step2,
3 => Sound.Step3,
4 => Sound.Step4,
5 => Sound.Step5,
_ => Sound.Step0
};
}
} }

View File

@ -39,8 +39,8 @@ public class Breaking
{ {
var tileRegistry = ctx.TileRegistry; var tileRegistry = ctx.TileRegistry;
var hardness = tileRegistry.GetTile(tileId).Hardness; var hardness = tileRegistry.GetTile(tileId).Hardness;
var hardnessBonus = Math.Min(1, player.GetHarvestLevel() / (double)hardness); var hardnessBonus = Math.Min(1, player.GetHarvestLevel() / hardness);
player.MiningCooldown = (int)(50 - (player.GetMiningSpeed() * hardnessBonus)); player.MiningCooldown = 50 - (player.GetMiningSpeed() * hardnessBonus);
if(tile.Hits == 0) { if(tile.Hits == 0) {
ctx.GameState.World.Cracks.Enqueue(new CrackQueueEntry ctx.GameState.World.Cracks.Enqueue(new CrackQueueEntry
{ {
@ -83,7 +83,7 @@ public class Breaking
} }
[Interaction(InteractorKind.Server, PacketType.BlockBroken)] [Interaction(InteractorKind.Server, PacketType.BlockBroken)]
public static void BlockBrokenServer(BlockBrokenPacket packet) public static void BreakServer(BlockBrokenPacket packet)
{ {
var ctx = Context.Get(); var ctx = Context.Get();
var tile = ctx.TileRegistry.GetTile(packet.Tile.Id); var tile = ctx.TileRegistry.GetTile(packet.Tile.Id);

View File

@ -21,7 +21,12 @@ public class Connect
Position = new Vector2(512244, 5390), Position = new Vector2(512244, 5390),
}; };
ctx.GameState.Players.Add( ctx.GameState.Players.Add(
player new Player
{
Name = packet.PlayerName,
Id = packet.PlayerGuid,
Position = new Vector2(512244, 5390),
}
); );
} }
} }

View File

@ -10,6 +10,8 @@ public class Bootstrapper
{ {
var ctx = Context.Get(); var ctx = Context.Get();
ctx.GameState.World = new World(); ctx.GameState.World = new World();
ChunkGenerator.CreateSpawnChunk(1000, 10); ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(0, 1, STile.From(Tiles.Stone)));
ctx.GameState.World.AddChunk(ChunkGenerator.CreateSpawnChunk(1000, 10));
ctx.GameState.World.AddChunk(ChunkGenerator.CreateFilledChunk(1, 0, STile.From(Tiles.Stone)));
} }
} }

View File

@ -15,6 +15,6 @@ public class Camera
var scale = ctx.FrontendGameState.Settings.GameScale; var scale = ctx.FrontendGameState.Settings.GameScale;
var windowWidth = ctx.FrontendGameState.WindowWidth; var windowWidth = ctx.FrontendGameState.WindowWidth;
var windowHeight = ctx.FrontendGameState.WindowHeight; var windowHeight = ctx.FrontendGameState.WindowHeight;
this.Position = target - (new Vector2(windowWidth, windowHeight) / 2 / scale); this.Position = target - (new Vector2(windowWidth, windowHeight) / 2) / scale;
} }
} }

View File

@ -1,3 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mine2d.game.core; namespace Mine2d.game.core;
public static class Debugger public static class Debugger
@ -6,4 +11,4 @@ public static class Debugger
{ {
Context.Get().FrontendGameState.DebugState.Messages.Enqueue(message); Context.Get().FrontendGameState.DebugState.Messages.Enqueue(message);
} }
} }

View File

@ -76,8 +76,8 @@ public class PlayerEntity
bool hasCollision; bool hasCollision;
do do
{ {
var pL = player.Position + new Vector2(3, -2); var pL = player.Position + new Vector2(0, -8);
var pL2 = player.Position + new Vector2(3, -24); var pL2 = player.Position + new Vector2(0, -24);
hasCollision = hasCollision =
(world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL)) (world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL))
|| (world.HasChunkAt(pL2) && world.GetChunkAt(pL2).HasSolidTileAt(pL2)); || (world.HasChunkAt(pL2) && world.GetChunkAt(pL2).HasSolidTileAt(pL2));
@ -89,8 +89,8 @@ public class PlayerEntity
} while (hasCollision); } while (hasCollision);
do do
{ {
var pR = player.Position + new Vector2(12, -2); var pR = player.Position + new Vector2(14, -8);
var pR2 = player.Position + new Vector2(12, -24); var pR2 = player.Position + new Vector2(14, -24);
hasCollision = hasCollision =
(world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR)) (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR))
|| (world.HasChunkAt(pR2) && world.GetChunkAt(pR2).HasSolidTileAt(pR2)); || (world.HasChunkAt(pR2) && world.GetChunkAt(pR2).HasSolidTileAt(pR2));
@ -102,8 +102,8 @@ public class PlayerEntity
} while (hasCollision); } while (hasCollision);
do do
{ {
var pL = player.Position + new Vector2(3, 0); var pL = player.Position + new Vector2(0, 0);
var pR = player.Position + new Vector2(12, 0); var pR = player.Position + new Vector2(14, 0);
hasCollision = hasCollision =
(world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL)) (world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL))
|| (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR)); || (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR));
@ -115,8 +115,8 @@ public class PlayerEntity
} while (hasCollision); } while (hasCollision);
do do
{ {
var pL = player.Position + new Vector2(3, -28); var pL = player.Position + new Vector2(0, -28);
var pR = player.Position + new Vector2(12, -28); var pR = player.Position + new Vector2(14, -28);
hasCollision = hasCollision =
(world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL)) (world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL))
|| (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR)); || (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR));
@ -129,8 +129,8 @@ public class PlayerEntity
{ {
var groundCheckPosition = player.Position - new Vector2(0, -1f); var groundCheckPosition = player.Position - new Vector2(0, -1f);
var pL = groundCheckPosition + new Vector2(3, 0); var pL = groundCheckPosition + new Vector2(0, 0);
var pR = groundCheckPosition + new Vector2(12, 0); var pR = groundCheckPosition + new Vector2(14, 0);
movement.IsGrounded = (world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL)) movement.IsGrounded = (world.HasChunkAt(pL) && world.GetChunkAt(pL).HasSolidTileAt(pL))
|| (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR)); || (world.HasChunkAt(pR) && world.GetChunkAt(pR).HasSolidTileAt(pR));
} }

View File

@ -19,16 +19,8 @@ public enum ItemId
Coal = 120, Coal = 120,
GoldIngot = 121, GoldIngot = 121,
IronIngot = 122, IronIngot = 122,
CopperIngot = 123,
SilverIngot = 124,
PickaxeBasic = 200, PickaxeBasic = 200,
PickaxeStone = 201, PickaxeStone = 201,
PickaxeIron = 202, PickaxeIron = 202,
PickaxeGold = 203, PickaxeGold = 203,
CopperWire = 300,
Silicon = 301,
CircuitBoard = 302,
ElectricCircuit = 303,
Fuse = 304,
Gps = 400,
} }

View File

@ -36,9 +36,4 @@ public class ItemStack
{ {
return Context.Get().ItemRegistry.GetItem(this.Id).GetKind(); return Context.Get().ItemRegistry.GetItem(this.Id).GetKind();
} }
public ItemStack Clone()
{
return new ItemStack(this.Id, this.Count);
}
} }

View File

@ -31,24 +31,12 @@ public class ItemRegistry
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.Coal, new Item(ItemId.Coal, "Coal", "items.coal" )); this.Register(ItemId.Coal, new Item(ItemId.Coal, "Coal", "items.coal" ));
// Ingots
this.Register(ItemId.IronIngot, new Item(ItemId.IronIngot, "Iron Ingot", "items.ingot-iron" )); this.Register(ItemId.IronIngot, new Item(ItemId.IronIngot, "Iron Ingot", "items.ingot-iron" ));
this.Register(ItemId.GoldIngot, new Item(ItemId.GoldIngot, "Gold Ingot", "items.ingot-gold" )); this.Register(ItemId.GoldIngot, new Item(ItemId.GoldIngot, "Gold Ingot", "items.ingot-gold" ));
this.Register(ItemId.CopperIngot, new Item(ItemId.CopperIngot, "Copper Ingot", "items.ingot-copper" ));
this.Register(ItemId.SilverIngot, new Item(ItemId.SilverIngot, "Silver Ingot", "items.ingot-silver" ));
// Pickaxes
this.Register(ItemId.PickaxeBasic, new PickaxeItem(ItemId.PickaxeBasic, "Basic Pickaxe", "items.pickaxe-basic", 15, 4)); 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)); this.Register(ItemId.PickaxeStone, new PickaxeItem(ItemId.PickaxeStone, "Stone Pickaxe", "items.pickaxe-stone", 25, 6));
this.Register(ItemId.PickaxeIron, new PickaxeItem(ItemId.PickaxeIron, "Iron Pickaxe", "items.pickaxe-iron", 30, 7)); this.Register(ItemId.PickaxeIron, new PickaxeItem(ItemId.PickaxeIron, "Iron Pickaxe", "items.pickaxe-iron", 40, 7));
this.Register(ItemId.PickaxeGold, new PickaxeItem(ItemId.PickaxeGold, "Gold Pickaxe", "items.pickaxe-gold", 35, 9)); this.Register(ItemId.PickaxeGold, new PickaxeItem(ItemId.PickaxeGold, "Gold Pickaxe", "items.pickaxe-gold", 60, 8));
// Materials
this.Register(ItemId.CopperWire, new Item(ItemId.CopperWire, "Copper Wire", "items.copper-wire" ));
this.Register(ItemId.Silicon, new Item(ItemId.Silicon, "Silicon", "items.silicon" ));
this.Register(ItemId.CircuitBoard, new Item(ItemId.CircuitBoard, "Circuit Board", "items.circuit-board" ));
this.Register(ItemId.ElectricCircuit, new Item(ItemId.ElectricCircuit, "Electric Circuit", "items.electric-circuit" ));
this.Register(ItemId.Fuse, new Item(ItemId.Fuse, "Fuse", "items.fuse" ));
// Utilities
this.Register(ItemId.Gps, new Item(ItemId.Gps, "GPS", "items.gps" ));
} }
public void Register(ItemId id, Item item) public void Register(ItemId id, Item item)

View File

@ -33,13 +33,17 @@ public class TileRegistry
public void RegisterTile() public void RegisterTile()
{ {
this.Tiles.Add(1, new Tile("stone", "stone", 5, ItemId.Stone)); this.Tiles.Add(1, new Tile("stone", "stone", 5, ItemId.Stone));
this.Tiles.Add(2, new OreTile("ore1", new[] { "stone", "ore1" }, 5));
this.Tiles.Add(3, new OreTile("ore2", new[] { "stone", "ore2" }, 7));
this.Tiles.Add(4, new OreTile("ore3", new[] { "stone", "ore3" }, 8));
this.Tiles.Add(5, new OreTile("ore4", new[] { "stone", "ore4" }, 10));
this.Tiles.Add(6, new Workbench("workbench", "workbench", 10)); this.Tiles.Add(6, new Workbench("workbench", "workbench", 10));
this.Tiles.Add(7, new OreTile("iron-ore", new[] { "stone", "iron-ore" }, 6, ItemId.RawIron)); this.Tiles.Add(7, new OreTile("iron-ore", new[] { "stone", "iron-ore" }, 6, ItemId.RawIron));
this.Tiles.Add(8, new OreTile("copper-ore", new[] { "stone", "copper-ore" }, 6, ItemId.RawCopper)); this.Tiles.Add(8, new OreTile("copper-ore", new[] { "stone", "copper-ore" }, 6, ItemId.RawCopper));
this.Tiles.Add(9, new OreTile("tin-ore", new[] { "stone", "tin-ore" }, 7, ItemId.RawTin)); this.Tiles.Add(9, new OreTile("tin-ore", new[] { "stone", "tin-ore" }, 6, ItemId.RawTin));
this.Tiles.Add(10, new OreTile("silver-ore", new[] { "stone", "silver-ore" }, 7, ItemId.RawSilver)); this.Tiles.Add(10, new OreTile("silver-ore", new[] { "stone", "silver-ore" }, 7, ItemId.RawSilver));
this.Tiles.Add(12, new OreTile("lead-ore", new[] { "stone", "lead-ore" }, 8, ItemId.RawLead)); this.Tiles.Add(11, new OreTile("gold-ore", new[] { "stone", "gold-ore" }, 8, ItemId.RawGold));
this.Tiles.Add(11, new OreTile("gold-ore", new[] { "stone", "gold-ore" }, 9, ItemId.RawGold)); this.Tiles.Add(12, new OreTile("lead-ore", new[] { "stone", "lead-ore" }, 9, ItemId.RawLead));
this.Tiles.Add(13, new OreTile("platinum-ore", new[] { "stone", "platinum-ore" }, 10, ItemId.RawPlatinum)); this.Tiles.Add(13, new OreTile("platinum-ore", new[] { "stone", "platinum-ore" }, 10, ItemId.RawPlatinum));
this.Tiles.Add(14, new OreTile("cobalt-ore", new[] { "stone", "cobalt-ore" }, 11, ItemId.RawCobalt)); this.Tiles.Add(14, new OreTile("cobalt-ore", new[] { "stone", "cobalt-ore" }, 11, ItemId.RawCobalt));
this.Tiles.Add(15, new OreTile("tungsten-ore", new[] { "stone", "tungsten-ore" }, 15, ItemId.RawTungsten)); this.Tiles.Add(15, new OreTile("tungsten-ore", new[] { "stone", "tungsten-ore" }, 15, ItemId.RawTungsten));

View File

@ -64,86 +64,6 @@ public class Workbench : Tile
new ItemStack(ItemId.RawGold, 1), new ItemStack(ItemId.RawGold, 1),
} }
}); });
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.CopperIngot, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.Coal, 1),
new ItemStack(ItemId.RawCopper, 1),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.SilverIngot, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.Coal, 1),
new ItemStack(ItemId.RawSilver, 1),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.CopperWire, 4),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.CopperIngot, 1),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.Silicon, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.Stone, 16),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.CircuitBoard, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.Silicon, 1),
new ItemStack(ItemId.CopperWire, 1),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.ElectricCircuit, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.CircuitBoard, 1),
new ItemStack(ItemId.CopperWire, 5),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.Fuse, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.CopperWire, 1),
new ItemStack(ItemId.Stone, 1),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.Gps, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.ElectricCircuit, 1),
new ItemStack(ItemId.Fuse, 1),
}
});
Recipes.Add(new Recipe
{
Result = new ItemStack(ItemId.Workbench, 1),
Ingredients = new List<ItemStack>
{
new ItemStack(ItemId.Stone, 1),
new ItemStack(ItemId.Fuse, 1),
new ItemStack(ItemId.CopperWire, 3),
}
});
} }
public override bool IsSolid() public override bool IsSolid()

View File

@ -33,8 +33,8 @@ public class ChunkGenerator
{ {
for (var j = 0; j < Constants.ChunkSize; j++) for (var j = 0; j < Constants.ChunkSize; j++)
{ {
var n = Noise.coherentNoise((int)((i + (x * 32)) * 0.6), (int)((j + (y * 32)) * 1), 0, 1, 25, 0.5f, 0.9f); var n = (Noise.coherentNoise(i + (x * 32), j + (y * 32), 0, 1, 25, 0.5f, 0.9f));
var n2 = Noise2.coherentNoise((int)((i + (x * 32)) * 0.6), (int)((j + (y * 32)) * 1), 0, 1, 25, 0.5f, 0.9f); var n2 = (Noise2.coherentNoise(i + (x * 32), j + (y * 32), 0, 1, 25, 0.5f, 0.9f));
// Console.WriteLine(i * (x * 32) + " "+ j * (y * 32)); // Console.WriteLine(i * (x * 32) + " "+ j * (y * 32));
if (n > 0.08 || n2 > 0.08) continue; if (n > 0.08 || n2 > 0.08) continue;
chunk.SetTile(i, j, fill); chunk.SetTile(i, j, fill);
@ -65,30 +65,10 @@ public class ChunkGenerator
else else
{ {
fill.Id = (int)WG.GetRandomOreAt(j + (y * 32)); fill.Id = (int)WG.GetRandomOreAt(j + (y * 32));
if (new Random().NextInt64(0, 100) < 1) if (new Random().NextInt64(0, 130) < 1)
{ {
fill.Id = (int)Tiles.CoalOre; fill.Id = (int)Tiles.CoalOre;
} }
if (fill.Id != 1)
{
var pX = i;
var pY = j;
var maxCount = new Random().NextInt64(fill.Id == (int)Tiles.CoalOre ? 3 : 1, fill.Id == (int)Tiles.CoalOre ? 10 : 6);
for (var count = 0; count < maxCount; count++)
{
var delta = new Random().NextInt64(-1, 2);
var dir = new Random().NextInt64(0, 2);
pX += (int)(dir == 0 ? delta : 0);
pY += (int)(dir == 1 ? delta : 0);
Console.WriteLine("Try Adding ader");
Console.WriteLine(pX + " " + pY);
if (chunk.HasTile(pX, pY))
{
chunk.SetTile(pX, pY, STile.From(fill.Id));
Console.WriteLine("Adding ader");
}
}
}
chunk.SetTile(i, j, fill); chunk.SetTile(i, j, fill);
} }
} }
@ -96,9 +76,16 @@ public class ChunkGenerator
return chunk; return chunk;
} }
public static void CreateSpawnChunk(int x, int y) public static Chunk CreateSpawnChunk(int x, int y)
{ {
var chunk = CreateChunk(x, y); var chunk = new Chunk(x, y);
for (var i = 0; i < Constants.ChunkSize; i++)
{
for (var j = 0; j < Constants.ChunkSize; j++)
{
chunk.SetTile(i, j, STile.From(Tiles.Stone));
}
}
chunk.SetTile(16, 16, STile.From(0)); chunk.SetTile(16, 16, STile.From(0));
chunk.SetTile(15, 16, STile.From(0)); chunk.SetTile(15, 16, STile.From(0));
chunk.SetTile(16, 15, STile.From(0)); chunk.SetTile(16, 15, STile.From(0));
@ -108,12 +95,7 @@ public class ChunkGenerator
chunk.SetTile(17, 16, STile.From(0)); chunk.SetTile(17, 16, STile.From(0));
chunk.SetTile(14, 16, STile.From(0)); chunk.SetTile(14, 16, STile.From(0));
chunk.SetTile(16, 14, STile.From(0)); chunk.SetTile(16, 14, STile.From(0));
chunk.SetTile(15, 14, STile.From(0));
chunk.SetTile(17, 16, STile.From((int)Tiles.Workbench)); chunk.SetTile(17, 16, STile.From((int)Tiles.Workbench));
chunk.SetTile(14, 17, STile.From((int)Tiles.Stone)); return chunk;
chunk.SetTile(15, 17, STile.From((int)Tiles.Stone));
chunk.SetTile(16, 17, STile.From((int)Tiles.Stone));
chunk.SetTile(17, 17, STile.From((int)Tiles.Stone));
Context.Get().GameState.World.AddChunk(chunk);
} }
} }

View File

@ -101,7 +101,7 @@ public class WorldGenerator
} }
} }
var rng = random.Next(0, 1050); var rng = random.Next(0, 700);
if (rng < ores.Count) if (rng < ores.Count)
{ {
return ores[rng]; return ores[rng];

View File

@ -12,13 +12,6 @@ public class GameAudio
this.audioPlayer.Register(Sound.BlockBreak, "assets.audio.block_break.wav"); this.audioPlayer.Register(Sound.BlockBreak, "assets.audio.block_break.wav");
this.audioPlayer.Register(Sound.BlockHit, "assets.audio.block_hit_alt.wav"); this.audioPlayer.Register(Sound.BlockHit, "assets.audio.block_hit_alt.wav");
this.audioPlayer.Register(Sound.ItemPickup, "assets.audio.item_pickup.wav"); this.audioPlayer.Register(Sound.ItemPickup, "assets.audio.item_pickup.wav");
this.audioPlayer.Register(Sound.MusicLoop, "assets.audio.music-loop.wav");
this.audioPlayer.Register(Sound.Step0, "assets.audio.step0.wav");
this.audioPlayer.Register(Sound.Step1, "assets.audio.step1.wav");
this.audioPlayer.Register(Sound.Step2, "assets.audio.step2.wav");
this.audioPlayer.Register(Sound.Step3, "assets.audio.step3.wav");
this.audioPlayer.Register(Sound.Step4, "assets.audio.step4.wav");
this.audioPlayer.Register(Sound.Step5, "assets.audio.step5.wav");
} }
public void Play(Sound sound) public void Play(Sound sound)

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Mine2d.engine;
using Mine2d.game.core.data; using Mine2d.game.core.data;
namespace Mine2d.game.frontend; namespace Mine2d.game.frontend;
@ -16,11 +15,6 @@ public static class ItemRenderer
var texture = stack.GetTexture(); var texture = stack.GetTexture();
var renderer = Context.Get().Renderer; var renderer = Context.Get().Renderer;
var uiScale = Context.Get().FrontendGameState.Settings.UiScale; var uiScale = Context.Get().FrontendGameState.Settings.UiScale;
Renderer.ProcessStatus(SDL_SetTextureColorMod(texture, 0, 0, 0));
Renderer.ProcessStatus(SDL_SetTextureAlphaMod(texture, 128));
renderer.DrawTexture(texture, (int)position.X + uiScale, (int)position.Y + uiScale, 16 * uiScale, 16 * uiScale);
Renderer.ProcessStatus(SDL_SetTextureColorMod(texture, 255, 255, 255));
Renderer.ProcessStatus(SDL_SetTextureAlphaMod(texture, 255));
renderer.DrawTexture(texture, (int)position.X, (int)position.Y, 16 * uiScale, 16 * uiScale); renderer.DrawTexture(texture, (int)position.X, (int)position.Y, 16 * uiScale, 16 * uiScale);
if (stack.Count > 1) if (stack.Count > 1)
{ {

View File

@ -54,7 +54,7 @@ public class PlayerInventoryRenderer : Inventory
var pickaxe = player.Inventory.Pickaxe; var pickaxe = player.Inventory.Pickaxe;
if (pickaxe != null) if (pickaxe != null)
{ {
ItemRenderer.RenderItemStack(pickaxe, new Vector2(((4 + (9 * 21)) * uiScale) + x, (((5 * 21) + 4) * uiScale) + y), player.Inventory.Cursor == null); ItemRenderer.RenderItemStack(pickaxe, new Vector2(((4 + (9 * 21)) * uiScale) + x, (((5 * 21) + 4) * uiScale) + y), player.Inventory.Cursor == null, "Test\nTT");
} }
} }

View File

@ -30,24 +30,14 @@ public class WorkbenchInventory : Inventory
PlayerInventoryRenderer.Render(this.x, this.y + (50 * uiScale)); PlayerInventoryRenderer.Render(this.x, this.y + (50 * uiScale));
var rX = this.x + (4 * uiScale); var rX = this.x + (4 * uiScale);
var xOffset = 0;
var yOffset = 0;
var rY = this.y + (4 * uiScale); var rY = this.y + (4 * uiScale);
foreach (var r in Workbench.Recipes) foreach ( var r in Workbench.Recipes) {
{
var desc = "Requires:\n"; var desc = "Requires:\n";
foreach (var i in r.Ingredients) foreach (var i in r.Ingredients) {
{
desc += $"{i.Count}x {i.GetName()}\n"; desc += $"{i.Count}x {i.GetName()}\n";
} }
ItemRenderer.RenderItemStack(r.Result, new Vector2(rX + xOffset, rY + yOffset), true, desc); ItemRenderer.RenderItemStack(r.Result, new Vector2(rX, rY), true, desc);
rX += 21 * uiScale;
xOffset += 21 * uiScale;
if (xOffset == 21 * uiScale * 9)
{
xOffset = 0;
yOffset += 21 * uiScale;
}
} }
} }
@ -59,39 +49,27 @@ public class WorkbenchInventory : Inventory
var cursorPosition = Context.Get().FrontendGameState.CursorPosition; var cursorPosition = Context.Get().FrontendGameState.CursorPosition;
var player = PlayerEntity.GetSelf(); var player = PlayerEntity.GetSelf();
var rX = this.x + (4 * uiScale); var rX = this.x + (4 * uiScale);
var xOffset = 0;
var yOffset = 0;
var rY = this.y + (4 * uiScale); var rY = this.y + (4 * uiScale);
foreach (var r in Workbench.Recipes) foreach ( var r in Workbench.Recipes) {
{ if(cursorPosition.X >= rX && cursorPosition.X <= rX + (21 * uiScale) && cursorPosition.Y >= rY && cursorPosition.Y <= rY + (21 * uiScale)) {
if (cursorPosition.X >= rX + xOffset && cursorPosition.X <= rX + xOffset + (21 * uiScale) && cursorPosition.Y >= rY + yOffset && cursorPosition.Y <= rY + yOffset + (21 * uiScale))
{
Console.WriteLine("Clicked on recipe" + r.Result.GetName()); Console.WriteLine("Clicked on recipe" + r.Result.GetName());
var canCraft = true; var canCraft = true;
foreach (var i in r.Ingredients) foreach (var i in r.Ingredients) {
{ if (!player.Inventory.HasItemStack(i)) {
if (!player.Inventory.HasItemStack(i))
{
canCraft = false; canCraft = false;
break; break;
} }
} }
if (canCraft) if (canCraft) {
{ foreach (var i in r.Ingredients) {
foreach (var i in r.Ingredients)
{
player.Inventory.RemoveItemStack(i); player.Inventory.RemoveItemStack(i);
} }
player.Inventory.PickupItemStack(r.Result.Clone()); player.Inventory.PickupItemStack(r.Result);
} }
} }
xOffset += 21 * uiScale;
if (xOffset == 21 * uiScale * 9) rX += 21 * uiScale;
{
xOffset = 0;
yOffset += 21 * uiScale;
}
} }
} }
} }

View File

@ -1,7 +1,6 @@
using Mine2d.engine; using Mine2d.engine;
using Mine2d.engine.utils; using Mine2d.engine.utils;
using Mine2d.game.core; using Mine2d.game.core;
using Mine2d.game.core.data;
namespace Mine2d.game.frontend.renderer; namespace Mine2d.game.frontend.renderer;
@ -31,7 +30,6 @@ public class HudRenderer : IRenderer
public void Render() public void Render()
{ {
this.RenderHotbar(); this.RenderHotbar();
this.RenderGps();
} }
private void RenderHotbar() private void RenderHotbar()
@ -54,22 +52,4 @@ public class HudRenderer : IRenderer
ItemRenderer.RenderItemStack(stack, new Vector2((4 + (i * 24)) * uiScale, 4 * uiScale)); ItemRenderer.RenderItemStack(stack, new Vector2((4 + (i * 24)) * uiScale, 4 * uiScale));
} }
} }
private void RenderGps()
{
var player = PlayerEntity.GetSelf();
if (player?.Inventory.HasItemStack(new ItemStack(ItemId.Gps, 1)) != true) return;
var renderer = Context.Get().Renderer;
var (wWidth, _) = Context.Get().Window.GetSize();
var x = player.PrettyPosition.X.ToString("F2");
var y = player.PrettyPosition.Y.ToString("F2");
var (texture, width, height, surfaceMessage) = renderer.CreateTextTexture("GPS");
renderer.DrawTexture(texture, wWidth - width, 0, width, height);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surfaceMessage);
(texture, width, height, surfaceMessage) = renderer.CreateTextTexture($"X: {x} Y: {y}");
renderer.DrawTexture(texture, wWidth - width, height, width, height);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surfaceMessage);
}
} }

View File

@ -30,7 +30,6 @@ public class TooltipRenderer : IRenderer
var tooltipX = (int)tooltipPosition.X; var tooltipX = (int)tooltipPosition.X;
var tooltipY = (int)tooltipPosition.Y; var tooltipY = (int)tooltipPosition.Y;
var (texture, width, height, surfaceMessage) = renderer.CreateTextTexture(tooltip); var (texture, width, height, surfaceMessage) = renderer.CreateTextTexture(tooltip);
var tooltipWidth = Math.Min(300, width);
renderer.DrawTexture( renderer.DrawTexture(
this.tooltipTexture, this.tooltipTexture,
tooltipX, tooltipX,
@ -47,7 +46,7 @@ public class TooltipRenderer : IRenderer
this.tooltipTexture, this.tooltipTexture,
tooltipX + 4 * uiScale, tooltipX + 4 * uiScale,
tooltipY, tooltipY,
tooltipWidth, width,
4 * uiScale, 4 * uiScale,
4, 4,
0, 0,
@ -57,7 +56,7 @@ public class TooltipRenderer : IRenderer
renderer.DrawTexture( renderer.DrawTexture(
this.tooltipTexture, this.tooltipTexture,
tooltipX + tooltipWidth + 4 * uiScale, tooltipX + width + 4 * uiScale,
tooltipY, tooltipY,
4 * uiScale, 4 * uiScale,
4 * uiScale, 4 * uiScale,
@ -83,7 +82,7 @@ public class TooltipRenderer : IRenderer
this.tooltipTexture, this.tooltipTexture,
tooltipX + 4 * uiScale, tooltipX + 4 * uiScale,
tooltipY + 4 * uiScale, tooltipY + 4 * uiScale,
tooltipWidth, width,
height, height,
4, 4,
4, 4,
@ -93,7 +92,7 @@ public class TooltipRenderer : IRenderer
renderer.DrawTexture( renderer.DrawTexture(
this.tooltipTexture, this.tooltipTexture,
tooltipX + tooltipWidth + 4 * uiScale, tooltipX + width + 4 * uiScale,
tooltipY + 4 * uiScale, tooltipY + 4 * uiScale,
4 * uiScale, 4 * uiScale,
height, height,
@ -119,7 +118,7 @@ public class TooltipRenderer : IRenderer
this.tooltipTexture, this.tooltipTexture,
tooltipX + 4 * uiScale, tooltipX + 4 * uiScale,
tooltipY + height + 4 * uiScale, tooltipY + height + 4 * uiScale,
tooltipWidth, width,
4 * uiScale, 4 * uiScale,
4, 4,
5, 5,
@ -129,7 +128,7 @@ public class TooltipRenderer : IRenderer
renderer.DrawTexture( renderer.DrawTexture(
this.tooltipTexture, this.tooltipTexture,
tooltipX + tooltipWidth + 4 * uiScale, tooltipX + width + 4 * uiScale,
tooltipY + height + 4 * uiScale, tooltipY + height + 4 * uiScale,
4 * uiScale, 4 * uiScale,
4 * uiScale, 4 * uiScale,

View File

@ -88,7 +88,7 @@ public class WorldRenderer : IRenderer
{ {
ctx.Renderer.DrawText("" + Math.Round(ChunkGenerator.Noise.coherentNoise( ctx.Renderer.DrawText("" + Math.Round(ChunkGenerator.Noise.coherentNoise(
(chunk.X * Constants.ChunkSize) + x, (chunk.X * Constants.ChunkSize) + x,
(int)(((chunk.Y * Constants.ChunkSize) + y)*0.6), (chunk.Y * Constants.ChunkSize) + y,
0 0
), 4), ), 4),
(drawX - (int)camera.Position.X) * scale, (drawX - (int)camera.Position.X) * scale,

View File

@ -20,8 +20,6 @@ public class FrontendGameState
public InventoryKind OpenInventory { get; set; } = InventoryKind.None; public InventoryKind OpenInventory { get; set; } = InventoryKind.None;
public InputState InputState { get; set; } = new(); public InputState InputState { get; set; } = new();
public DebugState DebugState { get; set; } = new(); public DebugState DebugState { get; set; } = new();
public DateTime NextMusicPlay { get; set; } = DateTime.MinValue;
public DateTime NextStepPlay { get; set; } = DateTime.MinValue;
} }
public class DebugState { public class DebugState {

View File

@ -6,7 +6,6 @@ public class Player
{ {
public string Name { get; set; } public string Name { get; set; }
public Vector2 Position { get; set; } public Vector2 Position { get; set; }
public Vector2 PrettyPosition { get => (this.Position - new Vector2(512244, 5390)) / 16; }
public Guid Id { get; set; } public Guid Id { get; set; }
public Vector2 Mining { get; set; } public Vector2 Mining { get; set; }
public int MiningCooldown { get; set; } public int MiningCooldown { get; set; }

View File

@ -4,24 +4,13 @@
### Requirements ### Requirements
- dotnet 7 - dotnet 6
### Run the Project ### Run the Project
```bash ```bash
# Run the Server Player opens on port 42069
dotnet run --host
# Run the Client Player
dotnet run dotnet run
``` ```
### Cheats
To run Cheats open the Console with F10 and type `help` for a list of commands
## Features
- Breaking Blocks
- Placing Blocks
- Crafting
- Interactive inventory
- Different Pickaxe Levels
- Caves
- Lighting