diff --git a/achterbahn.ino b/achterbahn.ino index 2e6cb59..27b5fb4 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -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 + //special spawns + if (random(0,50)==0){ + tmpr.setType(1); //make rainbow + tmpr.setLength(_randomlength*random(1,3)); + } + wagon_arr.push_back(tmpr); Serial.println("Spawned Wagon"); } diff --git a/wagon.cpp b/wagon.cpp index df9cd14..eeb2aa5 100644 --- a/wagon.cpp +++ b/wagon.cpp @@ -8,6 +8,8 @@ #define WRAPLEDPOS _numpixels //standard //#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, 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, @@ -42,6 +44,14 @@ Wagon::Wagon(int id,int numpixels, Adafruit_NeoPixel *strip,uint8_t *height,floa _lastpositivedirchangePosDifference=1000; _wagoncolor=wagoncolor; _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 { @@ -235,6 +245,9 @@ void Wagon::updateGraphics() } 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 _g = (uint8_t)(c >> 8)*healtpositive; uint8_t _b = (uint8_t)c*healtpositive; diff --git a/wagon.h b/wagon.h index e3d5f50..2d493b5 100644 --- a/wagon.h +++ b/wagon.h @@ -18,6 +18,8 @@ class Wagon int id(); long spawntime(); bool alive(); + void setType(uint8_t t); + void setLength(float l); private: int _numpixels; Adafruit_NeoPixel *_strip; @@ -33,6 +35,7 @@ class Wagon float _lastpositivedirchangePosDifference; uint32_t _wagoncolor; float _health; + uint8_t _type; }; #endif