Skip to content

Commit

Permalink
added menu and controls
Browse files Browse the repository at this point in the history
edit mode not working yet
  • Loading branch information
nponsard committed Aug 18, 2018
1 parent 5db8e11 commit 9729510
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 34 deletions.
Binary file modified binaries/game_of_life/game_of_life.bin
Binary file not shown.
137 changes: 104 additions & 33 deletions game_of_life/game_of_life.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#include <Gamebuino-Meta.h>


Color colors[10] = {BLACK, BLUE, LIGHTBLUE, LIGHTGREEN, GREEN, BEIGE, YELLOW, ORANGE, RED, WHITE};
const char* entriesEoff[] = {
"Enter Edit mode",
"Clear grid",
"Randomize grid",
"Return",
};
const char* entriesEon[] = {
"Quit Edit mode",
"Clear grid",
"Randomize grid",
"Return",
};
bool Emode = false;



Color colors[10] = {BLACK, BLUE, LIGHTBLUE, LIGHTGREEN, GREEN, BEIGE, YELLOW, ORANGE, RED, WHITE};

bool Play = true;
uint8_t grid[80][64] ;
unsigned long time = 0 ;
uint16_t temp = 0 ;
Expand All @@ -20,50 +36,105 @@ void setup() {

void loop() {
while (!gb.update());
updateG();
gb.display.clear();
if (gb.buttons.pressed(BUTTON_A)) {
if (Emode) {

} else {
if (Play) {
const char* text = "Paused" ;
gb.gui.popup( text, 25);
Play = false;
} else {
const char* text = "Playing" ;
gb.gui.popup( text, 25);
Play = true;
}
}

}
if (gb.buttons.pressed(BUTTON_HOME)) {
Play = false;
uint8_t entry;
if (Emode) {
entry = gb.gui.menu("--Menu--", entriesEon, 4);
if (entry == 0) {
Emode = 0;
const char* text = "Emode OFF, Playing" ;
gb.gui.popup( text, 25);
}
} else {
entry = gb.gui.menu("--Menu--", entriesEoff, 4);
if (entry == 0) {
Emode = 1;
const char* text = "Edit mode ON" ;
gb.gui.popup( text, 25);
}
}

switch (entry) {
case 1 :
for (int x = 0; x < 80; x++) {
for (int y = 0; y < 64; y++) {
grid[x][y] = 0;
const char* text = "Cleared !" ;
gb.gui.popup( text, 25);
}
}
break;
case 2 :
for (int x = 0; x < 80; x++) {
for (int y = 0; y < 64; y++) {
grid[x][y] = random(0, 2);
const char* text = "Randomized !" ;
gb.gui.popup( text, 25);
}
}
break;
}
Play = true;
}
gb.display.clear();
if (Play && !Emode) {
updateG();
}
for (int x = 0; x < 80; x++) {
for (int y = 0; y < 64; y++) {
gb.display.setColor(colors[grid[x][y]]);
gb.display.drawPixel(x, y);
}
}

/*
// debug hud
uint16_t ram = gb.getFreeRam();
uint8_t load = gb.getCpuLoad();
if (load > 85) {
gb.display.setColor(RED);
} else {
gb.display.setColor(LIGHTBLUE);
}
gb.display.fillRect(0, 0, 29, 7);
gb.display.fillRect(43, 0, 40 , 7);
gb.display.setColor(GREEN);
gb.display.fillRect(31, 0, 9 , 7);
gb.display.setColor(WHITE);

/*
// debug hud
uint16_t ram = gb.getFreeRam();
uint8_t load = gb.getCpuLoad();
if (load > 85) {
gb.display.setColor(RED);
} else {
gb.display.setColor(LIGHTBLUE);
}
gb.display.fillRect(0, 0, 29, 7);
gb.display.fillRect(43, 0, 40 , 7);
gb.display.setColor(GREEN);
gb.display.fillRect(31, 0, 9 , 7);
gb.display.setColor(WHITE);
gb.display.setCursor(1, 1);
gb.display.setFontSize(1);
gb.display.print("CPU:");
gb.display.print(load);
gb.display.println("%");
gb.display.setCursor(1, 1);
gb.display.setFontSize(1);
gb.display.print("CPU:");
gb.display.print(load);
gb.display.println("%");
gb.display.setCursor(32, 1);
temp = millis() - time ;
gb.display.print(1000 / temp);
time = millis();
gb.display.setCursor(44, 1);
gb.display.setCursor(32, 1);
temp = millis() - time ;
gb.display.print(1000 / temp);
time = millis();
gb.display.setCursor(44, 1);
gb.display.print("RAM:");
gb.display.println(ram);
*/
gb.display.print("RAM:");
gb.display.println(ram);
*/

}
Binary file removed game_of_life/game_of_life.ino.gamebuino_meta.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion game_of_life/update.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void updateG() {
for (int x = 0; x < 80; x++) {
for (int y = 0; y < 64; y++) {
n = neighbours(grid, x, y);
temp[x][y] = grid[x][y]+1;
temp[x][y] = grid[x][y] + 1;
if (grid[x][y] > 0) {
if (n > 3 || n < 2) {
temp[x][y] = 0;
Expand Down

0 comments on commit 9729510

Please sign in to comment.