removed pointless pointers in rectange, reset background clear color, fixed entity, and added some state functions

This commit is contained in:
herbglitch 2025-03-17 02:31:23 -06:00
parent dd1f3ca3e0
commit bd7e3212da
12 changed files with 161 additions and 86 deletions

View file

@ -1,4 +1,5 @@
#include "arc/math/rectangle.h"
#include "arc/std/bool.h"
//VERY TEMP
// #include <SDL.h>
@ -13,54 +14,54 @@ void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect *bounds){
rect->y = (bounds->y + (bounds->h / 2.0f)) - (rect->h / 2.0f);
}
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect *rect){
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect rect){
return (ARC_FRect){
.x = (float)rect->x,
.y = (float)rect->y,
.w = (float)rect->w,
.h = (float)rect->h,
.x = (float)rect.x,
.y = (float)rect.y,
.w = (float)rect.w,
.h = (float)rect.h,
};
}
ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect){
ARC_Rect ARC_FRect_CastToRect(ARC_FRect rect){
return (ARC_Rect){
.x = (int32_t)rect->x,
.y = (int32_t)rect->y,
.w = (int32_t)rect->w,
.h = (int32_t)rect->h,
.x = (int32_t)rect.x,
.y = (int32_t)rect.y,
.w = (int32_t)rect.w,
.h = (int32_t)rect.h,
};
}
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){
if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
return 1;
ARC_Bool ARC_Rect_Intersects(ARC_Rect rect1, ARC_Rect rect2){
if(rect1.x <= rect2.x + rect2.w && rect1.x + rect1.w >= rect2.x &&
rect1.y <= rect2.y + rect2.h && rect1.y + rect1.h >= rect2.y){
return ARC_True;
}
return 0;
return ARC_False;
}
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2){
if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
return 1;
ARC_Bool ARC_FRect_Intersects(ARC_FRect rect1, ARC_FRect rect2){
if(rect1.x <= rect2.x + rect2.w && rect1.x + rect1.w >= rect2.x &&
rect1.y <= rect2.y + rect2.h && rect1.y + rect1.h >= rect2.y){
return ARC_True;
}
return 0;
return ARC_False;
}
int32_t ARC_Rect_IntersectsPoint(ARC_Rect *rect, ARC_Point *point){
if(rect->x <= point->x && rect->x + rect->w >= point->x &&
rect->y <= point->y && rect->y + rect->h >= point->y){
return 1;
ARC_Bool ARC_Rect_IntersectsPoint(ARC_Rect rect, ARC_Point point){
if(rect.x <= point.x && rect.x + rect.w >= point.x &&
rect.y <= point.y && rect.y + rect.h >= point.y){
return ARC_True;
}
return 0;
return ARC_False;
}
int32_t ARC_FRect_IntersectsPoint(ARC_FRect *rect, ARC_Point *point){
if(rect->x <= point->x && rect->x + rect->w >= point->x &&
rect->y <= point->y && rect->y + rect->h >= point->y){
return 1;
ARC_Bool ARC_FRect_IntersectsPoint(ARC_FRect rect, ARC_Point point){
if(rect.x <= point.x && rect.x + rect.w >= point.x &&
rect.y <= point.y && rect.y + rect.h >= point.y){
return ARC_True;
}
return 0;
return ARC_False;
}
int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2){
@ -80,19 +81,19 @@ void ARC_FRect_CollideAndSlide(ARC_FRect *rect, ARC_Vector2 *velocity, ARC_FRect
};
//there is no collision, return
if(!ARC_FRect_Intersects(&nextRectPosition, wall)){
if(!ARC_FRect_Intersects(nextRectPosition, *wall)){
return;
}
nextRectPosition.x = rect->x + velocity->x;
nextRectPosition.y = rect->y;
if(ARC_FRect_Intersects(&nextRectPosition, wall)){
if(ARC_FRect_Intersects(nextRectPosition, *wall)){
velocity->x = 0;
}
nextRectPosition.x = rect->x;
nextRectPosition.y = rect->y + velocity->y;
if(ARC_FRect_Intersects(&nextRectPosition, wall)){
if(ARC_FRect_Intersects(nextRectPosition, *wall)){
velocity->y = 0;
}
}
}