This repository was archived by the owner on Jul 21, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (57 loc) · 2.04 KB
/
Copy pathProgram.cs
File metadata and controls
71 lines (57 loc) · 2.04 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
using guava;
using Raylib_cs;
using System.Runtime.InteropServices;
const int screenWidth = 1280;
const int screenHeight = 720;
const string title = "Kandy Match 3";
Raylib.InitWindow(screenWidth, screenHeight, title);
string mainDir = AppContext.BaseDirectory;
string assetsDir = Path.Combine(mainDir, "assets");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("This is Working on Windows");
Image icon = Raylib.LoadImage(Path.Combine(assetsDir, "logo.png"));
Raylib.SetWindowIcon(icon);
Raylib.UnloadImage(icon);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Console.WriteLine("This is Working on MAC OS");
}
// --- NEW: Dynamic Screen Management ---
// Instead of creating both Menu and Game, we just track the active screen
IScreen currentScreen = new Menu();
GameState globalGameState = GameState.MENU;
// --------------------------------------
Raylib.SetTargetFPS(45);
while (!Raylib.WindowShouldClose())
{
// 1. Update and get the requested state for the NEXT frame
GameState nextState = currentScreen.DrawAndUpdate();
// 2. If the state changed (e.g., clicked Play), swap the screens!
if (nextState != globalGameState)
{
// SAFELY CLEAN UP OLD TEXTURES ON THE MAIN THREAD
currentScreen.Dispose();
// LOAD THE NEW SCREEN
if (nextState == GameState.GAME)
{
currentScreen = new Game();
}
else if (nextState == GameState.MENU)
{
currentScreen = new Menu();
}
globalGameState = nextState;
}
// 3. Draw the current screen
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.SkyBlue);
// Note: The actual drawing happens inside the DrawAndUpdate method above,
// but it still needs to be wrapped by BeginDrawing/EndDrawing!
Raylib.EndDrawing();
}
// --- FINAL CLEANUP ---
// When the player clicks the 'X' to close the window, dispose whatever screen is currently open
currentScreen.Dispose();
Raylib.CloseWindow();