-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cs
More file actions
137 lines (114 loc) · 4.27 KB
/
Game.cs
File metadata and controls
137 lines (114 loc) · 4.27 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using CreatureBattler.Screens;
using CreatureBattler.Structure.Creature;
using CreatureBattler.Structure.Modules;
using Leaf;
using Type = CreatureBattler.Structure.Creature.Type;
namespace CreatureBattler;
public static class Game
{
// Internal stuff
public static int ScaleFactor { get; set; } = 2;
public static string Version { get; set; } = "indev-0.1";
public static Vector2 WindowSize => GameSize * ScaleFactor;
public static Vector2 GameSize = new(800, 300);
public static GameCamera? GameCamera;
public static Lua LuaState = new();
public static Dictionary<string, KeyboardKey> KeyBinds = new()
{
{"advance", X},
{"back", Z},
};
// Other
public static Screen? CurrentScreen = null;
public static Player Player;
public static string WindowTitle = "Creature Battler";
public static UIManager UIManager;
public static void Run(int targetFrameRate)
{
SetTraceLogLevel(Error);
SetConfigFlags(VSyncHint);
InitWindow((int)WindowSize.X, (int)WindowSize.Y, WindowTitle);
SetTargetFPS(targetFrameRate);
Leaf.Resources.InitResources();
UIManager = new UIManager(GameSize, "ui.css");
GameCamera = new GameCamera();
LuaState.DoString("""
luanet.load_assembly('CreatureBattler')
Type = luanet.import_type('CreatureBattler.Structure.Creature.Type')
""");
LoadModules();
Player = new Player();
Screen.LoadScreens();
var background = LoadSprite("bg");
/*for (int i = 0; i < 2500; i++)
{
Screen.SwitchScreens(i % 2 == 0 ? "party_viewer" : "battle_simulator");
}*/
int lastKey = 0;
while (!WindowShouldClose())
{
BeginTextureMode(GameCamera.RenderTexture);
ClearBackground(Black);
DrawTexturePro(
background,
new Rectangle(0, 0, background.Width, background.Height),
new Rectangle(0, 0, GameSize),
Vector2.Zero,
0,
White
);
BeginMode2D(GameCamera);
UIManager.Update();
foreach (Event evnt in UIManager.UIEvents)
{
CurrentScreen!.HandleEvent(evnt);
if (evnt.EventType == EventType.KeyPressed)
{
switch (evnt.KeyCode)
{
case One:
Screen.SwitchScreens("battle_simulator");
break;
case Two:
Screen.SwitchScreens("encyclopedia");
break;
case Three:
Screen.SwitchScreens("party_viewer");
break;
}
}
}
CurrentScreen!.Update();
UIManager.ResetEvents();
EndMode2D();
EndTextureMode();
BeginDrawing();
DrawTexturePro(
GameCamera.RenderTexture.Texture,
new Rectangle(0, 0,
GameCamera.RenderTexture.Texture.Width,
-GameCamera.RenderTexture.Texture.Height
),
new Rectangle(0, 0, WindowSize.X, WindowSize.Y),
Vector2.Zero,
0,
White
);
EndDrawing();
}
}
private static void LoadModules()
{
var modules = Directory.GetDirectories(DataPath);
foreach (var module in modules)
{
Module.LoadModule(module);
}
}
public static void FreeLuaGlobals()
{
LuaState["User"] = null;
LuaState["Target"] = null;
LuaState["MoveData"] = null;
}
}