Package Hexel.things.types

Source Code of Hexel.things.types.Deer

package Hexel.things.types;

import java.util.ArrayList;
import java.util.Random;

import javax.media.opengl.GL2;

import Hexel.Hexel;
import Hexel.blocks.types.Block;
import Hexel.blocks.types.BlockEmpty;
import Hexel.blocks.types.BlockTransparent;
import Hexel.math.Vector3d;
import Hexel.math.Vector3i;
import Hexel.rendering.Color;
import Hexel.rendering.GLObj;
import Hexel.rendering.Renderable;
import Hexel.things.ThingBridge;

public class Deer extends Humanoid implements Renderable, Healthful {

  /**
   *
   */
  private static final long serialVersionUID = -5747967960454262507L;

  private static GLObj obj = new GLObj(Hexel.class.getResourceAsStream("/deer.obj"), new Color(186/255., 135/255., 89/255., 1));
  private static GLObj objHurt = new GLObj(Hexel.class.getResourceAsStream("/deer.obj"), new Color(1, 0, 0, 1));

  public Deer(double x, double y, double z, ThingBridge thingBridge) {
    super(x, y, z);
    this.thingBridge = thingBridge;
  }

  private Vector3d playerXYZ = new Vector3d();
  public int step = 0;
  private double dir = 0;

  public double health = 1;
  public int lastHurt = 0;

  public double getHealth(){ return health; }

  public void step(){
    thingBridge.getPlayerXYZ(playerXYZ);
    double dx = this.x - playerXYZ.x;
    double dy = this.y - playerXYZ.y;
    double dz = this.z - playerXYZ.z;
    if (step % (60*3) == 0 || step - this.lastHurt < 100){
      double speed = 1;
      if (step - this.lastHurt < 100){
        dir = Math.atan2(dy,dx);
        speed = 4;
      }
      else {
        dir = Math.random()*2*Math.PI;
        if (Math.random() < .2)
          speed = 0;
      }
      this.setMovement(dir, speed);
    }
    if (step % (60*1) == 0)
      this.jump(4.0);
    step++;
  }

  @Override
  public void render(GL2 gl) {
    GLObj obj = Deer.obj;
    if (step - lastHurt < 10){
      obj = Deer.objHurt;
    }
    if (obj.buffer == null){
      obj.initBuffer(gl);
    }
    gl.glPushMatrix();
    gl.glTranslated((float)x+xlen/2, (float)y+ylen/2, (float)z);
    gl.glScaled(.5, .5, .5);
    gl.glRotated(this.dir*180/Math.PI, 0, 0, 1);
    gl.glRotated(90, 1, 0, 0);
    obj.render(gl);
    gl.glPopMatrix();
  }

}
TOP

Related Classes of Hexel.things.types.Deer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.