ELEC2645 (2018/19) / Mbed 2 deprecated el17set_

Dependencies:   mbed

Revision:
22:8e38efeae0c9
Parent:
21:7d4827af00d6
Child:
24:7770c7f27cdc
--- a/main.cpp	Wed May 08 23:17:35 2019 +0000
+++ b/main.cpp	Thu May 09 12:10:56 2019 +0000
@@ -1,72 +1,93 @@
+/*
+Name: Spencer Tingle
+Username: el17set
+Student ID: 201147893
+Date: 09/05/19
+*/
+
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
 #include "Game.h"
 #include "Menu.h"
+#include "Coin.h"
 
+// objects //
 Game game;
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 
+// prototypes //
 void init();
 void render();
 void startScreen();
+bool gameWin();
 
-int main(){
-        
-    int fps = 30;
-    lcd.setContrast(0.4);
-    lcd.setBrightness(1);
-    
-    init();
-    startScreen();
-    //game.UI(pad,lcd);
-    //render();    
-    wait(1.0f/fps);
+// functions //
+int main()
+{
+  int fps = 30;          // set frames per second 
+  lcd.setContrast(0.4);  // set contrast
+  lcd.setBrightness(1);  // set brightness
     
-    while (1) { 
-        game.UI(pad,lcd); 
-        game.init();  
-        int lives = game.get_lives();
-        int coins = game.get_coins();
-        while (lives > 0 || coins < 1) {
-            render();
-            wait(1.0f/fps);
-            lives = game.get_lives();
-            coins = game.get_coins();
-        }  
-    }
-}
+  init();               // initialises all initial variables
+  startScreen();        // displays start screen until start pressed
+  //game.UI(lcd, pad);
+  //render(); 
+  wait(1.0f/fps);       // sets wait between next frame
+
+  // game loop //
+  while (1) { 
+    game.UI(lcd, pad);  // displays the menus
+    game.init();
+    int lives = game.get_lives();
     
-void init(){
-    lcd.init();
-    pad.init();
+    // condition to allow for returning to // 
+    // main menu on win or loss //
+    while (lives > 0) {
+      render();
+      wait(1.0f/fps);
+      lives = game.get_lives();
+    }  
+  }
 }
-    
-void render(){
-    lcd.clear();
-    game.dirmag(pad);
-    game.drawSprite(lcd);
-    game.movement(lcd,pad);
-    game.collect(lcd,pad);
-    game.damage(lcd,pad);
-    game.death(lcd);
-    game.win(lcd);
-    game.display_health(lcd);
-    lcd.refresh();
+// initialises gamepad and lcd //
+void init()
+{
+  lcd.init();
+  pad.init();
 }
 
-void startScreen(){   
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
-        lcd.clear();
-        lcd.drawSprite(0,0,48,84,(int *)start_01);
-        lcd.refresh();
-        wait(0.5);
-        lcd.drawSprite(0,0,48,84,(int *)start_02);
-        lcd.refresh();
-        wait(0.5);
-        lcd.drawSprite(0,0,48,84,(int *)start_03);
-        lcd.refresh();
-        wait(0.5);
-    }
+// updates all sprites and updates all movements //
+// and conditional values every frame //
+void render()
+{
+  lcd.clear();
+  game.direc(pad);
+  game.drawSprite(lcd);
+  game.movement(lcd, pad);
+  game.collect(lcd, pad);
+  game.win(lcd);
+  game.damage(lcd, pad);
+  game.death(lcd);
+  game.display_health(lcd);
+  lcd.refresh();
+}
+
+// start screen with 3 frames //
+void startScreen()
+{
+  // until start pressed 3 frames will loop //
+  while (pad.check_event(Gamepad::START_PRESSED) == false) {
+    lcd.clear();
+    lcd.drawSprite(0,0,48,84,(int *)start_01);
+    lcd.refresh();
+    wait(0.5);
+    lcd.drawSprite(0,0,48,84,(int *)start_02);
+    lcd.refresh();
+    wait(0.5);
+    lcd.drawSprite(0,0,48,84,(int *)start_03);
+    lcd.refresh();
+    wait(0.5);
+  }
 }
\ No newline at end of file