feat: Grid af spawning
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "dxd_math.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
vec2 operator+(vec2 const &v)
|
||||
{
|
||||
return { .x = v.x, .y = v.y };
|
||||
@@ -40,6 +42,16 @@ bool operator>(vec2 const &a, vec2 const &b)
|
||||
return a.x > b.x && a.y > b.y;
|
||||
}
|
||||
|
||||
bool operator<(vec2i const &a, vec2i const &b)
|
||||
{
|
||||
return a.x < b.x && a.y < b.y;
|
||||
}
|
||||
|
||||
bool operator>(vec2i const &a, vec2i const &b)
|
||||
{
|
||||
return a.x > b.x && a.y > b.y;
|
||||
}
|
||||
|
||||
float dot(vec2 const &a, vec2 const &b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y;
|
||||
@@ -76,7 +88,7 @@ vec2 max2(vec2 const &a, vec2 const &b)
|
||||
};
|
||||
}
|
||||
|
||||
vec2 polar_to_vec2(const float angle, const float len)
|
||||
vec2 polar_to_vec2(float const angle, float const len)
|
||||
{
|
||||
return {
|
||||
.x = len * sinf(angle),
|
||||
@@ -84,11 +96,16 @@ vec2 polar_to_vec2(const float angle, const float len)
|
||||
};
|
||||
}
|
||||
|
||||
float vec2_angle(const vec2 v)
|
||||
float vec2_angle(vec2 const v)
|
||||
{
|
||||
return atan2f(v.x, v.y);
|
||||
}
|
||||
|
||||
vec2 v2i_to_v2(vec2i const v)
|
||||
{
|
||||
return { (float)v.x, (float)v.y };
|
||||
}
|
||||
|
||||
float normalize_angle(const float angle)
|
||||
{
|
||||
float a = angle;
|
||||
@@ -104,3 +121,28 @@ float normalize_angle_diff(const float diff)
|
||||
while (d < -M_PIf) d += 2*M_PIf;
|
||||
return d;
|
||||
}
|
||||
|
||||
int rand_int(int const min, int const max)
|
||||
{
|
||||
return SDL_rand(max - min) + min;
|
||||
}
|
||||
|
||||
float rand_float(float const min, float const max)
|
||||
{
|
||||
return SDL_randf() * (max - min) + min;
|
||||
}
|
||||
|
||||
float rand_angle()
|
||||
{
|
||||
return rand_float(0, 2*M_PIf);
|
||||
}
|
||||
|
||||
vec2i rand_v2i(vec2i const min, vec2i const max)
|
||||
{
|
||||
return { rand_int(min.x, max.x), rand_int(min.y, max.y) };
|
||||
}
|
||||
|
||||
vec2 rand_v2(vec2 const min, vec2 const max)
|
||||
{
|
||||
return { rand_float(min.x, max.x), rand_float(min.y, max.y) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user