Skip to content

Commit

Permalink
Merge pull request #1 from odaki/make-lavaclass-robust
Browse files Browse the repository at this point in the history
Make Lava class robust
  • Loading branch information
bdring authored Jan 31, 2018
2 parents e445748 + 103910d commit fdeaaef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Lava.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Lava
{
public:
void Spawn(int left, int right, int ontime, int offtime, int offset, char* state);
void Spawn(int left, int right, int ontime, int offtime, int offset, int state);
void Kill();
int Alive();
int _left;
Expand All @@ -12,12 +12,14 @@ class Lava
int _offtime;
int _offset;
long _lastOn;
char* _state;
int _state;
static const int OFF = 0;
static const int ON = 1;
private:
int _alive;
};

void Lava::Spawn(int left, int right, int ontime, int offtime, int offset, char* state){
void Lava::Spawn(int left, int right, int ontime, int offtime, int offset, int state){
_left = left;
_right = right;
_ontime = ontime;
Expand Down
20 changes: 10 additions & 10 deletions TWANG.ino
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void loadLevel(){
break;
case 3:
// Lava intro
spawnLava(400, 490, 2000, 2000, 0, "OFF");
spawnLava(400, 490, 2000, 2000, 0, Lava::OFF);
spawnEnemy(350, 0, 1, 0);
spawnPool[0].Spawn(1000, 5500, 3, 0, 0);
break;
Expand Down Expand Up @@ -362,9 +362,9 @@ void loadLevel(){
break;
case 9:
// Lava run
spawnLava(195, 300, 2000, 2000, 0, "OFF");
spawnLava(400, 500, 2000, 2000, 0, "OFF");
spawnLava(600, 700, 2000, 2000, 0, "OFF");
spawnLava(195, 300, 2000, 2000, 0, Lava::OFF);
spawnLava(400, 500, 2000, 2000, 0, Lava::OFF);
spawnLava(600, 700, 2000, 2000, 0, Lava::OFF);

spawnPool[0].Spawn(1000, 3800, 4, 0, 0);
break;
Expand Down Expand Up @@ -408,7 +408,7 @@ void spawnEnemy(int pos, int dir, int sp, int wobble){
}
}

void spawnLava(int left, int right, int ontime, int offtime, int offset, char* state){
void spawnLava(int left, int right, int ontime, int offtime, int offset, int state){
for(int i = 0; i<lavaCount; i++){
if(!lavaPool[i].Alive()){
lavaPool[i].Spawn(left, right, ontime, offtime, offset, state);
Expand Down Expand Up @@ -629,18 +629,18 @@ void tickLava(){
if(LP.Alive()){
A = getLED(LP._left);
B = getLED(LP._right);
if(LP._state == "OFF"){
if(LP._state == Lava::OFF){
if(LP._lastOn + LP._offtime < mm){
LP._state = "ON";
LP._state = Lava::ON;
LP._lastOn = mm;
}
for(p = A; p<= B; p++){
flicker = random8(3);
leds[p] = CRGB(3+flicker, (3+flicker)/1.5, 0);
}
}else if(LP._state == "ON"){
}else if(LP._state == Lava::ON){
if(LP._lastOn + LP._ontime < mm){
LP._state = "OFF";
LP._state = Lava::OFF;
LP._lastOn = mm;
}
for(p = A; p<= B; p++){
Expand Down Expand Up @@ -844,7 +844,7 @@ bool inLava(int pos){
Lava LP;
for(i = 0; i<lavaCount; i++){
LP = lavaPool[i];
if(LP.Alive() && LP._state == "ON"){
if(LP.Alive() && LP._state == Lava::ON){
if(LP._left < pos && LP._right > pos) return true;
}
}
Expand Down

0 comments on commit fdeaaef

Please sign in to comment.