add edge kill and configure random wagon parameters for new setup

This commit is contained in:
interfisch 2018-09-05 18:49:54 +02:00
parent ab4bffc85a
commit 62a5b3bc07
2 changed files with 29 additions and 2 deletions

View File

@ -241,7 +241,18 @@ void spawnWagon(){
// pos, wagonlength, startvel , startacc, trainmass, wagoncolor // pos, wagonlength, startvel , startacc, trainmass, wagoncolor
//Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, random(0, 20), _randomlength, random(map(_randomlength,3,40,1,1), map(_randomlength,3,40, 13,40))/10.0 , 0 , 5 , Wheel((uint8_t)random(0,255))); //spawn new wagon //Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, random(0, 20), _randomlength, random(map(_randomlength,3,40,1,1), map(_randomlength,3,40, 13,40))/10.0 , 0 , 5 , Wheel((uint8_t)random(0,255))); //spawn new wagon
Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, NUMPIXELS+_randomlength, _randomlength, -random(map(_randomlength,3,40,10,20), map(_randomlength,3,40, 22,60))/10.0 , 0 , 2.0 , Wheel((uint8_t)random(0,255))); //spawn new wagon int side_startpos=0;
int side_multi=1;
if (random(0,2)==0){ //spawn from other side
side_startpos=NUMPIXELS+_randomlength;
side_multi=-1;
}
Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(map(_randomlength,3,20,5,10), map(_randomlength,3,20, 5,40))/10.0 , 0 , 5.0 , Wheel((uint8_t)random(0,255))); //spawn new wagon
//special spawns //special spawns
if (random(0,50)==0){ if (random(0,50)==0){
@ -473,6 +484,7 @@ void loop_achterbahn(){
{ {
it = wagon_arr.erase(it); // After erasing, it is now pointing the next element. it = wagon_arr.erase(it); // After erasing, it is now pointing the next element.
--it; --it;
Serial.println("Killed train");
#ifdef RESPAWNWAGON #ifdef RESPAWNWAGON
spawnWagon(); //spawn new one spawnWagon(); //spawn new one
#endif #endif

View File

@ -2,7 +2,8 @@
#define WAGONLENGTH 3 #define WAGONLENGTH 3
#define EDGE_WALL #define EDGE_KILL
//#define EDGE_WALL
//#define EDGE_BOUNCE //#define EDGE_BOUNCE
//#define EDGE_WRAP //#define EDGE_WRAP
#define WRAPLEDPOS _numpixels //standard #define WRAPLEDPOS _numpixels //standard
@ -176,6 +177,11 @@ void Wagon::updatePhysics(float updatedelayms)
#ifdef EDGE_WALL #ifdef EDGE_WALL
//nothing //nothing
#endif #endif
#ifdef EDGE_KILL
if (_pos>=WRAPLEDPOS+(_trainlength*WAGONLENGTH)){
_health=0;
}
#endif
} }
if (_pos<0){ if (_pos<0){
#ifdef EDGE_WRAP #ifdef EDGE_WRAP
@ -187,6 +193,9 @@ void Wagon::updatePhysics(float updatedelayms)
#ifdef EDGE_WALL #ifdef EDGE_WALL
//nothing //nothing
#endif #endif
#ifdef EDGE_KILL
_health=0;
#endif
} }
//fade out if health got low //fade out if health got low
@ -206,6 +215,9 @@ float Wagon::getHeight(int p){
#ifdef EDGE_WALL #ifdef EDGE_WALL
return _height[0]+p*-100.0; //edges as wall return _height[0]+p*-100.0; //edges as wall
#endif #endif
#ifdef EDGE_KILL
return _height[0]+p*-100.0; //same like edges as wall
#endif
}else if(p>=_numpixels){ }else if(p>=_numpixels){
#ifdef EDGE_WRAP #ifdef EDGE_WRAP
p=p-_numpixels; //wrap edge p=p-_numpixels; //wrap edge
@ -213,6 +225,9 @@ float Wagon::getHeight(int p){
#ifdef EDGE_WALL #ifdef EDGE_WALL
return _height[_numpixels-1]+(p-_numpixels)*100.0; //edges as wall return _height[_numpixels-1]+(p-_numpixels)*100.0; //edges as wall
#endif #endif
#ifdef EDGE_KILL
return _height[_numpixels-1]+(p-_numpixels)*100.0; //samel like edges as wall
#endif
} }
return _height[p]; return _height[p];
} }