diff --git a/Mine2d/assets/hud/player-inventory.png b/Mine2d/assets/hud/player-inventory.png index a42212e..fa443bd 100644 Binary files a/Mine2d/assets/hud/player-inventory.png and b/Mine2d/assets/hud/player-inventory.png differ diff --git a/Mine2d/engine/FontManager.cs b/Mine2d/engine/FontManager.cs index 263f854..ca75af9 100644 --- a/Mine2d/engine/FontManager.cs +++ b/Mine2d/engine/FontManager.cs @@ -23,7 +23,7 @@ public class FontManager var (ptr, size) = this.resourceLoader.LoadToIntPtr(path); var sdlBuffer = SDL_RWFromConstMem(ptr, size); - var font = TTF_OpenFontRW(sdlBuffer, 1, fontSize); + var font = TTF_OpenFontRW(sdlBuffer, 1, fontSize+4); if (font == IntPtr.Zero) { throw new SDLException(TTF_GetError()); diff --git a/Mine2d/game/backend/interactor/Move.cs b/Mine2d/game/backend/interactor/Move.cs index 766c3c6..98958f3 100644 --- a/Mine2d/game/backend/interactor/Move.cs +++ b/Mine2d/game/backend/interactor/Move.cs @@ -41,7 +41,7 @@ public class Move } } } - + [Interaction(InteractorKind.Client, PacketType.Tick)] public static void SelfMovedClient() { diff --git a/Mine2d/game/core/world/ChunkGenerator.cs b/Mine2d/game/core/world/ChunkGenerator.cs index eae416b..6e56bac 100644 --- a/Mine2d/game/core/world/ChunkGenerator.cs +++ b/Mine2d/game/core/world/ChunkGenerator.cs @@ -30,7 +30,7 @@ public class ChunkGenerator { for (var j = 0; j < Constants.ChunkSize; j++) { - fill.Id = (int)wg.GetRandomOreAt(j + y); + fill.Id = (int)wg.GetRandomOreAt(j + y*32); chunk.SetTile(i, j, fill); } } diff --git a/Mine2d/game/core/world/WorldGenerator.cs b/Mine2d/game/core/world/WorldGenerator.cs index 1864c1f..90f6979 100644 --- a/Mine2d/game/core/world/WorldGenerator.cs +++ b/Mine2d/game/core/world/WorldGenerator.cs @@ -6,85 +6,109 @@ using Mine2d.game.core.tiles; namespace Mine2d.game.core.world; -public class GenerationSettings { +public class GenerationSettings +{ public int xOffset { get; set; } public int yOffset { get; set; } public Tiles tile { get; set; } - public int GetWeight(int height) { - return (int)((-Math.Pow(height - this.xOffset, 2)*0.01) + this.yOffset + (32*10)); + public int GetWeight(int height) + { + return (int)((-Math.Pow(height - (this.xOffset + (32 * 10)), 2) * 0.001) + this.yOffset); } } public class WorldGenerator { - private readonly List settings = new (); + private readonly List settings = new(); - public WorldGenerator() { - this.settings.Add(new GenerationSettings { + public WorldGenerator() + { + this.settings.Add(new GenerationSettings + { xOffset = 10, yOffset = 15, tile = Tiles.IronOre }); - this.settings.Add(new GenerationSettings { + this.settings.Add(new GenerationSettings + { xOffset = 15, yOffset = 20, tile = Tiles.CopperOre }); - this.settings.Add(new GenerationSettings { + this.settings.Add(new GenerationSettings + { xOffset = 20, yOffset = 10, tile = Tiles.TinOre }); - this.settings.Add(new GenerationSettings { + this.settings.Add(new GenerationSettings + { xOffset = 40, yOffset = 3, tile = Tiles.SilverOre }); - this.settings.Add(new GenerationSettings { - xOffset = 40, + this.settings.Add(new GenerationSettings + { + xOffset = 80, yOffset = 3, tile = Tiles.GoldOre }); - this.settings.Add(new GenerationSettings { - xOffset = 50, + this.settings.Add(new GenerationSettings + { + xOffset = 90, yOffset = 15, tile = Tiles.LeadOre }); - this.settings.Add(new GenerationSettings { - xOffset = 60, - yOffset = 2, + this.settings.Add(new GenerationSettings + { + xOffset = 160, + yOffset = 3, tile = Tiles.PlatinumOre }); - this.settings.Add(new GenerationSettings { - xOffset = 60, + this.settings.Add(new GenerationSettings + { + xOffset = 160, yOffset = 3, tile = Tiles.CobaltOre }); - this.settings.Add(new GenerationSettings { - xOffset = 65, + this.settings.Add(new GenerationSettings + { + xOffset = 165, yOffset = 10, tile = Tiles.TungstenOre }); - this.settings.Add(new GenerationSettings { - xOffset = 90, + this.settings.Add(new GenerationSettings + { + xOffset = 290, yOffset = 1, tile = Tiles.DiamondOre }); - this.settings.Add(new GenerationSettings { - xOffset = 94, + this.settings.Add(new GenerationSettings + { + xOffset = 294, yOffset = 2, tile = Tiles.UraniumOre }); } - public Tiles GetRandomOreAt(int height) { + public Tiles GetRandomOreAt(int height) + { var random = new Random(); - var weight = random.Next(0, 4000); - var ore = this.settings.FirstOrDefault(x => x.GetWeight(height) > weight, null); - if(ore == null) { - return Tiles.Stone; + var ores = new List(); + foreach (var setting in this.settings) + { + for (var i = 0; i < setting.GetWeight(height); i++) + { + ores.Add(setting.tile); + } } - return ore.tile; + + var rng = random.Next(0, 700); + if (rng < ores.Count) + { + return ores[rng]; + } + return Tiles.Stone; } } \ No newline at end of file diff --git a/Mine2d/game/frontend/inventory/PlayerInventoryRenderer.cs b/Mine2d/game/frontend/inventory/PlayerInventoryRenderer.cs index 8dedbb2..4a7400c 100644 --- a/Mine2d/game/frontend/inventory/PlayerInventoryRenderer.cs +++ b/Mine2d/game/frontend/inventory/PlayerInventoryRenderer.cs @@ -110,12 +110,23 @@ namespace Mine2d.game.frontend.inventory { player.Inventory.SwapWithCursor(index, hotbar); } + if (e.button.button == SDL_BUTTON_RIGHT) + { + if (player.Inventory.Cursor == null) + { + player.Inventory.TakeHalf(index, hotbar); + } + else + { + player.Inventory.DropOne(index, hotbar); + } + } } // is inventory if (cursorPosition.X >= this.x + (4 * Context.Get().FrontendGameState.Settings.UiScale) && cursorPosition.X <= this.x + (4 * Context.Get().FrontendGameState.Settings.UiScale) + (21 * 9 * Context.Get().FrontendGameState.Settings.UiScale) && cursorPosition.Y >= this.y + (4 * Context.Get().FrontendGameState.Settings.UiScale) + (21 * Context.Get().FrontendGameState.Settings.UiScale) - && cursorPosition.Y <= this.y + (4 * Context.Get().FrontendGameState.Settings.UiScale) + (21 * 5 * Context.Get().FrontendGameState.Settings.UiScale) + && cursorPosition.Y <= this.y + (4 * Context.Get().FrontendGameState.Settings.UiScale) + (21 * 6 * Context.Get().FrontendGameState.Settings.UiScale) ) { var player = PlayerEntity.GetSelf(); @@ -126,6 +137,17 @@ namespace Mine2d.game.frontend.inventory { player.Inventory.SwapWithCursor(index, inventory); } + if (e.button.button == SDL_BUTTON_RIGHT) + { + if (player.Inventory.Cursor == null) + { + player.Inventory.TakeHalf(index, inventory); + } + else + { + player.Inventory.DropOne(index, inventory); + } + } } } } diff --git a/Mine2d/game/state/FrontendGameState.cs b/Mine2d/game/state/FrontendGameState.cs index 5bbb1ad..4bfec6b 100644 --- a/Mine2d/game/state/FrontendGameState.cs +++ b/Mine2d/game/state/FrontendGameState.cs @@ -27,8 +27,8 @@ public class FrontendGameState public class Settings { - public int GameScale { get; set; } = 4; - public int UiScale { get; set; } = 3; + public int GameScale { get; set; } = 6; + public int UiScale { get; set; } = 4; public bool ShowCollision { get; set; } = true; public bool Fullscreen { get; set; } = false; } \ No newline at end of file diff --git a/Mine2d/game/state/PlayerInventory.cs b/Mine2d/game/state/PlayerInventory.cs index 9702979..511e7e7 100644 --- a/Mine2d/game/state/PlayerInventory.cs +++ b/Mine2d/game/state/PlayerInventory.cs @@ -34,6 +34,49 @@ public class PlayerInventory public void SwapWithCursor(int slot, ItemStack[] inventory) { - (inventory[slot], this.Cursor) = (this.Cursor, inventory[slot]); + if (this.Cursor != null && inventory[slot] != null && this.Cursor.Id == inventory[slot].Id) + { + inventory[slot].Count += this.Cursor.Count; + this.Cursor = null; + } + else + { + (inventory[slot], this.Cursor) = (this.Cursor, inventory[slot]); + } + } + + public void TakeHalf(int slot, ItemStack[] inventory) + { + if (inventory[slot] == null) + return; + if(inventory[slot].Count == 1) + { + this.Cursor = inventory[slot]; + inventory[slot] = null; + return; + } + this.Cursor = new ItemStack(inventory[slot].Id, inventory[slot].Count / 2); + inventory[slot].Count -= this.Cursor.Count; + } + + public void DropOne(int slot, ItemStack[] inventory) + { + if (inventory[slot] == null) + { + inventory[slot] = new ItemStack(this.Cursor.Id, 1); + } + else if (inventory[slot].Id == this.Cursor.Id) + { + inventory[slot].Count++; + } + else + { + return; + } + this.Cursor.Count--; + if (this.Cursor.Count == 0) + { + this.Cursor = null; + } } }