-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
98 lines (73 loc) · 3.12 KB
/
Copy pathProgram.cs
File metadata and controls
98 lines (73 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Numerics;
using ImGuiNET;
using Raylib_cs;
using rlImGui_cs;
namespace SharpSurv;
internal static class Program
{
[System.STAThread]
public static void Main()
{
Raylib.SetConfigFlags(ConfigFlags.ResizableWindow);
Raylib.InitWindow(GameConfig.WindowWidth, GameConfig.WindowHeight, GameConfig.WindowTitle);
TileMap tileMap = new(128, 128);
Player player = new(new Vector2(GameConfig.GetCenterScreen().X, GameConfig.GetCenterScreen().Y));
Camera2D camera = new();
camera.Target = player.position;
camera.Offset = new Vector2(GameConfig.GetCenterScreen().X, GameConfig.GetCenterScreen().Y);
camera.Rotation = 0.0f;
camera.Zoom = 1f;
GridIndicator gridIndicator = new(camera);
WorldInteraction interaction = new(player, tileMap);
TileDatabase.Load();
tileMap.GenerateWorld();
rlImGui.Setup(true);
while (!Raylib.WindowShouldClose())
{
float delta = Raylib.GetFrameTime();
if (Raylib.IsKeyPressed(KeyboardKey.F11)) {
Raylib.ToggleFullscreen();
}
player.Update(camera, tileMap, delta);
camera.Target = player.position;
camera.Offset = new Vector2(GameConfig.GetCenterScreen().X, GameConfig.GetCenterScreen().Y);
int holdingSlot = player.inventory.holdingSlot;
InventorySlot currentSlot = player.inventory.Get(holdingSlot);
TileId currentTile = currentSlot.tileId;
Texture2D currentTileTexture = TileDatabase.GetTexture(currentTile);
ImGuiIOPtr io = ImGui.GetIO();
if (!io.WantCaptureMouse)
{
gridIndicator.Update(camera, player);
interaction.Update(gridIndicator.mouseWorldPos, delta);
}
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.Black);
Raylib.BeginMode2D(camera);
tileMap.Draw();
player.Draw();
gridIndicator.Draw();
Raylib.EndMode2D();
Rectangle source = new(interaction.currentRotation * GameConfig.TileSize, interaction.currentRotation * GameConfig.TileSize, GameConfig.TileSize, GameConfig.TileSize);
Rectangle dest = new(Raylib.GetMouseX() + 13, Raylib.GetMouseY() + 13, 16, 16);
Vector2 origin = Vector2.Zero;
Raylib.DrawTexturePro(currentTileTexture, source, dest, origin, 0, Color.White);
rlImGui.Begin();
for (int i = 0; i < player.inventory.slots.Length; i++)
{
InventorySlot slot = player.inventory.Get(i);
ImGui.Text($"{i + 1} | {slot.tileId}");
}
ImGui.NewLine();
ImGui.Text($"Holding Item: {player.inventory.holdingSlot + 1} | {player.inventory.Get(player.inventory.holdingSlot).tileId}");
rlImGui.End();
Raylib.EndDrawing();
}
TileDatabase.Unload();
tileMap.Unload();
gridIndicator.Unload();
player.Unload();
rlImGui.Shutdown();
Raylib.CloseWindow();
}
}