59 lines
1.0 KiB
C++
59 lines
1.0 KiB
C++
/*
|
|
* TileComponent.h
|
|
*
|
|
* Created on: Mar 21, 2020
|
|
* Author: ayoungblood
|
|
*/
|
|
|
|
#ifndef SRC_ECS_TILECOMPONENT_H_
|
|
#define SRC_ECS_TILECOMPONENT_H_
|
|
|
|
#include "ECS.h"
|
|
#include <SDL.h>
|
|
#include "../assetmgr/AssetManager.h"
|
|
|
|
class TileComponent : public Component
|
|
{
|
|
public:
|
|
|
|
SDL_Texture* texture;
|
|
SDL_Rect srcRect, destRect;
|
|
Vector2D position;
|
|
|
|
TileComponent() = default;
|
|
|
|
~TileComponent()
|
|
{
|
|
SDL_DestroyTexture(texture);
|
|
}
|
|
|
|
|
|
TileComponent(int srcX, int srcY, int xpos, int ypos, int tsize, int tscale, std::string id)
|
|
{
|
|
texture = Game::assets->GetTexture(id);
|
|
position.x = xpos;
|
|
position.y = ypos;
|
|
|
|
srcRect.x = srcX;
|
|
srcRect.y = srcY;
|
|
srcRect.w = srcRect.h = tsize;
|
|
|
|
destRect.x = xpos;
|
|
destRect.y = ypos;
|
|
destRect.w = destRect.h = tsize * tscale;
|
|
}
|
|
|
|
void update() override
|
|
{
|
|
destRect.x = position.x - Game::camera.x;
|
|
destRect.y = position.y - Game::camera.y;
|
|
}
|
|
|
|
void draw() override
|
|
{
|
|
TextureManager::Draw(texture, srcRect, destRect, SDL_FLIP_NONE);
|
|
}
|
|
};
|
|
|
|
#endif /* SRC_ECS_TILECOMPONENT_H_ */
|