This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-gunner/source/sprites/Tile.cpp

66 lines
1.1 KiB
C++
Raw Normal View History

2013-04-29 14:49:16 +00:00
/*
* Tile.cpp
*
* Created on: 20.04.2013
* Author: Felix
*/
#include "Tile.h"
#include <Thor/Vectors.hpp>
#include "../util/Interval.h"
#include "../util/Loader.h"
#include "../util/Yaml.h"
#include "../World.h"
const sf::Vector2i Tile::TILE_SIZE = sf::Vector2i(75, 75);
/**
* Constructs a tile.
*
* @param pType Type of the tile to create.
* @param pPosition Position of the tile in tile coordinates.
* @param world Box2D world object.
*/
Tile::Tile(Type type, int x, int y) :
Sprite(Data(sf::Vector2f(x * TILE_SIZE.x, y * TILE_SIZE.y),
2013-05-01 17:07:47 +00:00
CATEGORY_WORLD, (isSolid(type)) ? 0xffff : 0),
Yaml(getConfig(type))),
2013-04-29 14:49:16 +00:00
mType(type) {
}
/**
* Returns the YAML config file name for the tile type.
*/
std::string
Tile::getConfig(Type type) {
switch (type) {
case Type::FLOOR:
return "tile_floor.yaml";
case Type::WALL:
return "tile_wall.yaml";
default:
assert(false);
return "";
}
}
bool
Tile::isSolid(Type type) {
switch (type) {
case Type::FLOOR:
return false;
case Type::WALL: // falltrough
default:
return true;
}
}
/**
* Returns the Type of this tile.
*/
Tile::Type
Tile::getType() const {
return mType;
}