Projectile Library

Revision:
9:64ba68ae2640
Parent:
8:36610092060f
diff -r 36610092060f -r 64ba68ae2640 Projectile.cpp
--- a/Projectile.cpp	Wed May 03 15:50:50 2017 +0000
+++ b/Projectile.cpp	Thu May 04 08:34:26 2017 +0000
@@ -11,7 +11,7 @@
 
 }
 
-
+//Obtains the player position coordinates in the initialisation stage.
 void Projectile::init(int playerx, int playery)
 {
     //printf("playerxy proj = %d %d \n", playerx, playery);
@@ -25,58 +25,46 @@
 
 void Projectile::draw(N5110 &lcd)
 {   
-    _velocity.x = 0;
-    _velocity.y = -7;
+    _velocity.x = 0; //Projectile doesn't move sideways.
+    _velocity.y = -7; //Projectile moves upwards on screen.
     
 
     //printf("playerxy projdraw = %d %d \n", _playerx, _playery);
     
     
-
+//Resets projectile if it reaches the top of the screen.
     if(_y <= -1){
         m = 0;
         }
 
-        
-        
-        
+//Sets projectile spawn location onto the player sprite.
     if(m == 0){
         _x = _playerx +2;  
         _y = _playery; 
         m = m+1;  
         }
-    lcd.drawRect(_x,_y,2,2,FILL_BLACK);
+    lcd.drawRect(_x,_y,2,2,FILL_BLACK); //Projectile is a 2x2 square.
     //printf("projdrawn %d %d \n", _x, _y);
     //printf("playerpos in proj = %d %d \n", playerx, playery);
     
 }
 
-void Projectile::update()
+void Projectile::update() //Updates projectile on screen.
 {
     _x += _velocity.x;
     _y += _velocity.y;
 }
 
-void Projectile::set_velocity(Vector2D v)
-{
-    _velocity.x = v.x;
-    _velocity.y = v.y;
-}
+
 
-Vector2D Projectile::get_velocity()
-{
-    Vector2D v = {_velocity.x,_velocity.y};
-    return v;
-}
-
-Vector2D Projectile::get_pos()
+Vector2D Projectile::get_pos() //Obtains the position of the projectile, used to check if a collision occurs.
 {
     Vector2D projpos = {_x,_y};
     //printf("projpos = %f %f \n", projpos.x, projpos.y);
     return projpos;
 }
 
-void Projectile::set_pos(Vector2D p)
+void Projectile::set_pos(Vector2D p) //Used to update the projectile location after colliding with another object.
 {
     _x = p.x;
     _y = p.y;