Commits

Pedro Ferreira committed 8eb6a3e

- remove bullets when out of bounds

Comments (0)

Files changed (3)

 
         collisions:
 
-            - remove bullets when out of bounds and hit stuff
             - you can outrun the bullets (and collide with them)
             - sniper bullet is too fast for the shape/body to be synced
+            - cant fire if mouse is outside of canvas
 
  */
 
 {
 return radians * 180 / Math.PI;
 }
+
+
+function outOfBounds( object )
+{
+var width = CANVAS.width;
+var height = CANVAS.height;
+
+var x = object.getX();
+var y = object.getY();
+
+if ( x < 0 || x > width || y < 0 || y > height )
+    {
+    return true;
+    }
+
+return false;
+}
     {
     this.tick_function();
     }
+
+var i;
+var bulletObject;
+
+    // check if the bullets are out of bounds (outside the canvas), and remove them if so
+for (i = 0 ; i < Weapons.allyBullets.length ; i++)
+    {
+    bulletObject = Weapons.allyBullets[ i ];
+
+    if ( outOfBounds( bulletObject ) )
+        {
+        bulletObject.remove();
+
+        i--;
+        }
+    }
+
+for (i = 0 ; i < Weapons.enemyBullets.length ; i++)
+    {
+    bulletObject = Weapons.enemyBullets[ i ];
+
+    if ( outOfBounds( bulletObject ) )
+        {
+        bulletObject.remove();
+
+        i--;
+        }
+    }
 };