子弹发射地方应该是从坦克面向的方向且炮口发出的。
这里需要微调子弹x,y的坐标。因为graphics默认左上角.
TankWar.prototype.fire = function () {
const { upIsDown, leftIsDown, downIsDown, rightIsDown } =
this.direction;
const { vx, vy } = defaultSpeed;
const {x,y,width,height} = this.player;
const gunX = x+width;
const gunY = y+height;
if ((this.gun.children.length === 0 && this.gun.children < 2) ) {
const graphics = new PIXI.Graphics();
graphics.beginFill(0xffffff);
graphics.drawRect(0, 0, 3, 3);
graphics.endFill();
this.gun.addChild(graphics);
if (!upIsDown) {
console.log(graphics);
graphics.vx = 0;
graphics.vy = 4;
graphics.x = gunX - width/2 - 2;
graphics.y = gunY;
}
else if (!leftIsDown){
graphics.vx = 4;
graphics.vy = 0;
graphics.x = gunX;
graphics.y = gunY - height/2 - 2;
}
else if(!rightIsDown){
graphics.vx = -4;
graphics.vy = 0;
graphics.x = gunX - width - 2;
graphics.y = gunY - height/2 - 2;
}
else if(!downIsDown){
graphics.vx = 0;
graphics.vy = -4;
graphics.x = gunX - width/2 - 3;
graphics.y = gunY - height - 2;
}
}
};