ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18zc_

Dependencies:   mbed

Revision:
7:f61ac963eb07
Parent:
6:b393cfe4e0a7
Child:
15:7ca2d1b2bd0e
--- a/Bullet/Bullet.cpp	Thu May 28 01:11:47 2020 +0000
+++ b/Bullet/Bullet.cpp	Fri May 29 02:55:37 2020 +0000
@@ -1,62 +1,50 @@
 #include "Bullet.h"
 
-Bullet::Bullet()
-{
-
-}
-
-Bullet::~Bullet()
-{
-
-}
 
 void Bullet::init(int x,int size,int speed,int height)
 {
     _size = size;
 
-    _x = x+(height)*0.5;
-    _y = HEIGHT - size;
+    _x = 24;
+    _y = 28;
     
     srand(time(NULL));
-    int direction = rand() % 4; // randomise initial direction. 
+    int direction = rand() % 2; // randomise initial direction. 
 
     // 4 possibilities. Get random modulo and set velocities accordingly
     if (direction == 0) {
         _velocity.x = speed;
-        _velocity.y = speed;
+        _velocity.y = -speed;
     } else if (direction == 1) {
-        _velocity.x = speed;
-        _velocity.y = -speed;
-    } else if (direction == 2) {
-        _velocity.x = speed;
-        _velocity.y = speed;
-    } else {
         _velocity.x = -speed;
         _velocity.y = -speed;
-    }
+    } 
 }
 
 void Bullet::draw(N5110 &lcd)
 {
     lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
-    if((_y >= 0)&&(_y <= 24))
+  /*  if((_y >= 0)&&(_y <= 24))
     {
- //        lcd.clearPixel(_x,_y-1);
+       X=_x;
+       Y=_y;   
          
     }
-    //lcd.drawRect(0,0,84,24,FILL_BLACK);
-   // lcd.clearPixel(_x,_y);
+   lcd.clearPixel(_x,_y);*/
 }
 
-void Bullet::update()
+void Bullet::update(N5110 &lcd)
 {
     _x += _velocity.x;
     _y += _velocity.y;
-    if((_y >= 0)&&(_y <= 24))
+  /*  if(( _y >= 0)&&( _y <= 24))
     {
-// lcd.clearPixel(_x,_y-1);
-         
+      
+      // lcd.clearPixel(_x,_y-1);
+      X=_x;
+      Y=_y;   
     }
+     lcd.clearPixel(X,Y-1);*/
 }
 
 void Bullet::set_velocity(Vector2D v)