aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-04-06 13:18:05 +0200
committerElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-04-06 13:18:05 +0200
commit668f40084c176633bd4e430e504c5632b0442774 (patch)
tree7d1cb010ff53f47b172bedd84eab87d509890d08
parent8bf53229c6d826ab40be57ba144681ec50aebdf2 (diff)
Arduino sketch: added arrows and score screen
-rw-r--r--arduino_sketch/arcerino/arcerino.ino77
1 files changed, 63 insertions, 14 deletions
diff --git a/arduino_sketch/arcerino/arcerino.ino b/arduino_sketch/arcerino/arcerino.ino
index fe582c8..b2b9c38 100644
--- a/arduino_sketch/arcerino/arcerino.ino
+++ b/arduino_sketch/arcerino/arcerino.ino
@@ -17,11 +17,16 @@ char x,y=0;
char drift_x,drift_y=0;
char score=0;
+char arrows=10;
+bool play=true;
void draw_game() {
u8g.setFont(u8g_font_5x7);
u8g.setPrintPos(0,8);
u8g.print(score,DEC);
+ u8g.setPrintPos(0,16);
+ u8g.print("->");
+ u8g.print(arrows,DEC);
u8g.drawCircle(42,24,24);
u8g.drawCircle(42,24,16);
u8g.drawCircle(42,24,8);
@@ -34,6 +39,9 @@ void draw_score() {
u8g.setFont(u8g_font_5x7);
u8g.setPrintPos(0,8);
u8g.print(score,DEC);
+ u8g.setPrintPos(0,16);
+ u8g.print("->");
+ u8g.print(arrows,DEC);
u8g.drawCircle(42,24,24);
u8g.drawCircle(42,24,16);
u8g.drawCircle(42,24,8);
@@ -50,6 +58,31 @@ void draw_title() {
u8g.print("Loading...");
}
+void draw_wait() {
+ u8g.setFont(u8g_font_5x7);
+ u8g.setPrintPos(0,8);
+ u8g.print("Your score: ");
+ u8g.print(score,DEC);
+ u8g.setPrintPos(0,46);
+ u8g.print("Press Z to start");
+ u8g.setPrintPos(0,24);
+ u8g.print("Rank: ");
+ u8g.setFont(u8g_font_9x15);
+ if (score >= 100) {
+ u8g.print("A++");
+ } else if (score >= 90) {
+ u8g.print("A");
+ } else if (score >= 80) {
+ u8g.print("B");
+ } else if (score >= 60) {
+ u8g.print("C");
+ } else if (score >= 30) {
+ u8g.print("D");
+ } else {
+ u8g.print("E");
+ }
+}
+
void update_position() {
drift_x = drift_x + random(-1,2);
drift_x = constrain(drift_x,-LCD_MAX,LCD_MAX);
@@ -61,7 +94,6 @@ void update_position() {
char get_score() {
int d = sqrt(pow(x,2) + pow(y,2)) / 4;
- Serial.println(d,DEC);
switch(d) {
case 0:
return 10;
@@ -97,20 +129,37 @@ void setup() {
void loop() {
nunchuk_get_data();
- if (nunchuk_zbutton()) {
- score = score + get_score();
- u8g.firstPage();
- do {
- draw_score();
- } while(u8g.nextPage());
- delay(3000);
+ if (play) {
+ if (nunchuk_zbutton()) {
+ score = score + get_score();
+ arrows = arrows--;
+ u8g.firstPage();
+ do {
+ draw_score();
+ } while(u8g.nextPage());
+ delay(3000);
+ if ( arrows <= 0 ) {
+ play = false;
+ arrows = 10;
+ }
+ } else {
+ update_position();
+ u8g.firstPage();
+ do {
+ draw_game();
+ } while(u8g.nextPage());
+ delay(100);
+ }
} else {
- update_position();
- u8g.firstPage();
- do {
- draw_game();
- } while(u8g.nextPage());
- delay(100);
+ if (nunchuk_zbutton()) {
+ play=true;
+ } else {
+ u8g.firstPage();
+ do {
+ draw_wait();
+ } while(u8g.nextPage());
+ delay(100);
+ }
}
}