export default class SeniorBarrage extends BaseBarrage {
constructor(seniorBarrageOptions: SeniorBarrageOptions, barrageRenderer: BarrageRenderer) {
this.calcActualLocation();
}
/**
* Calculate the actual coordinates of key points
*/
calcActualLocation() {
const { startLocation, endLocation, motionDuration } = this.seniorBarrageConfig;
// Calculate the position of the actual starting point
// Calculate actualStartLocation
let actualStartLocationX = (startLocation.type || 'PIXEL') === 'PIXEL' ? startLocation.x : startLocation.x * this.canvasSize.width;
let actualStartLocationY = (startLocation.type || 'PIXEL') === 'PIXEL' ? startLocation.y : startLocation.y * this.canvasSize.height;
if (startLocation.offsetX) actualStartLocationX += startLocation.offsetX;
if (startLocation.offsetY) actualStartLocationY += startLocation.offsetY;
this.actualStartLocation = {
x: actualStartLocationX,
y: actualStartLocationY
};
// Calculate actualEndLocation
let actualEndLocationX = (endLocation.type || 'PIXEL') === 'PIXEL' ? endLocation.x : endLocation.x * this.canvasSize.width;
let actualEndLocationY = (endLocation.type || 'PIXEL') === 'PIXEL' ? endLocation.y : endLocation.y * this.canvasSize.height;
if (endLocation.offsetX) actualEndLocationX += endLocation.offsetX;
if (endLocation.offsetY) actualEndLocationY += endLocation.offsetY;
this.actualEndLocation = {
x: actualEndLocationX,
y: actualEndLocationY
};
// Calculate vx and vy based on the actual starting point
this.vx = (this.actualEndLocation.x - this.actualStartLocation.x) / motionDuration;
this.vy = (this.actualEndLocation.y - this.actualStartLocation.y) / motionDuration;
}
}