/* * ColliderComponent.h * * Created on: Mar 8, 2020 * Author: ayoungblood */ #ifndef SRC_ECS_COLLIDERCOMPONENT_H_ #define SRC_ECS_COLLIDERCOMPONENT_H_ #include #include "SDL2/SDL.h" #include "Components.h" #include "ECS.h" #include "../assetmgr/TextureManager.h" #include class ColliderComponent : public Component { public: SDL_Rect collider; std::string tag; SDL_Texture* tex; SDL_Rect srcR, destR; int offsetX = 0; int offsetY = 0; TransformComponent* transform; ColliderComponent(std::string t) { tag = t; // collider.x = 10; // collider.y = 52; // collider.w = collider.h = 12; } ColliderComponent(std::string t, int xpos, int ypos, int size, int scale) { tag = t; collider.x = xpos; collider.y = ypos; collider.w = collider.h = size*scale; } ColliderComponent(std::string t, int width, int height, bool hasOffset, int oX, int oY) { tag = t; collider.w = width; collider.h = height; offsetX = oX; offsetY = oY; } void init() override { if (!entity->hasComponent()) { entity->addComponent(); } transform = &entity->getComponent(); collider.x = collider.x + offsetX; collider.y = collider.y + offsetX; tex = TextureManager::LoadTexture("assets/ColTex.png"); srcR = { 0, 0, 16, 16}; destR = { collider.x, collider.y, collider.w, collider.h }; // if(tag == "player"){ // destR = { 18, 28, 24, 24 }; // collider.w = 16; // collider.h = 16; // transform->height = 24; // transform->width = 24; // std::cout << "player collider init() ran" << std::endl; // std::cout << "destR.w: " << destR.w << std::endl; // std::cout << "destR.h: " << destR.h << std::endl; // } // Game::colliders.push_back(this); } void update() override { if(tag != "terrain") { collider.x = static_cast(transform->position.x+offsetX); collider.y = static_cast(transform->position.y+offsetY); // collider.w = transform->width * transform->scale; // collider.h = transform->height * transform->scale; // collider.w = 12 * transform->scale; // collider.h = 12 * transform->scale; } destR.x = collider.x - Game::camera.x; destR.y = collider.y - Game::camera.y; } void draw() override { if(tag == "terrain") { TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE); // TextureManager::DrawCollider(destR); } } }; #endif /* SRC_ECS_COLLIDERCOMPONENT_H_ */