package alive;

/**
 * <ALIVE Project>
 * Experiment 2 Food agent
 * Food is an animated agent, just falls down and
 * vanishes
 */

import javax.vecmath.*;
import javax.media.j3d.*;

public class xp2_Food extends Agent {

// ----------------------------- Constructors ------------------------------
  public xp2_Food(Environment env) {  // Environment Contructor
    super.configureToEnvironment(env); // Update references
    // Init vectors & parameters
    param = new double[2];
    paramName = new String[2];
    set(0, "energy", rnd(2,8));
    set(1, "fallspeed", rnd(.005,.025));
    color.set(.2f,.1f,.0f);
    position.set(rnd(env.config.xMin,env.config.xMax), env.config.yMax,
                 rnd(env.config.zMin,env.config.zMax));
    speed = generateRandomVector(); speed.scale(.01);
    System.out.print("."); // "Agent Created" char code
    super.makeAlive();
  }

// --------------------------- Overrided methods ----------------------------
  public void behavior() { //  ***  Main Cycle, evaluate common agent functions
    position.set(position.x,position.y-1*param[1],position.z);
    if (position.y<env.config.yMin+.1) die();
  }

  public Actor createActor() {
    return new Actor_Sphere();
  }

  public void updateActor() {
    actor.set(position,direction,.2*Math.pow(3*get("energy")/12.57, 1/3.0));
  }
}
