-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject01
185 lines (165 loc) · 7.65 KB
/
Project01
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*******************************************************************************************
*
* raylib [textures] example - Bunnymark
*
* Example originally created with raylib 1.6, last time updated with raylib 2.5
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2022 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
/////
#include "raylib.h"
#include <stdlib.h> // Required for: malloc(), free()
#define MAX_BUNNIES 50000 // 50K bunnies limit
// This is the maximum amount of elements (quads) per batch
// NOTE: This value is defined in [rlgl] module and can be changed there
#define MAX_BATCH_ELEMENTS 8192
typedef struct Bunny {
Vector2 position;
Vector2 speed;
Color color;
} Bunny;
typedef struct lantern {
int x, y;
}lantern;
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 1920; //800
const int screenHeight = 1080; //450
int flag = 1;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark");
InitAudioDevice();
Sound mp3 = LoadSound("resources/goodluck.mp3");
// Load bunny texture
Texture2D texBunny = LoadTexture("resources/star.png");
Texture2D cartoon2 = LoadTexture("resources/lanternmedium.png");
Texture2D cartoon = LoadTexture("resources/lantern.png");
struct lantern lan[30];
for (int i = 0; i < 30; i++)
{
lan[i].x = i * 60 + 100;
lan[i].y = GetRandomValue(300, 400);;
}
Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array
int bunniesCount = 0; // Bunnies counter
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
if (flag)
{
PlaySound(mp3);
flag = 0;
}
// Create more bunnies
for (int i = 0; i < 50; i++)
{
if (bunniesCount < MAX_BUNNIES)
{
bunnies[bunniesCount].position = GetMousePosition();
bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f;
bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f;
bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240),
GetRandomValue(80, 240),
GetRandomValue(100, 240), 255 };
bunniesCount++;
}
}
}
// Update bunnies
for (int i = 0; i < bunniesCount; i++)
{
bunnies[i].position.x += bunnies[i].speed.x;
bunnies[i].position.y += bunnies[i].speed.y;
if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) ||
((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1;
if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) ||
((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
for (int i = 0; i < bunniesCount; i++)
{
// NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
// a draw call is launched and buffer starts being filled again;
// before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
// Process of sending data is costly and it could happen that GPU data has not been completely
// processed for drawing while new data is tried to be sent (updating current in-use buffers)
// it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
DrawTexture(texBunny, (int)bunnies[i].position.x, (int)bunnies[i].position.y, WHITE);
}
//DrawRectangle(0, 0, screenWidth, 40, BLACK);
//DrawText(TextFormat("bunnies: %i", bunniesCount), 120, 10, 20, GREEN);
//DrawText(TextFormat("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);
DrawText("HAPPY NEW YEAR", 530, 530, 100, RED);
DrawText("2023", 50, 50, 50, GRAY);
DrawText("1.1", 70, 100, 50, GRAY);
DrawCircle(150, 170, 50, RED);
DrawCircle(200, 160, 70, RED);
DrawCircle(280, 175, 50, RED);
DrawCircle(330, 180, 80, RED);
DrawCircle(400, 170, 60, RED);
DrawCircle(580, 185, 55, RED);
DrawCircle(700, 180, 60, RED);
DrawCircle(780, 170, 50, RED);
DrawCircle(900, 180, 70, RED);
DrawCircle(1000, 175, 60, RED);
DrawCircle(1150, 170, 80, RED);
DrawCircle(1350, 180, 70, RED);
DrawCircle(1500, 170, 60, RED);
DrawCircle(1650, 165, 30, RED);
DrawCircle(1750, 170, 50, RED);
DrawCircle(1850, 180, 40, RED);
DrawCircle(150, 140, 20, YELLOW);
DrawCircle(200, 140, 20, YELLOW);
DrawCircle(280, 135, 20, YELLOW);
DrawCircle(330, 145, 20, YELLOW);
DrawCircle(400, 140, 20, YELLOW);
DrawCircle(580, 130, 20, YELLOW);
DrawCircle(700, 140, 20, YELLOW);
DrawCircle(780, 145, 20, YELLOW);
DrawCircle(900, 140, 20, YELLOW);
DrawCircle(1000, 130, 20, YELLOW);
DrawCircle(1150, 140, 20, YELLOW);
DrawCircle(1350, 135, 20, YELLOW);
DrawCircle(1450, 140, 20, YELLOW);
DrawCircle(1550, 130, 20, YELLOW);
DrawCircle(1650, 140, 20, YELLOW);
DrawCircle(1750, 135, 20, YELLOW);
DrawCircle(1850, 130, 20, YELLOW);
DrawTexture(cartoon2, 200, 700, WHITE);
DrawTexture(cartoon2, 1550, 700, WHITE);
for (int i = 0; i < 30; i++)
{
DrawTexture(cartoon, lan[i].x, lan[i].y, WHITE);
}
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
free(bunnies); // Unload bunnies data array
UnloadTexture(texBunny); // Unload bunny texture
UnloadTexture(cartoon2);
UnloadTexture(cartoon);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}