ELEC2645 (2018/19) / Mbed 2 deprecated fy14lkaa

Dependencies:   mbed

Revision:
126:c63c5ad39f73
Parent:
100:b0e9c067d80a
Child:
133:eed60548d170
--- a/Bullet/Bullet.cpp	Sun May 05 15:24:38 2019 +0000
+++ b/Bullet/Bullet.cpp	Sun May 05 15:30:32 2019 +0000
@@ -1,82 +1,56 @@
 #include "Bullet.h"
 
 
-bullet::bullet()
+Bullet::Bullet()
 {
-
 }
 
-bullet::~bullet()
+Bullet::~Bullet()
 {
-
 }
 
-
-
-const int bullet[4][10] =   {
-    { 0,0,0,0,0,1,1,1,0,0 },
-    { 0,0,0,0,0,1,1,1,0,0 },
-    { 0,0,0,1,1,1,1,0,0,0 },
-    { 0,0,1,1,1,1,0,1,0,0 },
-};
-
-
-
-
-void bullet::init(int size,int speed)
+void Bullet::init(int x_bullet, int y_bullet,int speed_bullet, int fired_bullet)
 {
-    
 
-    srand(time(NULL));
-    int direction = rand() % 4; // randomise initial direction. 
-
-    // 4 possibilities. Get random modulo and set velocities accordingly
-    if (direction == 0) {
-        _velocity.x = 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;
-    }    
-    
-    
+    _x_bullet= x_bullet;
+    _y_bullet= y_bullet;
+    _speed_bullet=speed_bullet;
+     _fired_bullet= fired_bullet;
     
 }
 
 
-void bullet::draw(N5110 &lcd)
+void Bullet::draw(N5110 &lcd)
+{
+    lcd.drawRect(_x_bullet,_y_bullet,_x_bullet+5,_y_bullet+5,FILL_BLACK);
+    //lcd.drawSprite(_x_bullet,_y_bullet,12,10,(int *)bullet);
+}
+void Bullet::update(Direction d,float mag)//no need for mag 
 {
-    lcd.drawSprite(x_bullet,y_bullet,4,10,(int *)bullet);
+    _speed_bullet = int(mag*10.0f);
+    if(d==E){
+        _fired_bullet=1;
+            //_x_bullet=11;
+            //_y_bullet=y;
+        }
+        if(_fired_bullet){
+            _x_bullet+=2;//velocity
+            }
 
 }
 
-void bullet::update()
+int  Bullet::get_pos_x()
 {
-    _x += _velocity.x;
-    _y += _velocity.y;
+    return _x_bullet;
+}
+int  Bullet::get_pos_y()
+{
+    return _y_bullet;
 }
 
 
-void bullet::set_velocity(Vector2D v)
-{
-    _velocity.x = v.x;
-    _velocity.y = v.y;
-}
-
-Vector2D bullet::get_velocity()
+void Bullet::set_pos(int x, int y)
 {
-    Vector2D v = {_velocity.x,_velocity.y};
-    return v;
-}
-
-Vector2D bullet::get_pos()
-{
-    Vector2D p = {_x,_y};
-    return p;
-}
+    _x_bullet = x;
+    _y_bullet = y;
+}
\ No newline at end of file