Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase speed based on score and owls #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion flappyhalloween.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int bugFrame = 0;
// owls can move from 'off screen' to 'off screen'
// -16 to 128 = 144 unique positions
bool owlActive = false; // is there an owl in flight
int owlCount = 0; // number of owls created
int owlX = 128;
int owlY = 0;
const int owlRate = 30;
Expand Down Expand Up @@ -72,7 +73,7 @@ void intro()
void setup()
{
arduboy.begin();
arduboy.setFrameRate(60);
setSpeed();
intro();
// put up the title screen until A is pressed
arduboy.clear();
Expand Down Expand Up @@ -114,6 +115,8 @@ void loop()
if( !owlActive ) {
if(2 > random(1,300)) { // 2 in 300 chances of an owl becoming active
owlActive = true;
owlCount++;
setSpeed();
owlX = 128;
}
}
Expand Down Expand Up @@ -193,6 +196,7 @@ void loop()
bugsX[i] = -1;
arduboy.tunes.tone(2000, 20);
score++;
setSpeed();
}
}
}
Expand Down Expand Up @@ -257,12 +261,20 @@ void loop()
// clear out variables to start again
score = 0;
owlActive = false;
owlCount = 0;
owlY = 128; // ensure it can't collide with bat
for (i=0; i<NUMBUGS; i++) {
bugsX[i] = -1;
}
setSpeed();
}
}

}

// Set the speed of the game
void setSpeed() {
int rate = 60 + (score / 2) + owlCount;
arduboy.setFrameRate(rate > 255 ? 255 : rate);
}