Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.URL;
- import java.util.HashMap;
- import java.util.Vector;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import jmetest.TutorialGuide.HelloKeyInput;
- import jmetest.flagrushtut.lesson5.FlagRushHandler;
- import com.jme.app.BaseGame;
- import com.jme.app.SimpleGame;
- import com.jme.bounding.BoundingBox;
- import com.jme.image.Texture;
- import com.jme.input.AbsoluteMouse;
- import com.jme.input.ChaseCamera;
- import com.jme.input.FirstPersonHandler;
- import com.jme.input.InputHandler;
- import com.jme.input.KeyBindingManager;
- import com.jme.input.KeyInput;
- import com.jme.input.MouseInput;
- import com.jme.input.joystick.JoystickInput;
- import com.jme.input.thirdperson.ThirdPersonMouseLook;
- import com.jme.intersection.PickResults;
- import com.jme.light.PointLight;
- import com.jme.math.FastMath;
- import com.jme.math.Vector3f;
- import com.jme.renderer.Camera;
- import com.jme.renderer.ColorRGBA;
- import com.jme.renderer.Renderer;
- import com.jme.scene.Node;
- import com.jme.scene.Skybox;
- import com.jme.scene.Spatial;
- import com.jme.scene.Text;
- import com.jme.scene.Spatial.TextureCombineMode;
- import com.jme.scene.shape.Box;
- import com.jme.scene.shape.Box2;
- import com.jme.scene.state.BlendState;
- import com.jme.scene.state.CullState;
- import com.jme.scene.state.LightState;
- import com.jme.scene.state.TextureState;
- import com.jme.scene.state.WireframeState;
- import com.jme.scene.state.ZBufferState;
- import com.jme.system.DisplaySystem;
- import com.jme.system.JmeException;
- import com.jme.util.TextureManager;
- import com.jme.util.Timer;
- import com.jme.util.geom.Debugger;
- import com.jme.util.resource.ResourceLocatorTool;
- import com.jme.util.resource.SimpleResourceLocator;
- /**
- * Started Date: Jul 29, 2004<br>
- * <br>
- *
- * Is used to demonstrate the inner workings of SimpleGame.
- *
- * @author Jack Lindamood
- */
- public class World2 extends BaseGame {
- private static final Logger logger = Logger.getLogger(World2.class
- .getName());
- static int world[][][] = new int [256][256][52];
- static Box2 Boxes[][][] = new Box2 [256][256][52]; // de wereld is 256x256x52 blokjes groot, lucht neemt ook een blokje in
- AbsoluteMouse am;
- PickResults pr;
- Skybox sb;
- Vector<Point> Water = new Vector<Point>();
- Box2 box;
- Node player;
- static Node Ai;
- int counter = 0;
- double r = 0;
- Vector<Box2> boxes= new Vector<Box2>();
- float angle = 0;
- ChaseCamera chaser;
- Node scene= new Node("scene");
- Point oldpos = new Point (7,2,7);
- Point pos2 = new Point(8,3,8);
- //maak 3d array van wereld aan
- //vul elk element met een of geen blokje
- //render elk element
- //startgame
- public static void main(String[] args) {
- World2 app = new World2();
- app.setConfigShowMode(ConfigShowMode.AlwaysShow);
- app.start();
- }
- /** The camera that we see through. */
- protected Camera cam;
- /** The root of our normal scene graph. */
- protected static Node rootNode;
- /** Handles our mouse/keyboard input. */
- protected InputHandler input;
- /** High resolution timer for jME. */
- protected static Timer timer;
- /** The root node of our text. */
- protected Node fpsNode;
- /** Displays all the lovely information at the bottom. */
- protected Text fps;
- /** Simply an easy way to get at timer.getTimePerFrame(). */
- protected static float tpf;
- /** True if the renderer should display bounds. */
- protected boolean showBounds = false;
- /** A wirestate to turn on and off for the rootNode */
- protected WireframeState wireState;
- /** A lightstate to turn on and off for the rootNode */
- protected LightState lightState;
- /** Location of the font for jME's text at the bottom */
- public static String fontLocation = "com/jme/app/defaultfont.tga";
- /**
- * This is called every frame in BaseGame.start()
- *
- * @param interpolation
- * unused in this implementation
- * @see com.jme.app.AbstractGame#update(float interpolation)
- */
- protected final void update(float interpolation) {
- //Aireload(Ai.getLocalTranslation(), counter);
- /** Recalculate the framerate. */
- timer.update();
- /** Update tpf to time per frame according to the Timer. */
- tpf = timer.getTimePerFrame();
- /** Check for key/mouse updates. */
- input.update(tpf);
- /** Send the fps to our fps bar at the bottom. */
- fps.print("FPS: " + (int) timer.getFrameRate());
- /** Call simpleUpdate in any derived classes of SimpleGame. */
- simpleUpdate();
- /** Update controllers/render states/transforms/bounds for rootNode. */
- rootNode.updateGeometricState(tpf, true);
- /** If toggle_wire is a valid command (via key T), change wirestates. */
- if (KeyBindingManager.getKeyBindingManager().isValidCommand(
- "toggle_wire", false)) {
- wireState.setEnabled(!wireState.isEnabled());
- rootNode.updateRenderState();
- }
- /** If toggle_lights is a valid command (via key L), change lightstate. */
- if (KeyBindingManager.getKeyBindingManager().isValidCommand(
- "toggle_lights", false)) {
- lightState.setEnabled(!lightState.isEnabled());
- rootNode.updateRenderState();
- }
- /** If toggle_bounds is a valid command (via key B), change bounds. */
- if (KeyBindingManager.getKeyBindingManager().isValidCommand(
- "toggle_bounds", false)) {
- showBounds = !showBounds;
- }
- /** If camera_out is a valid command (via key C), show camera location. */
- if (KeyBindingManager.getKeyBindingManager().isValidCommand(
- "camera_out", false)) {
- logger.info("Camera at: "
- + display.getRenderer().getCamera().getLocation());
- }
- if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit",
- false)) {
- finish();
- }
- // update the time to get the framerate
- timer.update();
- interpolation = timer.getTimePerFrame();
- //update the keyboard input (move the player around)
- input.update(interpolation);
- //update the chase camera to handle the player moving around.
- chaser.update(interpolation);
- //we want to keep the skybox around our eyes, so move it with
- //the camera
- sb.setLocalTranslation(cam.getLocation());
- // if escape was pressed, we exit
- if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
- finished = true;
- }
- //We don't want the chase camera to go below the world, so always keep
- //it 2 units above the level.
- try{
- if(cam.getLocation().y < highestBlockP(cam.getLocation().x/2, cam.getLocation().z/2, cam.getLocation().y/2) *2 +2.26) {
- cam.getLocation().y = (float) (highestBlockP(cam.getLocation().x/2, cam.getLocation().z/2, cam.getLocation().y/2) *2 +2.26);
- cam.update();
- }
- }
- catch (java.lang.ArrayIndexOutOfBoundsException e){
- }
- float xp = player.getLocalTranslation().x ;
- float zp = player.getLocalTranslation().y ;
- float yp = player.getLocalTranslation().z ;
- try{
- player.setLocalTranslation( xp, (float)(highestBlockP( xp/2, yp/2, (float) (zp/2+1.26) )*2 + 1.26), yp);
- } catch(java.lang.ArrayIndexOutOfBoundsException e) {
- if( xp < 0)
- player.setLocalTranslation( xp + 5 , zp, yp);
- else if( xp > 512 )
- player.setLocalTranslation( xp - 5 , zp, yp);
- else if( yp < 0 )
- player.setLocalTranslation( xp , zp, yp + 5);
- else if( yp > 512 )
- player.setLocalTranslation( xp , zp, yp - 5);
- }
- counter++;
- }
- /*float characterMinHeight = tb.getHeight(player
- .getLocalTranslation())+((BoundingBox)player.getWorldBound()).yExtent;
- if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
- player.getLocalTranslation().y = characterMinHeight;
- }
- //Because we are changing the scene (moving the skybox and player) we need to update
- //the graph.
- scene.updateGeometricState(interpolation, true);*/
- /**
- * This is called every frame in BaseGame.start(), after update()
- *
- * @param interpolation
- * unused in this implementation
- * @see com.jme.app.AbstractGame#render(float interpolation)
- */
- protected final void render(float interpolation) {
- /** Clears the previously rendered information. */
- display.getRenderer().clearBuffers();
- /** Draw the rootNode and all its children. */
- display.getRenderer().draw(rootNode);
- /**
- * If showing bounds, draw rootNode's bounds, and the bounds of all its
- * children.
- */
- if (showBounds)
- Debugger.drawBounds(rootNode, display.getRenderer());
- /** Draw the fps node to show the fancy information at the bottom. */
- display.getRenderer().draw(fpsNode);
- /** Call simpleRender() in any derived classes. */
- simpleRender();
- }
- /**
- * Creates display, sets up camera, and binds keys. Called in
- * BaseGame.start() directly after the dialog box.
- *
- * @see com.jme.app.AbstractGame#initSystem()
- */
- protected final void initSystem() {
- try {
- /**
- * Get a DisplaySystem acording to the renderer selected in the
- * startup box.
- */
- display = DisplaySystem.getDisplaySystem(settings.getRenderer());
- /** Create a window with the startup box's information. */
- display.createWindow(settings.getWidth(), settings.getHeight(),
- settings.getDepth(), settings.getFrequency(), settings
- .isFullscreen());
- /**
- * Create a camera specific to the DisplaySystem that works with the
- * display's width and height
- */
- cam = display.getRenderer().createCamera(display.getWidth(),
- display.getHeight());
- } catch (JmeException e) {
- /**
- * If the displaysystem can't be initialized correctly, exit
- * instantly.
- */
- logger.log(Level.SEVERE, "Could not create displaySystem", e);
- System.exit(1);
- }
- /** Set a black background. */
- display.getRenderer().setBackgroundColor(ColorRGBA.black.clone());
- /** Set up how our camera sees. */
- cam.setFrustumPerspective(45.0f, (float) display.getWidth()
- / (float) display.getHeight(), 1, 1000);
- Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
- Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
- Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
- Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
- /** Move our camera to a correct place and orientation. */
- cam.setFrame(loc, left, up, dir);
- /** Signal that we've changed our camera's location/frustum. */
- cam.update();
- /** Assign the camera to this renderer. */
- display.getRenderer().setCamera(cam);
- /** Create a basic input controller. */
- FirstPersonHandler firstPersonHandler = new FirstPersonHandler(cam);
- /** Signal to all key inputs they should work 10x faster. */
- firstPersonHandler.getKeyboardLookHandler().setActionSpeed(10f);
- firstPersonHandler.getMouseLookHandler().setActionSpeed(1f);
- input = firstPersonHandler;
- /** Get a high resolution timer for FPS updates. */
- timer = Timer.getTimer();
- /** Sets the title of our display. */
- display.setTitle("SimpleGame");
- /** Assign key T to action "toggle_wire". */
- KeyBindingManager.getKeyBindingManager().set("toggle_wire",
- KeyInput.KEY_T);
- /** Assign key L to action "toggle_lights". */
- KeyBindingManager.getKeyBindingManager().set("toggle_lights",
- KeyInput.KEY_L);
- /** Assign key B to action "toggle_bounds". */
- KeyBindingManager.getKeyBindingManager().set("toggle_bounds",
- KeyInput.KEY_B);
- /** Assign key C to action "camera_out". */
- KeyBindingManager.getKeyBindingManager().set("camera_out",
- KeyInput.KEY_C);
- KeyBindingManager.getKeyBindingManager().set("exit",
- KeyInput.KEY_ESCAPE);
- }
- /**
- * Creates rootNode, lighting, statistic text, and other basic render
- * states. Called in BaseGame.start() after initSystem().
- *
- * @see com.jme.app.AbstractGame#initGame()
- */
- protected final void initGame() {
- /** Create rootNode */
- rootNode = new Node("rootNode");
- /**
- * Create a wirestate to toggle on and off. Starts disabled with default
- * width of 1 pixel.
- */
- wireState = display.getRenderer().createWireframeState();
- wireState.setEnabled(false);
- rootNode.setRenderState(wireState);
- /**
- * Create a ZBuffer to display pixels closest to the camera above
- * farther ones.
- */
- ZBufferState buf = display.getRenderer().createZBufferState();
- buf.setEnabled(true);
- buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
- rootNode.setRenderState(buf);
- // -- FPS DISPLAY
- // First setup blend state
- /**
- * This allows correct blending of text and what is already rendered
- * below it
- */
- BlendState as1 = display.getRenderer().createBlendState();
- as1.setBlendEnabled(true);
- as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
- as1.setDestinationFunction(BlendState.DestinationFunction.One);
- as1.setTestEnabled(true);
- as1.setTestFunction(BlendState.TestFunction.GreaterThan);
- as1.setEnabled(true);
- // Now setup font texture
- TextureState font = display.getRenderer().createTextureState();
- /** The texture is loaded from fontLocation */
- font.setTexture(TextureManager.loadTexture(SimpleGame.class
- .getClassLoader().getResource(fontLocation),
- Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- font.setEnabled(true);
- // Then our font Text object.
- /** This is what will actually have the text at the bottom. */
- fps = Text.createDefaultTextLabel("FPS label", "");
- fps.setCullHint(Spatial.CullHint.Never);
- fps.setTextureCombineMode(TextureCombineMode.Replace);
- // Finally, a stand alone node (not attached to root on purpose)
- fpsNode = new Node("FPS node");
- fpsNode.attachChild(fps);
- fpsNode.setRenderState(font);
- fpsNode.setRenderState(as1);
- fpsNode.setCullHint(Spatial.CullHint.Never);
- // ---- LIGHTS
- /** Set up a basic, default light. */
- PointLight light = new PointLight();
- light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
- light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
- light.setLocation(new Vector3f(100, 100, 100));
- light.setEnabled(true);
- PointLight light2 = new PointLight();
- light2.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
- light2.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
- light2.setLocation(new Vector3f(-100, -100, 100));
- light2.setEnabled(true);
- PointLight light3 = new PointLight();
- light3.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
- light3.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
- light3.setLocation(new Vector3f(-100, 100, -100));
- light3.setEnabled(true);
- /** Attach the light to a lightState and the lightState to rootNode. */
- lightState = display.getRenderer().createLightState();
- lightState.setEnabled(true);
- lightState.attach(light);
- lightState.attach(light2);
- lightState.attach(light3);
- rootNode.setRenderState(lightState);
- /** Let derived classes initialize. */
- simpleInitGame();
- /**
- * Update geometric and rendering information for both the rootNode and
- * fpsNode.
- */
- rootNode.updateGeometricState(0.0f, true);
- rootNode.updateRenderState();
- fpsNode.updateGeometricState(0.0f, true);
- fpsNode.updateRenderState();
- }
- protected void simpleInitGame() {
- System.out.println("Building AI ");
- buildAi();
- System.out.println("Filling world ");
- fillworld(world);
- System.out.println("Adding mountains ");
- addMountains(world);
- System.out.println("Dripping water");
- addRivers();
- System.out.println("Letting it flow");
- //Flow();
- System.out.println("Making the beach");
- //beach();
- System.out.println("Adding grass ");
- //addGrass(world);
- System.out.println("Implementing mouse");
- implementMouse();
- System.out.println("Setting up skybox");
- setupSky();
- rootNode.attachChild(sb);
- System.out.println("Building player ");
- buildPlayer();
- System.out.println("Drawing world");
- drawworld();
- //for(int x = 0; x < 52; x ++)
- //{
- // for(int y = 0; y < 52; y++)
- //{
- // for(int z = 0; z < 52; z++ )
- //{
- // System.out.println(Boxes[x][y][z]);
- //}
- //}
- //}
- System.out.println("Building chasecamera ");
- buildChaseCamera();
- System.out.println("Building Input ");
- buildInput();
- //Aireload(new Vector3f(0, 5.25f, 9), counter);
- System.out.println("Done ");
- }
- private void addMountains(int[][][] world) {
- addLowMountains();
- addHighMountains();
- }
- private void implementMouse() {
- // Create a new mouse. Restrict its movements to the display screen.
- am = new AbsoluteMouse("The Mouse", display.getWidth(), display
- .getHeight());
- // Get a picture for my mouse.
- TextureState ts = display.getRenderer().createTextureState();
- URL cursorLoc = World2.class.getClassLoader().getResource(
- "jmetest/data/cursor/SteamPointer.png" );
- Texture t = TextureManager.loadTexture(cursorLoc, Texture.MinificationFilter.NearestNeighborNoMipMaps,
- Texture.MagnificationFilter.Bilinear);
- ts.setTexture(t);
- am.setRenderState(ts);
- // Make the mouse's background blend with what's already there
- BlendState as = display.getRenderer().createBlendState();
- as.setBlendEnabled(true);
- as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
- as.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
- as.setTestEnabled(true);
- as.setTestFunction(BlendState.TestFunction.GreaterThan);
- am.setRenderState(as);
- // Get the mouse input device and assign it to the AbsoluteMouse
- // Move the mouse to the middle of the screen to start with
- am.setLocalTranslation(new Vector3f(display.getWidth() / 2, display
- .getHeight() / 2, 0));
- // Assign the mouse to an input handler
- am.registerWithInputHandler( input );
- rootNode.attachChild(am);
- }
- /**
- * Can be defined in derived classes for custom updating. Called every frame
- * in update.
- */
- protected void simpleUpdate() {
- //RiverFlow(world, Water);
- // drawworld();
- playermoved(oldpos);
- double xp = ( player.getLocalTranslation().x) ;
- double zp = ((player.getLocalTranslation().y)) ;
- double yp = (player.getLocalTranslation().z) ;
- Point oldpos = new Point (xp, zp, yp);
- //oldpos = pos;
- //rootNode.updateGeometricState(timer.getTimePerFrame(), true);
- //gravity(world);
- }
- /**
- * Can be defined in derived classes for custom rendering. Called every
- * frame in render.
- */
- protected void simpleRender() {
- }
- /**
- * unused
- *
- * @see com.jme.app.AbstractGame#reinit()
- */
- protected void reinit() {
- }
- /**
- * Cleans up the keyboard.
- *
- * @see com.jme.app.AbstractGame#cleanup()
- */
- protected void cleanup() {
- logger.info("Cleaning up resources.");
- KeyInput.destroyIfInitalized();
- MouseInput.destroyIfInitalized();
- JoystickInput.destroyIfInitalized();
- }
- private void playermoved(Point oldpos){
- double xp = player.getLocalTranslation().x ;
- double zp = player.getLocalTranslation().z ;
- double yp = player.getLocalTranslation().y ;
- if (oldpos.x != xp||oldpos.y!= yp|| oldpos.z != zp){
- updateworld(xp, zp, yp);
- //HideBlock(xp,zp,yp);
- }
- }
- private void updateworld(double xp1, double zp1,double yp1)
- // poging was wel leuk
- {
- int xp = (int) (xp1/2);
- int yp = (int) (yp1/2);
- int zp = (int) (zp1/2);
- if(xp-6 > 0 && yp-6 > 0 && xp+6 < 255 && yp+6 < 255){
- for (int x1 = (int) (xp-6); x1 < xp+6; x1++ ){
- for (int y1 = (int) (yp-6); y1 < yp+6; y1++ ){
- for(int z1 = 0; z1 < 52; z1++ )
- {
- int x = x1;
- int y = z1;
- int z = y1;
- if( exposedBlock( x, y, z ) == 1 )
- {
- if( world[x][y][z] > 0){
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- System.out.println("UPDATING x: " + x +" y: " + y + " z: " + z);
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- box.updateRenderState();
- //System.out.println(box.drawed());
- }
- }
- }
- }
- }
- }
- }
- //System.out.println("Camera settings: " + x + " " + hoogte + " " + z );
- //System.out.println( display.getWidth() + " "+ display.getHeight());
- //camera pos, camera LoS
- // teken alles wat nog enti getekend is tot visualrange van 50 ?! + siderange van (display.getWidth(),
- //display.getHeight());
- //remove wat al getekend is maa rniet meer zichtbaar is.
- }
- private void drawworld()
- {
- for(int x = 0; x < 16; x ++)
- {
- for(int y = 0; y < 16; y++)
- {
- for(int z = 0; z < 52; z++ )
- {
- if( exposedBlock( x, y, z ) == 1 )
- {
- if( world[x][y][z] == 1)
- {
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- //System.out.println(box.drawed());
- }
- }
- else if( world[x][y][z] == 2)
- {
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- //System.out.println(box.drawed());
- }
- }
- else if( world[x][y][z] == 3){
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- //System.out.println(box.drawed());
- }
- }
- else if( world[x][y][z] == 4){
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- //System.out.println(box.drawed());
- }
- }
- else if( world[x][y][z] == 5){
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- //System.out.println(box.drawed());
- }
- }
- else if( world[x][y][z] == 6){
- box = Boxes[x][y][z];
- //System.out.println(box.drawed());
- if (box.drawed() == false)
- {
- scene.attachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(true);
- //System.out.println(box.drawed());
- }
- }
- }
- }
- }System.out.println("Done 1 x " + (52 - x) + " to go");
- }
- }
- private void fillworld(int[][][] world) {
- for(int x = 0; x < 50; x ++)
- {
- for(int y = 0; y < 50; y++){
- for(int z = 0 ; z < 1 ; z++){
- Point pos = new Point(x,z,y);
- {
- //waterBlock(pos);
- //earthblock(pos);
- //sandBlock(pos);
- lavaBlock(pos);
- }
- }
- }
- }
- }
- /* for(int x = 10; x < 30; x ++)
- {
- for(int y = 0; y < 10; y++){
- for(int z = 0 ; z < 3 ; z++){
- Point pos = new Point(x,z,y);
- {
- //waterBlock(pos);
- earthblock(pos);
- //sandBlock(pos);
- //lavaBlock(pos);
- }
- }
- }
- }
- for(int x = 20; x < 30; x ++)
- {
- for(int y = 10; y < 30; y++){
- for(int z = 0 ; z < 3 ; z++){
- Point pos = new Point(x,z,y);
- {
- //waterBlock(pos);
- earthblock(pos);
- //sandBlock(pos);
- //lavaBlock(pos);
- }
- }
- }
- }
- for(int x = 10; x < 20; x ++)
- {
- for(int y = 20; y < 30; y++){
- for(int z = 0 ; z < 3 ; z++){
- Point pos = new Point(x,z,y);
- {
- //waterBlock(pos);
- earthblock(pos);
- //sandBlock(pos);
- //lavaBlock(pos);
- }
- }
- }
- }
- Point poz = new Point (14,2, 14);
- waterBlock(poz);
- }
- */
- public void addGrass(int[][][] world){
- for(int x = 0; x < 256; x ++)
- {
- for(int y = 0; y < 256; y++){
- for(int z = 0 ; z < 6 ; z++){
- Point pos = new Point(x,z,y);
- {
- if (z >0){
- if( world[x][y][(z-1)] == 1 && world[x][y][z]== 0)
- {
- grassblock(lowerblock(pos));
- }
- }
- }
- }
- }
- }
- }
- public Point lowerblock( Point pos ){
- int check = 0;
- while(check ==0){
- if( pos.y > 0){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y-1] == 0 ){
- pos.y--;
- }
- else{
- check =1;
- }
- }
- else{
- check =1;
- }
- }
- return pos;
- }
- private void addRivers (){
- int times = 20;
- for (int t = 0; t < times; t++){
- float x = Math.round(Math.random()*50);
- float y = Math.round(Math.random()*50);
- float z = highestBlock(x,y,4)+1;
- Point waterpos = new Point(x, z, y);
- waterBlock(waterpos);
- //System.out.println("added a waterblock");
- }
- }
- private void Flow()
- {
- Vector<Point> waterexposed = Waterexposed();
- Boolean newwater = false;
- Point pos;
- for( int c = 0; c < waterexposed.size(); c++ )
- {
- double xcoord = waterexposed.get(c).x;
- double hoogte = waterexposed.get(c).y;
- double zcoord = waterexposed.get(c).z;
- if(xcoord < 51){
- if( world[(int) xcoord + 1][(int) zcoord][(int) hoogte] == 0)
- {
- pos = new Point(xcoord + 1, hoogte, zcoord);
- waterBlock(pos);
- newwater = true;
- }}
- if(xcoord > 0){
- if( world[(int) xcoord - 1][(int) zcoord][(int) hoogte] == 0)
- {
- pos = new Point(xcoord - 1, hoogte, zcoord);
- waterBlock(pos);
- newwater = true;
- }}
- if(zcoord < 51){
- if( world[(int) xcoord][(int) zcoord + 1][(int) hoogte] == 0)
- {
- pos = new Point(xcoord, hoogte, zcoord + 1);
- waterBlock(pos);
- newwater = true;
- }}
- if(zcoord > 0){
- if( world[(int) xcoord][(int) zcoord - 1][(int) hoogte] == 0)
- {
- pos = new Point(xcoord, hoogte, zcoord - 1);
- waterBlock(pos);
- newwater = true;
- }}
- if(hoogte > 0){
- if( world[(int) xcoord][(int) zcoord][(int) hoogte - 1] == 0)
- {
- pos = new Point(xcoord, hoogte - 1, zcoord);
- waterBlock(pos);
- newwater = true;
- }}
- if(newwater == true)
- {
- Flow();
- }
- }
- }
- private Vector<Point> Waterexposed()
- {
- Vector<Point> exposedwater = new Vector<Point>();
- for( int x = 0; x < Water.size(); x++)
- {
- if( waterexposedBlock( (int) Water.get(x).x, (int) Water.get(x).z, (int) Water.get(x).y ) == 1 )
- exposedwater.add(Water.get(x));
- }
- //System.out.println(exposedwater.get(0).x + " " + exposedwater.get(0).z + " " + exposedwater.get(0).y);
- return exposedwater;
- }
- private void addLowMountains() {
- int times = (int) 200;//(620);//(int) Math.round(Math.random()*400);
- System.out.println("Adding "+ times + " low mountains");
- for (int t = 0; t < times; t++){
- double height = Math.round(Math.random()*7);
- double radius= Math.round((height));
- float x = Math.round(Math.random()*50);
- float y = Math.round(Math.random()*50);
- float z = highestBlock(x,y,52);
- float counter = 0;
- float zplus = z;
- double radx = Math.round( x+ radius);
- while( height!= z){ //1 laag per keer
- if (radx > x){ //check voor legal mountain
- while (radx >= x){//zolang als de moutnain legal is
- float xpos = x + counter;
- Point pos = new Point( Math.abs(xpos), Math.abs(zplus+1), Math.abs(y));// maak een punt aan
- float xneg = x - counter;
- float ypos = y + counter;
- float yneg = y - counter;
- for (int c = 0; c < (radx-x); c++){//bouw dan evenveel blokjes totdat je het verchil tussen rad x en x bereikt hebt
- float newx = x;
- while(newx >= xneg) {
- float newy = y;
- while(newy >= yneg){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) ); // verander punt.
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- }//maak daar block
- //if (zplus+ 1 < 5){
- //earthblock(lowerblock(pos));
- //}
- //else
- // stoneBlock(lowerblock(pos));
- newy--;
- }
- newx--;
- }
- newx = x;
- while(newx <= xpos) {
- float newy = y;
- while(newy <= ypos){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- }
- newy++;
- }
- newx++;
- }
- while(newx >= xneg) {
- float newy = y;
- while(newy <= ypos){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- } newy++;
- }
- newx--;
- }
- newx = x;
- while(newx <= xpos+1) {
- float newy = y;
- while(newy >= yneg){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- } newy--;
- }
- newx++;
- }
- }
- radx--;
- counter++;
- }
- height--;
- zplus++;
- if (Math.round(Math.random()*100) > 15)
- {
- radx= x + (radius -1);
- }
- else
- radx = x + radius;
- radius--;
- counter= 0;
- }
- else{
- t++;
- break;
- }
- //System.out.println("Added a low Mountain! " + (times-t) +" low Mountains to go" );
- }
- }
- System.out.println("End of addLowMountains!");
- }
- public void addHighMountains(){
- int times = (int) Math.round(Math.random()*10);
- System.out.println("Adding "+ times + " High mountains");
- for (int t = 0; t < times; t++){
- double height = Math.round(Math.random()*10);
- double radius= Math.round((height));
- float x = Math.round(Math.random()*50);
- float y = Math.round(Math.random()*50);
- float z = highestBlock(x,y,52);
- float counter = 0;
- float zplus = z;
- double radx = Math.round( x+ radius);
- while( height!= z){
- if (radx > x){
- while (radx >= x){
- float xpos = x + counter;
- Point pos = new Point( Math.abs(xpos), Math.abs(zplus+1), Math.abs(y));
- //earthblock(pos);//+
- float xneg = x- counter;
- float ypos = y + counter;
- float yneg = y- counter;
- for (int c = 0; c < (radx-x); c++){
- float newx = x;
- while(newx >= xneg) {
- float newy = y;
- while(newy >= yneg){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- } newy--;
- }
- newx--;
- }
- newx = x;
- while(newx <= xpos) {
- float newy = y;
- while(newy <= ypos){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- } newy++;
- }
- newx++;
- }
- while(newx >= xneg) {
- float newy = y;
- while(newy <= ypos){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }
- else{
- createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- } newy++;
- }
- newx--;
- }
- newx = x;
- while(newx <= xpos+1) {
- float newy = y;
- while(newy >= yneg){
- pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
- if ((radx -x) < 2){
- if ((zplus+1+Math.round(Math.random()*3)) < 10){
- earthblock(lowerblock(pos));
- }
- else{createblock(lowerblock(pos));
- }
- }
- else{
- createblock(lowerblock(pos));
- }
- newy--;
- }
- newx++;
- }
- }
- radx--;
- counter++;
- }
- height--;
- zplus++;
- if (Math.round(Math.random()*100) > 15)
- {
- radx= x + (radius -1);
- }
- else
- radx = x + radius;
- radius--;
- counter= 0;
- }
- else{
- t++;
- break;
- }
- }
- System.out.println("Added a Mountain!");
- }
- System.out.println("End of addHighMountains!");
- }
- public int[][][] gravity(int[][][]world){
- for(int x = 0; x < 255; x ++)//loop de hele array door
- {
- for(int y = 0; y < 255; y++){
- for(int z = 0 ; z < 51 ; z++){
- if (z > 1){
- if (y > 1){
- if (x > 1){
- if( world[x][y][z] == 0 || world[x][y][(z-1)] != 0 ){ //|| world[x-1][y][z-1]!= 0 || world[x+1][y][z-1]!= 0|| world[x][y-1][z-1]!= 0 || world[x][y+1][z-1]!= 0|| world[x-1][y-1][z-1]!= 0|| world[x-1][y+1][z-1]!= 0|| world[x+1][y-1][z-1]!= 0)){
- //zoalng er eennee leuk blokje schuin onder of onder staat is het goed
- }
- else{
- int temp = world[x][y][z];
- world[x][y][z]=0;
- world[x][y][z-1]= temp;
- System.out.println("LOWERED A BLOCK" + temp);
- return world;
- //fix het doro het bloje 1 nnaar onder te zetten
- }
- }
- }
- }
- }
- }
- }
- return world;
- }
- /*public void earthblockadd(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 1;
- //System.out.println("Placed a block on "+ pos.x +" " + pos.z +" "+ pos.y );
- }
- }
- public void grassblockadd(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 2 ;
- }
- }
- public void waterblockadd(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 3;
- }
- }
- public void stoneblockadd(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 4;
- }
- }
- */
- public void createblock( Point pos )
- {
- if (pos.y+ 1 < 10){
- earthblock(lowerblock(pos));
- }
- else
- stoneBlock(lowerblock(pos));
- }
- private void HideBlock(double xp1, double zp1,double yp1)
- {
- int xp = (int) (xp1/2);
- int yp = (int) (yp1/2);
- int zp = (int) (zp1/2);
- if(xp-10 > 0 && yp-10 > 0 && xp+10 < 255 && yp+10 < 255){
- for (int x1 = (int) (xp-7); x1 > (xp-10); x1-- ){
- for (int y1 = (int) (yp-7); y1 > (yp-10); y1-- ){
- for(int z1 = 0; z1 < 51; z1++ )
- {
- int x = x1;
- int y = z1;
- int z = y1;
- if( exposedBlock( x, y, z ) == 1 )
- {
- if( world[x][y][z] > 0)
- {
- box = Boxes[x][y][z];
- if (box.drawed() == true)
- {
- scene.detachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(false);
- System.out.println("HIDING ");
- box.updateRenderState();
- }
- }
- rootNode.updateRenderState();
- }
- }
- }
- }
- for( int x2 = (int)(xp+7); x2 < xp+10; x2++ ){
- for (int y2 = (int) (yp+7); y2 < yp+10; y2++ ){
- for(int z1 = 0; z1 < 51; z1++ )
- {
- int x3 = x2;
- int y3 = z1;
- int z3 = y2;
- if( exposedBlock( x3, y3, z3 ) == 1 )
- {
- if( world[x3][y3][z3] > 0)
- {
- box = Boxes[x3][y3][z3];
- if (box.drawed() == true)
- {
- scene.detachChild(box);
- rootNode.attachChild(scene);
- scene.updateWorldBound();
- box.setDraw(false);
- box.updateRenderState();
- System.out.println("HIDING ");
- }
- }
- rootNode.updateRenderState();
- }
- }
- }
- }
- }
- }
- public void earthblock(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 1;
- String name = "earth "+ pos.x + " " + pos.z + " " + pos.y; //earth 0.0 0.0 0.0
- //System.out.println( name);
- box = new Box2( name, new Vector3f(0,0,0),1, 1,1, false );
- box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
- box.setModelBound(new BoundingBox());
- //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
- box.updateModelBound();
- URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/Rock.png");
- // Get my TextureState
- TextureState ts=display.getRenderer().createTextureState();
- // Get my Texture
- Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
- // Set the texture to the TextureState
- ts.setTexture(t);
- // Assign the TextureState to the box
- box.setRenderState(ts);
- //scene.attachChild(box);
- //rootNode.attachChild(scene);
- //scene.updateWorldBound();
- // add array vector/array
- //add elke box in een vector, add ze onder naam als box + pos ? dan kan je ze terugvinden in de vector.
- //Box box
- // box = vector element xxx
- //box.getname() = earth 0.0 0.0 0.0
- //scene.attachChild(box);
- //scene.DetachChild(box);
- //rootNode.updateRenderState();
- // Line of sight algoritme + "foggy" rand van zichtveld?
- boxes.add(box);
- Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
- }
- }
- public void grassblock(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 2;
- String name = "grass "+ pos.x + " " + pos.z + " " + pos.y;
- box = new Box2(name, new Vector3f(0,0,0),1, 1,1, false );
- box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
- box.setModelBound(new BoundingBox());
- //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
- box.updateModelBound();
- URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/Grass.png");
- // Get my TextureState
- TextureState ts=display.getRenderer().createTextureState();
- // Get my Texture
- Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
- // Set the texture to the TextureState
- ts.setTexture(t);
- // Assign the TextureState to the box
- box.setRenderState(ts);
- //scene.attachChild(box);
- //rootNode.attachChild(scene);
- //scene.updateWorldBound();
- boxes.add(box);
- Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
- }
- }
- public void lavaBlock(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 6;
- String name = "lava "+ pos.x + " " + pos.z + " " + pos.y;
- box = new Box2(name, new Vector3f(0,0,0),.999f, 0.999f,.999f, false );
- box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
- box.setModelBound(new BoundingBox());
- //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
- box.updateModelBound();
- URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/lava.jpg");
- // Get my TextureState
- TextureState ts=display.getRenderer().createTextureState();
- // Get my Texture
- Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
- // Set the texture to the TextureState
- ts.setTexture(t);
- // Assign the TextureState to the box
- box.setRenderState(ts);
- display.getRenderer();
- //box.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
- //scene.attachChild(box);
- //rootNode.attachChild(scene);
- //scene.updateWorldBound();
- //dit maakt hem transparant!
- boxes.add(box);
- Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
- }
- }
- public void waterBlock(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 3;
- String name = "water "+ pos.x + " " + pos.z + " " + pos.y;
- box = new Box2(name, new Vector3f(0,0,0),.999f, 0.999f,.999f, false );
- box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
- box.setModelBound(new BoundingBox());
- //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
- box.updateModelBound();
- URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/water.png");
- // Get my TextureState
- TextureState ts=display.getRenderer().createTextureState();
- // Get my Texture
- Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
- // Set the texture to the TextureState
- ts.setTexture(t);
- // Assign the TextureState to the box
- box.setRenderState(ts);
- display.getRenderer();
- //box.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
- //scene.attachChild(box);
- //rootNode.attachChild(scene);
- //scene.updateWorldBound();
- //dit maakt hem transparant!
- box.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
- BlendState tempBlendState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
- tempBlendState.setBlendEnabled(true);
- tempBlendState.setSourceFunction(BlendState.SourceFunction.SourceAlpha );
- tempBlendState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
- tempBlendState.setTestEnabled(true);
- tempBlendState.setTestFunction(BlendState.TestFunction.Always);
- tempBlendState.setEnabled(true);
- ZBufferState tempZBuffer = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
- tempZBuffer.setEnabled(true);
- tempZBuffer.setWritable(false);
- tempZBuffer.setFunction(ZBufferState.TestFunction.EqualTo);
- box.setRenderState(tempZBuffer);
- box.setRenderState(tempBlendState);
- box.updateRenderState();
- Water.add(pos);
- boxes.add(box);
- Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
- //
- }
- }
- public void stoneBlock(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0) {
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 4;
- String name = "stone "+ pos.x + " " + pos.z + " " + pos.y;
- box = new Box2(name, new Vector3f(0,0,0),1, 1,1, false );
- box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
- box.setModelBound(new BoundingBox());
- //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
- box.updateModelBound();
- URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/stone.png");
- // Get my TextureState
- TextureState ts=display.getRenderer().createTextureState();
- // Get my Texture
- Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
- // Set the texture to the TextureState
- ts.setTexture(t);
- // Assign the TextureState to the box
- box.setRenderState(ts);
- //scene.attachChild(box);
- //rootNode.attachChild(scene);
- //scene.updateWorldBound();
- boxes.add(box);
- Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
- }
- }
- public void sandBlock(Point pos ){
- if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0) {
- world [(int) pos.x][(int) pos.z][(int) pos.y] = 5;
- String name = "sand "+ pos.x + " " + pos.z + " " + pos.y;
- box = new Box2(name, new Vector3f(0,0,0),.999f, .999f,.999f, false );
- box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
- box.setModelBound(new BoundingBox());
- //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
- box.updateModelBound();
- URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/sand.png");
- // Get my TextureState
- TextureState ts=display.getRenderer().createTextureState();
- // Get my Texture
- Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
- // Set the texture to the TextureState
- ts.setTexture(t);
- // Assign the TextureState to the box
- box.setRenderState(ts);
- //scene.attachChild(box);
- //rootNode.attachChild(scene);
- //scene.updateWorldBound();
- boxes.add(box);
- Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
- }
- }
- private void setupSky() {
- sb = new Skybox("skybox", 200, 200, 200);
- try {
- ResourceLocatorTool.addResourceLocator(
- ResourceLocatorTool.TYPE_TEXTURE,
- new SimpleResourceLocator(getClass().getResource(
- "/jmetest/data/texture/")));
- } catch (Exception e) {
- logger.warning("Unable to access texture directory.");
- e.printStackTrace();
- }
- sb.setTexture(Skybox.Face.North, TextureManager.loadTexture(
- "north.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- sb.setTexture(Skybox.Face.West, TextureManager.loadTexture("west.jpg",
- Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- sb.setTexture(Skybox.Face.South, TextureManager.loadTexture(
- "south.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- sb.setTexture(Skybox.Face.East, TextureManager.loadTexture("east.jpg",
- Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- sb.setTexture(Skybox.Face.Up, TextureManager.loadTexture("top.jpg",
- Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- sb.setTexture(Skybox.Face.Down, TextureManager.loadTexture(
- "bottom.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
- Texture.MagnificationFilter.Bilinear));
- sb.preloadTextures();
- CullState cullState = display.getRenderer().createCullState();
- cullState.setCullFace(CullState.Face.None);
- cullState.setEnabled(true);
- sb.setRenderState(cullState);
- sb.updateRenderState();
- }
- private void buildPlayer() {
- //box stand in
- Box b = new Box("box", new Vector3f(), 0.35f,0.25f,0.5f);
- b.setModelBound(new BoundingBox());
- b.updateModelBound();
- player = new Node("Player Node");
- player.setLocalTranslation(new Vector3f(8, 10, 8));
- scene.attachChild(player);
- player.attachChild(b);
- //player.attachChild(s);
- player.updateWorldBound();
- }
- private void buildAi() {
- //box stand in
- Box c = new Box("box", new Vector3f(), 0.5f,0.25f,0.35f);
- c.setModelBound(new BoundingBox());
- c.updateModelBound();
- Ai = new Node("Ai Node");
- Ai.setLocalTranslation(new Vector3f(0, 5.25f, 9)); //x, z, y
- scene.attachChild(Ai);
- Ai.attachChild(c);
- Ai.updateWorldBound();
- }
- @SuppressWarnings("unchecked")
- private void buildChaseCamera()
- {
- Vector3f targetOffset = new Vector3f();
- targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;
- HashMap props = new HashMap();
- props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "3");
- props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "0");
- props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
- props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+45 * FastMath.DEG_TO_RAD);
- props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
- props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
- chaser = new ChaseCamera(cam, player, props);
- chaser.setMaxDistance(20);
- chaser.setMinDistance(0);
- }
- private void buildInput() {
- input = new FlagRushHandler(player, settings.getRenderer());
- @SuppressWarnings("unused")
- KeyBinds keybind = new KeyBinds( player, settings.getRenderer() );
- }
- @SuppressWarnings("unused")
- private void Aireload(Vector3f pos, int counter){
- Aiunderling AI= new Aiunderling(pos, counter);
- }
- protected static float highestBlock( float xcoord, float ycoord, float zcoord )
- {
- int x = Math.round( xcoord );
- int y = Math.round( ycoord );
- float height = 0;
- for( int z = 0; z < zcoord; z++)
- {
- if( world [x][y][z] == 1 || world [x][y][z] == 2|| world [x][y][z] == 3|| world [x][y][z] == 4|| world [x][y][z] == 5 || world [x][y][z] == 6 )
- height =(float) z;
- }
- return height;
- }
- protected static float highestBlockP( float xcoord, float ycoord, float zcoord )
- {
- int x = Math.round( xcoord );
- int y = Math.round( ycoord );
- float height = 0;
- for( int z = 0; z < zcoord; z++)
- {
- if( world [x][y][z] == 1 || world [x][y][z] == 2|| world [x][y][z] == 4|| world [x][y][z] == 5 )
- height =(float) z;
- }
- return height;
- }
- protected static int exposedBlock(int xcoord, int ycoord, int zcoord ){
- int return1 = 0;
- //if( xcoord > 0 && ycoord > 0 && zcoord > 0 && xcoord <255 && ycoord <255 && zcoord < 51)
- if (xcoord< 255)
- {
- //System.out.println("x + y + z "+ xcoord + " " + ycoord + " " + zcoord);
- if( world[xcoord+1][ycoord][zcoord] == 0 || world[xcoord+1][ycoord][zcoord] == 3 )
- return1 = 1;
- }
- if (xcoord > 0){
- if( world[xcoord-1][ycoord][zcoord] == 0 || world[xcoord-1][ycoord][zcoord] == 3 )
- return1 = 1;
- }
- if (ycoord < 255){
- if( world[xcoord][ycoord+1][zcoord] == 0 || world[xcoord][ycoord+1][zcoord] == 3 )
- return1 = 1;
- }
- if (ycoord > 0){
- if( world[xcoord][ycoord-1][zcoord] == 0 || world[xcoord][ycoord-1][zcoord] == 3 )
- return1 = 1;
- }
- if (zcoord < 51){
- if( world[xcoord][ycoord][zcoord+1] == 0 || world[xcoord][ycoord][zcoord+1] == 3 )
- return1 = 1;
- }
- if (zcoord > 0){
- if( world[xcoord][ycoord][zcoord-1] == 0 || world[xcoord][ycoord][zcoord-1] == 3 )
- return1 = 1;
- }
- return return1;
- }
- protected static int waterexposedBlock(int xcoord, int ycoord, int zcoord ){
- int return1 = 0;
- //if( xcoord > 0 && ycoord > 0 && zcoord > 0 && xcoord <255 && ycoord <255 && zcoord < 51)
- if (xcoord< 51)
- {
- //System.out.println("x + y + z "+ xcoord + " " + ycoord + " " + zcoord);
- if( world[xcoord+1][ycoord][zcoord] == 0 )
- return1 = 1;
- }
- if (xcoord > 0){
- if( world[xcoord-1][ycoord][zcoord] == 0 )
- return1 = 1;
- }
- if (ycoord < 51){
- if( world[xcoord][ycoord+1][zcoord] == 0 )
- return1 = 1;
- }
- if (ycoord > 0){
- if( world[xcoord][ycoord-1][zcoord] == 0 )
- return1 = 1;
- }
- if (zcoord > 0){
- if( world[xcoord][ycoord][zcoord-1] == 0 )
- return1 = 1;
- }
- return return1;
- }
- protected void beach()
- {
- Vector< Point> sandbox = new Vector<Point>();
- for( int x = 0; x < Water.size(); x++ )
- {
- int xcoord = (int) Water.get(x).x;
- int hoogte = (int) Water.get(x).y;
- int zcoord = (int) Water.get(x).z;
- Point replacepos = new Point (xcoord, hoogte,zcoord);
- if (xcoord<255 && zcoord < 255){
- if( world[xcoord+1][zcoord+1][hoogte] == 1 || world[xcoord+1][zcoord+1][hoogte] == 5 )
- {
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ (xcoord+1) + " " +(zcoord+1) + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- world[xcoord+1][zcoord+1][hoogte] = 0;
- replacepos = new Point (xcoord+1, hoogte, zcoord+1);
- sandBlock(replacepos);
- sandbox.add(replacepos);
- }
- }
- if (xcoord>0 && zcoord < 255){
- if( world[xcoord-1][zcoord+1][hoogte] == 1 || world[xcoord-1][zcoord+1][hoogte] == 5 )
- {
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ (xcoord-1) + " " +(zcoord+1) + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- world[xcoord-1][zcoord+1][hoogte] = 0;
- replacepos = new Point (xcoord-1, hoogte, zcoord+1);
- sandBlock(replacepos);
- sandbox.add(replacepos);
- }
- }
- if (xcoord> 0 && zcoord > 0){
- if( world[xcoord-1][zcoord-1][hoogte] == 1 || world[xcoord-1][zcoord-1][hoogte] == 5 )
- {
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ (xcoord-1) + " " +(zcoord-1) + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- world[xcoord-1][zcoord-1][hoogte] = 0;
- replacepos = new Point (xcoord-1, hoogte, zcoord-1);
- sandBlock(replacepos);
- sandbox.add(replacepos);
- }
- }
- if (xcoord<255 && zcoord > 0){
- if( world[xcoord+1][zcoord-1][hoogte] == 1 || world[xcoord+1][zcoord-1][hoogte] == 5 )
- {
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ (xcoord+1) + " " +(zcoord-1) + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- world[xcoord+1][zcoord-1][hoogte] = 0;
- replacepos = new Point (xcoord+1, hoogte, zcoord-1);
- sandBlock(replacepos);
- sandbox.add(replacepos);
- }
- }
- if( world[xcoord+1][zcoord][hoogte] == 1 || world[xcoord+1][zcoord][hoogte] == 5 )
- {
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ (xcoord+1) + " " +zcoord + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
- for(int g = 4; g > 0; g--)
- {
- if(world [xcoord+g][zcoord+1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength1 = g;
- break;
- }
- }
- for(int g = 4; g > 0; g--)
- {
- if (xcoord+ g < 255 && zcoord-1 > 0)
- if(world [xcoord+g][zcoord-1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength2 = g;
- break;
- }
- }
- if(beachlength1 > beachlength2)
- beachlength = beachlength1;
- else
- beachlength = beachlength2;
- //System.out.println(beachlength);
- double R = (double) (Math.random() * 4);
- if ( R > 2 ){
- beachlength= beachlength + 1;
- //System.out.println("adding sum beach");
- }
- else if ( R > 1 ){
- beachlength= beachlength ;
- }
- else{
- beachlength= beachlength - 1;
- }
- if(beachlength < 1){
- beachlength = 1;
- }
- for( int h = 0; h < beachlength; h ++)
- {
- world[xcoord+h+1][zcoord][hoogte] = 0 ;
- replacepos = new Point (xcoord+h+1, hoogte, zcoord);
- sandBlock(replacepos);
- //sandbox.add(replacepos);
- }
- }
- if (xcoord > 0){
- if( world[xcoord-1][zcoord][hoogte] == 1 || world[xcoord-1][zcoord][hoogte] == 5 ){
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ (xcoord-1) + " " +zcoord + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
- for(int g = 4; g > 0; g--)
- {
- if (xcoord-g > 0 && zcoord+1 < 255)
- if(world [xcoord-g][zcoord+1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength1 = g;
- break;
- }
- }
- for(int g = 4; g > 0; g--)
- {
- if (xcoord-g > 0 && zcoord-1 > 0)
- if(world [xcoord-g][zcoord-1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength2 = g;
- break;
- }
- }
- if(beachlength1 > beachlength2)
- beachlength = beachlength1;
- else
- beachlength = beachlength2;
- //System.out.println(beachlength);
- double R = (double) (Math.random() * 4);
- if ( R > 2 ){
- beachlength= beachlength + 1;
- //System.out.println("adding sum beach");
- }
- else if ( R > 1 ){
- beachlength= beachlength ;
- }
- else{
- beachlength= beachlength - 1;
- }
- if(beachlength < 1){
- beachlength = 1;
- }
- for( int h = 0; h < beachlength; h ++)
- {
- world[xcoord-h-1][zcoord][hoogte] = 0 ;
- replacepos = new Point (xcoord-h-1, hoogte, zcoord);
- sandBlock(replacepos);
- //sandbox.add(replacepos);
- }
- }
- }
- if (zcoord < 51){
- if( world[xcoord][zcoord+1][hoogte] == 1 || world[xcoord][zcoord+1][hoogte] == 5 ){
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ xcoord + " " +(zcoord+1) + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
- for(int g = 4; g > 0; g--)
- {
- if(world [xcoord+1][zcoord+g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength1 = g;
- break;
- }
- }
- for(int g = 4; g > 0; g--)
- {
- if(xcoord > 0 ){
- if(world [xcoord-1][zcoord+g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength2 = g;
- break;
- }}
- }
- if(beachlength1 > beachlength2)
- beachlength = beachlength1;
- else
- beachlength = beachlength2;
- //System.out.println(beachlength);
- double R = (double) (Math.random() * 4);
- if ( R > 2 ){
- beachlength= beachlength + 1;
- //System.out.println("adding sum beach");
- }
- else if ( R > 1 ){
- beachlength= beachlength ;
- }
- else{
- beachlength= beachlength - 1;
- }
- if(beachlength < 1){
- beachlength = 1;
- }
- for( int h = 0; h < beachlength; h ++)
- {
- world[xcoord][zcoord+h+1][hoogte] = 0 ;
- replacepos = new Point (xcoord, hoogte, zcoord+h+1);
- sandBlock(replacepos);
- //sandbox.add(replacepos);
- }
- }
- }
- if (zcoord > 0){
- if( world[xcoord][zcoord-1][hoogte] == 1 || world[xcoord][zcoord-1][hoogte] == 5 ){
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ xcoord + " " +(zcoord-1) + " " +hoogte;
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
- for(int g = 4; g > 0; g--)
- {
- if(zcoord-g>0){
- if(world [xcoord+1][zcoord-g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength1 = g;
- break;
- }}
- }
- for(int g = 4; g > 0; g--)
- {
- if(zcoord-g > 0 && xcoord > 0){
- if(world [xcoord-1][zcoord-g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
- {
- beachlength2 = g;
- break;
- }}
- }
- if(beachlength1 > beachlength2)
- beachlength = beachlength1;
- else
- beachlength = beachlength2;
- //System.out.println(beachlength);
- double R = (double) (Math.random() * 4);
- if ( R > 2 ){
- beachlength= beachlength + 1;
- //System.out.println("adding sum beach");
- }
- else if ( R > 1 ){
- beachlength= beachlength ;
- }
- else{
- beachlength= beachlength - 1;
- }
- if(beachlength < 1){
- beachlength = 1;
- }
- for( int h = 0; h < beachlength; h ++)
- {
- if(zcoord-h > 0)
- world[xcoord][zcoord-h-1][hoogte] = 0 ;
- replacepos = new Point (xcoord, hoogte, zcoord-h-1);
- sandBlock(replacepos);
- //sandbox.add(replacepos);
- }
- }
- }
- if (hoogte > 0){
- if( world[xcoord][zcoord][hoogte-1] == 1 )
- {
- for (int c = 0; c < boxes.size() ; c++ ){
- box = boxes.get(c);
- String name ="earth "+ xcoord+1 + " " +zcoord + " " +(hoogte-1);
- String name2 = box.getName();
- //System.out.println(name);
- //System.out.println(box.getName());
- if (name2.equals(name) )
- {
- boxes.removeElement(box);
- //System.out.println(box.drawed());
- break;
- }
- }
- world[xcoord][zcoord][hoogte-1] = 0;
- replacepos = new Point (xcoord, hoogte-1, zcoord);
- sandBlock(replacepos);
- sandbox.add(replacepos);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement