Quote:
Originally Posted by kittygirl765
Oh, this is actually a good starting place for a state machine (especially for gscript2, where making ai isn't easily done natively or ends up becoming spaghetti code)
Now I need to make an ai_execute_firing_my_lasers() function
|
PHP Code:
function ai_enter_float() {
this.ani = "idle";
this.aiPeriod = 1;
}
function ai_execute_float() {
temp.pl = this.acquireTarget(); //you can do findnearestplayers to see if there is a target
if (temp.pl != nil) {
this.ani = "alert";
changeState("attack");
return;
}
//logic here move?
this.ani = "move";
}
function ai_enter_attack() {
this.aiPeriod = 0.4 * this.attack_speed;
}
function ai_execute_attack() {
temp.target = this.acquireTarget();
if (temp.target == nil) {
changeState("float");
return;
}
attack(temp.target);
}
function attack(temp.target) {
temp.pos_x = this.x + 0.5 + vecx( this.dir ) * 1.5;
temp.pos_y = this.y - 1 + vecy( this.dir ) * 1.5;
temp.angle = getangle( temp.target.x - temp.pos_x, temp.target.y - temp.pos_y );
temp.speed = 1;
setshootparams( this, temp.dmg, params);
shoot(
temp.pos_x, temp.pos_y, 0,
temp.angle, 0.1, temp.speed,
this.ani_arrow, null
);
}
function acquireTarget() {
// Add aggro to players near entity
temp.targets = findnearestplayers(this.x, this.y);
return temp.targets[0];
}