Index: code/trunk/src/modules/hover/Hover.cc
===================================================================
--- code/trunk/src/modules/hover/Hover.cc	(revision 11071)
+++ code/trunk/src/modules/hover/Hover.cc	(revision 11493)
@@ -24,4 +24,5 @@
  *   Co-authors:
  *      Cyrill Burgener
+ *      Tomer Gidron
  *
  */
@@ -33,5 +34,5 @@
 
 #include "Hover.h"
-
+#include "chat/ChatManager.h"
 #include "HoverOrigin.h"
 #include "HoverWall.h"
@@ -39,4 +40,9 @@
 #include "MazeGenerator.h"
 #include "core/CoreIncludes.h"
+#include "gamestates/GSLevel.h"
+#include "HoverShip.h"
+
+#include "pickup/PickupSpawner.h"
+#include "pickup/Pickup.h"
 
 namespace orxonox
@@ -51,19 +57,34 @@
         this->numberOfFlags_ = 1;
         this->firstTick_ = true;
+        level = 1; //start at level 1
+        flagsTaken = 0;// took 0 flags in the beginning
+        lives = 3;
+
+        numCells = 0;
+        cellSize = 0;
+        cellHeight = 0;
+
+        bLevelUpgradeHUD = false;
+
+        totFlags = 0;
 
         this->setHUDTemplate("HoverHUD");
-    }
-
-    void Hover::tick(float dt)
-    {
-        SUPER(Hover, tick, dt);
-
+
+    }
+
+    void Hover::start()
+    {
+        Gametype::start();
         if(this->firstTick_ && this->origin_)
         {
             this->firstTick_ = false;
 
-            int numCells = this->origin_->getNumCells();
-            int cellSize = this->origin_->getCellSize();
-            int cellHeight = this->origin_->getCellHeight();
+            numCells = this->origin_->getNumCells();
+            cellSize = this->origin_->getCellSize();
+            cellHeight = this->origin_->getCellHeight();
+
+            //TODO
+            //create boolean array/vector to assert that no two objects are placed in the same way
+            
 
             MazeGenerator generator(numCells);
@@ -81,35 +102,187 @@
             }
 
+
+            //Ground
+            for(int i = 0; i<numCells; i++){
+                for(int j = 0; j<numCells; j++){
+                    StaticEntity* groundCell = new StaticEntity(origin_->getContext());
+
+                    groundCell->addTemplate(origin_->getGroundTemplate());
+                    groundCell->setPosition(get3dCoordinates(i,j,-60));
+                }
+
+            }
+
+
+
             //Generate inner Walls according to levelcode
             for(int y=0; y<numCells; y++){
                 for(int x=0; x<numCells; x++){
-                    switch(levelcode[ y * numCells + x ]){
+                    switch(levelcode[ y * numCells + x ])
+                    {
                         case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
-                                break;
+                            break;
                         case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
                         case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0);
-                        default: break;
+                        default:
+                            break;
                     }
-                }   
-            }
-
-            //Generate 5 flags randomly
-            for ( int i = 0; i < 5; i++ )
-            {
-                HoverFlag* flag = new HoverFlag(origin_->getContext());
-                flag->init(rand()%numCells, rand()%numCells, cellSize);
-                flags_.push_back(flag);
-            }
-
-        }//firsttick end
+                }
+            }
+
+            createFlags();
+
+            //Generate 3 PickupSpawners randomly (destroy hover pickup)
+            for (int i = 0; i<3; i++)
+            {
+                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
+
+                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f));
+                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate());
+                pickupSpawner->setMaxSpawnedItems(3);
+                pickupSpawner->setRespawnTime(30);
+                pickupSpawner->setTriggerDistance(40);
+                // Add pickup spawner to the pickup spawner list
+                pickupSpawners_.push_back(pickupSpawner);
+            }
+            
+            //Generate 3 PickupSpawners randomly (speed pickup)
+            for (int i = 0; i<3; i++)
+            {
+                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
+
+                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f));
+                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateSpeed());
+                pickupSpawner->setMaxSpawnedItems(3);
+                pickupSpawner->setRespawnTime(30);
+                pickupSpawner->setTriggerDistance(40);
+                // Add pickup spawner to the pickup spawner list
+                pickupSpawners_.push_back(pickupSpawner);
+            }
+
+            //Generate 3 PickupSpawners randomly (shrink pickup)
+            for (int i = 0; i<3; i++)
+            {
+                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
+
+                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f));
+                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateShrink());
+                pickupSpawner->setMaxSpawnedItems(3);
+                pickupSpawner->setRespawnTime(30);
+                pickupSpawner->setTriggerDistance(40);
+                // Add pickup spawner to the pickup spawner list
+                pickupSpawners_.push_back(pickupSpawner);
+            }
+
+            //*****************************************************************************
+
+            //Generate destroyable crates randomly on field
+
+            for (int i = 0; i<10; i++){
+
+                Pawn* crate = new Pawn(origin_->getContext());
+
+                crate->addTemplate(origin_->getObstacleTemplate());  
+                crate->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 43.0f));
+
+
+            }    
+            
+
+
+
+             //If no lives are left, end game
+            if(lives <= 0)
+            {
+                GSLevel::startMainMenu();
+            }
+            
+        }
+    }
+
+
+    // generate new Flags
+    void Hover::createFlags()
+    {
+        //TODO
+        //Generate flags randomly using bool array
+
+        //Generate 5 flags randomly on field
+        for ( int i = 0; i < 5; i++ )
+        {
+            HoverFlag* flag = new HoverFlag(origin_->getContext());
+            flag->init(rand()%numCells, rand()%numCells, cellSize);
+            flags_.push_back(flag);
+
+            
+
+            if(flags_[i]->getPosition() == get3dCoordinates(0,0,-60))
+            {
+                flags_[i]->destroyLater();
+                flags_.erase(flags_.begin()+i);
+            }
+        }
+            
+    }
+
+    void Hover::tick(float dt)
+    {
+        SUPER(Hover, tick, dt);
+
 
         // Check if ship collided with one of the flags
-        for ( unsigned int i = 0; i < flags_.size(); i++ ){
-            if(flags_[i]->getCollided()){
+        for ( unsigned int i = 0; i < flags_.size(); i++ )
+        {
+            if(flags_[i]->getCollided())
+            {
                 flags_[i]->destroyLater();
                 flags_.erase (flags_.begin()+i);
-            }
+                totFlags++;
+                if(flags_.size()<=0){
+                    //ChatManager::message("Level Up!");
+                    
+                    levelUp();
+                }
+            }
+
         }
         numberOfFlags_ = flags_.size();
+
+        if(lives <= 0){
+                GSLevel::startMainMenu();
+            }
+    }
+
+    //start new level - call to create new flags
+    void Hover::levelUp()
+    {
+        level++;
+        //increment lives after every 4 levels
+        if(level%4 == 0)
+        {
+            lives++;
+        }
+        createFlags();
+        toggleShowLevel();
+        showLevelTimer.setTimer(2.0f, false, createExecutor(createFunctor(&Hover::toggleShowLevel, this)));
+
+        //spawn one additional crate randomly
+        Pawn* crate = new Pawn(origin_->getContext());
+        crate->addTemplate(origin_->getObstacleTemplate());  
+        crate->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 43.0f));
+
+    }
+
+    Vector3 Hover::get3dCoordinates(int x, int y, float heightOffset)
+    {
+        return Vector3(x*cellSize*1.0f + cellSize/2, heightOffset, y*cellSize*1.0f + cellSize/2);
+    }
+
+    //if killed, subtract number of lives. If lives == 0, end game
+    void Hover::costLife()
+    {
+        lives--;
+        if (lives <= 0)
+            GSLevel::startMainMenu();
     }
 }
