-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
224 lines (188 loc) · 7.3 KB
/
main.cpp
File metadata and controls
224 lines (188 loc) · 7.3 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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*******************************************************************************************
*
* raylib-cpp [core] example - Basic window (adapted for HTML5 platform)
*
* This example is prepared to compile for PLATFORM_WEB, PLATFORM_DESKTOP and PLATFORM_RPI
* As you will notice, code structure is slightly diferent to the other examples...
* To compile it for PLATFORM_WEB just uncomment #define PLATFORM_WEB at beginning
*
* This example has been created using raylib-cpp (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
* Changed by LianYou, 2025.02.02
*
********************************************************************************************/
#include "raylib-assert.h"
#include "raylib-cpp.hpp"
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
// Main Enry Point
//----------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
// SomeSingleTest
//-------------------------------------------------------------------------------------
RLSetTraceLogLevel(LOG_INFO);
RLTraceLog(LOG_INFO, "---------------------");
RLTraceLog(LOG_INFO, "TEST: raylib-cpp test");
// Get a path to where the executable is so file loading is relative.
std::string path = "";
if (argc > 0) {
path = RLGetDirectoryPath(argv[0]);
}
// Vector
{
raylib::Vector2 position(50, 100);
AssertEqual(position.GetX() == position.x);
position.x = 150;
AssertEqual(position.GetX() == 150);
position.SetX(300);
AssertEqual(position.GetX() == 300);
raylib::Vector2 speed(10, 10);
position += speed;
AssertEqual(position.x == 310);
AssertEqual(raylib::Window::IsReady() == false);
raylib::Vector2 size{50, 100};
raylib::Vector2 halfsize = size / 2.0f;
AssertEqual(size.x == 50);
AssertEqual(size.y == 100);
AssertEqual(halfsize.x == 25);
AssertEqual(halfsize.y == 50);
raylib::Vector2 doublesize = size * 2.0f;
AssertEqual(size.x == 50);
AssertEqual(doublesize.x == 100);
}
// Color
{
raylib::Color color = RED;
AssertEqual(color.ToInt() == ::RLColorToInt(RED));
color = RAYWHITE;
::Color raylibColor = RAYWHITE;
AssertEqual(color.r == raylibColor.r);
}
// Math
{
raylib::Vector2 direction(50, 50);
raylib::Vector2 newDirection = direction.Rotate(30);
AssertEqual((int)newDirection.x == 57);
}
// Image
{
// Loading
raylib::Image image(path + "/resources/feynman.png");
Assert(image.IsValid());
// Chaining
image.Crop(100, 100).Resize(50, 50);
AssertEqual(image.GetWidth() == 50);
AssertEqual(image.GetHeight() == 50);
}
// Keyboard
{ AssertNot(raylib::Keyboard::IsKeyPressed(KEY_MINUS)); }
// raylib::LoadDirectoryFiles()
{
const char* AppDir = ::RLGetApplicationDirectory();
std::string resourcesDir(AppDir);
resourcesDir += "resources";
RLTraceLog(LOG_INFO, resourcesDir.c_str());
std::vector<std::string> files = raylib::LoadDirectoryFiles(resourcesDir);
RLTraceLog(LOG_INFO, std::to_string(files.size()).c_str());
Assert(files.size() == 3);
}
// raylib::TextReplace()
{
std::string input = "Hello World!";
std::string output = raylib::TextReplace(input, "World", "Moon");
AssertEqual(output == "Hello Moon!");
}
// raylib::TextInsert()
{
std::string input = "Hello World!";
std::string output = raylib::TextInsert(input, "Good!", 0);
AssertEqual(output == "Good! World!");
}
// raylib::TextSubtext()
{
std::string input = "Hello World!";
std::string output = raylib::TextSubtext(input, 6, 5);
AssertEqual(output == "World");
}
// TextSplit
{
std::vector<std::string> output = raylib::TextSplit("Hello|How|Are|You", '|');
AssertEqual(output.size() == 4);
AssertEqual(output[1] == "How");
}
// Wave
{
raylib::Wave wave(path + "/resources/weird.wav");
Assert(wave.IsValid()); // , "Expected wave to be loaded correctly"
}
// RaylibException
{
bool passed = false;
try {
raylib::Texture texture("notfound.png");
} catch (raylib::RaylibException& error) {
error.TraceLog(LOG_INFO);
passed = true;
}
Assert(passed); // , "Expected to have a RaylibException to be thrown"
}
// Load FileData
{
raylib::FileData file(path + "/resources/weird.wav");
Assert(file.GetBytesRead() > 0); // , "Expected file to be loaded correctly"
}
// Load FileText
{
raylib::FileText text(path + "/resources/lorem.txt");
Assert(text.GetLength() > 0); // , "Expected file to be loaded correctly"
AssertEqual(text.ToString().substr(0, 5) == "Lorem");
}
RLTraceLog(LOG_INFO, "TEST: raylib-cpp test");
RLTraceLog(LOG_INFO, "---------------------");
//--------------------------------------------------------------------------------------
RLTraceLog(LOG_INFO, "TEST: raylib-cpp CreateDemoWindow");
// Initialization
//--------------------------------------------------------------------------------------
raylib::Window window(screenWidth, screenHeight, "raylib-cpp [core] example - basic window", ConfigFlags::FLAG_WINDOW_RESIZABLE);
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
RLSetTargetFPS(120); // Set our game to run at 120 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!window.ShouldClose()) // Detect window close button or ESC key
{
UpdateDrawFrame();
}
#endif
return 0;
}
//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
void UpdateDrawFrame(void)
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
RLBeginDrawing();
RLClearBackground(RAYWHITE);
RLDrawText("Congrats! You created your first raylib-cpp window!", 160, 200, 20, LIGHTGRAY);
RLEndDrawing();
//----------------------------------------------------------------------------------
}