Testing some enemies

This commit is contained in:
2023-03-30 18:29:56 -07:00
parent 033a8864c1
commit 3bdf44994c
19 changed files with 348 additions and 70 deletions

View File

@ -68,12 +68,13 @@ namespace Dawn {
* @param b Number to modulo with. (a % b)
* @returns The modulo result.
*/
static float_t mathMod(float_t value, float_t modulo) {
return (float_t)fmod(value, modulo);
template<typename T>
static inline T mathMod(T value, T modulo) {
return ((value % modulo) + modulo) % modulo;
}
static int32_t mathMod(int32_t value, int32_t modulo) {
return ((value % modulo) + modulo) % modulo;
static inline float_t mathMod(float_t value, float_t modulo) {
return (float_t)fmod(value, modulo);
}
/**

View File

@ -4,40 +4,49 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "mathutils.hpp"
/**
* Seed the random number generator
* @param seed Seed to use for the seeded random number generator.
*/
static void randSeed(int32_t seed) {
srand(seed);
}
namespace Dawn {
/**
* Seed the random number generator
* @param seed Seed to use for the seeded random number generator.
*/
static void randSeed(int32_t seed) {
srand(seed);
}
static int32_t randomGeneratei32() {
return (int32_t)rand();
}
static int32_t randomGeneratei32() {
return (int32_t)rand();
}
/**
* Generates a random number.
* @returns A random number.
*/
template<typename T>
static T randomGenerate() {
return (T)((float_t)randomGeneratei32() * MATH_PI);
}
/**
* Generates a random number.
* @returns A random number.
*/
template<typename T>
static T randomGenerate() {
return (T)((float_t)randomGeneratei32() * MATH_PI);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
* Clamps a random number generation.
*
* @param min Minimum value to generate from. (Inclusive)
* @param max Maximum value to generate to. (Exclusive)
* @return Random number between min and max.
*/
template<typename T>
static inline T randRange(T min, T max) {
return mathMod(randomGenerate<T>(), (max - min)) + min;
/**
* Clamps a random number generation.
*
* @param min Minimum value to generate from. (Inclusive)
* @param max Maximum value to generate to. (Exclusive)
* @return Random number between min and max.
*/
template<typename T>
static inline T randRange(T min, T max) {
return mathMod<T>(randomGenerate<T>(), (max - min)) + min;
}
static inline float_t randRange(float_t min, float_t max) {
return mathMod(randomGenerate<float_t>(), (max - min)) + min;
}
static inline glm::vec2 randRange(glm::vec2 min, glm::vec2 max) {
return glm::vec2(randRange(min.x, max.x), randRange(min.y, max.y));
}
}