add special wagon rainbow

This commit is contained in:
interfisch 2018-06-10 19:59:01 +02:00
parent af8b86a0c0
commit b0edbbc7a1
3 changed files with 22 additions and 0 deletions

View File

@ -228,6 +228,12 @@ void spawnWagon(){
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 , 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 , 5 , Wheel((uint8_t)random(0,255))); //spawn new wagon
//special spawns
if (random(0,50)==0){
tmpr.setType(1); //make rainbow
tmpr.setLength(_randomlength*random(1,3));
}
wagon_arr.push_back(tmpr); wagon_arr.push_back(tmpr);
Serial.println("Spawned Wagon"); Serial.println("Spawned Wagon");
} }

View File

@ -8,6 +8,8 @@
#define WRAPLEDPOS _numpixels //standard #define WRAPLEDPOS _numpixels //standard
//#define WRAPLEDPOS (_numpixels-5) //led index which is also led 0 //#define WRAPLEDPOS (_numpixels-5) //led index which is also led 0
#define TYPE_RAINBOW 1
/*uint8_t GammaE[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*uint8_t GammaE[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
@ -42,6 +44,14 @@ Wagon::Wagon(int id,int numpixels, Adafruit_NeoPixel *strip,uint8_t *height,floa
_lastpositivedirchangePosDifference=1000; _lastpositivedirchangePosDifference=1000;
_wagoncolor=wagoncolor; _wagoncolor=wagoncolor;
_health=1.0; _health=1.0;
_type=0; //normal
}
void Wagon::setType(uint8_t t){
_type=t;
}
void Wagon::setLength(float l){
_trainlength=l;
} }
bool Wagon::operator==(const Wagon &r) const { bool Wagon::operator==(const Wagon &r) const {
@ -235,6 +245,9 @@ void Wagon::updateGraphics()
} }
uint32_t c=_wagoncolor; uint32_t c=_wagoncolor;
if (_type==TYPE_RAINBOW){
c=Wheel(((int)((i-_pos)*256/_trainlength))%256,1.0);
}
uint8_t _r = (uint8_t)(c >> 16)*healtpositive; uint8_t _r = (uint8_t)(c >> 16)*healtpositive;
uint8_t _g = (uint8_t)(c >> 8)*healtpositive; uint8_t _g = (uint8_t)(c >> 8)*healtpositive;
uint8_t _b = (uint8_t)c*healtpositive; uint8_t _b = (uint8_t)c*healtpositive;

View File

@ -18,6 +18,8 @@ class Wagon
int id(); int id();
long spawntime(); long spawntime();
bool alive(); bool alive();
void setType(uint8_t t);
void setLength(float l);
private: private:
int _numpixels; int _numpixels;
Adafruit_NeoPixel *_strip; Adafruit_NeoPixel *_strip;
@ -33,6 +35,7 @@ class Wagon
float _lastpositivedirchangePosDifference; float _lastpositivedirchangePosDifference;
uint32_t _wagoncolor; uint32_t _wagoncolor;
float _health; float _health;
uint8_t _type;
}; };
#endif #endif