added ores
This commit is contained in:
parent
19c5bed5fc
commit
6cd5852cd1
|
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
|
|
@ -2,6 +2,8 @@ using Mine2d.engine.system.annotations;
|
|||
using Mine2d.game.backend.network.packets;
|
||||
using Mine2d.game.core;
|
||||
using Mine2d.game.core.data;
|
||||
using Mine2d.game.core.tiles;
|
||||
using Mine2d.game.state;
|
||||
|
||||
namespace Mine2d.game.backend.interactor;
|
||||
|
||||
|
|
@ -29,7 +31,11 @@ public class Place
|
|||
{
|
||||
var chunk = ctx.GameState.World.GetChunkAt(packet.Target);
|
||||
var tile = chunk.GetTileAt(packet.Target);
|
||||
|
||||
var tileId = tile.Id;
|
||||
if(tileId == (int)Tiles.Workbench) {
|
||||
ctx.FrontendGameState.OpenInventory = InventoryKind.Workbench;
|
||||
}
|
||||
if (tileId != 0 || player.Inventory.Hotbar[packet.Slot] == null || player.Inventory.Hotbar[packet.Slot]?.Count <= 0)
|
||||
{
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -5,4 +5,15 @@ public enum ItemId
|
|||
Air = 0,
|
||||
Stone = 1,
|
||||
Workbench = 6,
|
||||
RawIron = 107,
|
||||
RawCopper = 108,
|
||||
RawTin = 109,
|
||||
RawSilver = 110,
|
||||
RawGold = 111,
|
||||
RawLead = 112,
|
||||
RawPlatinum = 113,
|
||||
RawCobalt = 114,
|
||||
RawTungsten = 115,
|
||||
RawUranium = 116,
|
||||
Diamond = 117,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class World
|
|||
this.SetTileAt((int)head.Pos.X, (int)head.Pos.Y, stile with { Hits = stile.Hits - 1 });
|
||||
if (stile.Hits >= 1)
|
||||
{
|
||||
this.Cracks.Enqueue(new CrackQueueEntry { Pos = head.Pos, ResetTime = now.AddSeconds(1) });
|
||||
this.Cracks.Enqueue(new CrackQueueEntry { Pos = head.Pos, ResetTime = now.AddSeconds(0.5) });
|
||||
needsReorder = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ public class Item
|
|||
this.texture = Context.Get().TextureFactory.CreateTexture(textureName);
|
||||
}
|
||||
|
||||
public Item(ItemId id, string name, string textureName)
|
||||
{
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.texture = Context.Get().TextureFactory.LoadTexture(textureName);
|
||||
}
|
||||
|
||||
public void Render(Vector2 position)
|
||||
{
|
||||
var ctx = Context.Get();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,17 @@ public class ItemRegistry
|
|||
{
|
||||
this.Register(ItemId.Stone, new Item(ItemId.Stone, "Stone", new[] { "stone" }));
|
||||
this.Register(ItemId.Workbench, new Item(ItemId.Workbench, "Workbench", new[] { "workbench" }));
|
||||
this.Register(ItemId.RawIron, new Item(ItemId.RawCobalt, "Raw Iron", "items.raw-iron" ));
|
||||
this.Register(ItemId.RawCopper, new Item(ItemId.RawCopper, "Raw Copper", "items.raw-copper" ));
|
||||
this.Register(ItemId.RawTin, new Item(ItemId.RawTin, "Raw Tin", "items.raw-tin" ));
|
||||
this.Register(ItemId.RawSilver, new Item(ItemId.RawSilver, "Raw Silver", "items.raw-silver" ));
|
||||
this.Register(ItemId.RawGold, new Item(ItemId.RawGold, "Raw Gold", "items.raw-gold" ));
|
||||
this.Register(ItemId.RawLead, new Item(ItemId.RawLead, "Raw Lead", "items.raw-lead" ));
|
||||
this.Register(ItemId.RawPlatinum, new Item(ItemId.RawPlatinum, "Raw Platinum", "items.raw-platinum" ));
|
||||
this.Register(ItemId.RawCobalt, new Item(ItemId.RawCobalt, "Raw Cobalt", "items.raw-cobalt" ));
|
||||
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" ));
|
||||
}
|
||||
|
||||
public void Register(ItemId id, Item item)
|
||||
|
|
|
|||
|
|
@ -7,4 +7,8 @@ public class OreTile : Tile
|
|||
public OreTile(string name, string[] texturePath, int hardness) : base(name, Context.Get().TextureFactory.CreateTexture(texturePath), hardness, ItemId.Air)
|
||||
{
|
||||
}
|
||||
|
||||
public OreTile(string name, string[] texturePath, int hardness, ItemId drop) : base(name, Context.Get().TextureFactory.CreateTexture(texturePath), hardness, drop)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,17 @@ public enum Tiles
|
|||
Ore3 = 4,
|
||||
Ore4 = 5,
|
||||
Workbench = 6,
|
||||
IronOre = 7,
|
||||
CopperOre = 8,
|
||||
TinOre = 9,
|
||||
SilverOre = 10,
|
||||
GoldOre = 11,
|
||||
LeadOre = 12,
|
||||
PlatinumOre = 13,
|
||||
CobaltOre = 14,
|
||||
TungstenOre = 15,
|
||||
UraniumOre = 16,
|
||||
DiamondOre = 17,
|
||||
}
|
||||
|
||||
public class TileRegistry
|
||||
|
|
@ -24,6 +35,17 @@ public class TileRegistry
|
|||
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(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(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));
|
||||
this.Tiles.Add(16, new OreTile("uranium-ore", new [] {"stone", "uranium-ore"}, 15, ItemId.RawUranium));
|
||||
this.Tiles.Add(17, new OreTile("diamond-ore", new [] {"stone", "diamond-ore"}, 10, ItemId.Diamond));
|
||||
}
|
||||
|
||||
public Tile GetTile(int id)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Mine2d.game.core.world;
|
|||
|
||||
public class ChunkGenerator
|
||||
{
|
||||
private static WorldGenerator wg = new WorldGenerator();
|
||||
public static Chunk CreateFilledChunk(int x, int y, STile fill)
|
||||
{
|
||||
var chunk = new Chunk(x, y);
|
||||
|
|
@ -29,26 +30,7 @@ public class ChunkGenerator
|
|||
{
|
||||
for (var j = 0; j < Constants.ChunkSize; j++)
|
||||
{
|
||||
if (new Random().Next(0, 100) < 10)
|
||||
{
|
||||
fill.Id = (int)Tiles.Ore1;
|
||||
}
|
||||
else if (new Random().Next(0, 100) < 10)
|
||||
{
|
||||
fill.Id = (int)Tiles.Ore2;
|
||||
}
|
||||
else if (new Random().Next(0, 100) < 10)
|
||||
{
|
||||
fill.Id = (int)Tiles.Ore3;
|
||||
}
|
||||
else if (new Random().Next(0, 100) < 10)
|
||||
{
|
||||
fill.Id = (int)Tiles.Ore4;
|
||||
}
|
||||
else
|
||||
{
|
||||
fill.Id = (int)Tiles.Stone;
|
||||
}
|
||||
fill.Id = (int)wg.GetRandomOreAt(j + y);
|
||||
chunk.SetTile(i, j, fill);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,85 @@ using Mine2d.game.core.tiles;
|
|||
|
||||
namespace Mine2d.game.core.world;
|
||||
|
||||
public struct 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);
|
||||
return (int)((-Math.Pow(height - this.xOffset, 2)*0.01) + this.yOffset + (32*10));
|
||||
}
|
||||
}
|
||||
|
||||
public class WorldGenerator
|
||||
{
|
||||
List<GenerationSettings> settings = new ();
|
||||
private readonly List<GenerationSettings> settings = new ();
|
||||
|
||||
public WorldGenerator() {
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 10,
|
||||
yOffset = 15,
|
||||
tile = Tiles.IronOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 15,
|
||||
yOffset = 20,
|
||||
tile = Tiles.CopperOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 20,
|
||||
yOffset = 10,
|
||||
tile = Tiles.TinOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 40,
|
||||
yOffset = 3,
|
||||
tile = Tiles.SilverOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 40,
|
||||
yOffset = 3,
|
||||
tile = Tiles.GoldOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 50,
|
||||
yOffset = 16,
|
||||
tile = Tiles.Stone
|
||||
yOffset = 15,
|
||||
tile = Tiles.LeadOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 60,
|
||||
yOffset = 2,
|
||||
tile = Tiles.PlatinumOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 60,
|
||||
yOffset = 3,
|
||||
tile = Tiles.CobaltOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 65,
|
||||
yOffset = 10,
|
||||
tile = Tiles.TungstenOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 90,
|
||||
yOffset = 1,
|
||||
tile = Tiles.DiamondOre
|
||||
});
|
||||
this.settings.Add(new GenerationSettings {
|
||||
xOffset = 94,
|
||||
yOffset = 2,
|
||||
tile = Tiles.UraniumOre
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return ore.tile;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,9 +14,9 @@ public class Exit
|
|||
[EventListener(EventType.KeyDown)]
|
||||
public static void OnKeyDown(SDL_Event e)
|
||||
{
|
||||
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_ESCAPE)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
// if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_ESCAPE)
|
||||
// {
|
||||
// Environment.Exit(0);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,12 +47,16 @@ public class InventoryInput
|
|||
var frontendGameState = Context.Get().FrontendGameState;
|
||||
if(e.key.keysym.sym == SDL_Keycode.SDLK_TAB)
|
||||
{
|
||||
if(frontendGameState.OpenInventory != InventoryKind.Player) {
|
||||
if(frontendGameState.OpenInventory == InventoryKind.None) {
|
||||
frontendGameState.OpenInventory = InventoryKind.Player;
|
||||
} else {
|
||||
frontendGameState.OpenInventory = InventoryKind.None;
|
||||
}
|
||||
}
|
||||
if(e.key.keysym.sym == SDL_Keycode.SDLK_ESCAPE)
|
||||
{
|
||||
frontendGameState.OpenInventory = InventoryKind.None;
|
||||
}
|
||||
if(frontendGameState.OpenInventory != InventoryKind.None)
|
||||
{
|
||||
throw new CancelEventException();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ public class InventoryRegistry
|
|||
public InventoryRegistry()
|
||||
{
|
||||
this.inventoryRenderers.Add(InventoryKind.Player, new PlayerInventoryRenderer());
|
||||
this.inventoryRenderers.Add(InventoryKind.Workbench, new WorkbenchInventory());
|
||||
}
|
||||
|
||||
public Inventory GetInventory(InventoryKind inventory)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mine2d.game.frontend.inventory;
|
||||
|
||||
public class WorkbenchInventory : Inventory
|
||||
{
|
||||
private IntPtr texture = IntPtr.Zero;
|
||||
public override void Render()
|
||||
{
|
||||
var ctx = Context.Get();
|
||||
if (this.texture == IntPtr.Zero)
|
||||
{
|
||||
this.texture = ctx.TextureFactory.LoadTexture("hud.workbench-inventory");
|
||||
}
|
||||
var (width, height) = ctx.Renderer.GetTextureSize(this.texture);
|
||||
var (windowWidth, windowHeight) = (ctx.FrontendGameState.WindowWidth, ctx.FrontendGameState.WindowHeight);
|
||||
var x = (windowWidth - width) / 2;
|
||||
var y = (windowHeight - height) / 2;
|
||||
var uiScale = ctx.FrontendGameState.Settings.UiScale;
|
||||
ctx.Renderer.DrawTexture(this.texture, x, y, width * uiScale, height * uiScale);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@ namespace Mine2d.game.state;
|
|||
|
||||
public enum InventoryKind {
|
||||
None,
|
||||
Player
|
||||
Player,
|
||||
Workbench
|
||||
}
|
||||
|
||||
public class FrontendGameState
|
||||
|
|
|
|||
Loading…
Reference in New Issue