Player Library

Revision:
12:1324d72d12a6
Parent:
11:1a8dc3242e13
Child:
13:8a52aa715b32
--- a/Player.cpp	Wed May 03 15:50:17 2017 +0000
+++ b/Player.cpp	Thu May 04 08:34:16 2017 +0000
@@ -10,6 +10,7 @@
 
 }
 
+//The Player Sprite.
 int sprite[5][6] = {
     {0,1,0,0,1,0},
     {1,1,0,0,1,1},
@@ -18,7 +19,7 @@
     {0,1,1,1,1,0},
     };
     
-int m = 0;
+int m = 0; //Variable used to allow a starting location for the player.
     
 
 void Player::init()
@@ -32,19 +33,19 @@
 void Player::draw(N5110 &lcd)
 {   
     if(m == 0){
-        _x = WIDTH/2 -1;  // Middle of screen // Change these values to change starting position
-        _y = HEIGHT/2 -1; // Near bottom of screen
+        _x = WIDTH/2 -3;  //Spawns player sprite near the middle of the screen.
+        _y = HEIGHT/2 -5; 
         m = m+1;  
         }
     //printf("SPRITE %d %d \n", _x, _y); 
-    lcd.drawSprite(_x,_y,5,6,(int *)sprite);
+    lcd.drawSprite(_x,_y,5,6,(int *)sprite); //Function used to draw the sprite.
 }
 
 
 
 Vector2D Player::get_pos()
 {
-    Vector2D playerpos = {_x,_y};
+    Vector2D playerpos = {_x,_y}; //Obtains the player position.
     //printf("playerpos from player = %f %f \n", playerpos.x, playerpos.y);
     return playerpos;
 }
@@ -57,11 +58,11 @@
 
 void Player::update(Direction d,float mag)
 {
-    _speed = int(mag*5.0f);  // scale is arbitrary, could be changed in future
+    _speed = int(mag*5.0f);  //Speed changes depending on how much you push the joystick.
 
 
-    // update y value depending on direction of movement
     // North is decrement as origin is at the top-left so decreasing moves up
+    // Diagonal speeds are /2 to prevent player from going double the speed.
     if (d == N) {
         _y-=_speed;
     }
@@ -75,7 +76,7 @@
         _x-=_speed;
     }
     if (d == NE) {
-        _y-=_speed/2;
+        _y-=_speed/2; 
         _x+=_speed/2;
     }
     if (d == NW) {
@@ -92,7 +93,7 @@
     }
 
 
-    // check the y origin to ensure that the paddle doesn't go off screen
+    //Limits set so that the sprite does not travel off the screen.
     if (_y <= 0) {
         _y = 0;
     }