[Orxonox-commit 5509] r10172 - code/branches/towerdefenseHS14/src/modules/towerdefense
maxima at orxonox.net
maxima at orxonox.net
Thu Dec 11 13:05:08 CET 2014
Author: maxima
Date: 2014-12-11 13:05:08 +0100 (Thu, 11 Dec 2014)
New Revision: 10172
Modified:
code/branches/towerdefenseHS14/src/modules/towerdefense/TDEnemy.h
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseHUDController.cc
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h
Log:
final version for presentation
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TDEnemy.h
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TDEnemy.h 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TDEnemy.h 2014-12-11 12:05:08 UTC (rev 10172)
@@ -4,7 +4,7 @@
* Created on: Mar 30, 2012
* Author: weigeltm
*/
-
+/*
#ifndef TDENEMY_H_
#define TDENEMY_H_
@@ -23,4 +23,4 @@
};
-#endif /* TDENEMY_H_ */
+#endif TDENEMY_H_ */
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc 2014-12-11 12:05:08 UTC (rev 10172)
@@ -19,7 +19,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * Author:
+ * Author:
*
* Co-authors:
* ...
@@ -72,22 +72,19 @@
*
*
*/
-
#include "TowerDefense.h"
#include "TowerDefenseTower.h"
-#include "TowerTurret.h"
#include "TowerDefenseCenterpoint.h"
//#include "TDCoordinate.h"
+#include "TowerTurret.h"
#include "worldentities/SpawnPoint.h"
#include "worldentities/pawns/Pawn.h"
#include "worldentities/pawns/SpaceShip.h"
#include "controllers/WaypointController.h"
-
#include "graphics/Model.h"
#include "infos/PlayerInfo.h"
#include "chat/ChatManager.h"
#include "core/CoreIncludes.h"
-
/* Part of a temporary hack to allow the player to add towers */
#include "core/command/ConsoleCommand.h"
@@ -98,12 +95,18 @@
TowerDefense::TowerDefense(Context* context) : Deathmatch(context)
{
RegisterObject(TowerDefense);
+/*
+ for (int i=0; i < 16 ; i++){
+ for (int j = 0; j< 16 ; j++){
+ towermatrix[i][j] = NULL;
+ }
+ }*/
this->setHUDTemplate("TowerDefenseHUD");
//this->stats_ = new TowerDefensePlayerStats();
- /* Temporary hack to allow the player to add towers */
+ /* Temporary hack to allow the player to add towers and upgrade them */
this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) );
this->dedicatedUpgradeTower_ = createConsoleCommand( "upgradeTower", createExecutor( createFunctor(&TowerDefense::upgradeTower, this) ) );
}
@@ -127,20 +130,16 @@
void TowerDefense::start()
{
- orxout() << "test0" << endl;
Deathmatch::start();
- /*credits = 5000;
- life = 20;
- waves = 0;
- time=0.0;*/
-// Waypoints: [1,3] [10,3] [10,11] [13,11]
+// Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
for (int i=0; i < 16 ; i++){
for (int j = 0; j< 16 ; j++){
towermatrix[i][j] = false;
}
}
+
for (int k=0; k<3; k++)
towermatrix[1][k]=true;
for (int l=1; l<11; l++)
@@ -152,36 +151,24 @@
for (int o=13; o<16; o++)
towermatrix[13][o]=true;
-
+//set initial credits, lifes and WaveNumber
this->setCredit(200);
- this->setLifes(10);
+ this->setLifes(50);
this->setWaveNumber(0);
time=0.0;
- const int kInitialTowerCount = 3;
-
- for (int i = 0; i < kInitialTowerCount; i++)
- {
- addTower(i+4,i+5);
- }
-
-
-
- //add some TowerDefenseEnemys
-
-
-
-
-
- //ChatManager::message("Use the console command addTower x y to add towers");
-
- //TODO: let the player control his controllable entity && TODO: create a new ControllableEntity for the player
- }
-
+//adds initial towers
+for (int i=0; i <7; i++){
+ addTower(i+3,4);
+ }/*
+for (int j=0; j < 7; j++){
+ addTower(9,j+5);
+ }*/
+}
// Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path.
-
void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){
+
TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext());
switch(templatenr)
@@ -189,58 +176,47 @@
case 1 :
en1->addTemplate("enemytowerdefense1");
en1->setScale(3);
+ en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
+
break;
case 2 :
en1->addTemplate("enemytowerdefense2");
en1->setScale(2);
+ en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
+ // en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2))
+
break;
case 3 :
- en1->addTemplate("enemytowerdefense3");
- en1->setScale(1);
- break;
+ en1->addTemplate("enemytowerdefense3");
+ en1->setScale(1);
+ en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
+ break;
}
-
- en1->getController();
+ en1->getController();
en1->setPosition(path.at(0)->get3dcoordinate());
-
-
TowerDefenseEnemyvector.push_back(en1);
-
for(unsigned int i = 0; i < path.size(); ++i)
- {
- en1->addWaypoint((path.at(i)));
- }
-
-
- /*
- WaypointController *newController = new WaypointController(en1->getContext());//
- newController->setAccuracy(3);
-
- for(int i =0; i < path.size(); ++i)
- {
-
- Model *wayPoint = new Model(en1->getContext());
- wayPoint->setMeshSource("cube.mesh");
- wayPoint->setPosition(path.at(i)->get3dcoordinate());
- wayPoint->setScale(0.2);
- newController->addWaypoint(wayPoint);
- }*/
+ {
+ en1->addWaypoint((path.at(i)));
+ }
}
void TowerDefense::end()
{
- Deathmatch::end();
+ Deathmatch::end();
ChatManager::message("Match is over! Gameover!");
+
}
+ //not working yet
void TowerDefense::upgradeTower(int x,int y)
{/*
- const TowerCost upgradeCost = TDDefaultUpgradeCost;
+ const int upgradeCost = 20;
if (!this->hasEnoughCreditForTower(upgradeCost))
{
@@ -260,7 +236,10 @@
}*/
}
+ /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret")
+ so towers have ability if the turrets
+ */
void TowerDefense::addTower(int x, int y)
{
const int towerCost = 20;
@@ -293,20 +272,15 @@
orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
-
-
//Reduce credit
this->buyTower(towerCost);
-
towermatrix [x][y]=true;
-
- // Create tower
+ //Creates tower
TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext());
towernew->addTemplate("towerturret");
towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75);
towernew->setGame(this);
-
}
bool TowerDefense::hasEnoughCreditForTower(int towerCost)
@@ -314,6 +288,7 @@
return ((this->getCredit()) >= towerCost);
}
+
bool TowerDefense::hasEnoughCreditForUpgrade()
{
return true;
@@ -328,64 +303,58 @@
TDCoordinate* coord1 = new TDCoordinate(1,1);
std::vector<TDCoordinate*> path;
path.push_back(coord1);
-
if(time>1 && TowerDefenseEnemyvector.size() < 30)
{
- addTowerDefenseEnemy(path, rand() %3 +1 );
- time = time-1;
+ //adds different types of enemys depending on the WaveNumber
+ addTowerDefenseEnemy(path, this->getWaveNumber() % 3 +1 );
+ time = time-1;
}
- Vector3* endpoint = new Vector3(500, 700, 150);
-
- for(int i =0; i < TowerDefenseEnemyvector.size(); ++i)
- {
-
- //orxout() << TowerDefenseEnemyvector.at(i) << endl;
- //continue;
-
- //ArtificialController* controller = (ArtificialController*)this->getController();
+ Vector3* endpoint = new Vector3(500, 700, 150);
+ //if ships are at the end they get destroyed
+ for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i)
+ {
if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive())
- {
- orxout() << "Variable i: " << i << endl;
+ {
+ //destroys enemys at the end of teh path and reduces the life by 1. no credits gifted
- Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition();
+ Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition();
+ float distance = ship.distance(*endpoint);
- float distance = ship.distance(*endpoint);
-
- //orxout() << "distance" << distance << endl;
- if(distance <50){
- // orxout() << "ENEMY KILLED!!!!" << endl;
- TowerDefenseEnemyvector.at(i)->destroy();
+ if(distance <50){
+ TowerDefenseEnemyvector.at(i)->destroy();
+ this->reduceLifes(1);
+ this->buyTower(1);
+ if (this->getLifes()==0)
+ {
+ this->end();
+ }
+ }
}
}
- else
+ //goes thorugh vector to see if an enemy is still alive. if not next wave is launched
+ int count= 0;
+ for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i)
{
- //TowerDefenseEnemyvector.erase(TowerDefenseEnemyvector.begin() +i);
+ if(TowerDefenseEnemyvector.at(i)!= NULL)
+ {
+ ++count;
+ }
}
- }
- int count= 0;
- for(int i =0; i < TowerDefenseEnemyvector.size(); ++i)
- {
- if(TowerDefenseEnemyvector.at(i)!= NULL)
- {
- ++count;
- }
- }
+ if(count== 0)
+ {
+ time2 +=dt;
+ if(time2 > 10)
+ {
+ TowerDefenseEnemyvector.clear();
+ this->nextwave();
+ time=0;
+ time2=0;
+ }
+ }
- if(count== 0)
- {
- time2 +=dt;
- if(time2 > 10)
- {
- TowerDefenseEnemyvector.clear();
- time=0;
- time2=0;
- }
- }
-
-
}
// Function to test if we can add waypoints using code only. Doesn't work yet
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h 2014-12-11 12:05:08 UTC (rev 10172)
@@ -41,10 +41,8 @@
#include "gametypes/Deathmatch.h"
#include "TowerDefenseEnemy.h"
#include "util/Output.h"
+#include "core/object/WeakPtr.h"
-
- #include "TowerDefensePlayerStats.h"
-
namespace orxonox
{
class _TowerDefenseExport TowerDefense : public Deathmatch
@@ -55,7 +53,7 @@
std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > TowerDefenseEnemyvector;
bool towermatrix[16][16];
- void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr);
+ void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr);
virtual void start(); //<! The function is called when the gametype starts
virtual void end();
virtual void tick(float dt);
@@ -107,6 +105,8 @@
bool hasEnoughCreditForTower(int towerCost);
bool hasEnoughCreditForUpgrade();
+
+
std::vector<TowerTurret*> towers_;
};
}
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc 2014-12-11 12:05:08 UTC (rev 10172)
@@ -11,7 +11,6 @@
@ingroup TowerDefense
*/
#include "TowerDefenseEnemy.h"
-
#include "core/CoreIncludes.h"
//#include "core/XMLPort.h"
@@ -28,13 +27,15 @@
RegisterObject(TowerDefenseEnemy);
this->setCollisionType(WorldEntity::Dynamic);
+ //needed to keep track of the PlayerStats coded in TowerDefense.h
this->td = orxonox_cast<TowerDefense*>(this->getGametype().get());
- once_ = false;
}
+ //add credit if enemy is destroyed
+ TowerDefenseEnemy::~TowerDefenseEnemy(){
+ this->td->addCredit(1);
+ }
- TowerDefenseEnemy::~TowerDefenseEnemy(){this->td->addCredit(20);}
-
void TowerDefenseEnemy::addWaypoint(TDCoordinate* coord)
{
this->Waypointsvector_.push_back(coord);
@@ -44,25 +45,6 @@
void TowerDefenseEnemy::tick(float dt)
{
SUPER(TowerDefenseEnemy, tick, dt);
-
- //ArtificialController* controller = (ArtificialController*)this->getController();
- Vector3 ship = this->getRVWorldPosition();
- Vector3* endpoint = new Vector3(500, 700, 150);
-
- float distance = ship.distance(*endpoint);
-
- //orxout() << "distance" << distance << endl;
- if(distance < 50 && once_ == false){
- this->td->reduceLifes(1);
- once_=true;
- orxout() << "ENEMY KILLED!!!!" << endl;
- this->td->buyTower(20);
- if (this->td->getLifes()==0)
- {
- this->td->end();
- }
-
- }
}
/*
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h 2014-12-11 12:05:08 UTC (rev 10172)
@@ -31,9 +31,7 @@
*/
class _TowerDefenseExport TowerDefenseEnemy : public SpaceShip
{
-
public:
-
TowerDefenseEnemy(Context* context);
virtual ~TowerDefenseEnemy();
@@ -46,7 +44,6 @@
private:
-
TowerDefense* td;
bool once_;
std::vector<TDCoordinate*> Waypointsvector_;
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseHUDController.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseHUDController.cc 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseHUDController.cc 2014-12-11 12:05:08 UTC (rev 10172)
@@ -51,14 +51,14 @@
SUPER(TowerDefenseHUDController, tick, dt);
const std::string& lifes = multi_cast<std::string>(this->td->getLifes());
const std::string& credits = multi_cast<std::string>(this->td->getCredit());
- const std::string& waves = multi_cast<std::string>(this->td->getWaveNumber());
+ const std::string& wave = multi_cast<std::string>(this->td->getWaveNumber());
if(showlives == true)
this->setCaption(multi_cast<std::string>(lifes));
else if(showcredits == true)
this->setCaption(multi_cast<std::string>(credits));
else if(showwaves == true)
- this->setCaption(multi_cast<std::string>(waves));
+ this->setCaption(multi_cast<std::string>(wave));
}
@@ -86,13 +86,5 @@
this->td = 0;
}
}
- /*if (this->getOwner() != NULL && this->getOwner()->getGametype())
- {
- this->owner_ = orxonox_cast<TowerDefense*>(this->getOwner()->getGametype().get());
- }
- else
- {
- this->owner_ = NULL;
- }*/
}
Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h 2014-12-11 12:01:28 UTC (rev 10171)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h 2014-12-11 12:05:08 UTC (rev 10172)
@@ -26,14 +26,14 @@
*
*/
- /**
+ /*
@brief
This manages the stats of the player. It is used by 'TowerDefense', the gametype
@ingroup TowerDefense
- */
+
#ifndef _TowerDefensePlayerStats_H__
#define _TowerDefensePlayerStats_H__
@@ -87,4 +87,4 @@
};
}
-#endif /* _TowerDefensePlayerStats_H__ */
+#endif _TowerDefensePlayerStats_H__ */
More information about the Orxonox-commit
mailing list