unibutton/common/shooter.js

38 lines
801 B
JavaScript
Raw Normal View History

2024-10-18 19:43:40 -04:00
import { distF, uuidv4 } from './util.js'
import Entity from "./entity.js";
class Shooter extends Entity {
constructor(you, game = false) {
super(game);
this.you = you || uuidv4();
this.type = 'Shooter';
this.immortal = true;
this.serverProps = [
'type', 'pos', 'vel', 'you', 'immortal', 'dir'
];
this.dir = Math.random() * 696969;
}
handleTick(game) {
this.ticks++;
this.vel.x += Math.sin(this.dir) * 1;
this.vel.y += Math.cos(this.dir) * 1;
this.vel.x *= 0.9;
this.vel.y *= 0.9;
this.pos.x += this.vel.x;
this.pos.y += this.vel.y;
if (this.bounce(game)) {
this.dir = Math.random() * 696969;
}
}
}
export default Shooter;