add enemy
This commit is contained in:
parent
276e11fb49
commit
edd005cb4d
7 changed files with 137 additions and 10 deletions
38
common/shooter.js
Normal file
38
common/shooter.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
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;
|
Loading…
Add table
Add a link
Reference in a new issue