ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18zc_

Dependencies:   mbed

Revision:
15:7ca2d1b2bd0e
Parent:
7:f61ac963eb07
Child:
16:f8a6834a0289
--- a/Bullet/Bullet.cpp	Fri May 29 04:25:22 2020 +0000
+++ b/Bullet/Bullet.cpp	Fri May 29 07:35:45 2020 +0000
@@ -1,17 +1,17 @@
 #include "Bullet.h"
 
 
-void Bullet::init(int x,int size,int speed,int height)
+void Bullet::init(int x,int size,int speed,int y)
 {
-    _size = size;
+    _size = size; // the size of bullet
 
-    _x = 24;
-    _y = 28;
+    _x = x;       //initial horizontal coordinate
+    _y = y;       //initial vertical coordinate
     
     srand(time(NULL));
     int direction = rand() % 2; // randomise initial direction. 
 
-    // 4 possibilities. Get random modulo and set velocities accordingly
+    // 2 random direction
     if (direction == 0) {
         _velocity.x = speed;
         _velocity.y = -speed;
@@ -21,51 +21,36 @@
     } 
 }
 
-void Bullet::draw(N5110 &lcd)
+void Bullet::draw(N5110 &lcd)  // bullet drawing function
 {
     lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
-  /*  if((_y >= 0)&&(_y <= 24))
-    {
-       X=_x;
-       Y=_y;   
-         
-    }
-   lcd.clearPixel(_x,_y);*/
 }
 
-void Bullet::update(N5110 &lcd)
+void Bullet::update(N5110 &lcd) // bullet updating
 {
     _x += _velocity.x;
     _y += _velocity.y;
-  /*  if(( _y >= 0)&&( _y <= 24))
-    {
-      
-      // lcd.clearPixel(_x,_y-1);
-      X=_x;
-      Y=_y;   
-    }
-     lcd.clearPixel(X,Y-1);*/
+
 }
-
-void Bullet::set_velocity(Vector2D v)
+void Bullet::set_velocity(Vector2D v) //bullet velocity setting
 {
     _velocity.x = v.x;
     _velocity.y = v.y;
 }
 
-Vector2D Bullet::get_velocity()
+Vector2D Bullet::get_velocity()       //bullet velocity reading
 {
     Vector2D v = {_velocity.x,_velocity.y};
     return v;
 }
 
-Vector2D Bullet::get_pos()
+Vector2D Bullet::get_pos()           //bullet  position reading
 {
     Vector2D p = {_x,_y};
     return p;
 }
 
-void Bullet::set_pos(Vector2D p)
+void Bullet::set_pos(Vector2D p)    // bullet position setting
 {
     _x = p.x;
     _y = p.y;