Implemented grid. Modified map renderer so that it can render tiles that have a different size than the map tiles. (Note: this change is not tested yet).
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
#ifndef COMPONENT_H_
|
||||
#define COMPONENT_H_
|
||||
|
||||
#include <model/ICloneable.h>
|
||||
#include <model/INonAssignable.h>
|
||||
#include <utils/ICloneable.h>
|
||||
#include <utils/INonAssignable.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace model {
|
||||
|
||||
class GameObject;
|
||||
|
||||
class Component : public INonAssignable, public ICloneable<Component>
|
||||
class Component : public utils::INonAssignable, public utils::ICloneable<Component>
|
||||
{
|
||||
public:
|
||||
Component();
|
||||
|
@@ -8,9 +8,9 @@
|
||||
#ifndef GAMEOBJECT_H_
|
||||
#define GAMEOBJECT_H_
|
||||
|
||||
#include <model/ICloneable.h>
|
||||
#include <model/INonAssignable.h>
|
||||
#include <utils/Assert.h>
|
||||
#include <utils/ICloneable.h>
|
||||
#include <utils/INonAssignable.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace model {
|
||||
class Component;
|
||||
class RenderContext;
|
||||
|
||||
class GameObject : public INonAssignable, public ICloneable<GameObject>
|
||||
class GameObject : public utils::INonAssignable, public utils::ICloneable<GameObject>
|
||||
{
|
||||
public:
|
||||
typedef std::unordered_map<std::type_index, Component*> ComponentContainer;
|
||||
|
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* ICloneable.h
|
||||
*
|
||||
* Created on: Dec 2, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef BASE_ICLONEABLE_H_
|
||||
#define BASE_ICLONEABLE_H_
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
template <typename T>
|
||||
class ICloneable
|
||||
{
|
||||
public:
|
||||
virtual ~ICloneable() { };
|
||||
virtual T* clone() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* BASE_ICLONEABLE_H_ */
|
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* INonAssignable.h
|
||||
*
|
||||
* Created on: Dec 2, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef BASE_INONASSIGNABLE_H_
|
||||
#define BASE_INONASSIGNABLE_H_
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
class INonAssignable
|
||||
{
|
||||
public:
|
||||
virtual ~INonAssignable() { };
|
||||
|
||||
INonAssignable() { }
|
||||
INonAssignable(const INonAssignable&) = delete;
|
||||
INonAssignable& operator=(const INonAssignable&) = delete;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* BASE_INONASSIGNABLE_H_ */
|
42
src/model/TileSet.h
Normal file
42
src/model/TileSet.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* TileMap.h
|
||||
*
|
||||
* Created on: Dec 5, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef MODEL_TILESET_H_
|
||||
#define MODEL_TILESET_H_
|
||||
|
||||
#include <resources/ResourceManager.h>
|
||||
#include <utils/Rect.h>
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
struct TileSet
|
||||
{
|
||||
resources::ResourceId texture;
|
||||
size_t width, height;
|
||||
size_t tileWidth, tileHeight;
|
||||
|
||||
// Gets the boundary of a cell based on its id
|
||||
utils::Rect<int> getCell(int cellId);
|
||||
};
|
||||
|
||||
inline utils::Rect<int> TileSet::getCell(int cellId)
|
||||
{
|
||||
utils::Rect<int> r;
|
||||
size_t tilesRow = width / tileWidth;
|
||||
|
||||
r.x = tileWidth * (cellId % tilesRow);
|
||||
r.y = tileHeight * (cellId / tilesRow);
|
||||
r.w = tileWidth;
|
||||
r.h = tileHeight;
|
||||
return r;
|
||||
}
|
||||
|
||||
} /* namespace model */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* MODEL_TILESET_H_ */
|
Reference in New Issue
Block a user