Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
30:d8af03f01cd4
Parent:
28:44b7b6e35548
Child:
31:5f039cbddee8
--- a/blobConfig.cpp	Wed Jun 20 03:25:49 2012 +0000
+++ b/blobConfig.cpp	Fri Sep 21 10:02:35 2012 +0000
@@ -1,24 +1,17 @@
 
 #include "blobConfig.h"
-#include "hardwareIO.h" // this is in fact only to get to know the initial position of the spots, as well as the mirror limits to set the bounding box for the blobs
 
 blobConfig::blobConfig(): numBlobs(0) {
     //blobArray.clear();// there is no need to do this, the vector does not contains anything here.
-
 }
 
 blobConfig::~blobConfig() {
     clearConfig();
-
 }
 
 // =========================================== STANDARD CONFIGURATIONS =============================================================================
 
-void blobConfig::computeBoundingBox() {
-    for (int i=0; i<blobArray.size(); i++) {
-        blobArray[i]->computeBoundingBox();
-    }
-}
+
 
 void blobConfig::clearConfig() {
     for (int i=0; i<blobArray.size(); i++) delete blobArray[i]; // we must delete the pointer created with new, so the memory for the object is liberated (calls its destructor)
@@ -26,9 +19,80 @@
     numBlobs=0;// this is just equal to blobArray.size()
 }
 
-void blobConfig::addOneElasticLoopRelax() {
+void blobConfig::initConfig(configType cfType,  unsigned char numblobs) {
+    myConfigType=cfType;
+    numBlobs=numblobs;
+    switch(myConfigType) {
+        case ONE_ELASTIC_FOLLOWING:
+            // computeBoundingBox();
+            clearConfig();
+            addOneElasticContourFollowing();
+        break;
+        case ONE_ELASTIC_MOUTH:
+            // computeBoundingBox();
+            clearConfig();
+            addOneElasticLoopContractCentral();
+        break;
+        case ONE_ELASTIC_MOUTH_SMALL:
+            // computeBoundingBox();
+            clearConfig();
+            addOneElasticLoopContractCentralFast();
+        break;
+        case BOUNCING_SPOTS:
+            // computeBoundingBox();
+           clearConfig();
+           for (int i=0; i<numBlobs ; i++) addOneRigidLoopBouncing();
+        break;
+        case LORENTZ_SPOTS:
+         // computeBoundingBox();
+            clearConfig();
+            for (int i=0; i<numBlobs ; i++) addOneRigidLoopLorentz();
+        break;
+        case FOLLOWING_SPOTS:
+         // computeBoundingBox();
+            clearConfig();
+            for (int i=0; i<numBlobs ; i++) addOneRigidLoopFollowing();
+        break;
+        case AIR_HOCKEY_GAME: 
+            // computeBoundingBox();
+            clearConfig();
+            for (int i=0; i<numBlobs ; i++) addOneRigidLoopAirHockey();
+        break;
+        case CIRCULAR_PONG_GAME:
+            // computeBoundingBox();
+            clearConfig();
+            // (1) One SPOT_TRACK to track the background. It will be the number 0 in the config. 
+            addOneRigidTrackingSpot();
+
+            // (2) Add bouncing spots:
+            for (int i=0; i<numBlobs ; i++) addOneRigidLoopBouncing();
+        break;
+        case VERTICAL_PINBALL_GAME:
+         clearConfig();
+         // (1) One SPOT_TRACK to track the background - It will be the number 0 in the config. 
+          addOneRigidTrackingSpot();
+
+        break; 
+        case PAC_MAN_GAME:
+            clearConfig();
+            //(1) add one very slowly slidind-bouncing spot, the PACMAN (number 0 in the config)
+            addOneRigidLoopPacman(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(2,0));
+     
+            // (2) Add some initial SPOT_FOLLOWING or SPOT_GHOST spots (the ghosts):
+            //for (int i=0; i<numBlobs; i++) 
+            addOneRigidLoopFollowing(vector2Df(CENTER_AD_MIRROR_X-200, CENTER_AD_MIRROR_Y-200), vector2Df(2,0));
+            addOneRigidLoopGhost(vector2Df(CENTER_AD_MIRROR_X+200, CENTER_AD_MIRROR_Y-200), vector2Df(2,0));
+        break;
+        default:
+        break;
+    }
+}
+
+ // ==================== Template spots from which to create multi-spot configurations: =====================
+
+void blobConfig::addOneElasticLoopRelax(vector2Df initpos, vector2Df initspeed) {
     elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), RELAX, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), RELAX, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -38,9 +102,9 @@
 }
 
 
-void blobConfig::addOneElasticLoopContract() {
+void blobConfig::addOneElasticLoopContract(vector2Df initpos, vector2Df initspeed) {
     elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), CONTRACT, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), CONTRACT, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -48,9 +112,9 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneElasticLoopContractCentral() {
+void blobConfig::addOneElasticLoopContractCentral(vector2Df initpos, vector2Df initspeed) {
     elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -58,9 +122,9 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneElasticLoopContractCentralFast() {
+void blobConfig::addOneElasticLoopContractCentralFast(vector2Df initpos, vector2Df initspeed) {
     elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL_FAST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL_FAST, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -68,10 +132,10 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneElasticContourFollowing() {
+void blobConfig::addOneElasticContourFollowing(vector2Df initpos, vector2Df initspeed) {
 
     elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -80,9 +144,19 @@
 }
 
 
-void blobConfig:: addOneElasticContourFollowingFAST() {
+void blobConfig:: addOneElasticContourFollowingFAST(vector2Df initpos, vector2Df initspeed) {
     elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST,  initpos, initspeed);
+    // add this relaxing loop to the present config:
+    blobArray.push_back(pBlob);
+
+    // update auxiliary variable numBlobs (just for easy reference):
+    numBlobs=blobArray.size();
+}
+
+void blobConfig::addOneElasticBouncing(vector2Df initpos, vector2Df initspeed) {
+    elasticLoop* pBlob= new elasticLoop();
+    pBlob->createBlob(blobArray.size(), BOUNCING,  initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -90,9 +164,9 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneElasticBouncing() {
-    elasticLoop* pBlob= new elasticLoop();
-    pBlob->createBlob(blobArray.size(), BOUNCING, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(1,1));
+void blobConfig::addOneRigidLoopBouncing(vector2Df initpos, vector2Df initspeed) {
+    rigidLoop* pBlob= new rigidLoop();
+    pBlob->createBlob(blobArray.size(), SPOT_BOUNCING, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -100,9 +174,18 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneRigidLoopBouncing() {
+void blobConfig::addOneRigidLoopPacman(vector2Df initpos, vector2Df initspeed) {
     rigidLoop* pBlob= new rigidLoop();
-    pBlob->createBlob(blobArray.size(), SPOT_BOUNCING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(rand()%3,rand()%3));
+    pBlob->createBlob(blobArray.size(), SPOT_PACMAN, initpos, initspeed);
+    // add this relaxing loop to the present config:
+    blobArray.push_back(pBlob);
+
+    // update auxiliary variable numBlobs (just for easy reference):
+    numBlobs=blobArray.size();
+}
+void blobConfig::addOneRigidLoopGhost(vector2Df initpos, vector2Df initspeed) {
+    rigidLoop* pBlob= new rigidLoop();
+    pBlob->createBlob(blobArray.size(), SPOT_GHOST, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -110,9 +193,10 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneRigidLoopFountain() {
+
+void blobConfig::addOneRigidLoopLorentz(vector2Df initpos, vector2Df initspeed) {
     rigidLoop* pBlob= new rigidLoop();
-    pBlob->createBlob(blobArray.size(), SPOT_FOUNTAIN, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(rand()%3,rand()%3));
+    pBlob->createBlob(blobArray.size(), SPOT_LORENTZ_FORCE, initpos, initspeed);
     // add this loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -120,9 +204,9 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneRigidLoopAirHockey() {
+void blobConfig::addOneRigidLoopAirHockey(vector2Df initpos, vector2Df initspeed) {
     rigidLoop* pBlob= new rigidLoop();
-    pBlob->createBlob(blobArray.size(), SPOT_AIR_HOCKEY, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), SPOT_AIR_HOCKEY,  initpos, initspeed);
     // add this loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -130,9 +214,9 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneRigidLoopFollowing() {
+void blobConfig::addOneRigidLoopFollowing(vector2Df initpos, vector2Df initspeed) {
     rigidLoop* pBlob= new rigidLoop();
-    pBlob->createBlob(blobArray.size(), SPOT_FOLLOWING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), SPOT_FOLLOWING, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -140,9 +224,9 @@
     numBlobs=blobArray.size();
 }
 
-void blobConfig::addOneRigidLoopTest() {
+void blobConfig::addOneRigidLoopTest(vector2Df initpos, vector2Df initspeed) {
     rigidLoop* pBlob= new rigidLoop();
-    pBlob->createBlob(blobArray.size(), SPOT_TEST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
+    pBlob->createBlob(blobArray.size(), SPOT_TEST, initpos, initspeed);
     // add this relaxing loop to the present config:
     blobArray.push_back(pBlob);
 
@@ -150,6 +234,15 @@
     numBlobs=blobArray.size();
 }
 
+void blobConfig::addOneRigidTrackingSpot(vector2Df initpos, vector2Df initspeed) {
+   rigidLoop* pBlob= new rigidLoop();
+    pBlob->createBlob(blobArray.size(), SPOT_TRACK, initpos, initspeed);
+    // add this relaxing loop to the present config:
+    blobArray.push_back(pBlob);
+
+    // update auxiliary variable numBlobs (just for easy reference):
+    numBlobs=blobArray.size();
+}
 
 // ==================================================================================================================================================
 
@@ -187,10 +280,47 @@
     for (int i=0; i<blobArray.size(); i++) blobArray[i]->setColor(c);
  }
 
-void blobConfig::update() { // update dynamics of the blob
+void blobConfig::update() { // update dynamics of the blob configuration:
+
+    // (1) First, update dynamics of each blob independently:
     for (int i=0; i<blobArray.size(); i++) {
         if (blobArray[i]->standByMode==false) blobArray[i]->update();
     }
+    // (2) Then, depending on the config type, perform some special test and updates: 
+   switch(myConfigType) {
+        // simple behaviours:
+        case ONE_ELASTIC_FOLLOWING:
+        break;
+        case ONE_ELASTIC_MOUTH:
+        break;
+        case ONE_ELASTIC_MOUTH_SMALL:
+        break;
+        case BOUNCING_SPOTS:
+        break;
+        case LORENTZ_SPOTS:
+        break;
+        case FOLLOWING_SPOTS:
+        break;
+        // more game-like:
+        case AIR_HOCKEY_GAME: 
+        break;
+        case CIRCULAR_PONG_GAME:
+        break;
+        case VERTICAL_PINBALL_GAME:
+        break; 
+        case PAC_MAN_GAME:
+        break;
+        default:
+        break;
+    }
+     
+    
+}
+
+void blobConfig::computeBoundingBox() {
+    for (int i=0; i<blobArray.size(); i++) {
+        blobArray[i]->computeBoundingBox();
+    }
 }
 
 void blobConfig::draw() { // draw uses the opengl like renderer (if any), and save projected trajectory in the LaserSensingTrajectory object of each blob