A WIP automation game
1using System.Numerics;
2using Electropunk.Containers;
3using Electropunk.Content.Biomes;
4using Electropunk.Content.Entities;
5using Electropunk.Content.Generators;
6using Electropunk.Content.Items;
7using Electropunk.Content.Tiles;
8using Electropunk.Content.UI;
9using Electropunk.Input;
10using Electropunk.Misc;
11using Electropunk.UI;
12using Electropunk.World;
13using Electropunk.World.Crafting;
14using Raylib_cs;
15
16namespace Electropunk;
17
18public static class Program
19{
20 public static View View { get; set; } = new();
21
22 public static float DeltaTime
23 {
24 get => Raylib.GetFrameTime() * 1000;
25 private set { }
26 }
27
28 public static Level? Level { get; set; }
29 public static EntityPlayer? Player { get; set; }
30 public static ItemInstance MouseItem { get; set; } = new(GameItems.Air);
31
32 public static UINode? Menu { get; set; }
33 public static UINode RootUI { get; private set; } = new(0, 0);
34
35 public static Random Rand { get; set; } = new();
36
37 public static bool UseBorderlessFullscreen { get; set; } = true;
38
39 private static Texture2D Cursor;
40 private static float CursorRotation = 0;
41
42
43 public static void Main()
44 {
45 Raylib.SetTargetFPS(60);
46 Raylib.InitWindow(800, 600, "Electropunk");
47 Raylib.HideCursor();
48 // Raylib.SetExitKey(KeyboardKey.Null);
49
50 Cursor = Raylib.LoadTexture("Assets/UI/cursor.png");
51
52 GameBiomes.NoOp();
53 GameTiles.NoOp();
54
55 RecipeTileSmashing.Load("Data/Crafting/tile_smashing.kdl");
56 RecipeItemSmashing.Load("Data/Crafting/item_smashing.kdl");
57
58 RootUI.AddChild(p => new UISelection(p));
59 RootUI.AddChild(p => new UIFps(0, 0, p));
60 /* November 5 - Jim's Birthday */
61 if (new Random().Next(1_000_000) == 1 || DateHelper.IsDate(Month.Nov, 5))
62 RootUI.AddChild(p => new UIJim(p));
63
64 int size = 1_000;
65 Level = new(size, size);
66 Level.Generate(new BasicLevelGenerator());
67 Vector2 centre = new(size / 2 * View.TileSize, size / 2 * View.TileSize);
68 Player = new EntityPlayer() { Pos = centre };
69 View.Camera.Target = centre;
70 View.Camera.Zoom = 1.5f;
71 Level.AddEntity(Player);
72
73 RootUI.AddChild(p => new UIInvPreview(Player.Inv, p));
74
75 while (!Raylib.WindowShouldClose())
76 {
77 if (Bindings.ToggleFullscreen.IsPressed())
78 {
79 if (UseBorderlessFullscreen)
80 Raylib.ToggleBorderlessWindowed();
81 else
82 Raylib.ToggleFullscreen();
83 }
84 else if (Bindings.ZoomOut.IsPressed() && View.GoalZoom > 1.00f)
85 View.GoalZoom -= 0.25f;
86 else if (Bindings.ZoomIn.IsPressed() && View.GoalZoom < 3.00f)
87 View.GoalZoom += 0.25f;
88 else if (Bindings.ResetZoom.IsPressed())
89 View.GoalZoom = 2f;
90 else if (Raylib.IsKeyPressed(KeyboardKey.Eight))
91 View.GoalZoom = 0.1f;
92 else if (Bindings.OpenInventory.IsPressed())
93 {
94 if (Menu == null)
95 Menu = new MenuInventory(Player.Inv);
96 else
97 Menu = null;
98 }
99
100 Level.Update();
101 RootUI.Update();
102 Menu?.Update();
103
104 Raylib.BeginDrawing();
105 {
106 Level.Render(View);
107
108 RootUI.Render();
109 Menu?.Render();
110
111 RootUI.RenderHoverBox();
112 Menu?.RenderHoverBox();
113
114 Vector2 delta = Raylib.GetMouseDelta();
115 if ((delta.X > 0 || delta.Y > 0) && CursorRotation < 30)
116 CursorRotation += 2;
117 else if ((delta.X < 0 || delta.Y < 0) && CursorRotation > -30)
118 CursorRotation -= 2;
119 CursorRotation = Raymath.LerpAngle(CursorRotation, 0, 0.2f);
120 Raylib.DrawTextureEx(Cursor, Raylib.GetMousePosition(), CursorRotation, 2f, Color.White);
121
122 if (!MouseItem.IsEmpty())
123 MouseItem.Item.Render(Level, View, new(Raylib.GetMouseX(), Raylib.GetMouseY(), 32, 32));
124 }
125 Raylib.EndDrawing();
126
127 View.Update();
128 }
129 }
130}