When you keep firing bullets (spam-click), you can shoot through obstacles. Not really sure what’s going on. [Here][1], you can see what’s happening. (Just keep clicking until you shoot through the platform. Pressing ‘H’ renders hitboxes to make this easier to see.) Here’s the weapon class:
package
{
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
import flash.utils.ByteArray;
/**
* ...
* @author David Williams
*/
public class WpnBase extends Entity
{
public var bullet:Projectile;
private var gfx:Image;
private var ma:Number;
public function WpnBase(_gfx:Image, _bullet:Projectile)
{
graphic = gfx = _gfx;
bullet = _bullet;
}
public function fire():void
{
var angAdj:Number = ma * Math.PI / -180;
var xAdj:Number = Math.round(13.375 + 15.63 * Math.cos(angAdj) - 9.29 * Math.sin(angAdj));
var yAdj:Number = Math.round(14.25 + 15.63 * Math.sin(angAdj) + 9.29 * Math.cos(angAdj));
bullet.x = this.x - 18 + xAdj;
bullet.y = this.y - 18 + yAdj;
var proj:Projectile = (FP.world.add(copy(bullet)) as Projectile);
proj.shoot(ma);
}
override public function update():void
{
ma = FP.angle(this.x, this.y, world.mouseX, world.mouseY);
gfx.angle = ma;
}
public function copy(_bul:Projectile):Projectile
{
var p:Projectile = new Projectile(_bul.damage);
p.graphic = _bul.graphic;
p.x = _bul.x;
p.y = _bul.y;
p.mask = _bul.mask;
return p;
}
}
}
And here’s the projectile class:
package
{
import net.flashpunk.Entity;
import net.flashpunk.FP;
/**
* ...
* @author David Williams
*/
public class Projectile extends Entity
{
public var damage:Number;
private var angle:Number;
private var xConst:Number = 0;
private var yConst:Number = 0;
public function Projectile(_dam:Number = 1)
{
damage = _dam;
type = "projectile";
}
public function shoot(ang:Number):void
{
angle = -ang + 90;
yConst = 5 * Math.cos(angle * Math.PI / 180);
xConst = 5 * Math.sin(angle * Math.PI / 180);
}
override public function update():void
{
y -= yConst;
x += xConst;
if (x < 0 || x > 640 || y < 0 || y > 480 || collide("platform", this.x, this.y)) world.remove(this);
}
}
}
Never had anything like this happen before. [1]: https://dl.dropboxusercontent.com/u/31366539/FPstuff/TestingEnviro.swf “Here you can see what’s goin on.”