ELEC2645 (2018/19) / Mbed 2 deprecated el17cd

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
el17cd
Date:
Wed May 08 18:17:59 2019 +0000
Parent:
45:6eb1a18019d0
Commit message:
Potentiometer now changes screen contrast for use on other devices.; Final Submission.; I have read and agreed with the Statement of Academic Integrity.

Changed in this revision

Game/Game.cpp Show annotated file Show diff for this revision Revisions of this file
Renderer/Renderer.cpp Show annotated file Show diff for this revision Revisions of this file
Renderer/Renderer.h Show annotated file Show diff for this revision Revisions of this file
--- a/Game/Game.cpp	Tue May 07 17:37:23 2019 +0000
+++ b/Game/Game.cpp	Wed May 08 18:17:59 2019 +0000
@@ -70,7 +70,7 @@
     for (int c = 0; c< noOfCubes; c++){  
         moveCubes(&cubeArray[c]); //translate cubes depending on joystick location and score
         cubeToBeRendered(&cubeArray[c], c); //add all cube faces to array to later be rendered
-        checkDespawn(&cubeArray[c]); //check if any cubes are behind the perspective
+        checkDespawn(&cubeArray[c]); //check if any cubes are behind the perspective, then respawn them
         checkDeath(&cubeArray[c]); //check if any cubes are too close to user
     }
     renderer.drawAllFaces(faceArray, noOfCubes, input.x); //draw all faces added to the face array
@@ -210,8 +210,9 @@
 }
 
 void Game::processInput(){ //Obtain user inputs and store in input struct
+    renderer.setContrast(gamepad.read_pot()); //Set the contrast of the screen based on the pot
     input.x = gamepad.get_coord().x; //Get value of joystick x axis
-    bool y = gamepad.check_event(Gamepad::Y_PRESSED);
+    bool y = gamepad.check_event(Gamepad::Y_PRESSED); //Get Y, A, B button states
     bool a = gamepad.check_event(Gamepad::A_PRESSED);
     bool b = gamepad.check_event(Gamepad::B_PRESSED);
 
--- a/Renderer/Renderer.cpp	Tue May 07 17:37:23 2019 +0000
+++ b/Renderer/Renderer.cpp	Wed May 08 18:17:59 2019 +0000
@@ -105,7 +105,7 @@
         1);
 }
 
-void Renderer::drawAllFaces(Face *faceArray, int noOfCubes, float angle) { //draw all faces in game
+void Renderer::drawAllFaces(Face *faceArray, int noOfCubes, float angle) { //draw all faces in game using the painters algorithm
     Face temp;
     for (int f = 0; f< (noOfCubes*6)-1; f++) { //sort the faces in decreasing average z value using bubble sort
         for (int f2 = 0; f2< (noOfCubes*6)-f-1; f2++) {
@@ -165,6 +165,10 @@
     lcd.turnOff();
 }
 
+void Renderer::setContrast(float contrast) { //set the contrast of the display
+    lcd.setContrast(contrast);
+}
+
 void Renderer::drawDeathScreen(int selection, int highScore) { //draw the screen once the user has collided with cube
     Face faces[6];
     int x, y, z;
--- a/Renderer/Renderer.h	Tue May 07 17:37:23 2019 +0000
+++ b/Renderer/Renderer.h	Wed May 08 18:17:59 2019 +0000
@@ -19,11 +19,6 @@
   private:
     float fov;
     Cube selectionCube;
-  public:
-    Renderer();
-    /** Initialises the LCD and sets the field of view
-    */
-    void init();
     /** Projects the 3D x coordinate to 2D perspective
     *@param The 3d x coordinate as a float
     *@param The 3d z coordinate as a float
@@ -36,6 +31,11 @@
     *@returns The 2D perspective of the y coordinate
     */
     float yTo2D(float y, float z);
+  public:
+    Renderer();
+    /** Initialises the LCD and sets the field of view
+    */
+    void init();
     /** Draws the games horizon line
     *@param The angle of the horizon determined by the joystick position
     */
@@ -98,6 +98,7 @@
     *@param The selected option as an integer
     *@param The high score as an integer
     */
+    void setContrast(float contrast);
     void drawDeathScreen(int selection, int highScore);
     /** Draws the death menus buttons
     */