Vigilante Game Framework
1.0.0.8
A 2D/3D C++ Game Framework using SFML.
|
Object that renders a 2D tilemap, with custom collision and autotiling support. More...
#include <VTilemap.h>
Public Types | |
typedef VObject | VSUPERCLASS |
Used to call parent class functions when they are overrided in class. | |
![]() | |
enum | SidesTouching : unsigned char { TOUCHNONE = 0, TOUCHLEFT = 1 << 0, TOUCHRIGHT = 1 << 1, TOUCHTOP = 1 << 2, TOUCHBOTTOM = 1 << 3, TOUCHWALL = TOUCHLEFT | TOUCHRIGHT, TOUCHALL = TOUCHLEFT | TOUCHRIGHT | TOUCHTOP | TOUCHBOTTOM } |
Flags for which sides are allowed to check if being overlapped for collision purposes. | |
typedef VBase | VSUPERCLASS |
Used to call parent class functions when they are overrided in class. | |
Public Member Functions | |
void | LoadFromCSV (const sf::String &mapData, const sf::String &graphicFile, int tileWidth=0, int tileHeight=0, bool autoTile=false, const std::vector< char > &collision={ '#' }, const sf::IntRect &graphicsArea=sf::IntRect()) |
void | LoadFromArray (std::vector< char > mapData, int mapWidth, int mapHeight, const sf::String &graphicFile, int tileWidth=0, int tileHeight=0, bool autoTile=false, const std::vector< char > &collision={ '#' }, const sf::IntRect &graphicsArea=sf::IntRect()) |
void | LoadFrom2DArray (std::vector< std::vector< char >> mapData, const sf::String &graphicFile, int tileWidth=0, int tileHeight=0, bool autoTile=false, const std::vector< char > &collision={ '#' }, const sf::IntRect &graphicsArea=sf::IntRect()) |
void | SetTileRenderID (char ID, int tileNumber=0, int autoTileNumber=0) |
void | SetTileCollisionID (char ID, int AllowCollisions=TOUCHALL, std::function< void(VObject *, VObject *)> Callback=nullptr) |
char | GetTileID (unsigned int x, unsigned int y) const |
char | GetTileID (sf::Vector2i position) const |
char | GetTileIDFromPosition (sf::Vector2f tilemapPosition) const |
void | ChangeTile (int x, int y, char ID) |
void | ChangeTile (const std::vector< sf::Vector2u > &positions, char ID) |
void | ResetCollision (const std::vector< char > &collision={ '#' }) |
virtual bool | OverlapWithCallback (VObject *object, std::function< bool(VObject *, VObject *)> Callback=nullptr, bool FlipCallback=false) |
void | SetTint (const sf::Color &color) |
sf::Color const & | GetTint () |
Get overall tint of tilemap. | |
int const & | GetMapWidth () |
Get width of tilemap grid. | |
int const & | GetMapHeight () |
Get height of tilemap grid. | |
const VTile * | GetCollisionTile (unsigned int index) |
const unsigned int | GetCollisionTileCount () |
virtual void | Reset (sf::Vector2f newPos) override |
Not used in VTilemap. | |
virtual void | Reset (float x, float y) override |
Not used in VTilemap. | |
virtual void | Hurt (float damage) override |
Not used in VTilemap. | |
virtual void | Destroy () override |
Deletes and clears all the tilemap data. | |
virtual void | Update (float dt) override |
virtual void | Draw (sf::RenderTarget &RenderTarget) override |
![]() | |
VObject (sf::Vector2f position, sf::Vector2f size=sf::Vector2f()) | |
VObject (float x=0, float y=0, float width=0, float height=0) | |
void | SetPositionAtCentre (float x, float y) |
void | SetPositionAtCentre (sf::Vector2f newPos) |
bool | IsSolid () |
![]() | |
virtual void | Kill () |
virtual void | Revive () |
Revives the object by setting both alive and exists back to true. | |
Public Attributes | |
sf::RenderStates | RenderState = sf::RenderStates::Default |
RenderState for the Tilemap. | |
sf::Vector2u | TileSize |
Size of an individual tile in the tilemap. | |
sf::Vector2f | Scale = sf::Vector2f(1, 1) |
Scale of the tilemap. | |
bool | AutoTile = false |
Sets the tilemap to use AutoTile mode or not. | |
![]() | |
sf::Vector2f | Position |
Position of the object. | |
sf::Vector2f | Size |
Size of the object. | |
sf::Vector2f | Last |
Position of the object on the previous frame. | |
float | Radius = 0 |
Radius amount for Circle Collisions. | |
float | Angle = 0 |
Angle of object. | |
float | AngleVelocity = 0 |
Velocity of rotation. | |
float | AngleAcceleration = 0 |
Acceleration of rotation. | |
float | AngleDrag = 0 |
Drag of rotation. | |
float | AngleMax = 10000 |
Maximum Velocity of rotation. | |
bool | Moves = true |
If true, updates the objects position and angle. | |
sf::Vector2f | Velocity |
Velocity of movement. | |
sf::Vector2f | Acceleration |
Acceleration of movement. | |
sf::Vector2f | Drag |
Drag of movement. | |
sf::Vector2f | MaxVelocity |
Maximum velocity of movement. | |
sf::Vector2f | ScrollFactor |
The amount the object will appear to move when the camera scrolls (1.0f = Scrolls as fast as the camera, 0.5f = Scrolls half as fast as the camera). Good for parallax scrolling. | |
float | RotateFactor = 1 |
The amount the object will appear to rotate when the camera rotates (1.0f = Rotates as fast as the camera, 0.5f = Rotates half as fast as the camera). Good for parallax scrolling. | |
float | ZoomFactor = 1 |
The amount the object will appear to scale when the camera zooms (1.0f = Scales as fast as the camera, 0.5f = Scales half as fast as the camera). Good for parallax scrolling. | |
float | Elasticity = 0 |
Bounciness of the object (0 assumes no bounce) | |
float | Mass = 1 |
Mass of object in comparison to other objects in world. | |
float | Health = 100 |
Standard health value (object dies if health is <= 0 when modified in the Hurt function) | |
bool | Immovable = false |
If true, the object will not change its velocity on collision. | |
unsigned char | Touching = SidesTouching::TOUCHNONE |
Which sides are currently touching (is reset on each Update call!) | |
unsigned char | WasTouching = SidesTouching::TOUCHNONE |
Which sides on previous frame were touching (is reset on each Update call!) | |
unsigned char | AllowCollisions = SidesTouching::TOUCHALL |
Which sides are allowed to check collisions for. | |
bool | CollisionXDrag = true |
Useful for moving platforms. | |
![]() | |
bool | active = true |
Base can be updated using Update if true. | |
bool | visible = true |
Base can be rendered using Draw if true. | |
bool | alive = true |
Helper member that is mainly used filter out behaviours to objects which aren't alive in the scene. | |
bool | exists = true |
Base can be updated and rendered if true, else it would no longer be treated as being part of the scene. | |
VType | type = NONE |
Base object type, typically set in the constructor of an inherited object to specify what type it is. | |
uint32_t | RefCount = 0 |
Counts the amount of times the object is referenced in groups, ensures an object is only destroyed when no longer part of a single group. | |
Protected Member Functions | |
void | setupTilemap (const sf::String &graphicFile, int tileWidth=0, int tileHeight=0, bool autoTile=false, const std::vector< char > &collision={ '#' }, const sf::IntRect &graphicsArea=sf::IntRect()) |
virtual void | updateTransform () override |
Updates the transform of the tilemap. | |
void | updateTilemap () |
Updates the tilemap rendering info. | |
void | updateCollisionBox () |
Updates the collision data in the tiles list. | |
void | clearTiles () |
Clears all the tilemap data. | |
![]() | |
virtual void | updateMotion (float dt) |
Protected Attributes | |
std::vector< char > | tilemap |
Tilemap data. | |
std::map< char, VTileCollisionInfo * > | collisionDir |
List of tile collision information. | |
std::map< char, VTileRenderInfo * > | renderDir |
List of tile render information. | |
std::vector< int > | autotile |
Autotile Map data (used when in AutoTile mode). | |
int | tileMapWidth = 0 |
The amount of tiles horizontally in a texture. | |
sf::Vector2u | textureOffset |
The offset of the texture to use. | |
int | mapWidth = 0 |
Width of the Tilemap in Tiles. | |
int | mapHeight = 0 |
Height of the Tilemap in Tiles. | |
sf::Vector2f | last |
Position during the last update of the collision boxes. | |
bool | dirty = true |
Updates the collision and render infomation of the tilemap if true. | |
bool | helperAutoTile = false |
Updates the render infomation of the tilemap if different from AutoTile. | |
sf::VertexArray | vertices |
Vertex data for render. | |
sf::Color | colour = sf::Color::White |
Colour Tint of rendered tilemap. | |
std::vector< VTile * > | tiles |
List of Collideable Tilesets. | |
Additional Inherited Members | |
![]() | |
static bool | separate (VObject *a, VObject *b) |
static bool | separateCircle (VObject *a, VObject *b) |
static bool | touchFlag (VObject *a, VObject *b) |
static float | computeVelocity (float v, float a, float d, float max, float dt) |
static bool | TestInView (const sf::View &renderTargetView, sf::View *defaultView, VObject *o, const sf::FloatRect &renderBox=sf::FloatRect()) |
![]() | |
static const wchar_t * | VString (const char *fmt,...) |
static void | VLog (const char *fmt,...) |
static void | VLogError (const char *fmt,...) |
static void | VClearLog () |
![]() | |
static float | SeparateBias |
Adds to the maximum overlap distance between objects. | |
Object that renders a 2D tilemap, with custom collision and autotiling support.
void VTilemap::ChangeTile | ( | int | x, |
int | y, | ||
char | ID | ||
) |
Change the tile at a specific point to an ID.
x | X Coordinate in Tiles. |
y | Y Coordinate in Tiles. |
ID | The new tile ID for that position in the tilemap. |
void VTilemap::ChangeTile | ( | const std::vector< sf::Vector2u > & | positions, |
char | ID | ||
) |
Change a list of tiles to a single ID.
positions | A list of coordinates to change the tile for. |
ID | The new tile ID for that position in the tilemap. |
|
overridevirtual |
Draws the tilemap.
RenderTarget | The game's sf::RenderTarget object to render data onto. |
Reimplemented from VObject.
const VTile* VTilemap::GetCollisionTile | ( | unsigned int | index | ) |
const unsigned int VTilemap::GetCollisionTileCount | ( | ) |
char VTilemap::GetTileID | ( | unsigned int | x, |
unsigned int | y | ||
) | const |
Get tile at specified map coordinate.
x | X Coordinate in Tiles. |
y | Y Coordinate in Tiles. |
char VTilemap::GetTileID | ( | sf::Vector2i | position | ) | const |
Get tile at specified map coordinate.
position | Coordinate in Tiles. |
char VTilemap::GetTileIDFromPosition | ( | sf::Vector2f | tilemapPosition | ) | const |
Get tile at specified world position.
tilemapPosition | Gets a tile at a specific position in the world (Position / TileSize). |
void VTilemap::LoadFrom2DArray | ( | std::vector< std::vector< char >> | mapData, |
const sf::String & | graphicFile, | ||
int | tileWidth = 0 , |
||
int | tileHeight = 0 , |
||
bool | autoTile = false , |
||
const std::vector< char > & | collision = { '#' } , |
||
const sf::IntRect & | graphicsArea = sf::IntRect() |
||
) |
Load map as a single two-dimensional char array.
mapData | The two-dimensional char array that makes up the tilemap data. |
graphicFile | The path and filename of the texture file. |
tileWidth | Frame Width of a single tile. |
tileHeight | Frame Height of a single tile. |
autoTile | If true, the tilemap will render as an autotiled map. |
collision | A list of chars in the mapData that are completely collideable. |
graphicsArea | The area of the texture to display. Default is the entire texture. |
void VTilemap::LoadFromArray | ( | std::vector< char > | mapData, |
int | mapWidth, | ||
int | mapHeight, | ||
const sf::String & | graphicFile, | ||
int | tileWidth = 0 , |
||
int | tileHeight = 0 , |
||
bool | autoTile = false , |
||
const std::vector< char > & | collision = { '#' } , |
||
const sf::IntRect & | graphicsArea = sf::IntRect() |
||
) |
Load map as a single char array.
mapData | The char array that makes up the tilemap data. |
mapWidth | Map Width in tiles. |
mapHeight | Map Height in tiles. |
graphicFile | The path and filename of the texture file. |
tileWidth | Frame Width of a single tile. |
tileHeight | Frame Height of a single tile. |
autoTile | If true, the tilemap will render as an autotiled map. |
collision | A list of chars in the mapData that are completely collideable. |
graphicsArea | The area of the texture to display. Default is the entire texture. |
void VTilemap::LoadFromCSV | ( | const sf::String & | mapData, |
const sf::String & | graphicFile, | ||
int | tileWidth = 0 , |
||
int | tileHeight = 0 , |
||
bool | autoTile = false , |
||
const std::vector< char > & | collision = { '#' } , |
||
const sf::IntRect & | graphicsArea = sf::IntRect() |
||
) |
Load map from a text file. Maps should be formatted so each tile is separated by comma (,). The amount of tiles on each row makes up the width of the map, and amount of lines the height.
Example: 0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0 1,1,1,0,0,0,0,0,0,0,1,1,1 0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,1,1,1,1,1,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0 1,1,1,1,1,1,1,1,1,1,1,1,1
mapData | The path and filename of the csv/text file of the path data. |
graphicFile | The path and filename of the texture file. |
tileWidth | Frame Width of a single tile. |
tileHeight | Frame Height of a single tile. |
autoTile | If true, the tilemap will render as an autotiled map. |
collision | A list of chars in the mapData that are completely collideable. |
graphicsArea | The area of the texture to display. Default is the entire texture. |
|
virtual |
When object overlaps tilemap, this function goes through all tiles to test overlap with specified overlap. This function is ideal to test if an object overlaps any of the collieable tiles instead of using VGlobal::Overlaps (which will only test if the object overlaps the tilemap area).
object | VObject to test for overlap with the tilemap. |
Callback | The Callback function that is used if an overlap has been found in the tilemap area (not individual tile sets!). |
FlipCallback | If true, will swap the parameters when calling the Callback. |
void VTilemap::ResetCollision | ( | const std::vector< char > & | collision = { '#' } | ) |
Reset collision infomation to all colliding tiles having default collision properties. The default tile collision allows collisions on all sides with no callback.
collision | List of tile IDs which are collideable. |
void VTilemap::SetTileCollisionID | ( | char | ID, |
int | AllowCollisions = TOUCHALL , |
||
std::function< void(VObject *, VObject *)> | Callback = nullptr |
||
) |
Sets tile with specific char to have certain collision restrictions and responses.
ID | The tile ID as defined in the tilemap data. |
AllowCollisions | A filter to set which sides of a tile and object can collide with. |
Callback | A callback function to call when a player is either colliding or overlapping a tile with the specified ID. |
void VTilemap::SetTileRenderID | ( | char | ID, |
int | tileNumber = 0 , |
||
int | autoTileNumber = 0 |
||
) |
Sets tile to render at specific char in tilemap (ignored if using autotile)
ID | The tile ID as defined in the tilemap data. |
tileNumber | The frame index the tile with the specific ID should use. |
autoTileNumber | The autotile level the tile should used if in AutoTile (useful if you want to display more than one set of autotiles in a single tilemap). |
void VTilemap::SetTint | ( | const sf::Color & | color | ) |
Set overall tint of tilemap.
color | The colour tint to set the tilemap to. |
|
protected |
Sets up all the tilemap visual infomation.
graphicFile | The filename and path of the texture file. |
tileWidth | Frame width of a tile. |
tileHeight | Frame height of a tile. |
autoTile | If true the tilemap will be rendered using the tilemap mode. |
collision | A list of tiles that are collideable in the tilemap data. |
graphicsArea | The area of the texture to use. Default is the entire texture area. |
|
overridevirtual |
Updates the tilemap. Sets up new render and collision infomation if flags have been set.
dt | Delta Time between the current and previous frames of the game. |
Reimplemented from VObject.