I don't get it run with sound, is some complicated with the gb.update()...., but without it works fine.
Hope anyone can add sound
Video-Emulator: Open
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
PROGMEM uint16_t UPSound[] = {
0x4E, 0x0000
};
PROGMEM uint16_t LEFTSound[] = {
0x1C4E, 0x0000
};
PROGMEM uint16_t DOWNSound[] = {
0x384E, 0x0000
};
PROGMEM uint16_t RIGHTSound[] = {
0x544E, 0x0000
};
///////////////////////////////////// SETUP
byte simonsay[500];
byte playersay = 0;
boolean GameOver = false;
int level = 0;
void setup() {
randomSeed(gb.battery.voltage + gb.backlight.ambientLight);
gb.begin(F("Simon Says"));
for (int i = 0; i < 500; i++) {
simonsay[i] = 0;
}
}
void loop() {
//Simon Says
simonsay[level] = random(1, 5);
for (int i = 0; i < level; i++) {
gb.display.clear();
gb.display.setCursor(18, (LCDHEIGHT / 2) - 4);
gb.display.print("Simon Says\n");
gb.display.update();
delay(500);
switch (simonsay[i]) {
case 1:
gb.display.setCursor(64, (LCDHEIGHT / 2) - 4);
gb.display.print("RIGHT");
break;
case 2:
gb.display.setCursor(0, (LCDHEIGHT / 2) - 4);
gb.display.print("LEFT");
break;
case 3:
gb.display.setCursor((LCDWIDTH / 2) - 4, 42);
gb.display.print("DOWN");
break;
case 4:
gb.display.setCursor((LCDWIDTH / 2) - 4, 0);
gb.display.print("UP");
break;
}
gb.display.update();
delay(500);
}
delay(1000);
//Player Says
for (int i = 0; i < level; i++) {
while (1) {
if (gb.update()) {
gb.display.clear();
gb.display.setCursor(18, (LCDHEIGHT / 2) - 4);
gb.display.print("Player Says");
gb.display.update();
if (gb.buttons.pressed(BTN_RIGHT)) {
playersay = 1;
delay(500);
gb.display.setCursor(64, (LCDHEIGHT / 2) - 4);
gb.display.print("RIGHT");
break;
}
if (gb.buttons.pressed(BTN_LEFT)) {
playersay = 2;
delay(500);
gb.display.setCursor(0, (LCDHEIGHT / 2) - 4);
gb.display.print("LEFT");
break;
}
if (gb.buttons.pressed(BTN_DOWN)) {
playersay = 3;
delay(500);
gb.display.setCursor((LCDWIDTH / 2) - 4, 42);
gb.display.print("DOWN");
break;
}
if (gb.buttons.pressed(BTN_UP)) {
playersay = 4;
delay(500);
gb.display.setCursor((LCDWIDTH / 2) - 4, 0);
gb.display.print("UP");
break;
}
}
}
//Player Says the same like Simon?
if (simonsay[i] == playersay) {
gb.display.setCursor(23, (LCDHEIGHT / 2) + 4);
gb.display.print("YES");
gb.display.update();
}
else
{
gb.display.setCursor(23, (LCDHEIGHT / 2) + 4);
gb.display.print("NO");
gb.display.update();
GameOver = true;
break;
}
delay(1000);
}
if (GameOver) {
gb.display.clear();
gb.display.print("Game Over\n");
gb.display.print("Level:\n");
gb.display.print(level);
gb.display.update();
level = 0;
GameOver = false;
delay(5000);
}
else
{
level++;
gb.display.clear();
gb.display.print("Next Level:\n");
gb.display.print(level);
gb.display.update();
delay(3000);
}
}