Alvaro Cassinelli
/
skinGames_II
save loops
blobConfig.cpp@1:3be7b7d050f4, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 08:29:59 2014 +0000
- Revision:
- 1:3be7b7d050f4
- Parent:
- 0:df6fdd9b99f0
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | |
mbedalvaro | 0:df6fdd9b99f0 | 2 | #include "blobConfig.h" |
mbedalvaro | 0:df6fdd9b99f0 | 3 | |
mbedalvaro | 0:df6fdd9b99f0 | 4 | blobConfig::blobConfig(): numBlobs(0) { |
mbedalvaro | 0:df6fdd9b99f0 | 5 | //blobArray.clear();// there is no need to do this, the vector does not contains anything here. |
mbedalvaro | 0:df6fdd9b99f0 | 6 | } |
mbedalvaro | 0:df6fdd9b99f0 | 7 | |
mbedalvaro | 0:df6fdd9b99f0 | 8 | blobConfig::~blobConfig() { |
mbedalvaro | 0:df6fdd9b99f0 | 9 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 10 | } |
mbedalvaro | 0:df6fdd9b99f0 | 11 | |
mbedalvaro | 0:df6fdd9b99f0 | 12 | // =========================================== STANDARD CONFIGURATIONS ============================================================================= |
mbedalvaro | 0:df6fdd9b99f0 | 13 | |
mbedalvaro | 0:df6fdd9b99f0 | 14 | |
mbedalvaro | 0:df6fdd9b99f0 | 15 | |
mbedalvaro | 0:df6fdd9b99f0 | 16 | void blobConfig::clearConfig() { |
mbedalvaro | 0:df6fdd9b99f0 | 17 | 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) |
mbedalvaro | 0:df6fdd9b99f0 | 18 | blobArray.clear(); |
mbedalvaro | 0:df6fdd9b99f0 | 19 | numBlobs=0;// this is just equal to blobArray.size() |
mbedalvaro | 0:df6fdd9b99f0 | 20 | } |
mbedalvaro | 0:df6fdd9b99f0 | 21 | |
mbedalvaro | 0:df6fdd9b99f0 | 22 | void blobConfig::initConfig(configType cfType, int numblobs) { |
mbedalvaro | 0:df6fdd9b99f0 | 23 | myConfigType=cfType; |
mbedalvaro | 0:df6fdd9b99f0 | 24 | int i; |
mbedalvaro | 0:df6fdd9b99f0 | 25 | switch(myConfigType) { |
mbedalvaro | 0:df6fdd9b99f0 | 26 | case ONE_ELASTIC_FOLLOWING: |
mbedalvaro | 0:df6fdd9b99f0 | 27 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 28 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 29 | addOneElasticContourFollowing(); |
mbedalvaro | 0:df6fdd9b99f0 | 30 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 31 | case ONE_ELASTIC_MOUTH: |
mbedalvaro | 0:df6fdd9b99f0 | 32 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 33 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 34 | addOneElasticLoopContractCentral(); |
mbedalvaro | 0:df6fdd9b99f0 | 35 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 36 | case ONE_ELASTIC_MOUTH_SMALL: |
mbedalvaro | 0:df6fdd9b99f0 | 37 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 38 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 39 | addOneElasticLoopContractCentralFast(); |
mbedalvaro | 0:df6fdd9b99f0 | 40 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 41 | case BOUNCING_SPOTS: |
mbedalvaro | 0:df6fdd9b99f0 | 42 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 43 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 44 | for (i=0; i<numblobs ; i++) addOneRigidLoopBouncing(); |
mbedalvaro | 0:df6fdd9b99f0 | 45 | randomizeAllColors(); |
mbedalvaro | 0:df6fdd9b99f0 | 46 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 47 | case LORENTZ_SPOTS: |
mbedalvaro | 0:df6fdd9b99f0 | 48 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 49 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 50 | for (i=0; i<numblobs ; i++) addOneRigidLoopLorentz(); |
mbedalvaro | 0:df6fdd9b99f0 | 51 | randomizeAllColors(); |
mbedalvaro | 0:df6fdd9b99f0 | 52 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 53 | case FOLLOWING_SPOTS: |
mbedalvaro | 0:df6fdd9b99f0 | 54 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 55 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 56 | for (i=0; i<numblobs ; i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 57 | addOneRigidLoopFollowing(vector2Df(CENTER_AD_MIRROR_X+i*200, CENTER_AD_MIRROR_Y+i*200), vector2Df(11,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 58 | } |
mbedalvaro | 0:df6fdd9b99f0 | 59 | // randomize colors: |
mbedalvaro | 0:df6fdd9b99f0 | 60 | randomizeAllColors(); |
mbedalvaro | 0:df6fdd9b99f0 | 61 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 62 | case ONE_TRACKING_SPOT: |
mbedalvaro | 0:df6fdd9b99f0 | 63 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 64 | addOneRigidTrackingSpot(); |
mbedalvaro | 0:df6fdd9b99f0 | 65 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 66 | case ONE_TRACKING_SPOT_DOT: |
mbedalvaro | 0:df6fdd9b99f0 | 67 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 68 | addOneRigidTrackingSpotDot(); |
mbedalvaro | 0:df6fdd9b99f0 | 69 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 70 | case AIR_HOCKEY_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 71 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 72 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 73 | for (i=0; i<numblobs ; i++) addOneRigidLoopAirHockey(); |
mbedalvaro | 0:df6fdd9b99f0 | 74 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 75 | case CIRCULAR_PONG_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 76 | // computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 77 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 78 | // (1) One SPOT_TRACK to track the background. It will be the number 0 in the config. |
mbedalvaro | 0:df6fdd9b99f0 | 79 | addOneRigidTrackingSpotDot(); |
mbedalvaro | 0:df6fdd9b99f0 | 80 | // (2) Add bouncing spots: |
mbedalvaro | 0:df6fdd9b99f0 | 81 | for (i=0; i<numblobs ; i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 82 | float anglaux=1.0*i/numblobs*2*PI; |
mbedalvaro | 0:df6fdd9b99f0 | 83 | addOneRigidLoopBouncing(vector2Df(CENTER_AD_MIRROR_X+200*cos(anglaux), CENTER_AD_MIRROR_Y+200*sin(anglaux)), |
mbedalvaro | 0:df6fdd9b99f0 | 84 | vector2Df(5*cos(anglaux),sin(anglaux))*10); |
mbedalvaro | 0:df6fdd9b99f0 | 85 | } |
mbedalvaro | 0:df6fdd9b99f0 | 86 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 87 | case VERTICAL_PINBALL_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 88 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 89 | // (1) one (or two) SPOT_TRACK or SPOT_TRACK_DOT to track the background - It will be the number 0 (and 1) in the config. |
mbedalvaro | 0:df6fdd9b99f0 | 90 | addOneRigidTrackingSpotDot(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y+600), |
mbedalvaro | 0:df6fdd9b99f0 | 91 | vector2Df(0,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 92 | // addOneRigidTrackingSpot(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y+600), |
mbedalvaro | 0:df6fdd9b99f0 | 93 | // vector2Df(0,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 94 | // (2) one or more bouncing spots with gravity: |
mbedalvaro | 0:df6fdd9b99f0 | 95 | for (i=0; i<numblobs ; i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 96 | addOneRigidLoopBouncingGravity(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y-600), |
mbedalvaro | 0:df6fdd9b99f0 | 97 | vector2Df(i*10-5,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 98 | } |
mbedalvaro | 0:df6fdd9b99f0 | 99 | |
mbedalvaro | 0:df6fdd9b99f0 | 100 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 101 | case RAIN_MODE: |
mbedalvaro | 0:df6fdd9b99f0 | 102 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 103 | // Add bouncing spot with gravity: |
mbedalvaro | 0:df6fdd9b99f0 | 104 | for (i=0; i<numblobs ; i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 105 | addOneRigidLoopBouncingGravity(vector2Df(CENTER_AD_MIRROR_X, 10), vector2Df(0,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 106 | } |
mbedalvaro | 0:df6fdd9b99f0 | 107 | randomizeAllColors(); |
mbedalvaro | 0:df6fdd9b99f0 | 108 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 109 | case FISH_NET_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 110 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 111 | // (1) one SPOT_TRACK_DOT to track the background - It will be the number 0 |
mbedalvaro | 0:df6fdd9b99f0 | 112 | addOneRigidTrackingSpotDot(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), // CENTERED |
mbedalvaro | 0:df6fdd9b99f0 | 113 | vector2Df(0,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 114 | // (2) Add bouncing spots without gravity: |
mbedalvaro | 0:df6fdd9b99f0 | 115 | for (i=0; i<numblobs ; i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 116 | float anglaux=1.0*i/numblobs*2*PI; |
mbedalvaro | 0:df6fdd9b99f0 | 117 | addOneRigidLoopBouncing(vector2Df(CENTER_AD_MIRROR_X+400*cos(anglaux), CENTER_AD_MIRROR_Y+400*sin(anglaux)), |
mbedalvaro | 0:df6fdd9b99f0 | 118 | vector2Df(cos(anglaux),sin(anglaux))*10); |
mbedalvaro | 0:df6fdd9b99f0 | 119 | } |
mbedalvaro | 0:df6fdd9b99f0 | 120 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 121 | case PAC_MAN_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 122 | clearConfig(); |
mbedalvaro | 0:df6fdd9b99f0 | 123 | //(1) add one very slowly slidind-bouncing spot, the PACMAN (number 0 in the config): |
mbedalvaro | 0:df6fdd9b99f0 | 124 | // addOneRigidLoopPacman(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(20,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 125 | |
mbedalvaro | 0:df6fdd9b99f0 | 126 | // note: the pacman behaviour is not so good... for the time being, let's just use a following spot: |
mbedalvaro | 0:df6fdd9b99f0 | 127 | addOneRigidLoopFollowing(vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(10,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 128 | // set the color to red+green: |
mbedalvaro | 0:df6fdd9b99f0 | 129 | blobArray.back()->setColor(0x06); |
mbedalvaro | 0:df6fdd9b99f0 | 130 | |
mbedalvaro | 0:df6fdd9b99f0 | 131 | |
mbedalvaro | 0:df6fdd9b99f0 | 132 | // (2) Add some initial SPOT_FOLLOWING or SPOT_GHOST spots (the ghosts): |
mbedalvaro | 0:df6fdd9b99f0 | 133 | addOneRigidLoopGhost(vector2Df(CENTER_AD_MIRROR_X+500, CENTER_AD_MIRROR_Y-500), vector2Df(-5,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 134 | addOneRigidLoopGhost(vector2Df(CENTER_AD_MIRROR_X-500, CENTER_AD_MIRROR_Y-500), vector2Df(5,0)); |
mbedalvaro | 0:df6fdd9b99f0 | 135 | |
mbedalvaro | 0:df6fdd9b99f0 | 136 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 137 | default: |
mbedalvaro | 0:df6fdd9b99f0 | 138 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 139 | } |
mbedalvaro | 0:df6fdd9b99f0 | 140 | |
mbedalvaro | 0:df6fdd9b99f0 | 141 | // make sure lockin red is ON (could be off if using blue for checking mirror delay...): |
mbedalvaro | 0:df6fdd9b99f0 | 142 | IO.setLaserLockinPower(1); |
mbedalvaro | 0:df6fdd9b99f0 | 143 | } |
mbedalvaro | 0:df6fdd9b99f0 | 144 | |
mbedalvaro | 0:df6fdd9b99f0 | 145 | void blobConfig::printParameters() { |
mbedalvaro | 0:df6fdd9b99f0 | 146 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 147 | pc.printf("Blob n.%d\n", i); |
mbedalvaro | 0:df6fdd9b99f0 | 148 | blobArray[i]->printParameters(); // a blob that is in stand-by mode may send data (good for testing with a fixed loop) |
mbedalvaro | 0:df6fdd9b99f0 | 149 | } |
mbedalvaro | 0:df6fdd9b99f0 | 150 | } |
mbedalvaro | 0:df6fdd9b99f0 | 151 | |
mbedalvaro | 0:df6fdd9b99f0 | 152 | // ==================== Template spots from which to create multi-spot configurations: ===================== |
mbedalvaro | 0:df6fdd9b99f0 | 153 | |
mbedalvaro | 0:df6fdd9b99f0 | 154 | void blobConfig::addOneElasticLoopRelax(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 155 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 156 | pBlob->createBlob(blobArray.size(), RELAX, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 157 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 158 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 159 | |
mbedalvaro | 0:df6fdd9b99f0 | 160 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 161 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 162 | |
mbedalvaro | 0:df6fdd9b99f0 | 163 | } |
mbedalvaro | 0:df6fdd9b99f0 | 164 | |
mbedalvaro | 0:df6fdd9b99f0 | 165 | |
mbedalvaro | 0:df6fdd9b99f0 | 166 | void blobConfig::addOneElasticLoopContract(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 167 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 168 | pBlob->createBlob(blobArray.size(), CONTRACT, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 169 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 170 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 171 | |
mbedalvaro | 0:df6fdd9b99f0 | 172 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 173 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 174 | } |
mbedalvaro | 0:df6fdd9b99f0 | 175 | |
mbedalvaro | 0:df6fdd9b99f0 | 176 | void blobConfig::addOneElasticLoopContractCentral(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 177 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 178 | pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 179 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 180 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 181 | |
mbedalvaro | 0:df6fdd9b99f0 | 182 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 183 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 184 | } |
mbedalvaro | 0:df6fdd9b99f0 | 185 | |
mbedalvaro | 0:df6fdd9b99f0 | 186 | void blobConfig::addOneElasticLoopContractCentralFast(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 187 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 188 | pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL_FAST, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 189 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 190 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 191 | |
mbedalvaro | 0:df6fdd9b99f0 | 192 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 193 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 194 | } |
mbedalvaro | 0:df6fdd9b99f0 | 195 | |
mbedalvaro | 0:df6fdd9b99f0 | 196 | void blobConfig::addOneElasticContourFollowing(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 197 | |
mbedalvaro | 0:df6fdd9b99f0 | 198 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 199 | pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 200 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 201 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 202 | |
mbedalvaro | 0:df6fdd9b99f0 | 203 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 204 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 205 | } |
mbedalvaro | 0:df6fdd9b99f0 | 206 | |
mbedalvaro | 0:df6fdd9b99f0 | 207 | |
mbedalvaro | 0:df6fdd9b99f0 | 208 | void blobConfig:: addOneElasticContourFollowingFAST(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 209 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 210 | pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 211 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 212 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 213 | |
mbedalvaro | 0:df6fdd9b99f0 | 214 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 215 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 216 | } |
mbedalvaro | 0:df6fdd9b99f0 | 217 | |
mbedalvaro | 0:df6fdd9b99f0 | 218 | void blobConfig::addOneElasticBouncing(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 219 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 220 | pBlob->createBlob(blobArray.size(), BOUNCING, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 221 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 222 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 223 | |
mbedalvaro | 0:df6fdd9b99f0 | 224 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 225 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 226 | } |
mbedalvaro | 0:df6fdd9b99f0 | 227 | void blobConfig::addOneRigidLoopBouncingGravity(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 228 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 229 | pBlob->createBlob(blobArray.size(), SPOT_BOUNCING_FACTOR, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 230 | // (We can use here methods of the child class, even if these are not declared virtual on the base class, because we are doing this BEFORE |
mbedalvaro | 0:df6fdd9b99f0 | 231 | // adding this to the blobArray as a pointer). This is good to set parameters... |
mbedalvaro | 0:df6fdd9b99f0 | 232 | pBlob->gravity.set(0,3.5); |
mbedalvaro | 0:df6fdd9b99f0 | 233 | pBlob->centerMass.dampMotion = 0.002; |
mbedalvaro | 0:df6fdd9b99f0 | 234 | pBlob->factorBouncingForce=0;//0.003; // this is because we will use a force on the central mass (not used in SPOT_BOUNCING_FACTOR) |
mbedalvaro | 0:df6fdd9b99f0 | 235 | pBlob->factorAbsorptionShock=0.9; // coef elastic bouncing |
mbedalvaro | 0:df6fdd9b99f0 | 236 | |
mbedalvaro | 0:df6fdd9b99f0 | 237 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 238 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 239 | |
mbedalvaro | 0:df6fdd9b99f0 | 240 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 241 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 242 | } |
mbedalvaro | 0:df6fdd9b99f0 | 243 | void blobConfig::addOneRigidLoopBouncing(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 244 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 245 | pBlob->createBlob(blobArray.size(), SPOT_BOUNCING_FACTOR, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 246 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 247 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 248 | |
mbedalvaro | 0:df6fdd9b99f0 | 249 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 250 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 251 | } |
mbedalvaro | 0:df6fdd9b99f0 | 252 | |
mbedalvaro | 0:df6fdd9b99f0 | 253 | void blobConfig::addOneRigidLoopPacman(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 254 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 255 | pBlob->createBlob(blobArray.size(), SPOT_PACMAN, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 256 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 257 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 258 | |
mbedalvaro | 0:df6fdd9b99f0 | 259 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 260 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 261 | } |
mbedalvaro | 0:df6fdd9b99f0 | 262 | void blobConfig::addOneRigidLoopGhost(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 263 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 264 | pBlob->createBlob(blobArray.size(), SPOT_GHOST, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 265 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 266 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 267 | |
mbedalvaro | 0:df6fdd9b99f0 | 268 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 269 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 270 | } |
mbedalvaro | 0:df6fdd9b99f0 | 271 | |
mbedalvaro | 0:df6fdd9b99f0 | 272 | |
mbedalvaro | 0:df6fdd9b99f0 | 273 | void blobConfig::addOneRigidLoopLorentz(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 274 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 275 | pBlob->createBlob(blobArray.size(), SPOT_LORENTZ_FORCE, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 276 | // add this loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 277 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 278 | |
mbedalvaro | 0:df6fdd9b99f0 | 279 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 280 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 281 | } |
mbedalvaro | 0:df6fdd9b99f0 | 282 | |
mbedalvaro | 0:df6fdd9b99f0 | 283 | void blobConfig::addOneRigidLoopAirHockey(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 284 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 285 | pBlob->createBlob(blobArray.size(), SPOT_AIR_HOCKEY, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 286 | // add this loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 287 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 288 | |
mbedalvaro | 0:df6fdd9b99f0 | 289 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 290 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 291 | } |
mbedalvaro | 0:df6fdd9b99f0 | 292 | |
mbedalvaro | 0:df6fdd9b99f0 | 293 | void blobConfig::addOneRigidLoopFollowing(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 294 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 295 | pBlob->createBlob(blobArray.size(), SPOT_FOLLOWING, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 296 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 297 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 298 | |
mbedalvaro | 0:df6fdd9b99f0 | 299 | // random color for Tokyo Designer Week: |
mbedalvaro | 0:df6fdd9b99f0 | 300 | //randomizeAllColors(); |
mbedalvaro | 0:df6fdd9b99f0 | 301 | |
mbedalvaro | 0:df6fdd9b99f0 | 302 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 303 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 304 | } |
mbedalvaro | 0:df6fdd9b99f0 | 305 | |
mbedalvaro | 0:df6fdd9b99f0 | 306 | void blobConfig::addOneRigidLoopTest(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 307 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 308 | pBlob->createBlob(blobArray.size(), SPOT_TEST, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 309 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 310 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 311 | |
mbedalvaro | 0:df6fdd9b99f0 | 312 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 313 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 314 | } |
mbedalvaro | 0:df6fdd9b99f0 | 315 | |
mbedalvaro | 0:df6fdd9b99f0 | 316 | void blobConfig::addOneRigidTrackingSpot(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 317 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 318 | pBlob->createBlob(blobArray.size(), SPOT_TRACK, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 319 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 320 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 321 | |
mbedalvaro | 0:df6fdd9b99f0 | 322 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 323 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 324 | } |
mbedalvaro | 0:df6fdd9b99f0 | 325 | |
mbedalvaro | 0:df6fdd9b99f0 | 326 | void blobConfig::addOneRigidTrackingSpotDot(vector2Df initpos, vector2Df initspeed) { |
mbedalvaro | 0:df6fdd9b99f0 | 327 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 0:df6fdd9b99f0 | 328 | pBlob->createBlob(blobArray.size(), SPOT_TRACK_DOT, initpos, initspeed); |
mbedalvaro | 0:df6fdd9b99f0 | 329 | // add this relaxing loop to the present config: |
mbedalvaro | 0:df6fdd9b99f0 | 330 | blobArray.push_back(pBlob); |
mbedalvaro | 0:df6fdd9b99f0 | 331 | |
mbedalvaro | 0:df6fdd9b99f0 | 332 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 0:df6fdd9b99f0 | 333 | numBlobs=blobArray.size(); |
mbedalvaro | 0:df6fdd9b99f0 | 334 | } |
mbedalvaro | 0:df6fdd9b99f0 | 335 | // ================================================================================================================================================== |
mbedalvaro | 0:df6fdd9b99f0 | 336 | void blobConfig::processSensedData() { |
mbedalvaro | 0:df6fdd9b99f0 | 337 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->displaySensingBuffer.processSensedData(); // note: region with light is -1, and without is 2 (TO CHANGE!!! then we don't need to do "if" in the moment computation, but just a product) |
mbedalvaro | 0:df6fdd9b99f0 | 338 | } |
mbedalvaro | 0:df6fdd9b99f0 | 339 | |
mbedalvaro | 0:df6fdd9b99f0 | 340 | void blobConfig::allKill() { // this put all the blobs in "dead" mode, meaning that neither rendering nor update is done (but they are not deleted). |
mbedalvaro | 0:df6fdd9b99f0 | 341 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 342 | blobArray[i]->render = false; |
mbedalvaro | 1:3be7b7d050f4 | 343 | blobArray[i]->standByMode = true; |
mbedalvaro | 0:df6fdd9b99f0 | 344 | } |
mbedalvaro | 0:df6fdd9b99f0 | 345 | } |
mbedalvaro | 0:df6fdd9b99f0 | 346 | void blobConfig::allAlive() { |
mbedalvaro | 0:df6fdd9b99f0 | 347 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 348 | blobArray[i]->render = true; |
mbedalvaro | 1:3be7b7d050f4 | 349 | blobArray[i]->standByMode = false; |
mbedalvaro | 0:df6fdd9b99f0 | 350 | } |
mbedalvaro | 0:df6fdd9b99f0 | 351 | } |
mbedalvaro | 0:df6fdd9b99f0 | 352 | |
mbedalvaro | 0:df6fdd9b99f0 | 353 | void blobConfig::allStandBy() { |
mbedalvaro | 0:df6fdd9b99f0 | 354 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = true; |
mbedalvaro | 0:df6fdd9b99f0 | 355 | } |
mbedalvaro | 0:df6fdd9b99f0 | 356 | |
mbedalvaro | 0:df6fdd9b99f0 | 357 | void blobConfig::allResume() { |
mbedalvaro | 0:df6fdd9b99f0 | 358 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = false; |
mbedalvaro | 0:df6fdd9b99f0 | 359 | } |
mbedalvaro | 0:df6fdd9b99f0 | 360 | |
mbedalvaro | 0:df6fdd9b99f0 | 361 | void blobConfig::allVisible() { |
mbedalvaro | 0:df6fdd9b99f0 | 362 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = true; |
mbedalvaro | 0:df6fdd9b99f0 | 363 | } |
mbedalvaro | 0:df6fdd9b99f0 | 364 | |
mbedalvaro | 0:df6fdd9b99f0 | 365 | void blobConfig::allInvisible() { // note that they may continue to evolve |
mbedalvaro | 0:df6fdd9b99f0 | 366 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = false; |
mbedalvaro | 0:df6fdd9b99f0 | 367 | } |
mbedalvaro | 0:df6fdd9b99f0 | 368 | |
mbedalvaro | 0:df6fdd9b99f0 | 369 | void blobConfig::allSetColor(unsigned char c) { |
mbedalvaro | 0:df6fdd9b99f0 | 370 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->setColor(c); |
mbedalvaro | 0:df6fdd9b99f0 | 371 | } |
mbedalvaro | 0:df6fdd9b99f0 | 372 | |
mbedalvaro | 0:df6fdd9b99f0 | 373 | void blobConfig::allSetGreen(unsigned char c) { |
mbedalvaro | 0:df6fdd9b99f0 | 374 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->setGreenColor(c); |
mbedalvaro | 0:df6fdd9b99f0 | 375 | } |
mbedalvaro | 0:df6fdd9b99f0 | 376 | |
mbedalvaro | 0:df6fdd9b99f0 | 377 | void blobConfig::allSetBlue(unsigned char c) { |
mbedalvaro | 0:df6fdd9b99f0 | 378 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->setBlueColor(c); |
mbedalvaro | 0:df6fdd9b99f0 | 379 | } |
mbedalvaro | 0:df6fdd9b99f0 | 380 | |
mbedalvaro | 0:df6fdd9b99f0 | 381 | void blobConfig::randomizeAllColors() { |
mbedalvaro | 0:df6fdd9b99f0 | 382 | int c; |
mbedalvaro | 0:df6fdd9b99f0 | 383 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 384 | c= rand() % 2; |
mbedalvaro | 0:df6fdd9b99f0 | 385 | blobArray[i]->setBlueColor(c); |
mbedalvaro | 0:df6fdd9b99f0 | 386 | c= rand() % 2; |
mbedalvaro | 0:df6fdd9b99f0 | 387 | blobArray[i]->setGreenColor(c); |
mbedalvaro | 0:df6fdd9b99f0 | 388 | } |
mbedalvaro | 0:df6fdd9b99f0 | 389 | } |
mbedalvaro | 0:df6fdd9b99f0 | 390 | |
mbedalvaro | 0:df6fdd9b99f0 | 391 | void blobConfig::update() { // update dynamics of the blob configuration: |
mbedalvaro | 0:df6fdd9b99f0 | 392 | int i; |
mbedalvaro | 0:df6fdd9b99f0 | 393 | float minDist=5000, dist; |
mbedalvaro | 0:df6fdd9b99f0 | 394 | bool win; |
mbedalvaro | 0:df6fdd9b99f0 | 395 | // Depending on the config type, perform some special test and updates: |
mbedalvaro | 0:df6fdd9b99f0 | 396 | switch(myConfigType) { |
mbedalvaro | 0:df6fdd9b99f0 | 397 | // simple behaviours: |
mbedalvaro | 0:df6fdd9b99f0 | 398 | case ONE_ELASTIC_FOLLOWING: |
mbedalvaro | 0:df6fdd9b99f0 | 399 | case ONE_ELASTIC_MOUTH: |
mbedalvaro | 0:df6fdd9b99f0 | 400 | case ONE_ELASTIC_MOUTH_SMALL: |
mbedalvaro | 0:df6fdd9b99f0 | 401 | case BOUNCING_SPOTS: |
mbedalvaro | 0:df6fdd9b99f0 | 402 | case LORENTZ_SPOTS: |
mbedalvaro | 0:df6fdd9b99f0 | 403 | case FOLLOWING_SPOTS: |
mbedalvaro | 0:df6fdd9b99f0 | 404 | case ONE_TRACKING_SPOT: |
mbedalvaro | 0:df6fdd9b99f0 | 405 | case AIR_HOCKEY_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 406 | // In all these simple cases, update dynamics of each blob independently: |
mbedalvaro | 0:df6fdd9b99f0 | 407 | for (i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 408 | if (blobArray[i]->standByMode==false) blobArray[i]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 409 | } |
mbedalvaro | 0:df6fdd9b99f0 | 410 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 411 | // more game-like: |
mbedalvaro | 0:df6fdd9b99f0 | 412 | case CIRCULAR_PONG_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 413 | // spot index 0 is a tracking spot, the background "anchor": |
mbedalvaro | 0:df6fdd9b99f0 | 414 | if (blobArray[0]->standByMode==false) blobArray[0]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 415 | // all the other spots are bouncing spots: |
mbedalvaro | 0:df6fdd9b99f0 | 416 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 417 | if (blobArray[i]->standByMode==false) blobArray[i]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 418 | } |
mbedalvaro | 0:df6fdd9b99f0 | 419 | // GAME CHECK: is some bouncing spot too far from the anchor? if so, make it "explode" (and then dissapear, but leave this for now): |
mbedalvaro | 0:df6fdd9b99f0 | 420 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 421 | dist=(blobArray[0]->getCenter()).distance(blobArray[i]->getCenter()); |
mbedalvaro | 0:df6fdd9b99f0 | 422 | if (dist>1000) { |
mbedalvaro | 0:df6fdd9b99f0 | 423 | blobArray[i]->explosion(); |
mbedalvaro | 0:df6fdd9b99f0 | 424 | float anglaux=1.0*(i-1)/(blobArray.size()-1)*2*PI; |
mbedalvaro | 0:df6fdd9b99f0 | 425 | blobArray[i]->setPositionSpeed(vector2Df(CENTER_AD_MIRROR_X+200*cos(anglaux), CENTER_AD_MIRROR_Y+200*sin(anglaux)), |
mbedalvaro | 0:df6fdd9b99f0 | 426 | vector2Df(cos(anglaux),sin(anglaux))*10); |
mbedalvaro | 0:df6fdd9b99f0 | 427 | } |
mbedalvaro | 0:df6fdd9b99f0 | 428 | } |
mbedalvaro | 0:df6fdd9b99f0 | 429 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 430 | case RAIN_MODE: // this is just spots with gravity that reapears in the top position when reaching the bottom: |
mbedalvaro | 0:df6fdd9b99f0 | 431 | // others are bouncing with gravity: |
mbedalvaro | 0:df6fdd9b99f0 | 432 | for (i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 433 | if (blobArray[i]->standByMode==false) blobArray[i]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 434 | } |
mbedalvaro | 0:df6fdd9b99f0 | 435 | // GAME CHECKS: |
mbedalvaro | 0:df6fdd9b99f0 | 436 | for (i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 437 | if (blobArray[i]->getCenter().y>MAX_AD_MIRRORS-20) { |
mbedalvaro | 0:df6fdd9b99f0 | 438 | // Replace position of spot to the initial position: |
mbedalvaro | 0:df6fdd9b99f0 | 439 | blobArray[i]->explosion(); |
mbedalvaro | 0:df6fdd9b99f0 | 440 | blobArray[i]->resetPositionSpeed(); |
mbedalvaro | 0:df6fdd9b99f0 | 441 | } |
mbedalvaro | 0:df6fdd9b99f0 | 442 | } |
mbedalvaro | 0:df6fdd9b99f0 | 443 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 444 | case VERTICAL_PINBALL_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 445 | // spot index 0 is a tracking spot, the background "anchor": |
mbedalvaro | 0:df6fdd9b99f0 | 446 | if (blobArray[0]->standByMode==false) blobArray[0]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 447 | // others are bouncing with gravity: |
mbedalvaro | 0:df6fdd9b99f0 | 448 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 449 | if (blobArray[i]->standByMode==false) blobArray[i]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 450 | } |
mbedalvaro | 0:df6fdd9b99f0 | 451 | // GAME CHECKS: |
mbedalvaro | 0:df6fdd9b99f0 | 452 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 453 | dist=(blobArray[0]->getCenter()).distance(blobArray[i]->getCenter()); |
mbedalvaro | 0:df6fdd9b99f0 | 454 | //(1) win (meaning bouncing spot very close to anchor): |
mbedalvaro | 0:df6fdd9b99f0 | 455 | if (dist<60) { |
mbedalvaro | 0:df6fdd9b99f0 | 456 | blobArray[i]->explosion(); |
mbedalvaro | 0:df6fdd9b99f0 | 457 | blobArray[i]->setPositionSpeed(vector2Df(blobArray[0]->getCenter().x-400+rand()%800, blobArray[0]->getCenter().y-1200), |
mbedalvaro | 0:df6fdd9b99f0 | 458 | vector2Df(0, 0)); |
mbedalvaro | 0:df6fdd9b99f0 | 459 | } |
mbedalvaro | 0:df6fdd9b99f0 | 460 | //(2) loose (meaning spot went outside range): |
mbedalvaro | 0:df6fdd9b99f0 | 461 | if (blobArray[i]->getCenter().y>blobArray[0]->getCenter().y) { |
mbedalvaro | 0:df6fdd9b99f0 | 462 | blobArray[i]->setPositionSpeed(vector2Df(blobArray[0]->getCenter().x-400+rand()%800, blobArray[0]->getCenter().y-1200), |
mbedalvaro | 0:df6fdd9b99f0 | 463 | vector2Df(i*10-5, 0)); |
mbedalvaro | 0:df6fdd9b99f0 | 464 | } |
mbedalvaro | 0:df6fdd9b99f0 | 465 | } |
mbedalvaro | 0:df6fdd9b99f0 | 466 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 467 | case FISH_NET_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 468 | // spot index 0 is a tracking spot, the background "anchor": |
mbedalvaro | 0:df6fdd9b99f0 | 469 | if (blobArray[0]->standByMode==false) blobArray[0]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 470 | // all the other spots are bouncing spots: |
mbedalvaro | 0:df6fdd9b99f0 | 471 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 472 | if (blobArray[i]->standByMode==false) blobArray[i]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 473 | } |
mbedalvaro | 0:df6fdd9b99f0 | 474 | // GAME CHECKS: a win only, when all the spots are very close to the mother spot: |
mbedalvaro | 0:df6fdd9b99f0 | 475 | win=true; |
mbedalvaro | 0:df6fdd9b99f0 | 476 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 477 | dist=(blobArray[0]->getCenter()).distance(blobArray[i]->getCenter()); |
mbedalvaro | 0:df6fdd9b99f0 | 478 | win&=(dist<80); |
mbedalvaro | 0:df6fdd9b99f0 | 479 | } |
mbedalvaro | 0:df6fdd9b99f0 | 480 | if (win) { |
mbedalvaro | 0:df6fdd9b99f0 | 481 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 482 | blobArray[i]->explosion(); |
mbedalvaro | 0:df6fdd9b99f0 | 483 | float anglaux=1.0*(i-1)/(blobArray.size()-1)*2*PI; |
mbedalvaro | 0:df6fdd9b99f0 | 484 | blobArray[i]->setPositionSpeed(vector2Df(CENTER_AD_MIRROR_X+400*cos(anglaux), CENTER_AD_MIRROR_Y+400*sin(anglaux)), |
mbedalvaro | 0:df6fdd9b99f0 | 485 | vector2Df(cos(anglaux),sin(anglaux))*10); |
mbedalvaro | 0:df6fdd9b99f0 | 486 | } |
mbedalvaro | 0:df6fdd9b99f0 | 487 | } |
mbedalvaro | 0:df6fdd9b99f0 | 488 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 489 | case PAC_MAN_GAME: |
mbedalvaro | 0:df6fdd9b99f0 | 490 | // spot index 0 is the pacman: |
mbedalvaro | 0:df6fdd9b99f0 | 491 | if (blobArray[0]->standByMode==false) blobArray[0]->update(); |
mbedalvaro | 0:df6fdd9b99f0 | 492 | // spot 1 and 2 are ghosts: |
mbedalvaro | 0:df6fdd9b99f0 | 493 | if (blobArray[1]->standByMode==false) blobArray[1]->update(blobArray[0]->getCenter()); |
mbedalvaro | 0:df6fdd9b99f0 | 494 | if (blobArray[2]->standByMode==false) blobArray[2]->update(blobArray[0]->getCenter()); // pass the position of the PACMAN! |
mbedalvaro | 0:df6fdd9b99f0 | 495 | |
mbedalvaro | 0:df6fdd9b99f0 | 496 | // GAME CHECK: are any ghost too close to the pacman? |
mbedalvaro | 0:df6fdd9b99f0 | 497 | for (i=1; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 498 | dist=(blobArray[0]->getCenter()).distance(blobArray[i]->getCenter()); |
mbedalvaro | 0:df6fdd9b99f0 | 499 | if (minDist>dist) minDist=dist; |
mbedalvaro | 0:df6fdd9b99f0 | 500 | } |
mbedalvaro | 0:df6fdd9b99f0 | 501 | if (minDist<50) { |
mbedalvaro | 0:df6fdd9b99f0 | 502 | blobArray[0]->explosion(); |
mbedalvaro | 0:df6fdd9b99f0 | 503 | // then restart the game: |
mbedalvaro | 0:df6fdd9b99f0 | 504 | // initConfig(PAC_MAN_GAME); |
mbedalvaro | 0:df6fdd9b99f0 | 505 | } |
mbedalvaro | 0:df6fdd9b99f0 | 506 | |
mbedalvaro | 0:df6fdd9b99f0 | 507 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 508 | default: |
mbedalvaro | 0:df6fdd9b99f0 | 509 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 510 | } |
mbedalvaro | 0:df6fdd9b99f0 | 511 | |
mbedalvaro | 0:df6fdd9b99f0 | 512 | |
mbedalvaro | 0:df6fdd9b99f0 | 513 | } |
mbedalvaro | 0:df6fdd9b99f0 | 514 | |
mbedalvaro | 0:df6fdd9b99f0 | 515 | void blobConfig::computeBoundingBox() { |
mbedalvaro | 0:df6fdd9b99f0 | 516 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 517 | blobArray[i]->computeBoundingBox(); |
mbedalvaro | 0:df6fdd9b99f0 | 518 | } |
mbedalvaro | 0:df6fdd9b99f0 | 519 | } |
mbedalvaro | 0:df6fdd9b99f0 | 520 | |
mbedalvaro | 0:df6fdd9b99f0 | 521 | void blobConfig::draw() { // draw uses the opengl like renderer (if any), and save projected trajectory in the LaserSensingTrajectory object of each blob |
mbedalvaro | 0:df6fdd9b99f0 | 522 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 523 | if (blobArray[i]->render==true) blobArray[i]->draw(); |
mbedalvaro | 0:df6fdd9b99f0 | 524 | } |
mbedalvaro | 0:df6fdd9b99f0 | 525 | } |
mbedalvaro | 0:df6fdd9b99f0 | 526 | |
mbedalvaro | 0:df6fdd9b99f0 | 527 | void blobConfig::sendConfData() { |
mbedalvaro | 0:df6fdd9b99f0 | 528 | // For the time being, only "per blob" data sending: |
mbedalvaro | 1:3be7b7d050f4 | 529 | // (b) Per-spot sending of data (note: both are NOT exclusive; so if we want just packaged data, |
mbedalvaro | 1:3be7b7d050f4 | 530 | // we need to make all the spot STOP sending data. |
mbedalvaro | 0:df6fdd9b99f0 | 531 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 0:df6fdd9b99f0 | 532 | if (blobArray[i]->render==true) blobArray[i]->sendData(); // a blob that is in stand-by mode may send data (good for testing with a fixed loop) |
mbedalvaro | 0:df6fdd9b99f0 | 533 | } |
mbedalvaro | 0:df6fdd9b99f0 | 534 | } |
mbedalvaro | 0:df6fdd9b99f0 | 535 | |
mbedalvaro | 0:df6fdd9b99f0 | 536 | |
mbedalvaro | 0:df6fdd9b99f0 | 537 | |
mbedalvaro | 0:df6fdd9b99f0 | 538 |