[Orxonox-commit 4471] r9142 - in code/branches/newlevel2012: data/levels src/modules/towerdefense src/orxonox/controllers
mentzerf at orxonox.net
mentzerf at orxonox.net
Sun Apr 29 17:22:57 CEST 2012
Author: mentzerf
Date: 2012-04-29 17:22:56 +0200 (Sun, 29 Apr 2012)
New Revision: 9142
Modified:
code/branches/newlevel2012/data/levels/towerDefense.oxw
code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc
code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h
code/branches/newlevel2012/src/orxonox/controllers/WaypointController.cc
Log:
+ Tried to create waypoints programmatically, succeeded, BUT: the spaceship does not follow them!!
* Changed WaypointController to log some debug info
Modified: code/branches/newlevel2012/data/levels/towerDefense.oxw
===================================================================
--- code/branches/newlevel2012/data/levels/towerDefense.oxw 2012-04-29 13:42:22 UTC (rev 9141)
+++ code/branches/newlevel2012/data/levels/towerDefense.oxw 2012-04-29 15:22:56 UTC (rev 9142)
@@ -64,21 +64,22 @@
<!-- Spawns the camera, attached to a crate -->
<SpawnPoint team=0 position="0,0,0" spawnclass=Pawn pawndesign=centerpointmark />
+ <!--TeamSpawnPoint team=1 position="-7,7,4" direction="-1,0,0" roll=90 yaw=0 spawnclass=SpaceShip pawndesign=spaceshipassff /-->
<!--SpawnPoint team=1 position="0,0,10" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /-->
<!--SpawnPoint team=0 position="0,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /-->
- <!--SpaceShip position="-10,0,20" lookat="0,0,0">
+ <!--SpaceShip position="-10,0,20" lookat="0,0,0" scale=0.3>
<templates>
<Template link=spaceshipassff />
</templates>
<controller>
<WaypointController accuracy=3>
<waypoints>
- <Model mesh="cube.mesh" scale=1 position="110,90,20" />
- <Model mesh="cube.mesh" scale=2 position="290,90,20" />
- <Model mesh="cube.mesh" scale=3 position="290,-90,20" />
- <Model mesh="cube.mesh" scale=4 position="110,-90,20" />
+ <Model mesh="cube.mesh" scale=0.2 position="-8,-8,3" />
+ <Model mesh="cube.mesh" scale=0.2 position="8,8,3" />
+ <Model mesh="cube.mesh" scale=0.2 position="8,-8,3" />
+ <Model mesh="cube.mesh" scale=0.2 position="-8,8,3" />
</waypoints>
</WaypointController>
</controller>
Modified: code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc 2012-04-29 13:42:22 UTC (rev 9141)
+++ code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc 2012-04-29 15:22:56 UTC (rev 9142)
@@ -61,7 +61,11 @@
#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"
/* Part of a temporary hack to allow the player to add towers */
@@ -77,7 +81,9 @@
/* Temporary hack to allow the player to add towers */
this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) );
-
+
+ // Quick hack to test waypoints
+ createConsoleCommand( "aw", createExecutor( createFunctor(&TowerDefense::addWaypointsAndFirstEnemy, this) ) );
}
TowerDefense::~TowerDefense()
@@ -148,14 +154,59 @@
{
SUPER(TowerDefense, tick, dt);
- static bool test = false;
- if (!test)
+ static int test = 0;
+ if (++test == 10)
{
- orxout()<< "First tick." <<endl;
+ orxout()<< "10th tick." <<endl;
+ /*
+ for (std::set<SpawnPoint*>::iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); it++)
+ {
+ orxout() << "checking spawnpoint with name " << (*it)->getSpawnClass()->getName() << endl;
+ }
+ */
+
+ //addWaypointsAndFirstEnemy();
+
}
- test = true;
}
+ // Function to test if we can add waypoints using code only. Doesn't work yet
+
+ // THE PROBLEM: WaypointController's getControllableEntity() returns null, so it won't track. How do we get the controlableEntity to NOT BE NULL???
+
+ void TowerDefense::addWaypointsAndFirstEnemy()
+ {
+ SpaceShip *newShip = new SpaceShip(this->center_);
+ newShip->addTemplate("spaceshipassff");
+
+ WaypointController *newController = new WaypointController(newShip);
+ newController->setAccuracy(3);
+
+ Model *wayPoint1 = new Model(newController);
+ wayPoint1->setMeshSource("crate.mesh");
+ wayPoint1->setPosition(7,-7,5);
+ wayPoint1->setScale(0.2);
+
+ Model *wayPoint2 = new Model(newController);
+ wayPoint2->setMeshSource("crate.mesh");
+ wayPoint2->setPosition(7,7,5);
+ wayPoint2->setScale(0.2);
+
+ newController->addWaypoint(wayPoint1);
+ newController->addWaypoint(wayPoint2);
+
+ // The following line causes the game to crash
+// newController -> getPlayer() -> startControl(newShip);
+ newShip->setController(newController);
+ newShip->setPosition(-7,-7,5);
+ newShip->setScale(0.1);
+ newShip->addSpeed(1);
+
+
+
+// this->center_->attach(newShip);
+ }
+
/*
void TowerDefense::playerEntered(PlayerInfo* player)
{
Modified: code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h
===================================================================
--- code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h 2012-04-29 13:42:22 UTC (rev 9141)
+++ code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h 2012-04-29 15:22:56 UTC (rev 9142)
@@ -57,6 +57,7 @@
//virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
//virtual void playerScored(PlayerInfo* player);
+
/* Called by TowerDefenseCenterpoint upon game start
The centerpoint is used to create towers
*/
@@ -71,6 +72,8 @@
private:
// WeakPtr<TowerDefenseCenterpoint> center_;
TowerDefenseCenterpoint *center_;
+
+ void addWaypointsAndFirstEnemy();
};
}
Modified: code/branches/newlevel2012/src/orxonox/controllers/WaypointController.cc
===================================================================
--- code/branches/newlevel2012/src/orxonox/controllers/WaypointController.cc 2012-04-29 13:42:22 UTC (rev 9141)
+++ code/branches/newlevel2012/src/orxonox/controllers/WaypointController.cc 2012-04-29 15:22:56 UTC (rev 9142)
@@ -61,15 +61,22 @@
void WaypointController::tick(float dt)
{
- if (!this->isActive())
+ if (!this->isActive())
return;
+ orxout() << "(" << this->waypoints_.size() << ") entity: " << this->getControllableEntity() << endl;
+
+
if (this->waypoints_.size() == 0 || !this->getControllableEntity())
return;
+ printf("3");
+
if (this->waypoints_[this->currentWaypoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->squaredaccuracy_)
this->currentWaypoint_ = (this->currentWaypoint_ + 1) % this->waypoints_.size();
+ printf("4");
+
this->moveToPosition(this->waypoints_[this->currentWaypoint_]->getWorldPosition());
}
More information about the Orxonox-commit
mailing list