Raylib Bubbles
C++11 Raylib bubble shooter game.
util.hpp
1 #ifndef UTIL_HPP_
2 #define UTIL_HPP_
3 
4 #include <cstddef>
5 #include <string>
6 #include <fstream>
7 #include <algorithm>
8 #include <stdexcept>
9 
10 #include <unistd.h>
11 
12 #include <raylib.h>
13 #include <inipp.h>
14 
26 class GameUtils {
27 public:
30 
43  static std::string getAbsDir();
44 
52  static std::string getCfgStr(const std::string& section, const std::string& key);
53 
61  static size_t getCfgSizeT(const std::string& section, const std::string& key);
62 
70  static float getCfgFloat(const std::string& section, const std::string& key);
71 
80  static bool getCfgBool(const std::string& section, const std::string& key);
81 
83 
86 
94  static inline float clampLH(float& value, const float lowLimit, const float highLimit) {
95  float original = value;
96  value = std::max(lowLimit, std::min(value, highLimit));
97  return original - value;
98  }
99 
106  static inline float clampL(float& value, const float lowLimit) {
107  float original = value;
108  value = std::max(value, lowLimit);
109  return original - value;
110  }
111 
118  static inline float clampH(float& value, const float highLimit) {
119  float original = value;
120  value = std::min(value, highLimit);
121  return original - value;
122  }
123 
125 
128 
133  inline static float randf() {
134  return static_cast<float>(GetRandomValue(0, RAND_MAX)) / static_cast<float>(RAND_MAX);
135  }
136 
143  inline static int randi(const int low, const int high) {
144  return GetRandomValue(low, high);
145  }
146 
148 };
149 
150 #endif
Provides utility functions for the game.
Definition: util.hpp:26
static float clampH(float &value, const float highLimit)
Clamp a float value to a maximum and return the excess.
Definition: util.hpp:118
static size_t getCfgSizeT(const std::string &section, const std::string &key)
Get a size_t from the configuration file.
Definition: util.cpp:29
static std::string getCfgStr(const std::string &section, const std::string &key)
Get a string from the configuration file.
Definition: util.cpp:15
static std::string getAbsDir()
Get the absolute path to the game's directory.
Definition: util.cpp:3
static float getCfgFloat(const std::string &section, const std::string &key)
Get a float from the configuration file.
Definition: util.cpp:44
static float clampLH(float &value, const float lowLimit, const float highLimit)
Clamp a float value between two limits and return the excess.
Definition: util.hpp:94
static bool getCfgBool(const std::string &section, const std::string &key)
Get a bool from the configuration file.
Definition: util.cpp:54
static float clampL(float &value, const float lowLimit)
Clamp a float value to a minimum and return the excess.
Definition: util.hpp:106
static float randf()
Get a random float value between 0.0f and 1.0f.
Definition: util.hpp:133
static int randi(const int low, const int high)
Get a random integer value between two limits.
Definition: util.hpp:143