ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Revision:
15:3571beaaeed8
Parent:
13:eb60628db8bf
Child:
16:cf2bfada3adf
--- a/shot/shot.cpp	Fri May 15 08:04:39 2020 +0000
+++ b/shot/shot.cpp	Fri May 15 12:21:45 2020 +0000
@@ -74,7 +74,7 @@
 
 }
 
-void shot::update(N5110 &lcd)
+void shot::update()
 {
     for (std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++) {
         if ((*i).dir == 0) {
@@ -97,11 +97,6 @@
             (*i).y +=1;//SW
         }
     }
-    // delete invalid shots
-    delete_shot();
-    //generate shot to keep constant number of shots
-    update_shot();
-    draw(lcd);
 }
 
 void shot::update_shot()
@@ -118,6 +113,11 @@
 
 void shot::draw(N5110 &lcd)
 {
+    update();
+    // delete invalid shots
+    delete_shot();
+    //generate shot to keep constant number of shots
+    update_shot();
     for (std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++) {
         lcd.drawSprite((*i).x,(*i).y,3,3,(int*)shots[(*i).type]);
         //printf("coordinate = %d,%d\n",(*i).x,(*i).y);
@@ -161,8 +161,28 @@
     _size = size;
 }
 
+void shot::set_shot(int x, int y, int type, int Direction)
+{
+    for (std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++){
+        (*i).x = x;
+        (*i).y = y;
+        (*i).type = type;
+        (*i).dir = Direction;
+    }
+}
 int shot::get_size() 
 {
     return _size;
 }
+
+Vector2D shot::get_shot()
+{
+    for (std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++){
+        _shot_pos.x =(*i).x;
+        _shot_pos.y =(*i).y;
+    }
+    return _shot_pos;
+}
+        
+
  
\ No newline at end of file