This repository was archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathenergyBall.ts
More file actions
65 lines (56 loc) · 1.58 KB
/
energyBall.ts
File metadata and controls
65 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {Graphics, Rectangle, Point} from 'pixi.js';
import {IEntity, teamType} from '../types';
import {ITimeEvent} from '../game-loop';
import {config} from '../../config';
import {
normalizeVector,
isOutOfBOunds,
wallCollision,
enemyCollision
} from '../functional';
import {Unit} from './unit';
export class EnergyBall extends Unit {
get type() { return 'energyBall'; }
get team(): teamType { return 'robot'; }
private _speed: Point;
private _config: any;
get hitbox() { return this.body; }
_initBody() {
return new Rectangle(0, 0, this._config.size, this._config.size);
}
_initView() {
return new Graphics()
.beginFill(0xFFFFFF)
.drawCircle( 0, 0, this._config.size / 2);
}
_preInit() {
this._config = Object.assign(config.entities.energyBall);
}
update(time: ITimeEvent) {
let enemy = enemyCollision(this._game.currentMap, this);
if (
isOutOfBOunds(this._game.currentMap, this.body) ||
wallCollision(this._game.currentMap, this.body) ||
enemy !== null
) {
if (enemy) {
enemy.hit(this._config.damage);
}
this.destroy();
} else if (this._speed) {
this.position = new Point(
this.position.x + this._speed.x,
this.position.y + this._speed.y,
);
}
}
setTarget(targetPosition: Point) {
let position = this.position;
this._speed = normalizeVector(
targetPosition.x - position.x,
targetPosition.y - position.y
);
this._speed.x = this._speed.x * this._config.speed;
this._speed.y = this._speed.y * this._config.speed;
}
}