Package Hexel.generation.terrainGenerator

Source Code of Hexel.generation.terrainGenerator.ForestTerrainMap

package Hexel.generation.terrainGenerator;

import java.util.Random;

import Hexel.blocks.types.Block;
import Hexel.blocks.types.BlockDirt;
import Hexel.blocks.types.BlockEmpty;
import Hexel.blocks.types.BlockSeed;
import Hexel.blocks.types.BlockWater;
import Hexel.generation.terrainGenerator.heightMaps.FractalHexagonalHeightMap;
import Hexel.generation.terrainGenerator.heightMaps.FractalHeightMapGenerator;
import Hexel.generation.terrainGenerator.heightMaps.WaterHeightMap;
import Hexel.math.Vector2i;
import Hexel.util.Util;

public class ForestTerrainMap implements TerrainMap {
 
  private FractalHexagonalHeightMap hm;
  private WaterHeightMap whm;
 
  private int seed;
 
  private Random random = new Random();
 
  public ForestTerrainMap(int seed){
    this.hm = new FractalHexagonalHeightMap(seed);
    this.whm = new WaterHeightMap(seed, this.hm);
    this.seed = seed;
  }
 
  public int getHeightMapAt(int x, int y, Vector2i tmp){
    return this.hm.getHeight(x, y, tmp);
  }

  @Override
  public Block getBlock(int x, int y, int z, Vector2i tmp) {
   
    int height = this.hm.getHeight(x, y, tmp);
    int waterLevel = this.whm.getHeight(x, y, tmp);
    if (z < height){
      return BlockDirt.Make(BlockDirt.MAX_HEALTH, false);
    }
    else if (z == height){
      return BlockDirt.Make(BlockDirt.MAX_HEALTH, true);
    }
    else if (z <= waterLevel){
      return BlockWater.Make(0, 0, 8);
    }
    else if (z == height+1){
      int hash = 3;
      hash = 97 * hash + x;
      hash = 97 * hash + y;
      hash = 97 * hash + z;
      if (Util.hashToDouble(hash+this.seed) < .025 ) {
        return BlockSeed.Make(50, BlockSeed.MAX_HEALTH);
      }
      else {
        return BlockEmpty.Make(0);
      }
    }
    else {
      return BlockEmpty.Make(0);
    }
  }

}
TOP

Related Classes of Hexel.generation.terrainGenerator.ForestTerrainMap

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.