From 97d6287a0710ec59d746f6340a796bbe6c7c8aa2 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 6 Jun 2015 15:39:02 +0200 Subject: Abstracted game objects into an entity base class --- include/alien.h | 7 ++++--- include/enemy_bullet.h | 7 ++++--- include/game_entity.h | 13 +++++++++++++ include/game_state.h | 1 + include/player_missile.h | 6 +++--- include/shield.h | 7 ++++--- include/spaceship.h | 7 ++++--- 7 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 include/game_entity.h (limited to 'include') diff --git a/include/alien.h b/include/alien.h index 2f7d596..5dda726 100644 --- a/include/alien.h +++ b/include/alien.h @@ -1,10 +1,11 @@ #pragma once -class Alien { +#include "game_entity.h" + +class Alien : public GameEntity +{ public: Alien(int x, int y); const static char MAP_CHAR = 'x'; private: - int x; - int y; }; diff --git a/include/enemy_bullet.h b/include/enemy_bullet.h index db3fcf9..ff3b001 100644 --- a/include/enemy_bullet.h +++ b/include/enemy_bullet.h @@ -1,11 +1,12 @@ #pragma once -class EnemyBullet { +#include "game_entity.h" + +class EnemyBullet: public GameEntity +{ public: EnemyBullet(int x, int y); const static char ALIEN_MAP_CHAR = '|'; const static char ENEMY_MISSILE_MAP_CHAR = 'i'; private: - int x; - int y; }; diff --git a/include/game_entity.h b/include/game_entity.h new file mode 100644 index 0000000..215333c --- /dev/null +++ b/include/game_entity.h @@ -0,0 +1,13 @@ +#pragma once + +class GameEntity +{ +public: + GameEntity(int x, int y); + int x() const {return _x;} + int y() const {return _y;} +private: + int _x; + int _y; +}; + diff --git a/include/game_state.h b/include/game_state.h index defe691..db20b84 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -12,6 +12,7 @@ class GameState { public: GameState(std::string mapFilename); + void logState(); private: std::vector aliens; std::vector bullets; diff --git a/include/player_missile.h b/include/player_missile.h index 6f304df..c504a79 100644 --- a/include/player_missile.h +++ b/include/player_missile.h @@ -1,11 +1,11 @@ #pragma once -class PlayerMissile +#include "game_entity.h" + +class PlayerMissile: public GameEntity { public: PlayerMissile(int x, int y); const static char MAP_CHAR = '!'; private: - int x; - int y; }; diff --git a/include/shield.h b/include/shield.h index bd64e3e..be65be3 100644 --- a/include/shield.h +++ b/include/shield.h @@ -1,11 +1,12 @@ #pragma once -class Shield { +#include "game_entity.h" + +class Shield: public GameEntity +{ public: Shield(int x, int y); const static char MAP_CHAR = '-'; private: - int x; - int y; }; diff --git a/include/spaceship.h b/include/spaceship.h index 5e6afd0..bd26b64 100644 --- a/include/spaceship.h +++ b/include/spaceship.h @@ -1,11 +1,12 @@ #pragma once -class Spaceship { +#include "game_entity.h" + +class Spaceship: public GameEntity +{ public: Spaceship(int x, int y); const static char ENEMY_MAP_CHAR = 'V'; const static char PLAYER_MAP_CHAR = 'A'; private: - int x; - int y; }; -- cgit v1.2.3