first commit
This commit is contained in:
104
src/ecs/ColliderComponent.h
Normal file
104
src/ecs/ColliderComponent.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* ColliderComponent.h
|
||||
*
|
||||
* Created on: Mar 8, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_ECS_COLLIDERCOMPONENT_H_
|
||||
#define SRC_ECS_COLLIDERCOMPONENT_H_
|
||||
|
||||
#include <string>
|
||||
#include "SDL2/SDL.h"
|
||||
#include "Components.h"
|
||||
#include "../assetmgr/TextureManager.h"
|
||||
#include <iostream>
|
||||
|
||||
class ColliderComponent : public Component
|
||||
{
|
||||
public:
|
||||
SDL_Rect collider;
|
||||
std::string tag;
|
||||
|
||||
SDL_Texture* tex;
|
||||
SDL_Rect srcR, destR;
|
||||
|
||||
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)
|
||||
{
|
||||
tag = t;
|
||||
collider.w = width;
|
||||
collider.h = height;
|
||||
}
|
||||
|
||||
void init() override
|
||||
{
|
||||
if (!entity->hasComponent<TransformComponent>())
|
||||
{
|
||||
entity->addComponent<TransformComponent>();
|
||||
}
|
||||
transform = &entity->getComponent<TransformComponent>();
|
||||
|
||||
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 };
|
||||
// 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<int>(transform->position.x)+9;
|
||||
// collider.y = static_cast<int>(transform->position.y)+28;
|
||||
//// collider.w = transform->width * transform->scale;
|
||||
//// collider.h = transform->height * transform->scale;
|
||||
// collider.w = 12 * transform->scale;
|
||||
// collider.h = 12 * transform->scale;
|
||||
//
|
||||
//// std::cout << "collider.w: " << collider.w << std::endl;
|
||||
//// std::cout << "collider.h: " << collider.h << std::endl;
|
||||
//// std::cout << "tag: " << tag << std::endl;
|
||||
// }
|
||||
destR.x = collider.x - Game::camera.x;
|
||||
destR.y = collider.y - Game::camera.y;
|
||||
// std::cout << "tag: " << tag << std::endl;
|
||||
}
|
||||
|
||||
void draw() override
|
||||
{
|
||||
if(tag == "terrain")
|
||||
{
|
||||
TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* SRC_ECS_COLLIDERCOMPONENT_H_ */
|
Reference in New Issue
Block a user