add enemy
This commit is contained in:
parent
276e11fb49
commit
edd005cb4d
7 changed files with 137 additions and 10 deletions
|
@ -10,13 +10,19 @@ class Entity {
|
|||
let ent = this;
|
||||
let { width, height } = game;
|
||||
|
||||
let bounced = false;
|
||||
|
||||
if (Math.abs(ent.pos.x) >= width / 2) {
|
||||
ent.vel.x = (Math.abs(ent.vel.x) + 10) * -Math.sign(ent.pos.x);
|
||||
bounced = true;
|
||||
}
|
||||
|
||||
if (Math.abs(ent.pos.y) >= height / 2) {
|
||||
ent.vel.y = (Math.abs(ent.vel.y) + 10) * -Math.sign(ent.pos.y);
|
||||
bounced = true;
|
||||
}
|
||||
|
||||
return bounced;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,11 @@ class Player extends Entity {
|
|||
ent.isMenu = true;
|
||||
ent.rot = 1.2;
|
||||
}
|
||||
|
||||
if (target.type == 'Shooter') {
|
||||
this.health = 0;
|
||||
}
|
||||
|
||||
if (target.immortal) continue;
|
||||
|
||||
let oldHealth = target.health
|
||||
|
|
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