Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.47 KB | None | 0 0
  1. import java.net.URL;
  2. import java.util.HashMap;
  3. import java.util.Vector;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6.  
  7. import jmetest.TutorialGuide.HelloKeyInput;
  8. import jmetest.flagrushtut.lesson5.FlagRushHandler;
  9.  
  10. import com.jme.app.BaseGame;
  11. import com.jme.app.SimpleGame;
  12. import com.jme.bounding.BoundingBox;
  13. import com.jme.image.Texture;
  14. import com.jme.input.AbsoluteMouse;
  15. import com.jme.input.ChaseCamera;
  16. import com.jme.input.FirstPersonHandler;
  17. import com.jme.input.InputHandler;
  18. import com.jme.input.KeyBindingManager;
  19. import com.jme.input.KeyInput;
  20. import com.jme.input.MouseInput;
  21. import com.jme.input.joystick.JoystickInput;
  22. import com.jme.input.thirdperson.ThirdPersonMouseLook;
  23. import com.jme.intersection.PickResults;
  24. import com.jme.light.PointLight;
  25. import com.jme.math.FastMath;
  26. import com.jme.math.Vector3f;
  27. import com.jme.renderer.Camera;
  28. import com.jme.renderer.ColorRGBA;
  29. import com.jme.renderer.Renderer;
  30. import com.jme.scene.Node;
  31. import com.jme.scene.Skybox;
  32. import com.jme.scene.Spatial;
  33. import com.jme.scene.Text;
  34. import com.jme.scene.Spatial.TextureCombineMode;
  35. import com.jme.scene.shape.Box;
  36. import com.jme.scene.shape.Box2;
  37. import com.jme.scene.state.BlendState;
  38. import com.jme.scene.state.CullState;
  39. import com.jme.scene.state.LightState;
  40. import com.jme.scene.state.TextureState;
  41. import com.jme.scene.state.WireframeState;
  42. import com.jme.scene.state.ZBufferState;
  43. import com.jme.system.DisplaySystem;
  44. import com.jme.system.JmeException;
  45. import com.jme.util.TextureManager;
  46. import com.jme.util.Timer;
  47. import com.jme.util.geom.Debugger;
  48. import com.jme.util.resource.ResourceLocatorTool;
  49. import com.jme.util.resource.SimpleResourceLocator;
  50.  
  51.  
  52. /**
  53. * Started Date: Jul 29, 2004<br>
  54. * <br>
  55. *
  56. * Is used to demonstrate the inner workings of SimpleGame.
  57. *
  58. * @author Jack Lindamood
  59. */
  60. public class World2 extends BaseGame {
  61.  
  62.  
  63.  
  64. private static final Logger logger = Logger.getLogger(World2.class
  65. .getName());
  66. static int world[][][] = new int [256][256][52];
  67. static Box2 Boxes[][][] = new Box2 [256][256][52]; // de wereld is 256x256x52 blokjes groot, lucht neemt ook een blokje in
  68. AbsoluteMouse am;
  69. PickResults pr;
  70. Skybox sb;
  71. Vector<Point> Water = new Vector<Point>();
  72. Box2 box;
  73. Node player;
  74. static Node Ai;
  75. int counter = 0;
  76. double r = 0;
  77. Vector<Box2> boxes= new Vector<Box2>();
  78. float angle = 0;
  79. ChaseCamera chaser;
  80. Node scene= new Node("scene");
  81. Point oldpos = new Point (7,2,7);
  82. Point pos2 = new Point(8,3,8);
  83. //maak 3d array van wereld aan
  84. //vul elk element met een of geen blokje
  85. //render elk element
  86. //startgame
  87.  
  88. public static void main(String[] args) {
  89. World2 app = new World2();
  90. app.setConfigShowMode(ConfigShowMode.AlwaysShow);
  91. app.start();
  92. }
  93.  
  94. /** The camera that we see through. */
  95. protected Camera cam;
  96. /** The root of our normal scene graph. */
  97. protected static Node rootNode;
  98. /** Handles our mouse/keyboard input. */
  99. protected InputHandler input;
  100. /** High resolution timer for jME. */
  101. protected static Timer timer;
  102. /** The root node of our text. */
  103. protected Node fpsNode;
  104. /** Displays all the lovely information at the bottom. */
  105. protected Text fps;
  106. /** Simply an easy way to get at timer.getTimePerFrame(). */
  107. protected static float tpf;
  108. /** True if the renderer should display bounds. */
  109. protected boolean showBounds = false;
  110.  
  111. /** A wirestate to turn on and off for the rootNode */
  112. protected WireframeState wireState;
  113. /** A lightstate to turn on and off for the rootNode */
  114. protected LightState lightState;
  115.  
  116. /** Location of the font for jME's text at the bottom */
  117. public static String fontLocation = "com/jme/app/defaultfont.tga";
  118.  
  119. /**
  120. * This is called every frame in BaseGame.start()
  121. *
  122. * @param interpolation
  123. * unused in this implementation
  124. * @see com.jme.app.AbstractGame#update(float interpolation)
  125. */
  126. protected final void update(float interpolation) {
  127. //Aireload(Ai.getLocalTranslation(), counter);
  128. /** Recalculate the framerate. */
  129. timer.update();
  130. /** Update tpf to time per frame according to the Timer. */
  131. tpf = timer.getTimePerFrame();
  132. /** Check for key/mouse updates. */
  133. input.update(tpf);
  134. /** Send the fps to our fps bar at the bottom. */
  135. fps.print("FPS: " + (int) timer.getFrameRate());
  136. /** Call simpleUpdate in any derived classes of SimpleGame. */
  137. simpleUpdate();
  138.  
  139. /** Update controllers/render states/transforms/bounds for rootNode. */
  140. rootNode.updateGeometricState(tpf, true);
  141.  
  142. /** If toggle_wire is a valid command (via key T), change wirestates. */
  143. if (KeyBindingManager.getKeyBindingManager().isValidCommand(
  144. "toggle_wire", false)) {
  145. wireState.setEnabled(!wireState.isEnabled());
  146. rootNode.updateRenderState();
  147. }
  148. /** If toggle_lights is a valid command (via key L), change lightstate. */
  149. if (KeyBindingManager.getKeyBindingManager().isValidCommand(
  150. "toggle_lights", false)) {
  151. lightState.setEnabled(!lightState.isEnabled());
  152. rootNode.updateRenderState();
  153. }
  154. /** If toggle_bounds is a valid command (via key B), change bounds. */
  155. if (KeyBindingManager.getKeyBindingManager().isValidCommand(
  156. "toggle_bounds", false)) {
  157. showBounds = !showBounds;
  158. }
  159. /** If camera_out is a valid command (via key C), show camera location. */
  160. if (KeyBindingManager.getKeyBindingManager().isValidCommand(
  161. "camera_out", false)) {
  162. logger.info("Camera at: "
  163. + display.getRenderer().getCamera().getLocation());
  164. }
  165.  
  166. if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit",
  167. false)) {
  168. finish();
  169. }
  170.  
  171. // update the time to get the framerate
  172. timer.update();
  173. interpolation = timer.getTimePerFrame();
  174. //update the keyboard input (move the player around)
  175. input.update(interpolation);
  176. //update the chase camera to handle the player moving around.
  177. chaser.update(interpolation);
  178.  
  179.  
  180.  
  181. //we want to keep the skybox around our eyes, so move it with
  182. //the camera
  183. sb.setLocalTranslation(cam.getLocation());
  184.  
  185. // if escape was pressed, we exit
  186. if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
  187. finished = true;
  188. }
  189.  
  190. //We don't want the chase camera to go below the world, so always keep
  191. //it 2 units above the level.
  192. try{
  193. if(cam.getLocation().y < highestBlockP(cam.getLocation().x/2, cam.getLocation().z/2, cam.getLocation().y/2) *2 +2.26) {
  194. cam.getLocation().y = (float) (highestBlockP(cam.getLocation().x/2, cam.getLocation().z/2, cam.getLocation().y/2) *2 +2.26);
  195. cam.update();
  196. }
  197. }
  198. catch (java.lang.ArrayIndexOutOfBoundsException e){
  199.  
  200. }
  201.  
  202. float xp = player.getLocalTranslation().x ;
  203. float zp = player.getLocalTranslation().y ;
  204. float yp = player.getLocalTranslation().z ;
  205. try{
  206. player.setLocalTranslation( xp, (float)(highestBlockP( xp/2, yp/2, (float) (zp/2+1.26) )*2 + 1.26), yp);
  207. } catch(java.lang.ArrayIndexOutOfBoundsException e) {
  208. if( xp < 0)
  209. player.setLocalTranslation( xp + 5 , zp, yp);
  210. else if( xp > 512 )
  211. player.setLocalTranslation( xp - 5 , zp, yp);
  212. else if( yp < 0 )
  213. player.setLocalTranslation( xp , zp, yp + 5);
  214. else if( yp > 512 )
  215. player.setLocalTranslation( xp , zp, yp - 5);
  216. }
  217. counter++;
  218. }
  219.  
  220.  
  221. /*float characterMinHeight = tb.getHeight(player
  222. .getLocalTranslation())+((BoundingBox)player.getWorldBound()).yExtent;
  223. if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
  224. player.getLocalTranslation().y = characterMinHeight;
  225. }
  226.  
  227. //Because we are changing the scene (moving the skybox and player) we need to update
  228. //the graph.
  229. scene.updateGeometricState(interpolation, true);*/
  230.  
  231. /**
  232. * This is called every frame in BaseGame.start(), after update()
  233. *
  234. * @param interpolation
  235. * unused in this implementation
  236. * @see com.jme.app.AbstractGame#render(float interpolation)
  237. */
  238. protected final void render(float interpolation) {
  239. /** Clears the previously rendered information. */
  240. display.getRenderer().clearBuffers();
  241. /** Draw the rootNode and all its children. */
  242. display.getRenderer().draw(rootNode);
  243. /**
  244. * If showing bounds, draw rootNode's bounds, and the bounds of all its
  245. * children.
  246. */
  247. if (showBounds)
  248. Debugger.drawBounds(rootNode, display.getRenderer());
  249. /** Draw the fps node to show the fancy information at the bottom. */
  250. display.getRenderer().draw(fpsNode);
  251. /** Call simpleRender() in any derived classes. */
  252. simpleRender();
  253. }
  254.  
  255. /**
  256. * Creates display, sets up camera, and binds keys. Called in
  257. * BaseGame.start() directly after the dialog box.
  258. *
  259. * @see com.jme.app.AbstractGame#initSystem()
  260. */
  261. protected final void initSystem() {
  262. try {
  263. /**
  264. * Get a DisplaySystem acording to the renderer selected in the
  265. * startup box.
  266. */
  267. display = DisplaySystem.getDisplaySystem(settings.getRenderer());
  268. /** Create a window with the startup box's information. */
  269. display.createWindow(settings.getWidth(), settings.getHeight(),
  270. settings.getDepth(), settings.getFrequency(), settings
  271. .isFullscreen());
  272. /**
  273. * Create a camera specific to the DisplaySystem that works with the
  274. * display's width and height
  275. */
  276. cam = display.getRenderer().createCamera(display.getWidth(),
  277. display.getHeight());
  278.  
  279. } catch (JmeException e) {
  280. /**
  281. * If the displaysystem can't be initialized correctly, exit
  282. * instantly.
  283. */
  284. logger.log(Level.SEVERE, "Could not create displaySystem", e);
  285. System.exit(1);
  286. }
  287.  
  288. /** Set a black background. */
  289. display.getRenderer().setBackgroundColor(ColorRGBA.black.clone());
  290.  
  291. /** Set up how our camera sees. */
  292. cam.setFrustumPerspective(45.0f, (float) display.getWidth()
  293. / (float) display.getHeight(), 1, 1000);
  294. Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
  295. Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
  296. Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
  297. Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
  298. /** Move our camera to a correct place and orientation. */
  299. cam.setFrame(loc, left, up, dir);
  300. /** Signal that we've changed our camera's location/frustum. */
  301. cam.update();
  302. /** Assign the camera to this renderer. */
  303. display.getRenderer().setCamera(cam);
  304.  
  305. /** Create a basic input controller. */
  306. FirstPersonHandler firstPersonHandler = new FirstPersonHandler(cam);
  307. /** Signal to all key inputs they should work 10x faster. */
  308. firstPersonHandler.getKeyboardLookHandler().setActionSpeed(10f);
  309. firstPersonHandler.getMouseLookHandler().setActionSpeed(1f);
  310. input = firstPersonHandler;
  311.  
  312. /** Get a high resolution timer for FPS updates. */
  313. timer = Timer.getTimer();
  314.  
  315. /** Sets the title of our display. */
  316. display.setTitle("SimpleGame");
  317.  
  318. /** Assign key T to action "toggle_wire". */
  319. KeyBindingManager.getKeyBindingManager().set("toggle_wire",
  320. KeyInput.KEY_T);
  321. /** Assign key L to action "toggle_lights". */
  322. KeyBindingManager.getKeyBindingManager().set("toggle_lights",
  323. KeyInput.KEY_L);
  324. /** Assign key B to action "toggle_bounds". */
  325. KeyBindingManager.getKeyBindingManager().set("toggle_bounds",
  326. KeyInput.KEY_B);
  327. /** Assign key C to action "camera_out". */
  328. KeyBindingManager.getKeyBindingManager().set("camera_out",
  329. KeyInput.KEY_C);
  330. KeyBindingManager.getKeyBindingManager().set("exit",
  331. KeyInput.KEY_ESCAPE);
  332. }
  333.  
  334. /**
  335. * Creates rootNode, lighting, statistic text, and other basic render
  336. * states. Called in BaseGame.start() after initSystem().
  337. *
  338. * @see com.jme.app.AbstractGame#initGame()
  339. */
  340. protected final void initGame() {
  341. /** Create rootNode */
  342. rootNode = new Node("rootNode");
  343.  
  344. /**
  345. * Create a wirestate to toggle on and off. Starts disabled with default
  346. * width of 1 pixel.
  347. */
  348. wireState = display.getRenderer().createWireframeState();
  349. wireState.setEnabled(false);
  350. rootNode.setRenderState(wireState);
  351.  
  352. /**
  353. * Create a ZBuffer to display pixels closest to the camera above
  354. * farther ones.
  355. */
  356. ZBufferState buf = display.getRenderer().createZBufferState();
  357. buf.setEnabled(true);
  358. buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
  359.  
  360. rootNode.setRenderState(buf);
  361.  
  362. // -- FPS DISPLAY
  363. // First setup blend state
  364. /**
  365. * This allows correct blending of text and what is already rendered
  366. * below it
  367. */
  368. BlendState as1 = display.getRenderer().createBlendState();
  369. as1.setBlendEnabled(true);
  370. as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
  371. as1.setDestinationFunction(BlendState.DestinationFunction.One);
  372. as1.setTestEnabled(true);
  373. as1.setTestFunction(BlendState.TestFunction.GreaterThan);
  374. as1.setEnabled(true);
  375.  
  376. // Now setup font texture
  377. TextureState font = display.getRenderer().createTextureState();
  378. /** The texture is loaded from fontLocation */
  379. font.setTexture(TextureManager.loadTexture(SimpleGame.class
  380. .getClassLoader().getResource(fontLocation),
  381. Texture.MinificationFilter.BilinearNearestMipMap,
  382. Texture.MagnificationFilter.Bilinear));
  383. font.setEnabled(true);
  384.  
  385. // Then our font Text object.
  386. /** This is what will actually have the text at the bottom. */
  387. fps = Text.createDefaultTextLabel("FPS label", "");
  388. fps.setCullHint(Spatial.CullHint.Never);
  389. fps.setTextureCombineMode(TextureCombineMode.Replace);
  390.  
  391. // Finally, a stand alone node (not attached to root on purpose)
  392. fpsNode = new Node("FPS node");
  393. fpsNode.attachChild(fps);
  394. fpsNode.setRenderState(font);
  395. fpsNode.setRenderState(as1);
  396. fpsNode.setCullHint(Spatial.CullHint.Never);
  397.  
  398. // ---- LIGHTS
  399. /** Set up a basic, default light. */
  400. PointLight light = new PointLight();
  401. light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
  402. light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
  403. light.setLocation(new Vector3f(100, 100, 100));
  404. light.setEnabled(true);
  405.  
  406. PointLight light2 = new PointLight();
  407. light2.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
  408. light2.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
  409. light2.setLocation(new Vector3f(-100, -100, 100));
  410. light2.setEnabled(true);
  411.  
  412. PointLight light3 = new PointLight();
  413. light3.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
  414. light3.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
  415. light3.setLocation(new Vector3f(-100, 100, -100));
  416. light3.setEnabled(true);
  417.  
  418. /** Attach the light to a lightState and the lightState to rootNode. */
  419. lightState = display.getRenderer().createLightState();
  420. lightState.setEnabled(true);
  421. lightState.attach(light);
  422. lightState.attach(light2);
  423. lightState.attach(light3);
  424. rootNode.setRenderState(lightState);
  425.  
  426. /** Let derived classes initialize. */
  427. simpleInitGame();
  428.  
  429. /**
  430. * Update geometric and rendering information for both the rootNode and
  431. * fpsNode.
  432. */
  433. rootNode.updateGeometricState(0.0f, true);
  434. rootNode.updateRenderState();
  435. fpsNode.updateGeometricState(0.0f, true);
  436. fpsNode.updateRenderState();
  437. }
  438.  
  439. protected void simpleInitGame() {
  440.  
  441. System.out.println("Building AI ");
  442. buildAi();
  443.  
  444. System.out.println("Filling world ");
  445. fillworld(world);
  446.  
  447. System.out.println("Adding mountains ");
  448. addMountains(world);
  449.  
  450. System.out.println("Dripping water");
  451. addRivers();
  452.  
  453. System.out.println("Letting it flow");
  454. //Flow();
  455.  
  456. System.out.println("Making the beach");
  457. //beach();
  458.  
  459. System.out.println("Adding grass ");
  460. //addGrass(world);
  461.  
  462.  
  463. System.out.println("Implementing mouse");
  464. implementMouse();
  465.  
  466. System.out.println("Setting up skybox");
  467. setupSky();
  468.  
  469. rootNode.attachChild(sb);
  470.  
  471.  
  472. System.out.println("Building player ");
  473. buildPlayer();
  474.  
  475. System.out.println("Drawing world");
  476. drawworld();
  477. //for(int x = 0; x < 52; x ++)
  478. //{
  479. // for(int y = 0; y < 52; y++)
  480. //{
  481. // for(int z = 0; z < 52; z++ )
  482. //{
  483. // System.out.println(Boxes[x][y][z]);
  484. //}
  485. //}
  486. //}
  487.  
  488. System.out.println("Building chasecamera ");
  489. buildChaseCamera();
  490.  
  491. System.out.println("Building Input ");
  492. buildInput();
  493. //Aireload(new Vector3f(0, 5.25f, 9), counter);
  494. System.out.println("Done ");
  495. }
  496.  
  497.  
  498.  
  499. private void addMountains(int[][][] world) {
  500. addLowMountains();
  501. addHighMountains();
  502.  
  503. }
  504.  
  505.  
  506. private void implementMouse() {
  507. // Create a new mouse. Restrict its movements to the display screen.
  508. am = new AbsoluteMouse("The Mouse", display.getWidth(), display
  509. .getHeight());
  510.  
  511. // Get a picture for my mouse.
  512. TextureState ts = display.getRenderer().createTextureState();
  513. URL cursorLoc = World2.class.getClassLoader().getResource(
  514. "jmetest/data/cursor/SteamPointer.png" );
  515. Texture t = TextureManager.loadTexture(cursorLoc, Texture.MinificationFilter.NearestNeighborNoMipMaps,
  516. Texture.MagnificationFilter.Bilinear);
  517. ts.setTexture(t);
  518. am.setRenderState(ts);
  519.  
  520. // Make the mouse's background blend with what's already there
  521. BlendState as = display.getRenderer().createBlendState();
  522. as.setBlendEnabled(true);
  523. as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
  524. as.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
  525. as.setTestEnabled(true);
  526. as.setTestFunction(BlendState.TestFunction.GreaterThan);
  527. am.setRenderState(as);
  528.  
  529. // Get the mouse input device and assign it to the AbsoluteMouse
  530. // Move the mouse to the middle of the screen to start with
  531. am.setLocalTranslation(new Vector3f(display.getWidth() / 2, display
  532. .getHeight() / 2, 0));
  533. // Assign the mouse to an input handler
  534. am.registerWithInputHandler( input );
  535. rootNode.attachChild(am);
  536. }
  537.  
  538. /**
  539. * Can be defined in derived classes for custom updating. Called every frame
  540. * in update.
  541. */
  542. protected void simpleUpdate() {
  543.  
  544.  
  545.  
  546.  
  547. //RiverFlow(world, Water);
  548. // drawworld();
  549. playermoved(oldpos);
  550. double xp = ( player.getLocalTranslation().x) ;
  551. double zp = ((player.getLocalTranslation().y)) ;
  552. double yp = (player.getLocalTranslation().z) ;
  553. Point oldpos = new Point (xp, zp, yp);
  554. //oldpos = pos;
  555.  
  556.  
  557. //rootNode.updateGeometricState(timer.getTimePerFrame(), true);
  558. //gravity(world);
  559.  
  560. }
  561.  
  562. /**
  563. * Can be defined in derived classes for custom rendering. Called every
  564. * frame in render.
  565. */
  566. protected void simpleRender() {
  567. }
  568.  
  569. /**
  570. * unused
  571. *
  572. * @see com.jme.app.AbstractGame#reinit()
  573. */
  574. protected void reinit() {
  575. }
  576.  
  577. /**
  578. * Cleans up the keyboard.
  579. *
  580. * @see com.jme.app.AbstractGame#cleanup()
  581. */
  582. protected void cleanup() {
  583. logger.info("Cleaning up resources.");
  584. KeyInput.destroyIfInitalized();
  585. MouseInput.destroyIfInitalized();
  586. JoystickInput.destroyIfInitalized();
  587. }
  588.  
  589. private void playermoved(Point oldpos){
  590. double xp = player.getLocalTranslation().x ;
  591. double zp = player.getLocalTranslation().z ;
  592. double yp = player.getLocalTranslation().y ;
  593.  
  594. if (oldpos.x != xp||oldpos.y!= yp|| oldpos.z != zp){
  595. updateworld(xp, zp, yp);
  596. //HideBlock(xp,zp,yp);
  597.  
  598. }
  599.  
  600. }
  601.  
  602. private void updateworld(double xp1, double zp1,double yp1)
  603. // poging was wel leuk
  604. {
  605. int xp = (int) (xp1/2);
  606. int yp = (int) (yp1/2);
  607. int zp = (int) (zp1/2);
  608. if(xp-6 > 0 && yp-6 > 0 && xp+6 < 255 && yp+6 < 255){
  609. for (int x1 = (int) (xp-6); x1 < xp+6; x1++ ){
  610. for (int y1 = (int) (yp-6); y1 < yp+6; y1++ ){
  611. for(int z1 = 0; z1 < 52; z1++ )
  612. {
  613.  
  614. int x = x1;
  615. int y = z1;
  616. int z = y1;
  617.  
  618.  
  619. if( exposedBlock( x, y, z ) == 1 )
  620. {
  621. if( world[x][y][z] > 0){
  622. box = Boxes[x][y][z];
  623. //System.out.println(box.drawed());
  624. if (box.drawed() == false)
  625. {
  626. System.out.println("UPDATING x: " + x +" y: " + y + " z: " + z);
  627. scene.attachChild(box);
  628. rootNode.attachChild(scene);
  629. scene.updateWorldBound();
  630. box.setDraw(true);
  631. box.updateRenderState();
  632. //System.out.println(box.drawed());
  633.  
  634. }
  635. }
  636.  
  637. }
  638. }
  639. }
  640. }
  641. }
  642.  
  643. //System.out.println("Camera settings: " + x + " " + hoogte + " " + z );
  644. //System.out.println( display.getWidth() + " "+ display.getHeight());
  645. //camera pos, camera LoS
  646. // teken alles wat nog enti getekend is tot visualrange van 50 ?! + siderange van (display.getWidth(),
  647. //display.getHeight());
  648. //remove wat al getekend is maa rniet meer zichtbaar is.
  649. }
  650.  
  651. private void drawworld()
  652. {
  653. for(int x = 0; x < 16; x ++)
  654. {
  655. for(int y = 0; y < 16; y++)
  656. {
  657. for(int z = 0; z < 52; z++ )
  658. {
  659. if( exposedBlock( x, y, z ) == 1 )
  660. {
  661. if( world[x][y][z] == 1)
  662. {
  663.  
  664. box = Boxes[x][y][z];
  665. //System.out.println(box.drawed());
  666. if (box.drawed() == false)
  667. {
  668. scene.attachChild(box);
  669. rootNode.attachChild(scene);
  670. scene.updateWorldBound();
  671. box.setDraw(true);
  672. //System.out.println(box.drawed());
  673.  
  674. }
  675. }
  676.  
  677. else if( world[x][y][z] == 2)
  678. {
  679.  
  680. box = Boxes[x][y][z];
  681. //System.out.println(box.drawed());
  682. if (box.drawed() == false)
  683. {
  684. scene.attachChild(box);
  685. rootNode.attachChild(scene);
  686. scene.updateWorldBound();
  687. box.setDraw(true);
  688. //System.out.println(box.drawed());
  689.  
  690. }
  691. }
  692.  
  693. else if( world[x][y][z] == 3){
  694.  
  695. box = Boxes[x][y][z];
  696. //System.out.println(box.drawed());
  697. if (box.drawed() == false)
  698. {
  699. scene.attachChild(box);
  700. rootNode.attachChild(scene);
  701. scene.updateWorldBound();
  702. box.setDraw(true);
  703. //System.out.println(box.drawed());
  704.  
  705. }
  706. }
  707.  
  708. else if( world[x][y][z] == 4){
  709.  
  710. box = Boxes[x][y][z];
  711. //System.out.println(box.drawed());
  712. if (box.drawed() == false)
  713. {
  714. scene.attachChild(box);
  715. rootNode.attachChild(scene);
  716. scene.updateWorldBound();
  717. box.setDraw(true);
  718. //System.out.println(box.drawed());
  719.  
  720. }
  721. }
  722.  
  723. else if( world[x][y][z] == 5){
  724.  
  725. box = Boxes[x][y][z];
  726. //System.out.println(box.drawed());
  727. if (box.drawed() == false)
  728. {
  729. scene.attachChild(box);
  730. rootNode.attachChild(scene);
  731. scene.updateWorldBound();
  732. box.setDraw(true);
  733. //System.out.println(box.drawed());
  734.  
  735. }
  736. }
  737.  
  738. else if( world[x][y][z] == 6){
  739.  
  740. box = Boxes[x][y][z];
  741. //System.out.println(box.drawed());
  742. if (box.drawed() == false)
  743. {
  744. scene.attachChild(box);
  745. rootNode.attachChild(scene);
  746. scene.updateWorldBound();
  747. box.setDraw(true);
  748. //System.out.println(box.drawed());
  749.  
  750. }
  751. }
  752.  
  753. }
  754. }
  755.  
  756. }System.out.println("Done 1 x " + (52 - x) + " to go");
  757. }
  758. }
  759. private void fillworld(int[][][] world) {
  760.  
  761.  
  762. for(int x = 0; x < 50; x ++)
  763. {
  764. for(int y = 0; y < 50; y++){
  765. for(int z = 0 ; z < 1 ; z++){
  766. Point pos = new Point(x,z,y);
  767. {
  768. //waterBlock(pos);
  769. //earthblock(pos);
  770. //sandBlock(pos);
  771. lavaBlock(pos);
  772. }
  773. }
  774. }
  775. }
  776. }
  777. /* for(int x = 10; x < 30; x ++)
  778. {
  779. for(int y = 0; y < 10; y++){
  780. for(int z = 0 ; z < 3 ; z++){
  781. Point pos = new Point(x,z,y);
  782. {
  783. //waterBlock(pos);
  784. earthblock(pos);
  785. //sandBlock(pos);
  786. //lavaBlock(pos);
  787. }
  788. }
  789. }
  790. }
  791. for(int x = 20; x < 30; x ++)
  792. {
  793. for(int y = 10; y < 30; y++){
  794. for(int z = 0 ; z < 3 ; z++){
  795. Point pos = new Point(x,z,y);
  796. {
  797. //waterBlock(pos);
  798. earthblock(pos);
  799. //sandBlock(pos);
  800. //lavaBlock(pos);
  801. }
  802. }
  803. }
  804. }
  805. for(int x = 10; x < 20; x ++)
  806. {
  807. for(int y = 20; y < 30; y++){
  808. for(int z = 0 ; z < 3 ; z++){
  809. Point pos = new Point(x,z,y);
  810. {
  811. //waterBlock(pos);
  812. earthblock(pos);
  813. //sandBlock(pos);
  814. //lavaBlock(pos);
  815. }
  816. }
  817. }
  818. }
  819. Point poz = new Point (14,2, 14);
  820. waterBlock(poz);
  821. }
  822.  
  823. */
  824. public void addGrass(int[][][] world){
  825. for(int x = 0; x < 256; x ++)
  826. {
  827. for(int y = 0; y < 256; y++){
  828. for(int z = 0 ; z < 6 ; z++){
  829. Point pos = new Point(x,z,y);
  830.  
  831. {
  832. if (z >0){
  833. if( world[x][y][(z-1)] == 1 && world[x][y][z]== 0)
  834. {
  835. grassblock(lowerblock(pos));
  836. }
  837. }
  838. }
  839. }
  840. }
  841. }
  842. }
  843.  
  844.  
  845. public Point lowerblock( Point pos ){
  846. int check = 0;
  847. while(check ==0){
  848. if( pos.y > 0){
  849. if (world [(int) pos.x][(int) pos.z][(int) pos.y-1] == 0 ){
  850. pos.y--;
  851.  
  852. }
  853. else{
  854. check =1;
  855. }
  856. }
  857.  
  858. else{
  859. check =1;
  860. }
  861. }
  862. return pos;
  863. }
  864.  
  865. private void addRivers (){
  866.  
  867. int times = 20;
  868. for (int t = 0; t < times; t++){
  869. float x = Math.round(Math.random()*50);
  870. float y = Math.round(Math.random()*50);
  871. float z = highestBlock(x,y,4)+1;
  872. Point waterpos = new Point(x, z, y);
  873. waterBlock(waterpos);
  874. //System.out.println("added a waterblock");
  875. }
  876.  
  877. }
  878.  
  879. private void Flow()
  880. {
  881. Vector<Point> waterexposed = Waterexposed();
  882. Boolean newwater = false;
  883. Point pos;
  884. for( int c = 0; c < waterexposed.size(); c++ )
  885. {
  886. double xcoord = waterexposed.get(c).x;
  887. double hoogte = waterexposed.get(c).y;
  888. double zcoord = waterexposed.get(c).z;
  889. if(xcoord < 51){
  890. if( world[(int) xcoord + 1][(int) zcoord][(int) hoogte] == 0)
  891. {
  892. pos = new Point(xcoord + 1, hoogte, zcoord);
  893. waterBlock(pos);
  894. newwater = true;
  895. }}
  896. if(xcoord > 0){
  897. if( world[(int) xcoord - 1][(int) zcoord][(int) hoogte] == 0)
  898. {
  899. pos = new Point(xcoord - 1, hoogte, zcoord);
  900. waterBlock(pos);
  901. newwater = true;
  902. }}
  903. if(zcoord < 51){
  904. if( world[(int) xcoord][(int) zcoord + 1][(int) hoogte] == 0)
  905. {
  906. pos = new Point(xcoord, hoogte, zcoord + 1);
  907. waterBlock(pos);
  908. newwater = true;
  909. }}
  910. if(zcoord > 0){
  911. if( world[(int) xcoord][(int) zcoord - 1][(int) hoogte] == 0)
  912. {
  913. pos = new Point(xcoord, hoogte, zcoord - 1);
  914. waterBlock(pos);
  915. newwater = true;
  916. }}
  917. if(hoogte > 0){
  918. if( world[(int) xcoord][(int) zcoord][(int) hoogte - 1] == 0)
  919. {
  920. pos = new Point(xcoord, hoogte - 1, zcoord);
  921. waterBlock(pos);
  922. newwater = true;
  923. }}
  924.  
  925. if(newwater == true)
  926. {
  927. Flow();
  928. }
  929. }
  930. }
  931.  
  932. private Vector<Point> Waterexposed()
  933. {
  934. Vector<Point> exposedwater = new Vector<Point>();
  935. for( int x = 0; x < Water.size(); x++)
  936. {
  937.  
  938. if( waterexposedBlock( (int) Water.get(x).x, (int) Water.get(x).z, (int) Water.get(x).y ) == 1 )
  939. exposedwater.add(Water.get(x));
  940.  
  941. }
  942.  
  943. //System.out.println(exposedwater.get(0).x + " " + exposedwater.get(0).z + " " + exposedwater.get(0).y);
  944. return exposedwater;
  945. }
  946.  
  947.  
  948.  
  949.  
  950.  
  951. private void addLowMountains() {
  952.  
  953. int times = (int) 200;//(620);//(int) Math.round(Math.random()*400);
  954. System.out.println("Adding "+ times + " low mountains");
  955. for (int t = 0; t < times; t++){
  956. double height = Math.round(Math.random()*7);
  957. double radius= Math.round((height));
  958. float x = Math.round(Math.random()*50);
  959. float y = Math.round(Math.random()*50);
  960. float z = highestBlock(x,y,52);
  961. float counter = 0;
  962. float zplus = z;
  963. double radx = Math.round( x+ radius);
  964.  
  965. while( height!= z){ //1 laag per keer
  966. if (radx > x){ //check voor legal mountain
  967. while (radx >= x){//zolang als de moutnain legal is
  968. float xpos = x + counter;
  969. Point pos = new Point( Math.abs(xpos), Math.abs(zplus+1), Math.abs(y));// maak een punt aan
  970. float xneg = x - counter;
  971. float ypos = y + counter;
  972. float yneg = y - counter;
  973. for (int c = 0; c < (radx-x); c++){//bouw dan evenveel blokjes totdat je het verchil tussen rad x en x bereikt hebt
  974. float newx = x;
  975. while(newx >= xneg) {
  976. float newy = y;
  977. while(newy >= yneg){
  978. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) ); // verander punt.
  979. if ((radx -x) < 2){
  980. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  981. earthblock(lowerblock(pos));
  982. }else{
  983. createblock(lowerblock(pos));
  984. }
  985. }
  986. else{
  987. createblock(lowerblock(pos));
  988. }//maak daar block
  989. //if (zplus+ 1 < 5){
  990.  
  991. //earthblock(lowerblock(pos));
  992. //}
  993. //else
  994. // stoneBlock(lowerblock(pos));
  995. newy--;
  996. }
  997. newx--;
  998. }
  999. newx = x;
  1000. while(newx <= xpos) {
  1001. float newy = y;
  1002. while(newy <= ypos){
  1003. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1004. if ((radx -x) < 2){
  1005. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1006. earthblock(lowerblock(pos));
  1007. }else{
  1008. createblock(lowerblock(pos));
  1009. }
  1010. }
  1011. else{
  1012. createblock(lowerblock(pos));
  1013. }
  1014. newy++;
  1015. }
  1016. newx++;
  1017. }
  1018. while(newx >= xneg) {
  1019. float newy = y;
  1020. while(newy <= ypos){
  1021. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1022. if ((radx -x) < 2){
  1023. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1024. earthblock(lowerblock(pos));
  1025. }else{
  1026. createblock(lowerblock(pos));
  1027. }
  1028. }
  1029. else{
  1030. createblock(lowerblock(pos));
  1031. } newy++;
  1032. }
  1033. newx--;
  1034. }
  1035. newx = x;
  1036. while(newx <= xpos+1) {
  1037. float newy = y;
  1038. while(newy >= yneg){
  1039. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1040. if ((radx -x) < 2){
  1041. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1042. earthblock(lowerblock(pos));
  1043. }else{
  1044. createblock(lowerblock(pos));
  1045. }
  1046. }
  1047. else{
  1048. createblock(lowerblock(pos));
  1049. } newy--;
  1050. }
  1051. newx++;
  1052. }
  1053. }
  1054. radx--;
  1055. counter++;
  1056. }
  1057. height--;
  1058. zplus++;
  1059. if (Math.round(Math.random()*100) > 15)
  1060. {
  1061. radx= x + (radius -1);
  1062. }
  1063. else
  1064. radx = x + radius;
  1065. radius--;
  1066. counter= 0;
  1067. }
  1068. else{
  1069. t++;
  1070. break;
  1071. }
  1072. //System.out.println("Added a low Mountain! " + (times-t) +" low Mountains to go" );
  1073. }
  1074. }
  1075. System.out.println("End of addLowMountains!");
  1076. }
  1077.  
  1078.  
  1079.  
  1080.  
  1081. public void addHighMountains(){
  1082. int times = (int) Math.round(Math.random()*10);
  1083. System.out.println("Adding "+ times + " High mountains");
  1084. for (int t = 0; t < times; t++){
  1085. double height = Math.round(Math.random()*10);
  1086. double radius= Math.round((height));
  1087. float x = Math.round(Math.random()*50);
  1088. float y = Math.round(Math.random()*50);
  1089. float z = highestBlock(x,y,52);
  1090. float counter = 0;
  1091. float zplus = z;
  1092. double radx = Math.round( x+ radius);
  1093. while( height!= z){
  1094. if (radx > x){
  1095. while (radx >= x){
  1096. float xpos = x + counter;
  1097. Point pos = new Point( Math.abs(xpos), Math.abs(zplus+1), Math.abs(y));
  1098. //earthblock(pos);//+
  1099. float xneg = x- counter;
  1100. float ypos = y + counter;
  1101. float yneg = y- counter;
  1102. for (int c = 0; c < (radx-x); c++){
  1103. float newx = x;
  1104. while(newx >= xneg) {
  1105. float newy = y;
  1106. while(newy >= yneg){
  1107. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1108. if ((radx -x) < 2){
  1109. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1110. earthblock(lowerblock(pos));
  1111. }else{
  1112. createblock(lowerblock(pos));
  1113. }
  1114. }
  1115. else{
  1116. createblock(lowerblock(pos));
  1117. } newy--;
  1118. }
  1119. newx--;
  1120. }
  1121. newx = x;
  1122. while(newx <= xpos) {
  1123. float newy = y;
  1124. while(newy <= ypos){
  1125. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1126. if ((radx -x) < 2){
  1127. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1128. earthblock(lowerblock(pos));
  1129. }else{
  1130. createblock(lowerblock(pos));
  1131. }
  1132. }
  1133. else{
  1134. createblock(lowerblock(pos));
  1135. } newy++;
  1136. }
  1137. newx++;
  1138. }
  1139. while(newx >= xneg) {
  1140. float newy = y;
  1141. while(newy <= ypos){
  1142. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1143. if ((radx -x) < 2){
  1144. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1145. earthblock(lowerblock(pos));
  1146. }
  1147. else{
  1148. createblock(lowerblock(pos));
  1149. }
  1150.  
  1151.  
  1152. }
  1153. else{
  1154. createblock(lowerblock(pos));
  1155. } newy++;
  1156. }
  1157. newx--;
  1158. }
  1159. newx = x;
  1160. while(newx <= xpos+1) {
  1161. float newy = y;
  1162. while(newy >= yneg){
  1163. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1164. if ((radx -x) < 2){
  1165. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1166. earthblock(lowerblock(pos));
  1167. }
  1168. else{createblock(lowerblock(pos));
  1169.  
  1170. }
  1171. }
  1172. else{
  1173. createblock(lowerblock(pos));
  1174. }
  1175. newy--;
  1176. }
  1177. newx++;
  1178. }
  1179. }
  1180. radx--;
  1181. counter++;
  1182. }
  1183. height--;
  1184. zplus++;
  1185. if (Math.round(Math.random()*100) > 15)
  1186. {
  1187. radx= x + (radius -1);
  1188. }
  1189. else
  1190. radx = x + radius;
  1191. radius--;
  1192. counter= 0;
  1193. }
  1194. else{
  1195. t++;
  1196. break;
  1197. }
  1198.  
  1199. }
  1200. System.out.println("Added a Mountain!");
  1201. }
  1202. System.out.println("End of addHighMountains!");
  1203. }
  1204.  
  1205. public int[][][] gravity(int[][][]world){
  1206. for(int x = 0; x < 255; x ++)//loop de hele array door
  1207. {
  1208. for(int y = 0; y < 255; y++){
  1209. for(int z = 0 ; z < 51 ; z++){
  1210. if (z > 1){
  1211. if (y > 1){
  1212. if (x > 1){
  1213. 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)){
  1214. //zoalng er eennee leuk blokje schuin onder of onder staat is het goed
  1215. }
  1216. else{
  1217. int temp = world[x][y][z];
  1218. world[x][y][z]=0;
  1219. world[x][y][z-1]= temp;
  1220. System.out.println("LOWERED A BLOCK" + temp);
  1221. return world;
  1222. //fix het doro het bloje 1 nnaar onder te zetten
  1223. }
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. return world;
  1231. }
  1232.  
  1233. /*public void earthblockadd(Point pos ){
  1234. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1235. world [(int) pos.x][(int) pos.z][(int) pos.y] = 1;
  1236. //System.out.println("Placed a block on "+ pos.x +" " + pos.z +" "+ pos.y );
  1237. }
  1238. }
  1239. public void grassblockadd(Point pos ){
  1240. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1241. world [(int) pos.x][(int) pos.z][(int) pos.y] = 2 ;
  1242. }
  1243. }
  1244. public void waterblockadd(Point pos ){
  1245. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1246. world [(int) pos.x][(int) pos.z][(int) pos.y] = 3;
  1247. }
  1248. }
  1249. public void stoneblockadd(Point pos ){
  1250. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1251. world [(int) pos.x][(int) pos.z][(int) pos.y] = 4;
  1252. }
  1253. }
  1254.  
  1255. */
  1256. public void createblock( Point pos )
  1257. {
  1258. if (pos.y+ 1 < 10){
  1259.  
  1260. earthblock(lowerblock(pos));
  1261. }
  1262. else
  1263. stoneBlock(lowerblock(pos));
  1264. }
  1265.  
  1266.  
  1267.  
  1268. private void HideBlock(double xp1, double zp1,double yp1)
  1269. {
  1270. int xp = (int) (xp1/2);
  1271. int yp = (int) (yp1/2);
  1272. int zp = (int) (zp1/2);
  1273. if(xp-10 > 0 && yp-10 > 0 && xp+10 < 255 && yp+10 < 255){
  1274. for (int x1 = (int) (xp-7); x1 > (xp-10); x1-- ){
  1275. for (int y1 = (int) (yp-7); y1 > (yp-10); y1-- ){
  1276. for(int z1 = 0; z1 < 51; z1++ )
  1277. {
  1278.  
  1279. int x = x1;
  1280. int y = z1;
  1281. int z = y1;
  1282. if( exposedBlock( x, y, z ) == 1 )
  1283. {
  1284. if( world[x][y][z] > 0)
  1285. {
  1286. box = Boxes[x][y][z];
  1287. if (box.drawed() == true)
  1288. {
  1289. scene.detachChild(box);
  1290. rootNode.attachChild(scene);
  1291. scene.updateWorldBound();
  1292. box.setDraw(false);
  1293. System.out.println("HIDING ");
  1294. box.updateRenderState();
  1295. }
  1296. }
  1297. rootNode.updateRenderState();
  1298. }
  1299. }
  1300. }
  1301. }
  1302. for( int x2 = (int)(xp+7); x2 < xp+10; x2++ ){
  1303. for (int y2 = (int) (yp+7); y2 < yp+10; y2++ ){
  1304. for(int z1 = 0; z1 < 51; z1++ )
  1305. {
  1306.  
  1307. int x3 = x2;
  1308. int y3 = z1;
  1309. int z3 = y2;
  1310. if( exposedBlock( x3, y3, z3 ) == 1 )
  1311. {
  1312. if( world[x3][y3][z3] > 0)
  1313. {
  1314. box = Boxes[x3][y3][z3];
  1315. if (box.drawed() == true)
  1316. {
  1317. scene.detachChild(box);
  1318. rootNode.attachChild(scene);
  1319. scene.updateWorldBound();
  1320. box.setDraw(false);
  1321. box.updateRenderState();
  1322. System.out.println("HIDING ");
  1323. }
  1324. }
  1325. rootNode.updateRenderState();
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. }
  1332.  
  1333.  
  1334. public void earthblock(Point pos ){
  1335. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1336. world [(int) pos.x][(int) pos.z][(int) pos.y] = 1;
  1337. String name = "earth "+ pos.x + " " + pos.z + " " + pos.y; //earth 0.0 0.0 0.0
  1338. //System.out.println( name);
  1339. box = new Box2( name, new Vector3f(0,0,0),1, 1,1, false );
  1340. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1341. box.setModelBound(new BoundingBox());
  1342. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1343. box.updateModelBound();
  1344. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/Rock.png");
  1345. // Get my TextureState
  1346. TextureState ts=display.getRenderer().createTextureState();
  1347. // Get my Texture
  1348. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1349. // Set the texture to the TextureState
  1350. ts.setTexture(t);
  1351.  
  1352. // Assign the TextureState to the box
  1353. box.setRenderState(ts);
  1354. //scene.attachChild(box);
  1355. //rootNode.attachChild(scene);
  1356. //scene.updateWorldBound();
  1357.  
  1358. // add array vector/array
  1359. //add elke box in een vector, add ze onder naam als box + pos ? dan kan je ze terugvinden in de vector.
  1360. //Box box
  1361. // box = vector element xxx
  1362. //box.getname() = earth 0.0 0.0 0.0
  1363. //scene.attachChild(box);
  1364. //scene.DetachChild(box);
  1365. //rootNode.updateRenderState();
  1366. // Line of sight algoritme + "foggy" rand van zichtveld?
  1367. boxes.add(box);
  1368. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1369.  
  1370.  
  1371. }
  1372. }
  1373.  
  1374.  
  1375. public void grassblock(Point pos ){
  1376.  
  1377. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1378. world [(int) pos.x][(int) pos.z][(int) pos.y] = 2;
  1379. String name = "grass "+ pos.x + " " + pos.z + " " + pos.y;
  1380. box = new Box2(name, new Vector3f(0,0,0),1, 1,1, false );
  1381. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1382. box.setModelBound(new BoundingBox());
  1383. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1384. box.updateModelBound();
  1385. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/Grass.png");
  1386. // Get my TextureState
  1387. TextureState ts=display.getRenderer().createTextureState();
  1388. // Get my Texture
  1389. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1390. // Set the texture to the TextureState
  1391. ts.setTexture(t);
  1392. // Assign the TextureState to the box
  1393. box.setRenderState(ts);
  1394. //scene.attachChild(box);
  1395. //rootNode.attachChild(scene);
  1396. //scene.updateWorldBound();
  1397.  
  1398. boxes.add(box);
  1399. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1400. }
  1401. }
  1402.  
  1403.  
  1404. public void lavaBlock(Point pos ){
  1405. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1406. world [(int) pos.x][(int) pos.z][(int) pos.y] = 6;
  1407. String name = "lava "+ pos.x + " " + pos.z + " " + pos.y;
  1408. box = new Box2(name, new Vector3f(0,0,0),.999f, 0.999f,.999f, false );
  1409. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1410. box.setModelBound(new BoundingBox());
  1411. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1412. box.updateModelBound();
  1413. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/lava.jpg");
  1414. // Get my TextureState
  1415. TextureState ts=display.getRenderer().createTextureState();
  1416. // Get my Texture
  1417. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1418. // Set the texture to the TextureState
  1419. ts.setTexture(t);
  1420. // Assign the TextureState to the box
  1421. box.setRenderState(ts);
  1422. display.getRenderer();
  1423. //box.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
  1424. //scene.attachChild(box);
  1425. //rootNode.attachChild(scene);
  1426. //scene.updateWorldBound();
  1427.  
  1428. //dit maakt hem transparant!
  1429.  
  1430.  
  1431. boxes.add(box);
  1432. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1433. }
  1434. }
  1435.  
  1436. public void waterBlock(Point pos ){
  1437. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1438. world [(int) pos.x][(int) pos.z][(int) pos.y] = 3;
  1439. String name = "water "+ pos.x + " " + pos.z + " " + pos.y;
  1440. box = new Box2(name, new Vector3f(0,0,0),.999f, 0.999f,.999f, false );
  1441. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1442. box.setModelBound(new BoundingBox());
  1443. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1444. box.updateModelBound();
  1445. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/water.png");
  1446. // Get my TextureState
  1447. TextureState ts=display.getRenderer().createTextureState();
  1448. // Get my Texture
  1449. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1450. // Set the texture to the TextureState
  1451. ts.setTexture(t);
  1452. // Assign the TextureState to the box
  1453. box.setRenderState(ts);
  1454. display.getRenderer();
  1455. //box.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
  1456. //scene.attachChild(box);
  1457. //rootNode.attachChild(scene);
  1458. //scene.updateWorldBound();
  1459.  
  1460. //dit maakt hem transparant!
  1461. box.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
  1462. BlendState tempBlendState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
  1463. tempBlendState.setBlendEnabled(true);
  1464. tempBlendState.setSourceFunction(BlendState.SourceFunction.SourceAlpha );
  1465. tempBlendState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
  1466. tempBlendState.setTestEnabled(true);
  1467. tempBlendState.setTestFunction(BlendState.TestFunction.Always);
  1468. tempBlendState.setEnabled(true);
  1469.  
  1470. ZBufferState tempZBuffer = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
  1471. tempZBuffer.setEnabled(true);
  1472. tempZBuffer.setWritable(false);
  1473. tempZBuffer.setFunction(ZBufferState.TestFunction.EqualTo);
  1474. box.setRenderState(tempZBuffer);
  1475. box.setRenderState(tempBlendState);
  1476. box.updateRenderState();
  1477. Water.add(pos);
  1478. boxes.add(box);
  1479. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1480. //
  1481. }
  1482. }
  1483.  
  1484.  
  1485.  
  1486. public void stoneBlock(Point pos ){
  1487. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0) {
  1488. world [(int) pos.x][(int) pos.z][(int) pos.y] = 4;
  1489. String name = "stone "+ pos.x + " " + pos.z + " " + pos.y;
  1490. box = new Box2(name, new Vector3f(0,0,0),1, 1,1, false );
  1491. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1492. box.setModelBound(new BoundingBox());
  1493. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1494. box.updateModelBound();
  1495. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/stone.png");
  1496. // Get my TextureState
  1497. TextureState ts=display.getRenderer().createTextureState();
  1498. // Get my Texture
  1499. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1500. // Set the texture to the TextureState
  1501. ts.setTexture(t);
  1502. // Assign the TextureState to the box
  1503. box.setRenderState(ts);
  1504. //scene.attachChild(box);
  1505. //rootNode.attachChild(scene);
  1506. //scene.updateWorldBound();
  1507. boxes.add(box);
  1508. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1509. }
  1510. }
  1511.  
  1512.  
  1513. public void sandBlock(Point pos ){
  1514. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0) {
  1515. world [(int) pos.x][(int) pos.z][(int) pos.y] = 5;
  1516. String name = "sand "+ pos.x + " " + pos.z + " " + pos.y;
  1517. box = new Box2(name, new Vector3f(0,0,0),.999f, .999f,.999f, false );
  1518. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1519. box.setModelBound(new BoundingBox());
  1520. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1521. box.updateModelBound();
  1522. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/sand.png");
  1523. // Get my TextureState
  1524. TextureState ts=display.getRenderer().createTextureState();
  1525. // Get my Texture
  1526. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1527. // Set the texture to the TextureState
  1528. ts.setTexture(t);
  1529. // Assign the TextureState to the box
  1530. box.setRenderState(ts);
  1531. //scene.attachChild(box);
  1532. //rootNode.attachChild(scene);
  1533. //scene.updateWorldBound();
  1534. boxes.add(box);
  1535. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1536. }
  1537. }
  1538.  
  1539. private void setupSky() {
  1540. sb = new Skybox("skybox", 200, 200, 200);
  1541. try {
  1542. ResourceLocatorTool.addResourceLocator(
  1543. ResourceLocatorTool.TYPE_TEXTURE,
  1544. new SimpleResourceLocator(getClass().getResource(
  1545. "/jmetest/data/texture/")));
  1546. } catch (Exception e) {
  1547. logger.warning("Unable to access texture directory.");
  1548. e.printStackTrace();
  1549. }
  1550. sb.setTexture(Skybox.Face.North, TextureManager.loadTexture(
  1551. "north.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
  1552. Texture.MagnificationFilter.Bilinear));
  1553. sb.setTexture(Skybox.Face.West, TextureManager.loadTexture("west.jpg",
  1554. Texture.MinificationFilter.BilinearNearestMipMap,
  1555. Texture.MagnificationFilter.Bilinear));
  1556. sb.setTexture(Skybox.Face.South, TextureManager.loadTexture(
  1557. "south.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
  1558. Texture.MagnificationFilter.Bilinear));
  1559. sb.setTexture(Skybox.Face.East, TextureManager.loadTexture("east.jpg",
  1560. Texture.MinificationFilter.BilinearNearestMipMap,
  1561. Texture.MagnificationFilter.Bilinear));
  1562. sb.setTexture(Skybox.Face.Up, TextureManager.loadTexture("top.jpg",
  1563. Texture.MinificationFilter.BilinearNearestMipMap,
  1564. Texture.MagnificationFilter.Bilinear));
  1565. sb.setTexture(Skybox.Face.Down, TextureManager.loadTexture(
  1566. "bottom.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
  1567. Texture.MagnificationFilter.Bilinear));
  1568. sb.preloadTextures();
  1569. CullState cullState = display.getRenderer().createCullState();
  1570. cullState.setCullFace(CullState.Face.None);
  1571. cullState.setEnabled(true);
  1572. sb.setRenderState(cullState);
  1573. sb.updateRenderState();
  1574. }
  1575.  
  1576. private void buildPlayer() {
  1577. //box stand in
  1578. Box b = new Box("box", new Vector3f(), 0.35f,0.25f,0.5f);
  1579. b.setModelBound(new BoundingBox());
  1580. b.updateModelBound();
  1581.  
  1582. player = new Node("Player Node");
  1583. player.setLocalTranslation(new Vector3f(8, 10, 8));
  1584. scene.attachChild(player);
  1585. player.attachChild(b);
  1586. //player.attachChild(s);
  1587. player.updateWorldBound();
  1588. }
  1589. private void buildAi() {
  1590. //box stand in
  1591. Box c = new Box("box", new Vector3f(), 0.5f,0.25f,0.35f);
  1592. c.setModelBound(new BoundingBox());
  1593. c.updateModelBound();
  1594.  
  1595. Ai = new Node("Ai Node");
  1596. Ai.setLocalTranslation(new Vector3f(0, 5.25f, 9)); //x, z, y
  1597. scene.attachChild(Ai);
  1598. Ai.attachChild(c);
  1599. Ai.updateWorldBound();
  1600.  
  1601. }
  1602.  
  1603. @SuppressWarnings("unchecked")
  1604. private void buildChaseCamera()
  1605. {
  1606. Vector3f targetOffset = new Vector3f();
  1607. targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;
  1608. HashMap props = new HashMap();
  1609. props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "3");
  1610. props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "0");
  1611. props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
  1612. props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+45 * FastMath.DEG_TO_RAD);
  1613. props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
  1614. props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
  1615. chaser = new ChaseCamera(cam, player, props);
  1616. chaser.setMaxDistance(20);
  1617. chaser.setMinDistance(0);
  1618.  
  1619. }
  1620. private void buildInput() {
  1621. input = new FlagRushHandler(player, settings.getRenderer());
  1622. @SuppressWarnings("unused")
  1623. KeyBinds keybind = new KeyBinds( player, settings.getRenderer() );
  1624.  
  1625. }
  1626. @SuppressWarnings("unused")
  1627. private void Aireload(Vector3f pos, int counter){
  1628.  
  1629. Aiunderling AI= new Aiunderling(pos, counter);
  1630.  
  1631. }
  1632.  
  1633. protected static float highestBlock( float xcoord, float ycoord, float zcoord )
  1634. {
  1635. int x = Math.round( xcoord );
  1636. int y = Math.round( ycoord );
  1637. float height = 0;
  1638. for( int z = 0; z < zcoord; z++)
  1639. {
  1640. 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 )
  1641. height =(float) z;
  1642. }
  1643. return height;
  1644. }
  1645.  
  1646. protected static float highestBlockP( float xcoord, float ycoord, float zcoord )
  1647. {
  1648. int x = Math.round( xcoord );
  1649. int y = Math.round( ycoord );
  1650. float height = 0;
  1651. for( int z = 0; z < zcoord; z++)
  1652. {
  1653. if( world [x][y][z] == 1 || world [x][y][z] == 2|| world [x][y][z] == 4|| world [x][y][z] == 5 )
  1654. height =(float) z;
  1655. }
  1656. return height;
  1657. }
  1658. protected static int exposedBlock(int xcoord, int ycoord, int zcoord ){
  1659. int return1 = 0;
  1660. //if( xcoord > 0 && ycoord > 0 && zcoord > 0 && xcoord <255 && ycoord <255 && zcoord < 51)
  1661. if (xcoord< 255)
  1662. {
  1663. //System.out.println("x + y + z "+ xcoord + " " + ycoord + " " + zcoord);
  1664. if( world[xcoord+1][ycoord][zcoord] == 0 || world[xcoord+1][ycoord][zcoord] == 3 )
  1665. return1 = 1;
  1666. }
  1667. if (xcoord > 0){
  1668. if( world[xcoord-1][ycoord][zcoord] == 0 || world[xcoord-1][ycoord][zcoord] == 3 )
  1669. return1 = 1;
  1670. }
  1671. if (ycoord < 255){
  1672. if( world[xcoord][ycoord+1][zcoord] == 0 || world[xcoord][ycoord+1][zcoord] == 3 )
  1673. return1 = 1;
  1674. }
  1675. if (ycoord > 0){
  1676. if( world[xcoord][ycoord-1][zcoord] == 0 || world[xcoord][ycoord-1][zcoord] == 3 )
  1677. return1 = 1;
  1678. }
  1679. if (zcoord < 51){
  1680. if( world[xcoord][ycoord][zcoord+1] == 0 || world[xcoord][ycoord][zcoord+1] == 3 )
  1681. return1 = 1;
  1682. }
  1683. if (zcoord > 0){
  1684. if( world[xcoord][ycoord][zcoord-1] == 0 || world[xcoord][ycoord][zcoord-1] == 3 )
  1685. return1 = 1;
  1686. }
  1687.  
  1688. return return1;
  1689. }
  1690. protected static int waterexposedBlock(int xcoord, int ycoord, int zcoord ){
  1691. int return1 = 0;
  1692. //if( xcoord > 0 && ycoord > 0 && zcoord > 0 && xcoord <255 && ycoord <255 && zcoord < 51)
  1693. if (xcoord< 51)
  1694. {
  1695. //System.out.println("x + y + z "+ xcoord + " " + ycoord + " " + zcoord);
  1696. if( world[xcoord+1][ycoord][zcoord] == 0 )
  1697. return1 = 1;
  1698. }
  1699. if (xcoord > 0){
  1700. if( world[xcoord-1][ycoord][zcoord] == 0 )
  1701. return1 = 1;
  1702. }
  1703. if (ycoord < 51){
  1704. if( world[xcoord][ycoord+1][zcoord] == 0 )
  1705. return1 = 1;
  1706. }
  1707. if (ycoord > 0){
  1708. if( world[xcoord][ycoord-1][zcoord] == 0 )
  1709. return1 = 1;
  1710. }
  1711. if (zcoord > 0){
  1712. if( world[xcoord][ycoord][zcoord-1] == 0 )
  1713. return1 = 1;
  1714. }
  1715.  
  1716. return return1;
  1717. }
  1718.  
  1719. protected void beach()
  1720. {
  1721. Vector< Point> sandbox = new Vector<Point>();
  1722. for( int x = 0; x < Water.size(); x++ )
  1723. {
  1724. int xcoord = (int) Water.get(x).x;
  1725. int hoogte = (int) Water.get(x).y;
  1726. int zcoord = (int) Water.get(x).z;
  1727. Point replacepos = new Point (xcoord, hoogte,zcoord);
  1728. if (xcoord<255 && zcoord < 255){
  1729. if( world[xcoord+1][zcoord+1][hoogte] == 1 || world[xcoord+1][zcoord+1][hoogte] == 5 )
  1730. {
  1731. for (int c = 0; c < boxes.size() ; c++ ){
  1732. box = boxes.get(c);
  1733. String name ="earth "+ (xcoord+1) + " " +(zcoord+1) + " " +hoogte;
  1734. String name2 = box.getName();
  1735. //System.out.println(name);
  1736. //System.out.println(box.getName());
  1737. if (name2.equals(name) )
  1738. {
  1739. boxes.removeElement(box);
  1740. //System.out.println(box.drawed());
  1741. break;
  1742. }
  1743. }
  1744. world[xcoord+1][zcoord+1][hoogte] = 0;
  1745. replacepos = new Point (xcoord+1, hoogte, zcoord+1);
  1746. sandBlock(replacepos);
  1747. sandbox.add(replacepos);
  1748. }
  1749. }
  1750. if (xcoord>0 && zcoord < 255){
  1751. if( world[xcoord-1][zcoord+1][hoogte] == 1 || world[xcoord-1][zcoord+1][hoogte] == 5 )
  1752. {
  1753. for (int c = 0; c < boxes.size() ; c++ ){
  1754. box = boxes.get(c);
  1755. String name ="earth "+ (xcoord-1) + " " +(zcoord+1) + " " +hoogte;
  1756. String name2 = box.getName();
  1757. //System.out.println(name);
  1758. //System.out.println(box.getName());
  1759. if (name2.equals(name) )
  1760. {
  1761. boxes.removeElement(box);
  1762. //System.out.println(box.drawed());
  1763. break;
  1764. }
  1765. }
  1766. world[xcoord-1][zcoord+1][hoogte] = 0;
  1767. replacepos = new Point (xcoord-1, hoogte, zcoord+1);
  1768. sandBlock(replacepos);
  1769. sandbox.add(replacepos);
  1770. }
  1771. }
  1772. if (xcoord> 0 && zcoord > 0){
  1773. if( world[xcoord-1][zcoord-1][hoogte] == 1 || world[xcoord-1][zcoord-1][hoogte] == 5 )
  1774. {
  1775. for (int c = 0; c < boxes.size() ; c++ ){
  1776. box = boxes.get(c);
  1777. String name ="earth "+ (xcoord-1) + " " +(zcoord-1) + " " +hoogte;
  1778. String name2 = box.getName();
  1779. //System.out.println(name);
  1780. //System.out.println(box.getName());
  1781. if (name2.equals(name) )
  1782. {
  1783. boxes.removeElement(box);
  1784. //System.out.println(box.drawed());
  1785. break;
  1786. }
  1787. }
  1788. world[xcoord-1][zcoord-1][hoogte] = 0;
  1789. replacepos = new Point (xcoord-1, hoogte, zcoord-1);
  1790. sandBlock(replacepos);
  1791. sandbox.add(replacepos);
  1792. }
  1793. }
  1794. if (xcoord<255 && zcoord > 0){
  1795. if( world[xcoord+1][zcoord-1][hoogte] == 1 || world[xcoord+1][zcoord-1][hoogte] == 5 )
  1796. {
  1797. for (int c = 0; c < boxes.size() ; c++ ){
  1798. box = boxes.get(c);
  1799. String name ="earth "+ (xcoord+1) + " " +(zcoord-1) + " " +hoogte;
  1800. String name2 = box.getName();
  1801. //System.out.println(name);
  1802. //System.out.println(box.getName());
  1803. if (name2.equals(name) )
  1804. {
  1805. boxes.removeElement(box);
  1806. //System.out.println(box.drawed());
  1807. break;
  1808. }
  1809. }
  1810. world[xcoord+1][zcoord-1][hoogte] = 0;
  1811. replacepos = new Point (xcoord+1, hoogte, zcoord-1);
  1812. sandBlock(replacepos);
  1813. sandbox.add(replacepos);
  1814. }
  1815. }
  1816. if( world[xcoord+1][zcoord][hoogte] == 1 || world[xcoord+1][zcoord][hoogte] == 5 )
  1817. {
  1818. for (int c = 0; c < boxes.size() ; c++ ){
  1819. box = boxes.get(c);
  1820. String name ="earth "+ (xcoord+1) + " " +zcoord + " " +hoogte;
  1821. String name2 = box.getName();
  1822. //System.out.println(name);
  1823. //System.out.println(box.getName());
  1824. if (name2.equals(name) )
  1825. {
  1826. boxes.removeElement(box);
  1827. //System.out.println(box.drawed());
  1828. break;
  1829. }
  1830. }
  1831.  
  1832. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  1833.  
  1834. for(int g = 4; g > 0; g--)
  1835. {
  1836. if(world [xcoord+g][zcoord+1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1837. {
  1838. beachlength1 = g;
  1839. break;
  1840. }
  1841. }
  1842. for(int g = 4; g > 0; g--)
  1843. {
  1844. if (xcoord+ g < 255 && zcoord-1 > 0)
  1845. if(world [xcoord+g][zcoord-1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1846. {
  1847. beachlength2 = g;
  1848. break;
  1849. }
  1850. }
  1851. if(beachlength1 > beachlength2)
  1852. beachlength = beachlength1;
  1853. else
  1854. beachlength = beachlength2;
  1855. //System.out.println(beachlength);
  1856. double R = (double) (Math.random() * 4);
  1857. if ( R > 2 ){
  1858. beachlength= beachlength + 1;
  1859. //System.out.println("adding sum beach");
  1860. }
  1861. else if ( R > 1 ){
  1862. beachlength= beachlength ;
  1863. }
  1864. else{
  1865. beachlength= beachlength - 1;
  1866.  
  1867. }
  1868. if(beachlength < 1){
  1869. beachlength = 1;
  1870. }
  1871. for( int h = 0; h < beachlength; h ++)
  1872. {
  1873. world[xcoord+h+1][zcoord][hoogte] = 0 ;
  1874. replacepos = new Point (xcoord+h+1, hoogte, zcoord);
  1875. sandBlock(replacepos);
  1876. //sandbox.add(replacepos);
  1877. }
  1878. }
  1879.  
  1880. if (xcoord > 0){
  1881. if( world[xcoord-1][zcoord][hoogte] == 1 || world[xcoord-1][zcoord][hoogte] == 5 ){
  1882. for (int c = 0; c < boxes.size() ; c++ ){
  1883. box = boxes.get(c);
  1884. String name ="earth "+ (xcoord-1) + " " +zcoord + " " +hoogte;
  1885. String name2 = box.getName();
  1886. //System.out.println(name);
  1887. //System.out.println(box.getName());
  1888. if (name2.equals(name) )
  1889. {
  1890. boxes.removeElement(box);
  1891. //System.out.println(box.drawed());
  1892. break;
  1893. }
  1894. }
  1895. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  1896.  
  1897. for(int g = 4; g > 0; g--)
  1898. {
  1899. if (xcoord-g > 0 && zcoord+1 < 255)
  1900. if(world [xcoord-g][zcoord+1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1901. {
  1902. beachlength1 = g;
  1903. break;
  1904. }
  1905. }
  1906. for(int g = 4; g > 0; g--)
  1907. {
  1908. if (xcoord-g > 0 && zcoord-1 > 0)
  1909. if(world [xcoord-g][zcoord-1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1910. {
  1911. beachlength2 = g;
  1912. break;
  1913. }
  1914. }
  1915. if(beachlength1 > beachlength2)
  1916. beachlength = beachlength1;
  1917. else
  1918. beachlength = beachlength2;
  1919. //System.out.println(beachlength);
  1920. double R = (double) (Math.random() * 4);
  1921. if ( R > 2 ){
  1922. beachlength= beachlength + 1;
  1923. //System.out.println("adding sum beach");
  1924. }
  1925. else if ( R > 1 ){
  1926. beachlength= beachlength ;
  1927. }
  1928. else{
  1929. beachlength= beachlength - 1;
  1930.  
  1931. }
  1932. if(beachlength < 1){
  1933. beachlength = 1;
  1934. }
  1935. for( int h = 0; h < beachlength; h ++)
  1936. {
  1937. world[xcoord-h-1][zcoord][hoogte] = 0 ;
  1938. replacepos = new Point (xcoord-h-1, hoogte, zcoord);
  1939. sandBlock(replacepos);
  1940. //sandbox.add(replacepos);
  1941. }
  1942. }
  1943.  
  1944. }
  1945. if (zcoord < 51){
  1946. if( world[xcoord][zcoord+1][hoogte] == 1 || world[xcoord][zcoord+1][hoogte] == 5 ){
  1947. for (int c = 0; c < boxes.size() ; c++ ){
  1948. box = boxes.get(c);
  1949. String name ="earth "+ xcoord + " " +(zcoord+1) + " " +hoogte;
  1950. String name2 = box.getName();
  1951. //System.out.println(name);
  1952. //System.out.println(box.getName());
  1953. if (name2.equals(name) )
  1954. {
  1955. boxes.removeElement(box);
  1956. //System.out.println(box.drawed());
  1957. break;
  1958. }
  1959. }
  1960. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  1961.  
  1962. for(int g = 4; g > 0; g--)
  1963. {
  1964. if(world [xcoord+1][zcoord+g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1965. {
  1966. beachlength1 = g;
  1967. break;
  1968. }
  1969. }
  1970. for(int g = 4; g > 0; g--)
  1971. {
  1972. if(xcoord > 0 ){
  1973. if(world [xcoord-1][zcoord+g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1974. {
  1975. beachlength2 = g;
  1976. break;
  1977. }}
  1978. }
  1979. if(beachlength1 > beachlength2)
  1980. beachlength = beachlength1;
  1981. else
  1982. beachlength = beachlength2;
  1983. //System.out.println(beachlength);
  1984. double R = (double) (Math.random() * 4);
  1985. if ( R > 2 ){
  1986. beachlength= beachlength + 1;
  1987. //System.out.println("adding sum beach");
  1988. }
  1989. else if ( R > 1 ){
  1990. beachlength= beachlength ;
  1991. }
  1992. else{
  1993. beachlength= beachlength - 1;
  1994.  
  1995. }
  1996. if(beachlength < 1){
  1997. beachlength = 1;
  1998. }
  1999. for( int h = 0; h < beachlength; h ++)
  2000. {
  2001. world[xcoord][zcoord+h+1][hoogte] = 0 ;
  2002. replacepos = new Point (xcoord, hoogte, zcoord+h+1);
  2003. sandBlock(replacepos);
  2004. //sandbox.add(replacepos);
  2005. }
  2006. }
  2007.  
  2008. }
  2009. if (zcoord > 0){
  2010. if( world[xcoord][zcoord-1][hoogte] == 1 || world[xcoord][zcoord-1][hoogte] == 5 ){
  2011. for (int c = 0; c < boxes.size() ; c++ ){
  2012. box = boxes.get(c);
  2013. String name ="earth "+ xcoord + " " +(zcoord-1) + " " +hoogte;
  2014. String name2 = box.getName();
  2015. //System.out.println(name);
  2016. //System.out.println(box.getName());
  2017. if (name2.equals(name) )
  2018. {
  2019. boxes.removeElement(box);
  2020. //System.out.println(box.drawed());
  2021. break;
  2022. }
  2023. }
  2024. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  2025.  
  2026. for(int g = 4; g > 0; g--)
  2027. {
  2028. if(zcoord-g>0){
  2029. if(world [xcoord+1][zcoord-g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  2030. {
  2031. beachlength1 = g;
  2032. break;
  2033. }}
  2034. }
  2035. for(int g = 4; g > 0; g--)
  2036. {
  2037. if(zcoord-g > 0 && xcoord > 0){
  2038. if(world [xcoord-1][zcoord-g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  2039. {
  2040. beachlength2 = g;
  2041. break;
  2042. }}
  2043. }
  2044. if(beachlength1 > beachlength2)
  2045. beachlength = beachlength1;
  2046. else
  2047. beachlength = beachlength2;
  2048. //System.out.println(beachlength);
  2049. double R = (double) (Math.random() * 4);
  2050. if ( R > 2 ){
  2051. beachlength= beachlength + 1;
  2052. //System.out.println("adding sum beach");
  2053. }
  2054. else if ( R > 1 ){
  2055. beachlength= beachlength ;
  2056. }
  2057. else{
  2058. beachlength= beachlength - 1;
  2059.  
  2060. }
  2061. if(beachlength < 1){
  2062. beachlength = 1;
  2063. }
  2064. for( int h = 0; h < beachlength; h ++)
  2065. {
  2066. if(zcoord-h > 0)
  2067. world[xcoord][zcoord-h-1][hoogte] = 0 ;
  2068. replacepos = new Point (xcoord, hoogte, zcoord-h-1);
  2069. sandBlock(replacepos);
  2070. //sandbox.add(replacepos);
  2071. }
  2072. }
  2073.  
  2074. }
  2075. if (hoogte > 0){
  2076. if( world[xcoord][zcoord][hoogte-1] == 1 )
  2077. {
  2078. for (int c = 0; c < boxes.size() ; c++ ){
  2079. box = boxes.get(c);
  2080. String name ="earth "+ xcoord+1 + " " +zcoord + " " +(hoogte-1);
  2081. String name2 = box.getName();
  2082. //System.out.println(name);
  2083. //System.out.println(box.getName());
  2084. if (name2.equals(name) )
  2085. {
  2086. boxes.removeElement(box);
  2087. //System.out.println(box.drawed());
  2088. break;
  2089. }
  2090. }
  2091. world[xcoord][zcoord][hoogte-1] = 0;
  2092. replacepos = new Point (xcoord, hoogte-1, zcoord);
  2093. sandBlock(replacepos);
  2094. sandbox.add(replacepos);
  2095. }
  2096.  
  2097.  
  2098. }
  2099. }
  2100. }
  2101.  
  2102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement