Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Revision:
5:5667c4ec3d7e
Parent:
4:59175720d8ee
Child:
6:478f81e79d9b
diff -r 59175720d8ee -r 5667c4ec3d7e main.cpp
--- a/main.cpp	Sun May 05 02:27:37 2019 +0000
+++ b/main.cpp	Sun May 05 03:29:31 2019 +0000
@@ -17,9 +17,6 @@
 int direction;
 int menu_option_pos = 0;
 int arrow_pos = 0;
-float brightness = 0.5;
-float contrast = 0.430;
-int volume = 1;
 
 int main() {
     init();  // initialise peripherals
@@ -115,19 +112,50 @@
     lcd.refresh();
     wait(1.0);
 }
+
 // Game State--------------------------------------------------------------
+int donkeykong_x = 0;
+int donkeykong_y = 32;
+int donkey_kong_speed = 25;
 void game_engine_run() {
     wait_ms(250);
-
+   
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
         //printf("Game State");
         lcd.clear();
         lcd.printString("Game",0,0);
-        lcd.refresh();
+        donkeykong_x_movement();
         wait_ms(1.0f/fps);
     }
 }
 
+void donkeykong_x_movement() {
+    direction = pad.get_direction();
+        if (direction == NE || direction == E || direction == SE) {
+            donkeykong_x = donkeykong_x + 1;
+            lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_right_1);
+            wait_ms(donkey_kong_speed);
+            lcd.refresh();
+        } 
+        else if (direction == NW || direction == W || direction == SW) {
+            donkeykong_x = donkeykong_x - 1;
+            lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_left_1);
+            wait_ms(donkey_kong_speed);
+            lcd.refresh();
+        } 
+        else {
+            lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_stationary);
+            lcd.refresh();
+        }
+        if (donkeykong_x > 68) {
+            donkeykong_x = 68;
+        }
+        if (donkeykong_x < 0) {
+            donkeykong_x = 0;
+        }
+}
+
+
 // Controls State----------------------------------------------------------
 void controls_run() {
     wait_ms(250);
@@ -155,6 +183,10 @@
 }
 
 // Options State-----------------------------------------------------------
+float brightness = 0.5;
+float contrast = 0.396;
+int volume = 1;
+
 void options_run() {
     wait_ms(250);
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
@@ -184,6 +216,7 @@
     contrast = pad.read_pot();
     lcd.setContrast(contrast);
     lcd.printString("Pot = Contrast",0,3);
+    printf("Contrast = %f", contrast);
 }
 
 void options_volume() {