Collider debug boxes with SDL_Rect
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user