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.chunk.Chunk;
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 Zombie extends Humanoid implements Renderable, Healthful {
/**
*
*/
private static final long serialVersionUID = -5747967960454262507L;
private static GLObj obj = new GLObj(Hexel.class.getResourceAsStream("/zombie.obj"), new Color(1, 1, 1, 1));
private static GLObj objHurt = new GLObj(Hexel.class.getResourceAsStream("/zombie.obj"), new Color(1, 0, 0, 1));
public Zombie(double x, double y, double z, ThingBridge thingBridge) {
super(x, y, z);
this.thingBridge = thingBridge;
}
private Vector3d playerXYZ = new Vector3d();
private int step = 0;
private double dir = 0;
public double health = 1;
public int hurt = 10;
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 (Math.sqrt(dx*dx+dy*dy+dz*dz) < 1)
thingBridge.damagePlayerHealth(.01);
if (step % 10 == 0){
this.dir = 0;
double speed = 2;
this.dir = Math.atan2(-dy,-dx);
this.dir += new Random().nextGaussian()/10.0;
this.setMovement(this.dir, speed);
}
if (step %10 == 0)
this.jump(4.0);
if (step % (60) == 0){
ArrayList<Vector3i> blocksIntersectingThing = thingBridge.thingTools.getBlocksIntersectingThing(this, thingBridge.fixOffsetTmps);
Vector3i tmp = new Vector3i();
if (thingBridge.engine.getAmbientLight() > .75){
for (Vector3i v : blocksIntersectingThing){
Block b = thingBridge.engine.chunks.getBlock(v.x, v.y, v.z, tmp, (Chunk)null);
if (b instanceof BlockEmpty){
BlockEmpty be = (BlockEmpty)b;
double lightLevel = thingBridge.engine.getAmbientLight() - be.naturalLightLevel*1.0/BlockTransparent.MAX_LIGHT_LEVEL;
if (lightLevel > .9){
this.health -= .1;
this.hurt = 10;
break;
}
}
}
}
}
step++;
}
@Override
public void render(GL2 gl) {
GLObj obj = Zombie.obj;
if (this.hurt > 0){
obj = Zombie.objHurt;
this.hurt -= 1;
}
if (obj.buffer == null){
obj.initBuffer(gl);
}
gl.glPushMatrix();
gl.glTranslated((float)x+xlen/2, (float)y+ylen/2, (float)z);
gl.glScaled(1, 1, 1);
gl.glRotated(this.dir*180/Math.PI, 0, 0, 1);
gl.glRotated(90, 1, 0, 0);
obj.render(gl);
gl.glPopMatrix();
}
}