prosperon/scripts/ai.js

64 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-27 14:29:55 -06:00
var AI = {
race(list) {
2023-11-27 17:04:04 -06:00
return function(dt) {
2023-11-27 14:29:55 -06:00
var good = false;
2023-11-27 17:04:04 -06:00
list.forEach(function(x) { if (x.call(this,dt)) good = true; }, this);
2023-11-27 14:29:55 -06:00
return good;
};
},
do(times, list) {
},
2023-11-27 17:04:04 -06:00
sequence(list) {
var i = 0;
return function(dt) {
while (i !== list.length) {
if (list[i].call(this,dt))
i++;
else
return false;
}
return true;
};
},
parallel(list) {
return function(dt) {
2023-11-27 14:29:55 -06:00
var good = true;
2023-11-27 17:04:04 -06:00
list.forEach(function(x){ if (!x.call(this,dt)) good = false; },this);
2023-11-27 14:29:55 -06:00
return good;
};
},
2023-11-27 17:04:04 -06:00
moveto() {
return function(dt) {
var dir = this.randomloc.sub(this.pos);
2023-11-27 14:29:55 -06:00
if (Vector.length(dir) < 10) return true;
2023-11-27 17:04:04 -06:00
this.velocity = Vector.norm(this.randomloc.sub(this.pos)).scale(20);
2023-11-27 14:29:55 -06:00
return false;
}
},
2023-11-29 07:32:32 -06:00
move() {
return function(dt) {
this.velocity = this.left().scale(20);
return false;
}
},
2023-11-27 14:29:55 -06:00
wait(secs) {
secs ??= 1;
var accum = 0;
2023-11-27 17:04:04 -06:00
return function(dt) {
accum += dt;
2023-11-27 14:29:55 -06:00
if (accum >= secs)
return true;
return false;
};
},
};