-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathraylib_app.c
132 lines (105 loc) · 4.45 KB
/
raylib_app.c
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
#include "raylib.h"
#include <stdlib.h>
#define MAX_DROPS 300
#define MAX_SIZE 10
typedef struct {
Vector2 position;
float speed;
float windSpeed;
float gravity;
int type;
} Snowdrop;
Color snowColor = (Color){255, 255, 255, 200};
int snowDropSize = MAX_SIZE;
int snowDensity = MAX_DROPS;
void DrawUI()
{
const int padding = 10;
const int buttonWidth = 100;
const int buttonHeight = 30;
Vector2 colorButtonPos = {padding + 10, padding + 10};
DrawRectangleRec((Rectangle){colorButtonPos.x, colorButtonPos.y, buttonWidth, buttonHeight}, snowColor);
DrawText("Snow Color", colorButtonPos.x + buttonWidth / 2 - MeasureText("Snow Color", 10) / 2, colorButtonPos.y + buttonHeight / 2 - 5, 10, WHITE);
Vector2 sizeButtonPos = {padding + 10, padding + 50};
DrawRectangle(sizeButtonPos.x, sizeButtonPos.y, buttonWidth, buttonHeight, GRAY);
DrawText(TextFormat("Drop Size: %02d", snowDropSize), sizeButtonPos.x + buttonWidth / 2 - MeasureText(TextFormat("Drop Size: %02d", snowDropSize), 10) / 2, sizeButtonPos.y + buttonHeight / 2 - 5, 10, WHITE);
Vector2 densityButtonPos = {padding + 10, padding + 90};
DrawRectangle(densityButtonPos.x, densityButtonPos.y, buttonWidth, buttonHeight, GRAY);
DrawText(TextFormat("Density: %03d", snowDensity), densityButtonPos.x + buttonWidth / 2 - MeasureText(TextFormat("Density: %03d", snowDensity), 10) / 2, densityButtonPos.y + buttonHeight / 2 - 5, 10, WHITE);
Vector2 windSpeedButtonPos = {padding + 10, padding + 130};
DrawRectangle(windSpeedButtonPos.x, windSpeedButtonPos.y, buttonWidth, buttonHeight, GRAY);
DrawText("Wind Speed", windSpeedButtonPos.x + buttonWidth / 2 - MeasureText("Wind Speed", 10) / 2, windSpeedButtonPos.y + buttonHeight / 2 - 5, 10, WHITE);
}
void DrawSnowflake(Vector2 position, float size, Color color)
{
DrawPoly(position, 6, size, GetRandomValue(0, 360), color);
}
int main(void)
{
const int screenWidth = 1920;
const int screenHeight = 1080;
InitWindow(screenWidth, screenHeight, "Relaxing Snow Application");
ToggleFullscreen();
Snowdrop drops[MAX_DROPS];
for (int i = 0; i < MAX_DROPS; i++) {
drops[i].position.x = GetRandomValue(0, screenWidth);
drops[i].position.y = GetRandomValue(-screenHeight, 0);
drops[i].speed = (float)GetRandomValue(50, 100) / 100.0f;
drops[i].windSpeed = (float)GetRandomValue(-50, 50) / 100.0f;
drops[i].gravity = (float)GetRandomValue(90, 110) / 100.0f;
}
SetTargetFPS(60);
while (!WindowShouldClose())
{
for (int i = 0; i < MAX_DROPS; i++) {
drops[i].position.y += drops[i].speed * drops[i].gravity;
drops[i].position.x += drops[i].windSpeed;
// If a snowdrop reaches the bottom, reset its position to the top
if (drops[i].position.y > screenHeight) {
drops[i].position.y = GetRandomValue(-screenHeight, 0);
drops[i].position.x = GetRandomValue(0, screenWidth);
}
}
// user input
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
Vector2 mousePos = GetMousePosition();
Rectangle colorButton = {10, 10, 75, 30};
if (CheckCollisionPointRec(mousePos, colorButton))
{
snowColor.r = (snowColor.r + 50 > 255) ? 100 : snowColor.r + 50;
snowColor.g = snowColor.r;
snowColor.b = snowColor.r;
}
Rectangle sizeButton = {10, 50, 75, 30};
if (CheckCollisionPointRec(mousePos, sizeButton))
{
snowDropSize = (snowDropSize + 2) % 20;
}
Rectangle densityButton = {10, 90, 75, 30};
if (CheckCollisionPointRec(mousePos, densityButton))
{
snowDensity = (snowDensity + 25) % (MAX_DROPS + 1);
}
Rectangle windSpeedButton = {10, 130, 75, 30};
if (CheckCollisionPointRec(mousePos, windSpeedButton))
{
for (int i = 0; i < MAX_DROPS; i++)
{
drops[i].windSpeed = (float)GetRandomValue(-100, 100) / 100.0f;
}
}
}
// Draw
BeginDrawing();
ClearBackground(BLACK);
for (int i = 0; i < snowDensity; i++)
{
DrawSnowflake(drops[i].position, snowDropSize, snowColor);
}
DrawUI();
EndDrawing();
}
CloseWindow();
return 0;
}