0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 09:03:42 +00:00
SDL_Minigame/src/ColliderComponent.h

36 lines
702 B
C++

#pragma once
#include <string>
#include "SDL.h"
#include "Components.h"
class ColliderComponent : public Component
{
public:
SDL_Rect collider;
const char* tag;
TransformComponent* transform;
ColliderComponent(const char* tag)
{
this->tag = tag;
}
void init() override
{
if (!entity->hasComponent<TransformComponent>())
{
entity->addComponent<TransformComponent>();
}
transform = &entity->getComponent<TransformComponent>();
Game::colliders.push_back(this);
}
void update() override
{
collider.x = transform->position.x;
collider.y = transform->position.y;
collider.w = transform->width * transform->scale;
collider.h = transform->height * transform->scale;
}
};