1. Ivan Vučica
  2. Pucaljka

Commits

Ivan Vučica  committed c96a3c9

All game objects now derive from GameObject

  • Participants
  • Parent commits 56a8c82
  • Branches default

Comments (0)

Files changed (3)

File enemyship.h

View file
 #include <SDL/SDL_events.h>
 #include <string>
 #include "texture.h"
+#include "gameobject.h"
 
-class EnemyShip
+class EnemyShip : public GameObject
 {
     public:
     EnemyShip(const std::string& textureFile,

File gm_level.cpp

View file
     EnemyShip *blueenemyShip(new EnemyShip("enemyship02.png", 800, 400));
     RedEnemyShip *redEnemyShip(new RedEnemyShip(320, 0));
     BlueEnemyShip *blueEnemyShip(new BlueEnemyShip(320, 0));
-    this->enemyShips.push_back(enemyShip);
-    this->enemyShips.push_back(blueenemyShip);
+    this->gameObjects.push_back(enemyShip);
+    this->gameObjects.push_back(blueenemyShip);
     this->layers.push_back(layer);
-    this->enemyShips.push_back(redEnemyShip);
-    this->enemyShips.push_back(blueEnemyShip);
+    this->gameObjects.push_back(redEnemyShip);
+    this->gameObjects.push_back(blueEnemyShip);
 
     for(int i = 0; i < 50; i++)
     {
         YellowEnemyShip *yellowEnemyShip(new YellowEnemyShip(320 + i * 60, 240));
-        this->enemyShips.push_back(yellowEnemyShip);
+        this->gameObjects.push_back(yellowEnemyShip);
     }
 
     for(int i = 0; i < 50; i++)
     {
         YellowEnemyShip *yellowEnemyShip(new YellowEnemyShip(320 + i * 60, -240));
-        this->enemyShips.push_back(yellowEnemyShip);
+        this->gameObjects.push_back(yellowEnemyShip);
     }
 
 
     for(int i = 0; i < 50; i++)
     {
         YellowEnemyShip *yellowEnemyShip(new YellowEnemyShip(320 + i * 60, 120));
-        this->enemyShips.push_back(yellowEnemyShip);
+        this->gameObjects.push_back(yellowEnemyShip);
     }
 
     for(int i = 0; i < 50; i++)
     {
         YellowEnemyShip *yellowEnemyShip(new YellowEnemyShip(320 + i * 60, -120));
-        this->enemyShips.push_back(yellowEnemyShip);
+        this->gameObjects.push_back(yellowEnemyShip);
     }
 }
 
             const double BX = this->playership->getX();
             const double BY = this->playership->getY();
             Bullet*bullet(new Bullet(BX,BY));
-            this->bullets.push_back(bullet);
+            this->gameObjects.push_back(bullet);
         }
         break;
 
 
 
     playership->paintSelf();
-    for(std::vector<EnemyShip*>::iterator it = enemyShips.begin(); it != enemyShips.end(); it++)
-    {
-        (*it)->paintSelf();
-    }
-
-
-
-    for(std::vector<Bullet*>::iterator it = bullets.begin(); it != bullets.end(); it++)
+    for(std::vector<GameObject*>::iterator it = gameObjects.begin(); it != gameObjects.end(); it++)
     {
         (*it)->paintSelf();
     }
 void GM_Level::updateSelf(double timeDelta)
 {
     this->playership->updateSelf(timeDelta);
-    for(std::vector<EnemyShip*>::iterator it = enemyShips.begin(); it != enemyShips.end(); it++)
-    {
-        (*it)->updateSelf(timeDelta);
-    }
-
-     for(std::vector<Bullet*>::iterator it = bullets.begin(); it != bullets.end(); it++)
+    for(std::vector<GameObject*>::iterator it = this->gameObjects.begin(); it != this->gameObjects.end(); it++)
     {
         (*it)->updateSelf(timeDelta);
     }

File gm_level.h

View file
 
     private:
     std::vector<GameObject*> gameObjects;
-    std::vector<EnemyShip*> enemyShips;
-    std::vector<Bullet*> bullets;
-    std::vector<RedEnemyShip*> redEnemyShip;
-    std::vector<BlueEnemyShip*> blueEnemyShip;
     std::vector<Layer*> layers;
     PlayerShip * playership;
 };