Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
92 lines (74 loc) · 3.12 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (74 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
using System.Numerics;
using Raylib_cs;
using Source.Upgrades;
using Source.Utils;
namespace Source;
internal static class Program
{
private static void Main()
{
//FIRST
// set config flags to resizable
Raylib.SetConfigFlags(ConfigFlags.ResizableWindow);
// initialize the window
Raylib.InitWindow(1280, 720, "Raylib Clicker Game");
// set frame rate to 60
Raylib.SetTargetFPS(60);
// MAKE AFTER UPGRADE
double score = 0.0; // starting score (debug is 250)
List<Upgrade> shop = new()
{
new Upgrade("Stupid Drill", 2, 0.05),
new Upgrade("Copper Drill", 50, 2),
new Upgrade("Diamond Drill", 10000, 1000)
};
// FIRST
while (!Raylib.WindowShouldClose())
{
// MAKE AFTER UPGRADE
float deltaTime = Raylib.GetFrameTime();
double totalPassiveIncome = shop.Sum(item => item.GetTotalIncome());
score += totalPassiveIncome * deltaTime;
float screenW = Raylib.GetScreenWidth();
float screenH = Raylib.GetScreenHeight();
// SECOND
Rectangle clickButtonBounds = new(50, (screenH / 2f) - 100, 300, 200);
Rectangle shopPanel = new(screenW - 380, 20, 350, screenH - 40);
//SECOND
// main click button
Vector2 mousePos = Raylib.GetMousePosition();
bool isClickHover = Raylib.CheckCollisionPointRec(mousePos, clickButtonBounds);
// FIRST
Raylib.BeginDrawing();
{
Raylib.ClearBackground(Color.Black);
// SECOND
Raylib.DrawRectangleRec(clickButtonBounds, isClickHover ? Color.LightGray : Color.Gray);
Raylib.DrawText("CLICK ME", (int)clickButtonBounds.X + 90, (int)clickButtonBounds.Y + 85, 24, Color.White);
// THIRD
// if mouse clicks the button
if (Raylib.IsMouseButtonPressed(MouseButton.Left) && isClickHover)
score += 1.0;
// MAKE AFTER UPGRADE
// shop panel
Raylib.DrawRectangleLinesEx(shopPanel, 2, Color.LightGray);
Raylib.DrawText("UPGRADE SHOP", (int)shopPanel.X + 10, (int)shopPanel.Y + 10, 24, Color.White);
// loop through shop dynamically
for (int i = 0; i < shop.Count; i++)
{
Rectangle dynamicBtnBounds = new(
shopPanel.X + 20,
shopPanel.Y + 50 + (i * 80),
shopPanel.Width - 40,
65
);
shop[i].UpdateAndDraw(ref score, dynamicBtnBounds);
}
Raylib.DrawText($"Score: {score:F2}", 50, 50, 32, Color.RayWhite);
Raylib.DrawText($"Income/Sec: {GameUtils.FormatNumber(totalPassiveIncome)}", 50, 100, 24, Color.RayWhite);
}
Raylib.EndDrawing();
}
Raylib.CloseWindow();
}
}