aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-08 12:53:10 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-08 12:53:10 +0100
commit2e65d249e04e1450a4c45a4fb5d48213a75cf3e0 (patch)
tree087433201cc4dd7727cf8aac5f7950b857e8e66f /game
parentb5ed442444d7243935f7ba58c7d0e0ada743d230 (diff)
parentc9c9702edc58ff8f40b13dc6b86b216421f79e9b (diff)
Merge remote-tracking branch 'origin/master' into max/game2
Diffstat (limited to 'game')
-rw-r--r--game/CMakeLists.txt2
-rw-r--r--game/Random.cpp28
-rw-r--r--game/Random.h11
3 files changed, 40 insertions, 1 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 662a5e7..4e31f80 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -4,7 +4,6 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_BUILD_TYPE Debug)
-
project(game C CXX)
add_subdirectory(../src crepe)
@@ -51,6 +50,7 @@ add_executable(main
hud/HudSubScene.cpp
hud/HudScript.cpp
hud/SpeedScript.cpp
+ Random.cpp
)
target_link_libraries(main PUBLIC crepe)
diff --git a/game/Random.cpp b/game/Random.cpp
new file mode 100644
index 0000000..59be3c5
--- /dev/null
+++ b/game/Random.cpp
@@ -0,0 +1,28 @@
+#include <cstdlib>
+
+#include "Random.h"
+
+float Random::f(float upper, float lower) {
+ float range = upper - lower;
+ float x = ((float) rand() / (float) (RAND_MAX)) * range;
+ return x + lower;
+}
+
+double Random::d(double upper, double lower) {
+ double range = upper - lower;
+ double x = ((double) rand() / (double) (RAND_MAX)) * range;
+ return x + lower;
+}
+
+int Random::i(int upper, int lower) {
+ int range = upper - lower;
+ int x = rand() % range;
+ return x + lower;
+}
+
+unsigned Random::u(unsigned upper, unsigned lower) {
+ unsigned range = upper - lower;
+ unsigned x = rand() % range;
+ return x + lower;
+}
+
diff --git a/game/Random.h b/game/Random.h
new file mode 100644
index 0000000..cf05e87
--- /dev/null
+++ b/game/Random.h
@@ -0,0 +1,11 @@
+#pragma once
+
+class Random {
+public:
+ static float f(float upper = 1.0, float lower = 0.0);
+ static double d(double upper = 1.0, double lower = 0.0);
+ static int i(int upper, int lower = 0);
+ static unsigned u(unsigned upper, unsigned lower = 0);
+
+};
+