Skip to content
Snippets Groups Projects
Commit 560c410e authored by David Maul's avatar David Maul :crab:
Browse files

change enum to enum class

parent d08404f5
Branches
No related tags found
1 merge request!5Spritesheet
......@@ -10,7 +10,7 @@ void Building::render(Engine &engine, int scale) {
Spritesheet *spritesheet = engine.get_spritesheet();
SDL_Rect src;
src.x = id * spritesheet->get_building_width();
src.x = static_cast<int>(id) * spritesheet->get_building_width();
src.y = 0;
src.w = spritesheet->get_building_width();
src.h = spritesheet->get_building_height();
......@@ -21,9 +21,10 @@ void Building::render(Engine &engine, int scale) {
dst.w = spritesheet->get_building_width() * scale;
dst.h = spritesheet->get_building_height() * scale;
SDL_RenderCopyEx(engine.renderer(),
spritesheet->get_building_textures()[faction], &src, &dst, 0,
NULL, SDL_FLIP_NONE);
SDL_RenderCopyEx(
engine.renderer(),
spritesheet->get_building_textures()[static_cast<int>(faction)], &src,
&dst, 0, NULL, SDL_FLIP_NONE);
}
} // namespace advanced_wars
\ No newline at end of file
......@@ -5,16 +5,16 @@
namespace advanced_wars {
enum BuildingFaction {
BRED = 0,
BBLUE = 1,
BYELLOW = 2,
BGREEN = 3,
BPURPLE = 4,
BNEUTRAL = 5,
enum class BuildingFaction {
RED = 0,
BLUE = 1,
YELLOW = 2,
GREEN = 3,
PURPLE = 4,
NEUTRAL = 5,
};
enum BuildingId {
enum class BuildingId {
HEADQUARTER = 0,
CITY = 1,
FACTORY = 2,
......
......
......@@ -4,7 +4,7 @@
namespace advanced_wars {
enum EffectId {
enum class EffectId {
LAND_EXPLOSION = 0,
AIR_EXPLOSION = 1,
NAVAL_EXPLOSION = 2,
......
......
#include "tile.hpp"
#include "spritesheet.hpp"
#include <stdexcept>
#include <vector>
namespace advanced_wars {
......@@ -16,13 +15,6 @@ void Tile::render(Engine &engine, int scale) {
int step = engine.get_stage() %
spritesheet->get_tile_textures().at(static_cast<int>(id)).second;
if (step >=
spritesheet->get_tile_textures().at(static_cast<int>(id)).second ||
step < 0) {
throw std::runtime_error("Tried to access step " + std::to_string(step) +
" for tile " + std::to_string(this->id));
}
SDL_Rect src;
src.x = step * spritesheet->get_tile_width();
src.y = 0;
......
......
......@@ -5,7 +5,7 @@
namespace advanced_wars {
enum TileId {
enum class TileId {
PLAIN = 0,
WATER = 1,
FOREST = 2,
......
......
......@@ -4,7 +4,7 @@
namespace advanced_wars {
enum UnitFaction {
enum class UnitFaction {
URED = 0,
UBLUE = 1,
UGREEN = 2,
......@@ -12,7 +12,7 @@ enum UnitFaction {
UPURPLE = 4,
};
enum UnitId {
enum class UnitId {
INFANTERY = 0,
MECHANIZED_INFANTERY = 1,
RECON = 2,
......@@ -34,7 +34,7 @@ enum UnitId {
SUBMARINE = 18,
};
enum UnitState {
enum class UnitState {
IDLE = 0,
UNAVAILABLE = 1,
MOVEMENTLEFT = 2,
......@@ -43,6 +43,15 @@ enum UnitState {
MOVEMENTUP = 5,
};
enum class MovementType {
FOOT = 0,
TIRES = 1,
TREAD = 2,
AIR = 3,
SHIP = 4,
LANDER = 5,
};
class Unit {
public:
Unit(int x, int y, UnitFaction faction, UnitId id, UnitState state);
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment