first commit
This commit is contained in:
58
src/ecs/TileComponent.h
Normal file
58
src/ecs/TileComponent.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* TileComponent.h
|
||||
*
|
||||
* Created on: Mar 21, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_ECS_TILECOMPONENT_H_
|
||||
#define SRC_ECS_TILECOMPONENT_H_
|
||||
|
||||
#include "ECS.h"
|
||||
#include "SDL2/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_ */
|
Reference in New Issue
Block a user