ELEC2645 (2018/19) / Mbed 2 deprecated ll16o2l_ELEC2645

Dependencies:   mbed Gamepad

Revision:
3:aa82968b7a8e
Parent:
2:888634fff8ff
Child:
15:807eba7c7811
--- a/Player/Player.cpp	Sat Apr 06 12:08:39 2019 +0000
+++ b/Player/Player.cpp	Thu Apr 25 15:08:52 2019 +0000
@@ -1,4 +1,3 @@
-
 #include "Player.h"
 
 // nothing doing in the constructor and destructor
@@ -12,21 +11,13 @@
 
 }
 
-
-
-//void Player::PlayerSprite()
-//{
-//  // First declare the pixel map data using '1' for black,
-//  // or '0' for white pixels
-//  
-//} 
-//    // x origin, y origin, rows, cols, sprite
-//        //lcd.drawSprite(20,6,8,5,(int *)sprite);
-//        //lcd.refresh();
-//        //wait(5.0);
-        
-  
-  
+/**
+*   This method will be used to initialise the player variables.
+*   Saves global variable values to local variables.
+*   @author Oliver Luong
+*   @param player_height, player_width
+*   @date 22/04/2019
+*/
 void Player::init(int player_height,int player_width)
 {
     // Initialise at the centre
@@ -40,8 +31,12 @@
     _speed = 1;  // default speed
 }
 
-
-
+/**
+*   This method will be used to store the sprite for player and draw it
+*   onto the LCD.
+*   @author Oliver Luong
+*   @date 22/04/2019
+*/
 void Player::draw(N5110 &lcd)
 {
     int Player_sprite[14][14] = {
@@ -62,19 +57,25 @@
     };
     
     // Instantiate the Bitmap object using the data above
-    lcd.drawSprite(_x, _y, _player_height, _player_width,(int *)Player_sprite); //Need a initial position to move from
+    lcd.drawSprite(_x, _y, _player_height, _player_width,(int *)Player_sprite);
 }
 
-
-void Player::update(Direction d,float mag)
+/**
+*   This method will be used to update the positioning of 
+*   the player in one of 8 directions.
+*   @author Oliver Luong
+*   @param d, mag
+*   @date 22/04/2019
+*/
+void Player::update(Direction d, float mag)
 {
     _speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
 
     // update y value depending on direction of movement
     // North is decrement as origin is at the top-left so decreasing moves up
     if (d == N) {
-        _y-=_speed;   // check for -1.0 angle
-    } else if (d == NE) {  // then keep going in 45 degree increments
+        _y-=_speed; // updates the speed in directions depending on joystick position, d.
+    } else if (d == NE) {
         _y-=_speed;
         _x+=_speed;
     } else if (d == E) {
@@ -94,7 +95,7 @@
         _x-=_speed;
     }
 
-    // check the y origin to ensure that the spacecraft doesn't go off screen
+    // check the y origin to ensure that the player doesn't go off screen
     if (_y < 1) {
         _y = 1;
     }
@@ -102,7 +103,7 @@
         _y = HEIGHT - _player_height - 1;
     }
     
-    // check the y origin to ensure that the spacecraft doesn't go off screen
+    // check the x origin to ensure that the player doesn't go off screen
     if (_x < 1) {
         _x = 1;
     }
@@ -111,17 +112,11 @@
     }
 }
 
-
-//void Player::add_score()
-//{
-    //  Timer code ------ https://os.mbed.com/forum/mbed/topic/2265/?page=1#comment-11449
-//    _score++;
-//}
-//int Player::get_score()
-//{
-//   return _score;
-//}
-
+/**
+*   This method will be used to retun the position of the player.
+*   @author Oliver Luong
+*   @date 22/04/2019
+*/
 Vector2D Player::get_pos() {
     Vector2D p = {_x,_y};
     return p;