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

67 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 Vector2i Tile::TILE_SIZE = sf::Vector2i(75, 75);
2013-04-29 14:49:16 +00:00
/**
* 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) :
Rectangle(Vector2f(x * TILE_SIZE.x, y * TILE_SIZE.y),
CATEGORY_WORLD, (isSolid(type)) ? 0xffff : 0,
2013-05-01 17:07:47 +00:00
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;
2013-07-10 21:25:53 +00:00
case Type::WALL:
// falltrough
2013-04-29 14:49:16 +00:00
default:
return true;
}
}
/**
* Returns the Type of this tile.
*/
Tile::Type
Tile::getType() const {
return mType;
}