feat: add poc
This commit is contained in:
parent
43d27b04d9
commit
4a4fa05ce4
53 changed files with 6191 additions and 0 deletions
52
src/components/AI.js
Normal file
52
src/components/AI.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { Component } from '../core/Component.js';
|
||||
|
||||
export class AI extends Component {
|
||||
constructor(behaviorType = 'wander') {
|
||||
super('AI');
|
||||
this.behaviorType = behaviorType; // 'wander', 'patrol', 'chase', 'flee', 'combat'
|
||||
this.state = 'idle'; // 'idle', 'moving', 'attacking', 'fleeing'
|
||||
this.target = null; // Entity ID to target
|
||||
this.awareness = 0; // 0-1, how aware of player
|
||||
this.alertRadius = 150;
|
||||
this.chaseRadius = 300;
|
||||
this.fleeRadius = 100;
|
||||
|
||||
// Behavior parameters
|
||||
this.wanderSpeed = 50;
|
||||
this.wanderDirection = Math.random() * Math.PI * 2;
|
||||
this.wanderChangeTime = 0;
|
||||
this.wanderChangeInterval = 2.0; // seconds
|
||||
}
|
||||
|
||||
/**
|
||||
* Set behavior type
|
||||
*/
|
||||
setBehavior(type) {
|
||||
this.behaviorType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set target entity
|
||||
*/
|
||||
setTarget(entityId) {
|
||||
this.target = entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear target
|
||||
*/
|
||||
clearTarget() {
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update awareness
|
||||
*/
|
||||
updateAwareness(delta, maxAwareness = 1.0) {
|
||||
this.awareness = Math.min(maxAwareness, this.awareness + delta);
|
||||
if (this.awareness <= 0) {
|
||||
this.awareness = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue