I'm coding a space shooter on three.js (WebGL) and since the game I'm doing is rather simple, plus I want to keep controll of the structure, I'm not using a game engine.
I'm using oop classes and inheritance to optimize code reusability and maintenability.
The classes so far look like the following :
MovingObject, the base class possessing the attributes : position, speed, weapon, mesh, etc.
Asteroid, inheriting MovingObject
PlayerShip, inheriting MovingObject
Weapons, Base class of other weapons, possessiong the class shoot, that every other inheriting class redefines in order to shoot the projectile it wants at the position and frquency it wants
MovingSystem, Base class of other moving classes, possessing the function update(inputs,time) that move the MovingObject according to the class behaviour
What I'm searchign is a common architecture / data-model of how an AI controlling an enemy space ship should look like.
So far I've only found algorithms of A* search, a following / escaping path search, etc.
However I don't need the logic code, I want the structure of HOW and WHERE to execute the AI. (If possible in an oop model, so there can be inheritances with slight variations)
I'll post an example of code here, so you see how the code actually use the different classes and inhertance :
//MovingObject class
MovingObject.prototype.update = function(time, inputs)
{
this.lastPos = this.mesh.position.clone();
//console.log("this: ",this);
//console.log("inputs: ", inputs);
this.movingSys.move(this, time, inputs);
this.particularUpdateFunctions(time);
};
//PlayerShip class
function PlayerShip(MAX_SPEED, speed, COEFF_ACCEL, mesh)
{
this.particularUpdateFunctions = function(time){
this.weapons[this.currentWeap].update(this,time, this.shooting);
};
}