Replaced enum with enum class where possible.

This commit is contained in:
Felix Ableitner 2012-10-01 09:41:38 +02:00
parent 197ef6b398
commit 8d295df943
5 changed files with 27 additions and 27 deletions

View file

@ -134,16 +134,16 @@ Game::keyUp(const sf::Event& event) {
mPaused = !mPaused; mPaused = !mPaused;
break; break;
case sf::Keyboard::W: case sf::Keyboard::W:
mPlayer.setDirection(Player::DIRECTION_UP, true); mPlayer.setDirection(Player::Direction::UP, true);
break; break;
case sf::Keyboard::S: case sf::Keyboard::S:
mPlayer.setDirection(Player::DIRECTION_DOWN, true); mPlayer.setDirection(Player::Direction::DOWN, true);
break; break;
case sf::Keyboard::A: case sf::Keyboard::A:
mPlayer.setDirection(Player::DIRECTION_LEFT, true); mPlayer.setDirection(Player::Direction::LEFT, true);
break; break;
case sf::Keyboard::D: case sf::Keyboard::D:
mPlayer.setDirection(Player::DIRECTION_RIGHT, true); mPlayer.setDirection(Player::Direction::RIGHT, true);
break; break;
default: default:
break; break;
@ -157,16 +157,16 @@ void
Game::keyDown(const sf::Event& event) { Game::keyDown(const sf::Event& event) {
switch (event.key.code) { switch (event.key.code) {
case sf::Keyboard::W: case sf::Keyboard::W:
mPlayer.setDirection(Player::DIRECTION_UP, false); mPlayer.setDirection(Player::Direction::UP, false);
break; break;
case sf::Keyboard::S: case sf::Keyboard::S:
mPlayer.setDirection(Player::DIRECTION_DOWN, false); mPlayer.setDirection(Player::Direction::DOWN, false);
break; break;
case sf::Keyboard::A: case sf::Keyboard::A:
mPlayer.setDirection(Player::DIRECTION_LEFT, false); mPlayer.setDirection(Player::Direction::LEFT, false);
break; break;
case sf::Keyboard::D: case sf::Keyboard::D:
mPlayer.setDirection(Player::DIRECTION_RIGHT, false); mPlayer.setDirection(Player::Direction::RIGHT, false);
break; break;
default: default:
break; break;

View file

@ -33,7 +33,7 @@ TileManager::TileManager(b2World& world) :
*/ */
TileManager::Tile::Tile(Type type, const TilePosition& position, 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), 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) { mType(type) {
} }
@ -47,10 +47,10 @@ std::shared_ptr<sf::Texture>
TileManager::Tile::getTexture(Type type) { TileManager::Tile::getTexture(Type type) {
sf::String filename; sf::String filename;
switch (type) { switch (type) {
case TYPE_FLOOR: case Type::FLOOR:
filename = "floor.png"; filename = "floor.png";
break; break;
case TYPE_WALL: case Type::WALL:
filename = "wall.png"; filename = "wall.png";
break; break;
default: default:
@ -82,11 +82,11 @@ void
TileManager::generate() { TileManager::generate() {
for (int x = 0; x < 10; x++) for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++) 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 x = 1; x < 9; x++)
for (int y = 1; y < 9; y++) for (int y = 1; y < 9; y++)
setTile(TilePosition(x, y), TYPE_FLOOR); setTile(TilePosition(x, y), Type::FLOOR);
} }
/** /**

View file

@ -35,9 +35,9 @@ public:
// Private types. // Private types.
private: private:
enum Type { enum class Type {
TYPE_FLOOR, FLOOR,
TYPE_WALL WALL
}; };
/** /**

View file

@ -76,22 +76,22 @@ Player::move(const Vector2f& destination) {
void void
Player::setDirection(Direction direction, bool unset) { Player::setDirection(Direction direction, bool unset) {
if (unset) { if (unset) {
mDirection = mDirection & ~direction; mDirection = mDirection & ~(uint8) direction;
} else { } else {
mDirection = mDirection | direction; mDirection = mDirection | (uint8) direction;
} }
// Convert directions into a vector. // Convert directions into a vector.
Vector2f dirVec(0, 0); Vector2f dirVec(0, 0);
if (mDirection & DIRECTION_RIGHT) { if (mDirection & (uint8) Direction::RIGHT) {
dirVec.x += 1.0f; dirVec.x += 1.0f;
} }
if (mDirection & DIRECTION_LEFT) { if (mDirection & (uint8) Direction::LEFT) {
dirVec.x += - 1.0f; dirVec.x += - 1.0f;
} }
if (mDirection & DIRECTION_DOWN) { if (mDirection & (uint8) Direction::DOWN) {
dirVec.y += 1.0f; dirVec.y += 1.0f;
} }
if (mDirection & DIRECTION_UP) { if (mDirection & (uint8) Direction::UP) {
dirVec.y += - 1.0f; dirVec.y += - 1.0f;
} }
setSpeed(dirVec, SPEED); setSpeed(dirVec, SPEED);

View file

@ -31,11 +31,11 @@ public:
/** /**
* Movement directions that can be set via Player::setDirection(). * Movement directions that can be set via Player::setDirection().
*/ */
enum Direction { enum class Direction : uint8 {
DIRECTION_RIGHT = 1 << 0, RIGHT = 1 << 0,
DIRECTION_LEFT = 1 << 1, LEFT = 1 << 1,
DIRECTION_UP = 1 << 2, UP = 1 << 2,
DIRECTION_DOWN = 1 << 3 DOWN = 1 << 3
}; };
// Public functions. // Public functions.