ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
el19tb
Date:
Wed May 27 01:54:46 2020 +0000
Parent:
60:e1ac7fa5cf17
Commit message:
Final Submission. I have read and agreed with Statement of Academic Integrity.

Changed in this revision

Frogger/Frogger.cpp Show annotated file Show diff for this revision Revisions of this file
GraphicEngine/GraphicEngine.cpp Show annotated file Show diff for this revision Revisions of this file
GraphicEngine/GraphicEngine.h Show annotated file Show diff for this revision Revisions of this file
IntroScreen/IntroScreen.h Show annotated file Show diff for this revision Revisions of this file
Sprite/Background.h Show annotated file Show diff for this revision Revisions of this file
Sprite/Vehicle.h Show annotated file Show diff for this revision Revisions of this file
--- a/Frogger/Frogger.cpp	Wed May 27 01:21:19 2020 +0000
+++ b/Frogger/Frogger.cpp	Wed May 27 01:54:46 2020 +0000
@@ -36,6 +36,7 @@
     frogOnLog = false;
     goal_post_xpos = (36); // generate random position for end post
     next_goal = false;
+    
     // grid values
     grid = 4; // size of game grid system
     grid_width = 22; // size of screen width in grid units
@@ -112,24 +113,19 @@
 {     
     //keep reading and processing user input
     while(1) {
-        graphics.clear(); // clear the lcd screen
-        
+        graphics.clear(); // clear the lcd screen 
         if(introScreen) { // shows tutorial, setting
             graphics.getPointerPos(intro.selection); // draw the initial pointer pos
             home(); // draw menu selections
         } else if (play_game) { // shows actual gameplay
             run();
             //printf("show turtle state %d" turtle_state);
-            
         } else if(tutorial) {
             gotoPage();
-            
         } else if(bonus_round) {
             run_bonus();
-        } 
-         
+        }   
         graphics.refresh(); // refresh the lcd screen
-        
         wait_ms(85); // fpms
     } 
 }
@@ -192,24 +188,18 @@
 void Frogger::run_bonus()
 {
     current_level = 0;
-
     checkBonusProgress(); 
       
     //printf("FROG y position, %d", frog->y);
     //printf("Display the current level, %d", current_level); 
     
-    drawBackGround();
-        
-    generateLevelOneGoalPost();
-            
+    drawBackGround();    
+    generateLevelOneGoalPost();     
     process_input(); // user controls the frog object
-       
     actOnFrogBonus();
-    
     checkFrogInDeathZone();
-        
+
     graphics.showFrog(frog->x, frog->y, frog->width, frog->height, state_frog); // display current position of frog 
-    
     graphics.drawVoidBackGround();
 }
 
@@ -375,29 +365,27 @@
     return (rand() % 80) + 12;      
 }
 
-void Frogger::process_input() 
-{
+
+
+void Frogger::process_input() {
     //determine the input 
     if(gamepad.A_pressed()){
         state_frog = 1;
-        moveFrog(1,0);
+        moveFrog(1,0); // move frog right
         frogOnLog = false;
     } else if(gamepad.X_pressed()){
         state_frog = 0;
-        moveFrog(0,-1);
+        moveFrog(0,-1);// move it down
         frogOnLog = false;
-
     } else if(gamepad.B_pressed()){
         state_frog = 3;
-        moveFrog(0,1);
+        moveFrog(0,1); // move the frog up
         frogOnLog = false;
-
     } else if(gamepad.Y_pressed()){
         state_frog = 2;
-        moveFrog(-1,0);
+        moveFrog(-1,0); // move the frog left
         frogOnLog = false;
     } 
-    
     wait_ms(10);
 }
 
@@ -557,6 +545,8 @@
     updateTurtleState();
 }
 
+
+
 void Frogger::updateTurtleState()
 {
     switch(turtle_state)
@@ -573,12 +563,8 @@
         case 3001 ... 4000:
             turtle_state++;  
             break;
-        case 4001 ... 5000:
-            turtle_state++;  
-            break;
-        case 5001:
-            turtle_state = 0;
-            break;
+        case 4001 ... 5000: turtle_state++; break;
+        case 5001: turtle_state = 0; break;
     }
 }
 /* ENGINE RUN */
@@ -651,11 +637,11 @@
     switch (log.object.dir)
     {
         case 1:
-            frog->x += log.speed;
+            frog->x += log.speed; // move it right
             break;
                 
         case 2:
-            frog->x = frog->x - log.speed;
+            frog->x = frog->x - log.speed; // move it left
             break;
     }
     
--- a/GraphicEngine/GraphicEngine.cpp	Wed May 27 01:21:19 2020 +0000
+++ b/GraphicEngine/GraphicEngine.cpp	Wed May 27 01:54:46 2020 +0000
@@ -2,6 +2,7 @@
 
 GraphicEngine::GraphicEngine(){}
 
+/** Draw the pointer next to the menu texts */
 void GraphicEngine::getPointerPos(int sel)
 {    
     switch(sel)
@@ -100,16 +101,13 @@
 {
     lcd.drawSprite(20, 48-4*12, 36, 43,(int *)frogger_intro);  
     lcd.printString("|  FROGGER!  |", 0,5);
-
 }
 
-
 void GraphicEngine::init()
 {
     lcd.init();
 }
 
-/* TO-DO: ADD CONTROLS FOR BACKLIGHT */
 void GraphicEngine::contrast()
 {
     lcd.setContrast(0.45);  
@@ -130,6 +128,7 @@
     lcd.backLightOn();
 }
 
+/** To save function space, call different drawing functions based on the char */
 void GraphicEngine::showObj(Object *obj, int turtles_state)
 {
     if(obj->object.c == 'G' || obj->object.c == 'M') {
@@ -159,6 +158,7 @@
     lcd.drawRect(55, 0, 35, 48, FILL_BLACK);
 }
 
+/** To increase the duration of the states, make it by a factor of 1000 */
 void GraphicEngine::displayTurtles(int x, int y, char c, int turtle_sate){
     switch(turtle_sate)
     {
@@ -180,6 +180,7 @@
     }
 }
 
+/** Based on the char values you can determine the sprite */
 void GraphicEngine::displayVehicle(int x, int y, char c)
 {
     switch(c)
--- a/GraphicEngine/GraphicEngine.h	Wed May 27 01:21:19 2020 +0000
+++ b/GraphicEngine/GraphicEngine.h	Wed May 27 01:54:46 2020 +0000
@@ -13,7 +13,7 @@
 #include "Gamepad.h"
 #include <vector>
 
-/** Graphicengine Class
+/** GraphicEngine Class
  * @brief displays objects to lcd, stores all the graphical objects
  * @author Tarek Bessalah
  * @date May, 2020
--- a/IntroScreen/IntroScreen.h	Wed May 27 01:21:19 2020 +0000
+++ b/IntroScreen/IntroScreen.h	Wed May 27 01:54:46 2020 +0000
@@ -18,7 +18,6 @@
          * @return the current pointer tutorial screen
          */
         int tutorial_screens;
-
 };
 
 #endif
\ No newline at end of file
--- a/Sprite/Background.h	Wed May 27 01:21:19 2020 +0000
+++ b/Sprite/Background.h	Wed May 27 01:54:46 2020 +0000
@@ -1,17 +1,6 @@
 #ifndef BACKGROUND_H
 #define BACKGROUND_H
 
-/*
- { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
-    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
-    */
-
 const int danger_zone[7][83] = {
     
     { 0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0 },
--- a/Sprite/Vehicle.h	Wed May 27 01:21:19 2020 +0000
+++ b/Sprite/Vehicle.h	Wed May 27 01:54:46 2020 +0000
@@ -1,9 +1,6 @@
 #ifndef VEHICLE_H
 #define VEHICLE_H
 
-// size of grid of the game
-// three states of the frog
-// still, movement 1 , movement two
 
 const int frog_state_up[4][6] = {
   //final and initial state of frog