Parameritized projectile parabola
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { LayeredTileFactory } from './layered_tile_factory.js';
|
||||
import { TileFactory } from './tile_factory.js';
|
||||
export class ProjectileTileFactory extends TileFactory {
|
||||
constructor(tile_factory) {
|
||||
constructor(tile_factory, target_relative_x, target_relative_y, spin, speed) {
|
||||
super(tile_factory.layer_name, tile_factory.width, tile_factory.height);
|
||||
this.source_tile_factory = tile_factory;
|
||||
this.target_relative_x = target_relative_x;
|
||||
this.target_relative_y = target_relative_y;
|
||||
this.spin = spin;
|
||||
this.speed = speed;
|
||||
const copy = tile_factory.copy();
|
||||
const distance = Math.sqrt(target_relative_x ** 2 + target_relative_y ** 2);
|
||||
copy.add_animation('launch-x', [
|
||||
{
|
||||
'offset': 0.0,
|
||||
@@ -14,11 +19,11 @@ export class ProjectileTileFactory extends TileFactory {
|
||||
},
|
||||
{
|
||||
'offset': 1.0,
|
||||
'left': '1000%',
|
||||
'transform': 'rotate(720deg)',
|
||||
'left': `${target_relative_x / tile_factory.width * 100}%`,
|
||||
'transform': `rotate(${Math.sign(target_relative_x) * distance * spin * 10}deg)`,
|
||||
},
|
||||
], {
|
||||
'duration': 1500,
|
||||
'duration': distance * (1 / speed) * 100,
|
||||
'iterations': 1,
|
||||
});
|
||||
copy.add_animation('launch-y', [
|
||||
@@ -30,14 +35,14 @@ export class ProjectileTileFactory extends TileFactory {
|
||||
{
|
||||
'offset': 0.50,
|
||||
'easing': 'cubic-bezier(0.33, 0.00, 0.66, 0.33)',
|
||||
'top': '-500%',
|
||||
'top': `-500%`,
|
||||
},
|
||||
{
|
||||
'offset': 1.0,
|
||||
'top': '0',
|
||||
'top': `${target_relative_y / tile_factory.height * 100}%`,
|
||||
},
|
||||
], {
|
||||
'duration': 1500,
|
||||
'duration': distance * (1 / speed) * 100,
|
||||
'iterations': 1,
|
||||
});
|
||||
this.tile_factory = new LayeredTileFactory([copy]);
|
||||
@@ -49,7 +54,7 @@ export class ProjectileTileFactory extends TileFactory {
|
||||
return tile;
|
||||
}
|
||||
copy() {
|
||||
return new ProjectileTileFactory(this.source_tile_factory);
|
||||
return new ProjectileTileFactory(this.source_tile_factory, this.target_relative_x, this.target_relative_y, this.spin, this.speed);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=projectile_tile_factory.js.map
|
||||
Reference in New Issue
Block a user