-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoe.js
More file actions
40 lines (38 loc) · 1.2 KB
/
aoe.js
File metadata and controls
40 lines (38 loc) · 1.2 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
import {Component, System} from "./engine.js";
export class AOEComponent extends Component{
constructor(tag, radius, callback){
super("aoe");
this.tag = tag;
this.radius = radius;
this.callback = callback;
}
}
export class AOESystem extends System{
constructor(){
super("AoE");
// put any innitilization code here
}
update(entities, dt){
let effects = [];
for(const entity of entities){
if(entity.hasComponent("aoe")){
effects.push(entity);
}
}
for(const entity of entities){
for(const effect of effects){
if (entity == effect){
continue;
}
const aoe = effect.getComponent("aoe");
const effectTransform = effect.getComponent("transform");
if(entity.hasComponent(aoe.tag)){
const entityTransform = entity.getComponent("transform");
if(entityTransform.distanceSquared(effectTransform)<aoe.radius*aoe.radius){
aoe.callback(entity,effect,dt);
}
}
}
}
}
}