Collider debug boxes with SDL_Rect

This commit is contained in:
2021-11-03 17:37:56 -04:00
parent 165052a617
commit bd0c49b3ae
10 changed files with 162 additions and 24 deletions

View File

@ -14,10 +14,13 @@
#include "ECS.h"
#include "../assetmgr/TextureManager.h"
#include <iostream>
#include "../game/Vector2D.h"
class ColliderComponent : public Component
{
public:
SDL_Rect collider;
std::string tag;
@ -28,9 +31,16 @@ public:
int offsetY = 0;
bool hidden = true;
Vector2D center;
TransformComponent* transform;
ColliderComponent()
{
center.Zero();
}
ColliderComponent(std::string t)
{
tag = t;
@ -43,6 +53,8 @@ public:
collider.y = ypos;
collider.w = collider.h = size*scale;
setTex(texture);
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
}
ColliderComponent(std::string t, int width, int height, bool hasOffset, int oX, int oY, std::string texture)
@ -53,6 +65,8 @@ public:
offsetX = oX;
offsetY = oY;
setTex(texture);
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
}
void init() override
@ -78,6 +92,10 @@ public:
}
destR.x = collider.x - Game::camera.x;
destR.y = collider.y - Game::camera.y;
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
// collider.x = transform->position.x;
// collider.y = transform->position.y;
}
void draw() override
@ -88,7 +106,10 @@ public:
// }
if(hidden == false)
{
TextureManager::Draw(tex, srcR,destR,SDL_FLIP_NONE);
// TextureManager::Draw(tex, srcR,destR,SDL_FLIP_NONE);
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
SDL_RenderDrawRect(Game::renderer, &destR);
// SDL_RenderDrawPoint(Game::renderer, center.x, center.y);
}
}