-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
149 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#ifndef SFUTILS_GEOMETRY_BASETILE_HPP | ||
#define SFUTILS_GEOMETRY_BASETILE_HPP | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include <cmath> | ||
|
||
namespace sfutils | ||
{ | ||
namespace geometry | ||
{ | ||
template<typename T> | ||
struct BaseTile | ||
{ | ||
static const sf::ConvexShape& getShape() {return T::_shape;}; | ||
protected: | ||
static sf::ConvexShape _shape; | ||
}; | ||
|
||
#define SFML_UTILS_BASE_TILE_INIT(klass) \ | ||
template <> sf::ConvexShape BaseTile<klass>::_shape = sf::ConvexShape(); | ||
|
||
template<typename T> | ||
struct _BaseSquare : public BaseTile<T> | ||
{ | ||
static sf::Vector2i round(float x,float y) | ||
{ | ||
if(x>=0) | ||
x+=0.5; | ||
else | ||
x-=0.5; | ||
|
||
if(y>=0) | ||
y+=0.5; | ||
else | ||
y-=0.5; | ||
|
||
return sf::Vector2i(x,y); | ||
} | ||
|
||
|
||
static sf::IntRect getTextureRect(int x,int y,float scale) | ||
{ | ||
sf::Vector2f pos = T::mapCoordsToPixel(x,y,scale); | ||
sf::IntRect res(pos.x, | ||
pos.y, | ||
T::width * scale, | ||
T::height * scale); | ||
return res; | ||
} | ||
|
||
static int distance(int x1,int y1, int x2,int y2) | ||
{ | ||
float x = x1 - x2; | ||
x = x*x; | ||
|
||
float y = y1 - y2; | ||
y = y*y; | ||
|
||
return std::ceil(sqrt(x + y)); | ||
} | ||
}; | ||
|
||
template<typename T> | ||
struct BaseSquare : public _BaseSquare<T> | ||
{ | ||
static constexpr float height = 2; | ||
static constexpr float width = height; | ||
|
||
protected: | ||
static void init() | ||
{ | ||
T::_shape.setPointCount(4); | ||
T::_shape.setPoint(0,sf::Vector2f(0,0)); | ||
T::_shape.setPoint(1,sf::Vector2f(0,T::height)); | ||
T::_shape.setPoint(2,sf::Vector2f(T::height,T::height)); | ||
T::_shape.setPoint(3,sf::Vector2f(T::height,0)); | ||
|
||
T::_shape.setOrigin(T::height/2.0,T::height/2.0); | ||
} | ||
|
||
static struct _Initiatiser { | ||
_Initiatiser(){ | ||
T::init(); | ||
}; | ||
} _initiatiser_; | ||
}; | ||
#define SFML_UTILS_BASE_SQUARE_INIT(klass) \ | ||
SFML_UTILS_BASE_TILE_INIT(klass);\ | ||
template <> BaseSquare<klass>::_Initiatiser BaseSquare<klass>::_initiatiser_ = BaseSquare<klass>::_Initiatiser(); | ||
|
||
template<typename T> | ||
struct BaseSquareIso : public _BaseSquare<T> | ||
{ | ||
static constexpr float height = 1; | ||
static constexpr float width = 2; | ||
|
||
protected: | ||
static void init() | ||
{ | ||
T::_shape.setPointCount(4); | ||
T::_shape.setPoint(0,sf::Vector2f(T::width/2,0)); | ||
T::_shape.setPoint(1,sf::Vector2f(T::width,T::height/2.0)); | ||
T::_shape.setPoint(2,sf::Vector2f(T::width/2.0,T::height)); | ||
T::_shape.setPoint(3,sf::Vector2f(0,T::height/2.0)); | ||
|
||
T::_shape.setOrigin(T::width/2.0,T::height/2.0); | ||
} | ||
static struct _Initiatiser { | ||
_Initiatiser(){ | ||
T::init(); | ||
}; | ||
} _initiatiser_; | ||
}; | ||
|
||
#define SFML_UTILS_BASE_SQUARE_ISO_INIT(klass) \ | ||
SFML_UTILS_BASE_TILE_INIT(klass);\ | ||
template <> BaseSquareIso<klass>::_Initiatiser BaseSquareIso<klass>::_initiatiser_ = BaseSquareIso<klass>::_Initiatiser(); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,19 @@ | ||
#ifndef SFUTILS_GEOMETRY_SQUAREISOSTAGGERED_HPP | ||
#define SFUTILS_GEOMETRY_SQUAREISOSTAGGERED_HPP | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include <SFML-utils/map/tileShapes/BaseTile.hpp> | ||
|
||
namespace sfutils | ||
{ | ||
namespace geometry | ||
{ | ||
struct SquareIsoStaggered | ||
struct SquareIsoStaggered : public BaseSquareIso<SquareIsoStaggered> | ||
{ | ||
static const sf::ConvexShape& getShape(); | ||
static sf::Vector2f mapCoordsToPixel(int x,int y,float scale); | ||
static sf::Vector2i mapPixelToCoords(float x,float y,float scale); | ||
static sf::IntRect getTextureRect(int x,int y,float scale); | ||
static sf::Vector2i round(float x,float y); | ||
static int distance(int x1,int y1, int x2,int y2); | ||
|
||
|
||
private: | ||
static sf::ConvexShape _shape; | ||
static void init(); | ||
|
||
static struct __Initiatiser { | ||
__Initiatiser(){ | ||
SquareIsoStaggered::init(); | ||
}; | ||
} __initiatiser__; | ||
}; | ||
|
||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.