aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-04-05 22:08:08 +0200
committerElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-04-05 22:08:08 +0200
commit1e151d8869780b25c16fb372c19af4d8516ec94f (patch)
tree3e081420b52f14bdb7d7dfc38143ece3a9997ab1
parent3ad10a8654288f61a1138aba756fbeefd157937a (diff)
Arduino sketch: playable game (with joystick)
-rw-r--r--arduino_sketch/arcerino/arcerino.ino67
1 files changed, 49 insertions, 18 deletions
diff --git a/arduino_sketch/arcerino/arcerino.ino b/arduino_sketch/arcerino/arcerino.ino
index e07f2a8..141af70 100644
--- a/arduino_sketch/arcerino/arcerino.ino
+++ b/arduino_sketch/arcerino/arcerino.ino
@@ -8,41 +8,72 @@
U8GLIB_TLS8204_84X48 u8g(15, 16, 13, 4, 5); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 4, Reset = 5
+#define LCD_MAX 24
+#define JOY_MAX 100
+#define LCD_0X 42
+#define LCD_0Y 24
+
+char x,y=0;
+char drift_x,drift_y=0;
+
+char score=0;
+
void setup() {
- Serial.begin(9600);
nunchuk_init();
u8g.setColorIndex(1);
u8g.setContrast(192);
+ // TODO: draw startup screen
+ delay(1000);
}
void draw() {
u8g.setFont(u8g_font_5x7);
u8g.setPrintPos(0,8);
- u8g.print("acc: ");
- u8g.print(String(nunchuk_rollangle(),DEC));
- u8g.print(";");
- u8g.print(String(nunchuk_pitchangle(),DEC));
- u8g.setPrintPos(0,16);
- u8g.print("joy: ");
- u8g.print(String(nunchuk_cjoy_x(),DEC));
- u8g.print(";");
- u8g.print(String(nunchuk_cjoy_y(),DEC));
- u8g.setPrintPos(0,24);
- u8g.print("but: ");
- u8g.print(String(nunchuk_zbutton(),DEC));
- u8g.print(";");
- u8g.print(String(nunchuk_cbutton(),DEC));
+ u8g.print(score,DEC);
+ u8g.drawCircle(42,24,24);
+ u8g.drawCircle(42,24,16);
+ u8g.drawCircle(42,24,8);
+ drift_x = drift_x + random(-1,2);
+ drift_x = constrain(drift_x,-LCD_MAX,LCD_MAX);
+ drift_y = drift_y + random(-1,2);
+ drift_y = constrain(drift_y,-LCD_MAX,LCD_MAX);
+ x = map(nunchuk_cjoy_x(),-JOY_MAX,JOY_MAX,-LCD_MAX,LCD_MAX) + drift_x;
+ y = map(nunchuk_cjoy_y(),-JOY_MAX,JOY_MAX,LCD_MAX,-LCD_MAX) + drift_y;
+ u8g.drawVLine(x+LCD_0X,y-4+LCD_0Y,9);
+ u8g.drawHLine(x-4+LCD_0X,y+LCD_0Y,9);
}
void loop() {
nunchuk_get_data();
- Serial.println(nunchuk_joy_x());
-
u8g.firstPage();
do {
draw();
} while(u8g.nextPage());
- delay(100);
+ if (nunchuk_zbutton()) {
+ score = score + get_score();
+ // TODO: draw score screen
+ delay(3000);
+ } else {
+ delay(100);
+ }
+}
+
+char get_score() {
+ int d = sqrt(pow(x,2) + pow(y,2)) / 8;
+ Serial.println(d,DEC);
+ switch(d) {
+ case 0:
+ return 10;
+ break;
+ case 1:
+ return 5;
+ break;
+ case 2:
+ return 1;
+ break;
+ default:
+ return 0;
+ }
}