Replaced enum with enum class where possible.
This commit is contained in:
parent
197ef6b398
commit
8d295df943
5 changed files with 27 additions and 27 deletions
|
@ -134,16 +134,16 @@ Game::keyUp(const sf::Event& event) {
|
|||
mPaused = !mPaused;
|
||||
break;
|
||||
case sf::Keyboard::W:
|
||||
mPlayer.setDirection(Player::DIRECTION_UP, true);
|
||||
mPlayer.setDirection(Player::Direction::UP, true);
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
mPlayer.setDirection(Player::DIRECTION_DOWN, true);
|
||||
mPlayer.setDirection(Player::Direction::DOWN, true);
|
||||
break;
|
||||
case sf::Keyboard::A:
|
||||
mPlayer.setDirection(Player::DIRECTION_LEFT, true);
|
||||
mPlayer.setDirection(Player::Direction::LEFT, true);
|
||||
break;
|
||||
case sf::Keyboard::D:
|
||||
mPlayer.setDirection(Player::DIRECTION_RIGHT, true);
|
||||
mPlayer.setDirection(Player::Direction::RIGHT, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -157,16 +157,16 @@ void
|
|||
Game::keyDown(const sf::Event& event) {
|
||||
switch (event.key.code) {
|
||||
case sf::Keyboard::W:
|
||||
mPlayer.setDirection(Player::DIRECTION_UP, false);
|
||||
mPlayer.setDirection(Player::Direction::UP, false);
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
mPlayer.setDirection(Player::DIRECTION_DOWN, false);
|
||||
mPlayer.setDirection(Player::Direction::DOWN, false);
|
||||
break;
|
||||
case sf::Keyboard::A:
|
||||
mPlayer.setDirection(Player::DIRECTION_LEFT, false);
|
||||
mPlayer.setDirection(Player::Direction::LEFT, false);
|
||||
break;
|
||||
case sf::Keyboard::D:
|
||||
mPlayer.setDirection(Player::DIRECTION_RIGHT, false);
|
||||
mPlayer.setDirection(Player::Direction::RIGHT, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -33,7 +33,7 @@ TileManager::TileManager(b2World& world) :
|
|||
*/
|
||||
TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) :
|
||||
Sprite(getTexture(type), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y),
|
||||
TILE_SIZE, world, CATEGORY_WORLD, (type == TYPE_FLOOR) ? MASK_NONE : MASK_ALL, false)),
|
||||
TILE_SIZE, world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)),
|
||||
mType(type) {
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ std::shared_ptr<sf::Texture>
|
|||
TileManager::Tile::getTexture(Type type) {
|
||||
sf::String filename;
|
||||
switch (type) {
|
||||
case TYPE_FLOOR:
|
||||
case Type::FLOOR:
|
||||
filename = "floor.png";
|
||||
break;
|
||||
case TYPE_WALL:
|
||||
case Type::WALL:
|
||||
filename = "wall.png";
|
||||
break;
|
||||
default:
|
||||
|
@ -82,11 +82,11 @@ void
|
|||
TileManager::generate() {
|
||||
for (int x = 0; x < 10; x++)
|
||||
for (int y = 0; y < 10; y++)
|
||||
setTile(TilePosition(x, y), TYPE_WALL);
|
||||
setTile(TilePosition(x, y), Type::WALL);
|
||||
|
||||
for (int x = 1; x < 9; x++)
|
||||
for (int y = 1; y < 9; y++)
|
||||
setTile(TilePosition(x, y), TYPE_FLOOR);
|
||||
setTile(TilePosition(x, y), Type::FLOOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,9 +35,9 @@ public:
|
|||
|
||||
// Private types.
|
||||
private:
|
||||
enum Type {
|
||||
TYPE_FLOOR,
|
||||
TYPE_WALL
|
||||
enum class Type {
|
||||
FLOOR,
|
||||
WALL
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,22 +76,22 @@ Player::move(const Vector2f& destination) {
|
|||
void
|
||||
Player::setDirection(Direction direction, bool unset) {
|
||||
if (unset) {
|
||||
mDirection = mDirection & ~direction;
|
||||
mDirection = mDirection & ~(uint8) direction;
|
||||
} else {
|
||||
mDirection = mDirection | direction;
|
||||
mDirection = mDirection | (uint8) direction;
|
||||
}
|
||||
// Convert directions into a vector.
|
||||
Vector2f dirVec(0, 0);
|
||||
if (mDirection & DIRECTION_RIGHT) {
|
||||
if (mDirection & (uint8) Direction::RIGHT) {
|
||||
dirVec.x += 1.0f;
|
||||
}
|
||||
if (mDirection & DIRECTION_LEFT) {
|
||||
if (mDirection & (uint8) Direction::LEFT) {
|
||||
dirVec.x += - 1.0f;
|
||||
}
|
||||
if (mDirection & DIRECTION_DOWN) {
|
||||
if (mDirection & (uint8) Direction::DOWN) {
|
||||
dirVec.y += 1.0f;
|
||||
}
|
||||
if (mDirection & DIRECTION_UP) {
|
||||
if (mDirection & (uint8) Direction::UP) {
|
||||
dirVec.y += - 1.0f;
|
||||
}
|
||||
setSpeed(dirVec, SPEED);
|
||||
|
|
|
@ -31,11 +31,11 @@ public:
|
|||
/**
|
||||
* Movement directions that can be set via Player::setDirection().
|
||||
*/
|
||||
enum Direction {
|
||||
DIRECTION_RIGHT = 1 << 0,
|
||||
DIRECTION_LEFT = 1 << 1,
|
||||
DIRECTION_UP = 1 << 2,
|
||||
DIRECTION_DOWN = 1 << 3
|
||||
enum class Direction : uint8 {
|
||||
RIGHT = 1 << 0,
|
||||
LEFT = 1 << 1,
|
||||
UP = 1 << 2,
|
||||
DOWN = 1 << 3
|
||||
};
|
||||
|
||||
// Public functions.
|
||||
|
|
Reference in a new issue