Only auto aim and healthbars
This commit is contained in:
1 parent
54c6327ac7
commit
a914bd74fe
14 files changed
+95
-89
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import { GameObject } from '../engine/GameObject.js';
|
||||
import { Vector2D } from '../engine/Vector2D.js';
|
||||
import { Bullet } from './Bullet.js';
|
||||
import { Zombie } from './Zombie.js';
|
||||
|
||||
export class Player extends GameObject {
|
||||
constructor(
|
||||
@@ -23,7 +22,6 @@ export class Player extends GameObject {
|
||||
particles = null,
|
||||
sounds = null,
|
||||
size = 24,
|
||||
autoAim = false,
|
||||
} = {},
|
||||
) {
|
||||
super(viewport.width / 2, viewport.height / 2);
|
||||
@@ -51,7 +49,6 @@ export class Player extends GameObject {
|
||||
this._recoil = new Vector2D(0, 0);
|
||||
this._damageCooldown = 0;
|
||||
this._time = 0;
|
||||
this.autoAim = autoAim;
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
@@ -81,15 +78,6 @@ export class Player extends GameObject {
|
||||
this.pos.y = Math.min(Math.max(this.pos.y, maxY), height - maxY);
|
||||
|
||||
let aim = this.input.mouse.subV(this.pos);
|
||||
if (this.autoAim) {
|
||||
const nearest = this._nearestZombie();
|
||||
if (nearest) {
|
||||
const toEnemy = nearest.pos.subV(this.pos);
|
||||
if (toEnemy.lengthSqrt() > 1) {
|
||||
aim = toEnemy;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (aim.lengthSqrt() > 1) {
|
||||
this._aimDirection = aim.divS(aim.length());
|
||||
}
|
||||
@@ -104,21 +92,6 @@ export class Player extends GameObject {
|
||||
}
|
||||
}
|
||||
|
||||
_nearestZombie() {
|
||||
let best = null;
|
||||
let bestDistSq = Infinity;
|
||||
for (const obj of this.container || []) {
|
||||
if (!(obj instanceof Zombie)) continue;
|
||||
const delta = obj.pos.subV(this.pos);
|
||||
const distSq = delta.lengthSqrt();
|
||||
if (distSq < bestDistSq) {
|
||||
bestDistSq = distSq;
|
||||
best = obj;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
shoot() {
|
||||
const aimAngle = Math.atan2(this._aimDirection.y, this._aimDirection.x);
|
||||
this._recoil = this._aimDirection.mulS(-this.recoilSpeed);
|
||||
|
||||
Reference in new issue
Block a user