halsafar/libtmx-parser added to project
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
#include "PlayerController.h"
|
||||
#include "ProjectileComponent.h"
|
||||
#include "TileComponent.h"
|
||||
#include "TileMapComponent.h"
|
||||
#include "UITextComponent.h"
|
||||
|
||||
#endif /* SRC_COMPONENTS_H_ */
|
||||
|
79
src/ecs/TileMapComponent.h
Normal file
79
src/ecs/TileMapComponent.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* TileMapComponent.h
|
||||
*
|
||||
* Created on: Mar 21, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_ECS_TILEMAPCOMPONENT_H_
|
||||
#define SRC_ECS_TILEMAPCOMPONENT_H_
|
||||
|
||||
#include "ECS.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include "../assetmgr/AssetManager.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
class TileMapComponent : public Component
|
||||
{
|
||||
public:
|
||||
TransformComponent *transform;
|
||||
SDL_Texture* texture;
|
||||
SDL_Rect srcRect, destRect;
|
||||
Vector2D position;
|
||||
std::tuple <SDL_Rect,SDL_Rect> tile;
|
||||
|
||||
TileMapComponent() = default;
|
||||
|
||||
~TileMapComponent()
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
TileMapComponent(std::string id, int tsize, int tscale)
|
||||
{
|
||||
setTex(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
|
||||
{
|
||||
//iterate through rows and columns of the map to draw the tiles
|
||||
|
||||
TextureManager::Draw(texture, srcRect, destRect, SDL_FLIP_NONE);
|
||||
}
|
||||
|
||||
std::tuple<SDL_Rect,SDL_Rect> getTile(char currentTile, int i)
|
||||
{
|
||||
std::tuple<SDL_Rect,SDL_Rect> tileTuple;
|
||||
|
||||
|
||||
tileTuple = std::make_tuple(srcRect,destRect);
|
||||
return tileTuple;
|
||||
}
|
||||
|
||||
void setTex(std::string id)
|
||||
{
|
||||
texture = Game::assets->GetTexture(id);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* SRC_ECS_TILEMAPCOMPONENT_H_ */
|
||||
|
@ -34,9 +34,7 @@ private:
|
||||
SDL_RendererFlip spriteFlip = SDL_FLIP_NONE;
|
||||
std::tuple <SDL_Rect, SDL_Rect> letter;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
public:
|
||||
UITextComponent(std::string id, std::string textToPrint, int letterW, int letterH, int letterScale)
|
||||
{
|
||||
setTex(id);
|
||||
|
Reference in New Issue
Block a user