[ADD] simple enemy collision
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "toolbox.h"
|
||||
|
||||
|
||||
float toolbox_random_float(float a, float b)
|
||||
{
|
||||
float random = ((float)rand()) / (float)RAND_MAX;
|
||||
@@ -8,11 +9,11 @@ float toolbox_random_float(float a, float b)
|
||||
return a + r;
|
||||
}
|
||||
|
||||
size_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2)
|
||||
uint8_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2)
|
||||
{
|
||||
//TODO make it work
|
||||
return x1 < x2 + width2 / 2 &&
|
||||
x1 + width1 / 2 > x2 &&
|
||||
y1 < y2 + height2 / 2 &&
|
||||
y1 + heigth1 / 2 > y2;
|
||||
//TODO make it work?
|
||||
return x1 - width1 / 2 < x2 + width2 / 2 &&
|
||||
x1 + width1 / 2 > x2 - width2 / 2 &&
|
||||
y1 - heigth1 / 2 < y2 + height2 / 2 &&
|
||||
y1 + heigth1 / 2 > y2 - height2 / 2;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef TOOLBOX_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "../sprites/sprites.h"
|
||||
|
||||
/**
|
||||
* @brief generates a random float between the given floats
|
||||
@@ -21,8 +22,8 @@ float toolbox_random_float(float a, float b);
|
||||
* @param y2 the center y of the second object
|
||||
* @param width2 the width of the second object
|
||||
* @param height2 the heigth of the second object
|
||||
* @return size_t 0 if no collision, 1 if there is a collision.
|
||||
* @return uint8_t 0 if no collision, 1 if there is a collision.
|
||||
*/
|
||||
size_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2);
|
||||
uint8_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2);
|
||||
|
||||
#endif // !TOOLBOX_H
|
||||
Reference in New Issue
Block a user