Compare commits

...

13 Commits
v0.1 ... main

Author SHA1 Message Date
Gordon Goldbach b1593f0094
Update readme.md 2024-03-20 09:31:26 +01:00
MasterGordon 5d0a0fa622 fixed artifact upload 2023-01-04 15:35:21 +01:00
MasterGordon 94f353af5b updated pipeline 2023-01-04 15:32:15 +01:00
MasterGordon c400fd62fe fixed warnings 2023-01-04 15:28:43 +01:00
MasterGordon 7e71ade965 added credits 2023-01-04 15:26:32 +01:00
MasterGordon 22b5f6e62d Added Background Music 2023-01-04 14:53:51 +01:00
MasterGordon 82fddae704 fixed debug overlay 2023-01-04 14:04:27 +01:00
MasterGordon 08249fc196 World Gen Improvements 2023-01-04 14:03:08 +01:00
MasterGordon 8525ea8c69 Updated Iron visibility + Added Workbench recipe 2023-01-04 13:42:11 +01:00
MasterGordon ed4231d777 Added make script 2023-01-04 12:37:37 +01:00
MasterGordon 7b7f2a2a69 updated crafting 2023-01-04 12:32:23 +01:00
MasterGordon 15bd3b14dc updated readme 2023-01-02 20:11:54 +01:00
MasterGordon 3fc74bf22f fixed realse build 2023-01-02 20:10:03 +01:00
53 changed files with 339 additions and 80 deletions

View File

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

@ -0,0 +1 @@
build/

14
Mine2d/Makefile Normal file
View File

@ -0,0 +1,14 @@
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: 255 B

After

Width:  |  Height:  |  Size: 279 B

BIN
Mine2d/assets/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

BIN
Mine2d/assets/items/gps.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 B

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

17
Mine2d/credits.md Normal file
View File

@ -0,0 +1,17 @@
# 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,6 +5,13 @@ public enum Sound
BlockHit,
BlockBreak,
ItemPickup,
MusicLoop,
Step0,
Step1,
Step2,
Step3,
Step4,
Step5,
}
public class AudioPlayer

View File

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

View File

@ -14,6 +14,10 @@ public class Window
h,
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)

View File

@ -1,6 +1,7 @@
using Mine2d.engine;
using Mine2d.engine.system.annotations;
using Mine2d.game.backend.network.packets;
using Mine2d.game.core;
namespace Mine2d.game.backend.interactor;
@ -13,4 +14,35 @@ public class Audio
var ctx = Context.Get();
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 hardness = tileRegistry.GetTile(tileId).Hardness;
var hardnessBonus = Math.Min(1, player.GetHarvestLevel() / hardness);
player.MiningCooldown = 50 - (player.GetMiningSpeed() * hardnessBonus);
var hardnessBonus = Math.Min(1, player.GetHarvestLevel() / (double)hardness);
player.MiningCooldown = (int)(50 - (player.GetMiningSpeed() * hardnessBonus));
if(tile.Hits == 0) {
ctx.GameState.World.Cracks.Enqueue(new CrackQueueEntry
{
@ -83,7 +83,7 @@ public class Breaking
}
[Interaction(InteractorKind.Server, PacketType.BlockBroken)]
public static void BreakServer(BlockBrokenPacket packet)
public static void BlockBrokenServer(BlockBrokenPacket packet)
{
var ctx = Context.Get();
var tile = ctx.TileRegistry.GetTile(packet.Tile.Id);

View File

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

View File

@ -10,8 +10,6 @@ public class Bootstrapper
{
var ctx = Context.Get();
ctx.GameState.World = new World();
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)));
ChunkGenerator.CreateSpawnChunk(1000, 10);
}
}

View File

@ -15,6 +15,6 @@ public class Camera
var scale = ctx.FrontendGameState.Settings.GameScale;
var windowWidth = ctx.FrontendGameState.WindowWidth;
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,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mine2d.game.core;
public static class Debugger

View File

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

View File

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

View File

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

View File

@ -31,12 +31,24 @@ public class ItemRegistry
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.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.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.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", 40, 7));
this.Register(ItemId.PickaxeGold, new PickaxeItem(ItemId.PickaxeGold, "Gold Pickaxe", "items.pickaxe-gold", 60, 8));
this.Register(ItemId.PickaxeIron, new PickaxeItem(ItemId.PickaxeIron, "Iron Pickaxe", "items.pickaxe-iron", 30, 7));
this.Register(ItemId.PickaxeGold, new PickaxeItem(ItemId.PickaxeGold, "Gold Pickaxe", "items.pickaxe-gold", 35, 9));
// 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)

View File

@ -33,17 +33,13 @@ public class TileRegistry
public void RegisterTile()
{
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(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(9, new OreTile("tin-ore", new[] { "stone", "tin-ore" }, 6, ItemId.RawTin));
this.Tiles.Add(9, new OreTile("tin-ore", new[] { "stone", "tin-ore" }, 7, ItemId.RawTin));
this.Tiles.Add(10, new OreTile("silver-ore", new[] { "stone", "silver-ore" }, 7, ItemId.RawSilver));
this.Tiles.Add(11, new OreTile("gold-ore", new[] { "stone", "gold-ore" }, 8, ItemId.RawGold));
this.Tiles.Add(12, new OreTile("lead-ore", new[] { "stone", "lead-ore" }, 9, ItemId.RawLead));
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" }, 9, ItemId.RawGold));
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(15, new OreTile("tungsten-ore", new[] { "stone", "tungsten-ore" }, 15, ItemId.RawTungsten));

View File

@ -64,6 +64,86 @@ public class Workbench : Tile
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()

View File

@ -33,8 +33,8 @@ public class ChunkGenerator
{
for (var j = 0; j < Constants.ChunkSize; j++)
{
var n = (Noise.coherentNoise(i + (x * 32), j + (y * 32), 0, 1, 25, 0.5f, 0.9f));
var n2 = (Noise2.coherentNoise(i + (x * 32), j + (y * 32), 0, 1, 25, 0.5f, 0.9f));
var n = Noise.coherentNoise((int)((i + (x * 32)) * 0.6), (int)((j + (y * 32)) * 1), 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);
// Console.WriteLine(i * (x * 32) + " "+ j * (y * 32));
if (n > 0.08 || n2 > 0.08) continue;
chunk.SetTile(i, j, fill);
@ -65,10 +65,30 @@ public class ChunkGenerator
else
{
fill.Id = (int)WG.GetRandomOreAt(j + (y * 32));
if (new Random().NextInt64(0, 130) < 1)
if (new Random().NextInt64(0, 100) < 1)
{
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);
}
}
@ -76,16 +96,9 @@ public class ChunkGenerator
return chunk;
}
public static Chunk CreateSpawnChunk(int x, int y)
public static void CreateSpawnChunk(int x, int 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));
}
}
var chunk = CreateChunk(x, y);
chunk.SetTile(16, 16, STile.From(0));
chunk.SetTile(15, 16, STile.From(0));
chunk.SetTile(16, 15, STile.From(0));
@ -95,7 +108,12 @@ public class ChunkGenerator
chunk.SetTile(17, 16, STile.From(0));
chunk.SetTile(14, 16, 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));
return chunk;
chunk.SetTile(14, 17, STile.From((int)Tiles.Stone));
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, 700);
var rng = random.Next(0, 1050);
if (rng < ores.Count)
{
return ores[rng];

View File

@ -12,6 +12,13 @@ public class GameAudio
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.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)

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mine2d.engine;
using Mine2d.game.core.data;
namespace Mine2d.game.frontend;
@ -15,6 +16,11 @@ public static class ItemRenderer
var texture = stack.GetTexture();
var renderer = Context.Get().Renderer;
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);
if (stack.Count > 1)
{

View File

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

View File

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

View File

@ -1,6 +1,7 @@
using Mine2d.engine;
using Mine2d.engine.utils;
using Mine2d.game.core;
using Mine2d.game.core.data;
namespace Mine2d.game.frontend.renderer;
@ -30,6 +31,7 @@ public class HudRenderer : IRenderer
public void Render()
{
this.RenderHotbar();
this.RenderGps();
}
private void RenderHotbar()
@ -52,4 +54,22 @@ public class HudRenderer : IRenderer
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,6 +30,7 @@ public class TooltipRenderer : IRenderer
var tooltipX = (int)tooltipPosition.X;
var tooltipY = (int)tooltipPosition.Y;
var (texture, width, height, surfaceMessage) = renderer.CreateTextTexture(tooltip);
var tooltipWidth = Math.Min(300, width);
renderer.DrawTexture(
this.tooltipTexture,
tooltipX,
@ -46,7 +47,7 @@ public class TooltipRenderer : IRenderer
this.tooltipTexture,
tooltipX + 4 * uiScale,
tooltipY,
width,
tooltipWidth,
4 * uiScale,
4,
0,
@ -56,7 +57,7 @@ public class TooltipRenderer : IRenderer
renderer.DrawTexture(
this.tooltipTexture,
tooltipX + width + 4 * uiScale,
tooltipX + tooltipWidth + 4 * uiScale,
tooltipY,
4 * uiScale,
4 * uiScale,
@ -82,7 +83,7 @@ public class TooltipRenderer : IRenderer
this.tooltipTexture,
tooltipX + 4 * uiScale,
tooltipY + 4 * uiScale,
width,
tooltipWidth,
height,
4,
4,
@ -92,7 +93,7 @@ public class TooltipRenderer : IRenderer
renderer.DrawTexture(
this.tooltipTexture,
tooltipX + width + 4 * uiScale,
tooltipX + tooltipWidth + 4 * uiScale,
tooltipY + 4 * uiScale,
4 * uiScale,
height,
@ -118,7 +119,7 @@ public class TooltipRenderer : IRenderer
this.tooltipTexture,
tooltipX + 4 * uiScale,
tooltipY + height + 4 * uiScale,
width,
tooltipWidth,
4 * uiScale,
4,
5,
@ -128,7 +129,7 @@ public class TooltipRenderer : IRenderer
renderer.DrawTexture(
this.tooltipTexture,
tooltipX + width + 4 * uiScale,
tooltipX + tooltipWidth + 4 * uiScale,
tooltipY + height + 4 * uiScale,
4 * uiScale,
4 * uiScale,

View File

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

View File

@ -20,6 +20,8 @@ public class FrontendGameState
public InventoryKind OpenInventory { get; set; } = InventoryKind.None;
public InputState InputState { 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 {

View File

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

View File

@ -4,13 +4,24 @@
### Requirements
- dotnet 6
- dotnet 7
### Run the Project
```bash
# Run the Server Player opens on port 42069
dotnet run --host
# Run the Client Player
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