Package MineGod

Source Code of MineGod.EntityWater

package MineGod;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.geom.Rectangle;

public class EntityWater extends Entity{
  public double durability;
  public double maxDurability;
  public double y;
  public static double posYSpeed = .15;
  public static double posXSpeed = .15;
  public double xSpeed;
  public double ySpeed;
 
  public EntityWater(double xMove, double yMove, double x, double y, double dur){
    durability = dur;
    maxDurability = 1;
    this.x = x;
    this.y = y;
    this.zIndex = 1;
    dead = false;
   
    xSpeed = posXSpeed*xMove;
    ySpeed = posYSpeed*yMove;
   
    mask = new Rectangle((float)(x), (float)(y), (float)BlockSand.WIDTH, (float)BlockSand.WIDTH);
  }
  @Override
  public void interactWithPlayerOnCollision(Player player) {
    player.setOnFireZero();
  }

  @Override
  public void doLogic(int delta, Chunk prevChunk, Chunk currChunk, Chunk nextChunk) {
    // TODO Auto-generated method stub
   
    //System.out.println("HERE: "+x + "," +y);
   
    //Change current block to block water
    Block b = new BlockWater();
    b.durability = durability;
    Utils.changeCurrentBlock(b, x, y);
   
    int moveX = 0;
    int moveY = 0;
   
    if (ySpeed != 0){
      moveY = 1;
    }
    if (xSpeed < 0){
      moveX = -1;
    }else if (xSpeed > 0){
      moveX = 1;
    }
    if (moveY==0){
      Block b3 = Utils.pointToBlock(x, y+Block.WIDTH);
      if (b3!=null && b3.type == BlockType.air){
        dead = true;
        Utils.delayAddEntity(new EntityWater(0,1,x - (x%Block.WIDTH),y - (y%Block.WIDTH),durability));
        return;
      }
    }
    Block b2 = Utils.pointToBlock(x+Block.WIDTH*moveX, y+Block.WIDTH*moveY);
    if (b2==null || (b2.type != BlockType.air && !(b2.type == BlockType.water && moveY==0))){
        dead = true;
       
        //Spawn Water entity(s) in correct direction(s)
        if (moveY != 0){
          //Check left and right, and if possible spawn in that direction.
          b2 = Utils.pointToBlock(x+Block.WIDTH, y);
          if (b2!=null && (b2.type == BlockType.air || b2.type == BlockType.water)){
            Utils.delayAddEntity(new EntityWater(1,0,x - (x%Block.WIDTH),y - (y%Block.WIDTH),durability));
          }
          b2 = Utils.pointToBlock(x-Block.WIDTH, y);
          if (b2!=null && (b2.type == BlockType.air || b2.type == BlockType.water)){
            Utils.delayAddEntity(new EntityWater(-1,0,x - (x%Block.WIDTH),y - (y%Block.WIDTH),durability));
          }
         
        }else{
          //Check below, and if possible spawn in that direction
          b2 = Utils.pointToBlock(x, y+Block.WIDTH);
          if (b2!=null && b2.type == BlockType.air){
            Utils.delayAddEntity(new EntityWater(0,1,x - (x%Block.WIDTH),y - (y%Block.WIDTH),durability));
          }
         
        }
    }
    y = y+ySpeed*delta;
    x = x+xSpeed*delta;
    mask = new Rectangle((float)(x), (float)(y), (float)BlockWater.WIDTH, (float)BlockWater.WIDTH);
   
   
  }

  @Override
  public void render(double worldPos) {
    if (!(x+Block.WIDTH-worldPos<0 || x-Block.WIDTH-worldPos>Chunk.CHUNK_WIDTH*Block.WIDTH)){
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
      BlockWater.waterTex.bind();
      double renderX = x - worldPos;
      GL11.glColor3d((durability)/maxDurability, (durability)/maxDurability, (durability)/maxDurability); // Could make this faster!!
      GL11.glBegin(GL11.GL_QUADS);
        GL11.glNormal3d(0, 0, 1);
        GL11.glTexCoord2d(0.0, 0.0);
        GL11.glVertex3d(renderX, y, zIndex);
        GL11.glTexCoord2d(1.0, 0.0);
        GL11.glVertex3d(renderX + BlockSand.WIDTH, y, zIndex);
        GL11.glTexCoord2d(1.0, 1.0);
        GL11.glVertex3d(renderX + BlockSand.WIDTH, y + BlockSand.WIDTH, zIndex);
        GL11.glTexCoord2d(0.0, 1.0);
        GL11.glVertex3d(renderX, y + BlockSand.WIDTH, zIndex);
      GL11.glEnd();
    }
  }

}
TOP

Related Classes of MineGod.EntityWater

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.