ArduBreakout should use shared libraries for music

This commit is contained in:
Josh Goebel 2016-02-21 05:55:43 -05:00 committed by Scott Allen
parent c22e156f60
commit 2223f5e835
1 changed files with 19 additions and 13 deletions

View File

@ -10,9 +10,12 @@
*/ */
#include <Arduboy.h> #include <Arduboy.h>
#include "Arduboy.h"
#include <ArduboyPlaytune.h>
#include "breakout_bitmaps.h" #include "breakout_bitmaps.h"
Arduboy arduboy; Arduboy arduboy;
ArduboyPlaytune tunes;
const unsigned int COLUMNS = 13; //Columns of bricks const unsigned int COLUMNS = 13; //Columns of bricks
const unsigned int ROWS = 4; //Rows of bricks const unsigned int ROWS = 4; //Rows of bricks
@ -54,6 +57,9 @@ void setup()
{ {
arduboy.begin(); arduboy.begin();
arduboy.setFrameRate(60); arduboy.setFrameRate(60);
tunes.initChannel(PIN_SPEAKER_1);
tunes.initChannel(PIN_SPEAKER_2);
} }
void loop() void loop()
@ -173,7 +179,7 @@ void moveBall()
{ {
yb = 2; yb = 2;
dy = -dy; dy = -dy;
arduboy.tunes.tone(523, 250); tunes.tone(523, 250);
} }
//Lose a life if bottom edge hit //Lose a life if bottom edge hit
@ -185,7 +191,7 @@ void moveBall()
released = false; released = false;
lives--; lives--;
drawLives(); drawLives();
arduboy.tunes.tone(175, 250); tunes.tone(175, 250);
if (random(0, 2) == 0) if (random(0, 2) == 0)
{ {
dx = 1; dx = 1;
@ -201,7 +207,7 @@ void moveBall()
{ {
xb = 2; xb = 2;
dx = -dx; dx = -dx;
arduboy.tunes.tone(523, 250); tunes.tone(523, 250);
} }
//Bounce off right side //Bounce off right side
@ -209,7 +215,7 @@ void moveBall()
{ {
xb = WIDTH - 4; xb = WIDTH - 4;
dx = -dx; dx = -dx;
arduboy.tunes.tone(523, 250); tunes.tone(523, 250);
} }
//Bounce off paddle //Bounce off paddle
@ -221,7 +227,7 @@ void moveBall()
if (dx == 0) { if (dx == 0) {
dx = (random(0,2) == 1) ? 1 : -1; dx = (random(0,2) == 1) ? 1 : -1;
} }
arduboy.tunes.tone(200, 250); tunes.tone(200, 250);
} }
//Bounce off Bricks //Bounce off Bricks
@ -255,7 +261,7 @@ void moveBall()
dy =- dy; dy =- dy;
yb += dy; yb += dy;
bounced = true; bounced = true;
arduboy.tunes.tone(261, 250); tunes.tone(261, 250);
} }
} }
@ -268,7 +274,7 @@ void moveBall()
dx =- dx; dx =- dx;
xb += dx; xb += dx;
bounced = true; bounced = true;
arduboy.tunes.tone(261, 250); tunes.tone(261, 250);
} }
} }
} }
@ -572,7 +578,7 @@ void enterInitials()
index = 0; index = 0;
} else } else
{ {
arduboy.tunes.tone(1046, 250); tunes.tone(1046, 250);
} }
} }
@ -583,14 +589,14 @@ void enterInitials()
{ {
index = 2; index = 2;
} else { } else {
arduboy.tunes.tone(1046, 250); tunes.tone(1046, 250);
} }
} }
if (arduboy.pressed(DOWN_BUTTON)) if (arduboy.pressed(DOWN_BUTTON))
{ {
initials[index]++; initials[index]++;
arduboy.tunes.tone(523, 250); tunes.tone(523, 250);
// A-Z 0-9 :-? !-/ ' ' // A-Z 0-9 :-? !-/ ' '
if (initials[index] == '0') if (initials[index] == '0')
{ {
@ -613,7 +619,7 @@ void enterInitials()
if (arduboy.pressed(UP_BUTTON)) if (arduboy.pressed(UP_BUTTON))
{ {
initials[index]--; initials[index]--;
arduboy.tunes.tone(523, 250); tunes.tone(523, 250);
if (initials[index] == ' ') { if (initials[index] == ' ') {
initials[index] = '?'; initials[index] = '?';
} }
@ -633,9 +639,9 @@ void enterInitials()
if (index < 2) if (index < 2)
{ {
index++; index++;
arduboy.tunes.tone(1046, 250); tunes.tone(1046, 250);
} else { } else {
arduboy.tunes.tone(1046, 250); tunes.tone(1046, 250);
return; return;
} }
} }