Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
67
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 < 24)
  209. player.setLocalTranslation( xp + 5 , zp, yp);
  210. else if( xp > 488 )
  211. player.setLocalTranslation( xp - 5 , zp, yp);
  212. else if( yp < 24 )
  213. player.setLocalTranslation( xp , zp, yp + 5);
  214. else if( yp > 488 )
  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 yp = player.getLocalTranslation().z ;
  592. double hoogte = player.getLocalTranslation().y ;
  593.  
  594.  
  595. if (oldpos.x != xp||oldpos.y!= hoogte|| oldpos.z != yp){
  596. updateworld(xp, yp);
  597. //HideBlock(xp,zp,yp);
  598.  
  599. }
  600.  
  601. }
  602.  
  603. private void updateworld(double xp1, double yp1)
  604. // poging was wel leuk
  605. {
  606. int xp = (int) (xp1/2);
  607. int yp = (int) (yp1/2);
  608.  
  609. if(xp-12 > 0 && yp-12 > 0 && xp+12 < 255 && yp+12 < 255){
  610. for (int x1 = (int) (xp-12); x1 < xp+12; x1++ ){
  611. for (int y1 = (int) (yp-12); y1 < yp+12; y1++ ){
  612. for(int z1 = 0; z1 < 52; z1++ )
  613. {
  614.  
  615. int x = x1;
  616. int y = y1;
  617. int z = z1;
  618.  
  619.  
  620. if( exposedBlock( x, y, z ) == 1 )
  621. {
  622. if( world[x][y][z] > 0){
  623. box = Boxes[x][y][z];
  624. //System.out.println(box.drawed());
  625. if (box.drawed() == false)
  626. {
  627. System.out.println("UPDATING x: " + x +" y: " + y + " z: " + z);
  628. scene.attachChild(box);
  629. rootNode.attachChild(scene);
  630. scene.updateWorldBound();
  631. box.setDraw(true);
  632. box.updateRenderState();
  633. //System.out.println(box.drawed());
  634.  
  635. }
  636. }
  637.  
  638. }
  639. }
  640. }
  641. }
  642. }
  643.  
  644. //System.out.println("Camera settings: " + x + " " + hoogte + " " + z );
  645. //System.out.println( display.getWidth() + " "+ display.getHeight());
  646. //camera pos, camera LoS
  647. // teken alles wat nog enti getekend is tot visualrange van 50 ?! + siderange van (display.getWidth(),
  648. //display.getHeight());
  649. //remove wat al getekend is maa rniet meer zichtbaar is.
  650. }
  651.  
  652. private void drawworld()
  653. {
  654. for(int x = 0; x < 16; x ++)
  655. {
  656. for(int y = 0; y < 16; y++)
  657. {
  658. for(int z = 0; z < 52; z++ )
  659. {
  660. if( exposedBlock( x, y, z ) == 1 )
  661. {
  662. if( world[x][y][z] == 1)
  663. {
  664.  
  665. box = Boxes[x][y][z];
  666. //System.out.println(box.drawed());
  667. if (box.drawed() == false)
  668. {
  669. scene.attachChild(box);
  670. rootNode.attachChild(scene);
  671. scene.updateWorldBound();
  672. box.setDraw(true);
  673. //System.out.println(box.drawed());
  674.  
  675. }
  676. }
  677.  
  678. else if( world[x][y][z] == 2)
  679. {
  680.  
  681. box = Boxes[x][y][z];
  682. //System.out.println(box.drawed());
  683. if (box.drawed() == false)
  684. {
  685. scene.attachChild(box);
  686. rootNode.attachChild(scene);
  687. scene.updateWorldBound();
  688. box.setDraw(true);
  689. //System.out.println(box.drawed());
  690.  
  691. }
  692. }
  693.  
  694. else if( world[x][y][z] == 3){
  695.  
  696. box = Boxes[x][y][z];
  697. //System.out.println(box.drawed());
  698. if (box.drawed() == false)
  699. {
  700. scene.attachChild(box);
  701. rootNode.attachChild(scene);
  702. scene.updateWorldBound();
  703. box.setDraw(true);
  704. //System.out.println(box.drawed());
  705.  
  706. }
  707. }
  708.  
  709. else if( world[x][y][z] == 4){
  710.  
  711. box = Boxes[x][y][z];
  712. //System.out.println(box.drawed());
  713. if (box.drawed() == false)
  714. {
  715. scene.attachChild(box);
  716. rootNode.attachChild(scene);
  717. scene.updateWorldBound();
  718. box.setDraw(true);
  719. //System.out.println(box.drawed());
  720.  
  721. }
  722. }
  723.  
  724. else if( world[x][y][z] == 5){
  725.  
  726. box = Boxes[x][y][z];
  727. //System.out.println(box.drawed());
  728. if (box.drawed() == false)
  729. {
  730. scene.attachChild(box);
  731. rootNode.attachChild(scene);
  732. scene.updateWorldBound();
  733. box.setDraw(true);
  734. //System.out.println(box.drawed());
  735.  
  736. }
  737. }
  738.  
  739. else if( world[x][y][z] == 6){
  740.  
  741. box = Boxes[x][y][z];
  742. //System.out.println(box.drawed());
  743. if (box.drawed() == false)
  744. {
  745. scene.attachChild(box);
  746. rootNode.attachChild(scene);
  747. scene.updateWorldBound();
  748. box.setDraw(true);
  749. //System.out.println(box.drawed());
  750.  
  751. }
  752. }
  753.  
  754. }
  755. }
  756.  
  757. }System.out.println("Done 1 x " + (52 - x) + " to go");
  758. }
  759. }
  760. private void fillworld(int[][][] world) {
  761.  
  762.  
  763. for(int x = 0; x < 50; x ++)
  764. {
  765. for(int y = 0; y < 50; y++){
  766. for(int z = 0 ; z < 1 ; z++){
  767. Point pos = new Point(x,z,y);
  768. {
  769. //waterBlock(pos);
  770. //earthblock(pos);
  771. //sandBlock(pos);
  772. lavaBlock(pos);
  773. }
  774. }
  775. }
  776. }
  777. }
  778. /* for(int x = 10; x < 30; x ++)
  779. {
  780. for(int y = 0; y < 10; y++){
  781. for(int z = 0 ; z < 3 ; z++){
  782. Point pos = new Point(x,z,y);
  783. {
  784. //waterBlock(pos);
  785. earthblock(pos);
  786. //sandBlock(pos);
  787. //lavaBlock(pos);
  788. }
  789. }
  790. }
  791. }
  792. for(int x = 20; x < 30; x ++)
  793. {
  794. for(int y = 10; y < 30; y++){
  795. for(int z = 0 ; z < 3 ; z++){
  796. Point pos = new Point(x,z,y);
  797. {
  798. //waterBlock(pos);
  799. earthblock(pos);
  800. //sandBlock(pos);
  801. //lavaBlock(pos);
  802. }
  803. }
  804. }
  805. }
  806. for(int x = 10; x < 20; x ++)
  807. {
  808. for(int y = 20; y < 30; y++){
  809. for(int z = 0 ; z < 3 ; z++){
  810. Point pos = new Point(x,z,y);
  811. {
  812. //waterBlock(pos);
  813. earthblock(pos);
  814. //sandBlock(pos);
  815. //lavaBlock(pos);
  816. }
  817. }
  818. }
  819. }
  820. Point poz = new Point (14,2, 14);
  821. waterBlock(poz);
  822. }
  823.  
  824. */
  825. public void addGrass(int[][][] world){
  826. for(int x = 0; x < 256; x ++)
  827. {
  828. for(int y = 0; y < 256; y++){
  829. for(int z = 0 ; z < 6 ; z++){
  830. Point pos = new Point(x,z,y);
  831.  
  832. {
  833. if (z >0){
  834. if( world[x][y][(z-1)] == 1 && world[x][y][z]== 0)
  835. {
  836. grassblock(lowerblock(pos));
  837. }
  838. }
  839. }
  840. }
  841. }
  842. }
  843. }
  844.  
  845.  
  846. public Point lowerblock( Point pos ){
  847. int check = 0;
  848. while(check ==0){
  849. if( pos.y > 0){
  850. if (world [(int) pos.x][(int) pos.z][(int) pos.y-1] == 0 ){
  851. pos.y--;
  852.  
  853. }
  854. else{
  855. check =1;
  856. }
  857. }
  858.  
  859. else{
  860. check =1;
  861. }
  862. }
  863. return pos;
  864. }
  865.  
  866. private void addRivers (){
  867.  
  868. int times = 20;
  869. for (int t = 0; t < times; t++){
  870. float x = Math.round(Math.random()*50);
  871. float y = Math.round(Math.random()*50);
  872. float z = highestBlock(x,y,4)+1;
  873. Point waterpos = new Point(x, z, y);
  874. waterBlock(waterpos);
  875. //System.out.println("added a waterblock");
  876. }
  877.  
  878. }
  879.  
  880. private void Flow()
  881. {
  882. Vector<Point> waterexposed = Waterexposed();
  883. Boolean newwater = false;
  884. Point pos;
  885. for( int c = 0; c < waterexposed.size(); c++ )
  886. {
  887. double xcoord = waterexposed.get(c).x;
  888. double hoogte = waterexposed.get(c).y;
  889. double zcoord = waterexposed.get(c).z;
  890. if(xcoord < 51){
  891. if( world[(int) xcoord + 1][(int) zcoord][(int) hoogte] == 0)
  892. {
  893. pos = new Point(xcoord + 1, hoogte, zcoord);
  894. waterBlock(pos);
  895. newwater = true;
  896. }}
  897. if(xcoord > 0){
  898. if( world[(int) xcoord - 1][(int) zcoord][(int) hoogte] == 0)
  899. {
  900. pos = new Point(xcoord - 1, hoogte, zcoord);
  901. waterBlock(pos);
  902. newwater = true;
  903. }}
  904. if(zcoord < 51){
  905. if( world[(int) xcoord][(int) zcoord + 1][(int) hoogte] == 0)
  906. {
  907. pos = new Point(xcoord, hoogte, zcoord + 1);
  908. waterBlock(pos);
  909. newwater = true;
  910. }}
  911. if(zcoord > 0){
  912. if( world[(int) xcoord][(int) zcoord - 1][(int) hoogte] == 0)
  913. {
  914. pos = new Point(xcoord, hoogte, zcoord - 1);
  915. waterBlock(pos);
  916. newwater = true;
  917. }}
  918. if(hoogte > 0){
  919. if( world[(int) xcoord][(int) zcoord][(int) hoogte - 1] == 0)
  920. {
  921. pos = new Point(xcoord, hoogte - 1, zcoord);
  922. waterBlock(pos);
  923. newwater = true;
  924. }}
  925.  
  926. if(newwater == true)
  927. {
  928. Flow();
  929. }
  930. }
  931. }
  932.  
  933. private Vector<Point> Waterexposed()
  934. {
  935. Vector<Point> exposedwater = new Vector<Point>();
  936. for( int x = 0; x < Water.size(); x++)
  937. {
  938.  
  939. if( waterexposedBlock( (int) Water.get(x).x, (int) Water.get(x).z, (int) Water.get(x).y ) == 1 )
  940. exposedwater.add(Water.get(x));
  941.  
  942. }
  943.  
  944. //System.out.println(exposedwater.get(0).x + " " + exposedwater.get(0).z + " " + exposedwater.get(0).y);
  945. return exposedwater;
  946. }
  947.  
  948.  
  949.  
  950.  
  951.  
  952. private void addLowMountains() {
  953.  
  954. int times = (int) 200;//(620);//(int) Math.round(Math.random()*400);
  955. System.out.println("Adding "+ times + " low mountains");
  956. for (int t = 0; t < times; t++){
  957. double height = Math.round(Math.random()*7);
  958. double radius= Math.round((height));
  959. float x = Math.round(Math.random()*50);
  960. float y = Math.round(Math.random()*50);
  961. float z = highestBlock(x,y,52);
  962. float counter = 0;
  963. float zplus = z;
  964. double radx = Math.round( x+ radius);
  965.  
  966. while( height!= z){ //1 laag per keer
  967. if (radx > x){ //check voor legal mountain
  968. while (radx >= x){//zolang als de moutnain legal is
  969. float xpos = x + counter;
  970. Point pos = new Point( Math.abs(xpos), Math.abs(zplus+1), Math.abs(y));// maak een punt aan
  971. float xneg = x - counter;
  972. float ypos = y + counter;
  973. float yneg = y - counter;
  974. for (int c = 0; c < (radx-x); c++){//bouw dan evenveel blokjes totdat je het verchil tussen rad x en x bereikt hebt
  975. float newx = x;
  976. while(newx >= xneg) {
  977. float newy = y;
  978. while(newy >= yneg){
  979. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) ); // verander punt.
  980. if ((radx -x) < 2){
  981. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  982. earthblock(lowerblock(pos));
  983. }else{
  984. createblock(lowerblock(pos));
  985. }
  986. }
  987. else{
  988. createblock(lowerblock(pos));
  989. }//maak daar block
  990. //if (zplus+ 1 < 5){
  991.  
  992. //earthblock(lowerblock(pos));
  993. //}
  994. //else
  995. // stoneBlock(lowerblock(pos));
  996. newy--;
  997. }
  998. newx--;
  999. }
  1000. newx = x;
  1001. while(newx <= xpos) {
  1002. float newy = y;
  1003. while(newy <= ypos){
  1004. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1005. if ((radx -x) < 2){
  1006. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1007. earthblock(lowerblock(pos));
  1008. }else{
  1009. createblock(lowerblock(pos));
  1010. }
  1011. }
  1012. else{
  1013. createblock(lowerblock(pos));
  1014. }
  1015. newy++;
  1016. }
  1017. newx++;
  1018. }
  1019. while(newx >= xneg) {
  1020. float newy = y;
  1021. while(newy <= ypos){
  1022. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1023. if ((radx -x) < 2){
  1024. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1025. earthblock(lowerblock(pos));
  1026. }else{
  1027. createblock(lowerblock(pos));
  1028. }
  1029. }
  1030. else{
  1031. createblock(lowerblock(pos));
  1032. } newy++;
  1033. }
  1034. newx--;
  1035. }
  1036. newx = x;
  1037. while(newx <= xpos+1) {
  1038. float newy = y;
  1039. while(newy >= yneg){
  1040. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1041. if ((radx -x) < 2){
  1042. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1043. earthblock(lowerblock(pos));
  1044. }else{
  1045. createblock(lowerblock(pos));
  1046. }
  1047. }
  1048. else{
  1049. createblock(lowerblock(pos));
  1050. } newy--;
  1051. }
  1052. newx++;
  1053. }
  1054. }
  1055. radx--;
  1056. counter++;
  1057. }
  1058. height--;
  1059. zplus++;
  1060. if (Math.round(Math.random()*100) > 15)
  1061. {
  1062. radx= x + (radius -1);
  1063. }
  1064. else
  1065. radx = x + radius;
  1066. radius--;
  1067. counter= 0;
  1068. }
  1069. else{
  1070. t++;
  1071. break;
  1072. }
  1073. //System.out.println("Added a low Mountain! " + (times-t) +" low Mountains to go" );
  1074. }
  1075. }
  1076. System.out.println("End of addLowMountains!");
  1077. }
  1078.  
  1079.  
  1080.  
  1081.  
  1082. public void addHighMountains(){
  1083. int times = (int) Math.round(Math.random()*10);
  1084. System.out.println("Adding "+ times + " High mountains");
  1085. for (int t = 0; t < times; t++){
  1086. double height = Math.round(Math.random()*10);
  1087. double radius= Math.round((height));
  1088. float x = Math.round(Math.random()*50);
  1089. float y = Math.round(Math.random()*50);
  1090. float z = highestBlock(x,y,52);
  1091. float counter = 0;
  1092. float zplus = z;
  1093. double radx = Math.round( x+ radius);
  1094. while( height!= z){
  1095. if (radx > x){
  1096. while (radx >= x){
  1097. float xpos = x + counter;
  1098. Point pos = new Point( Math.abs(xpos), Math.abs(zplus+1), Math.abs(y));
  1099. //earthblock(pos);//+
  1100. float xneg = x- counter;
  1101. float ypos = y + counter;
  1102. float yneg = y- counter;
  1103. for (int c = 0; c < (radx-x); c++){
  1104. float newx = x;
  1105. while(newx >= xneg) {
  1106. float newy = y;
  1107. while(newy >= yneg){
  1108. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1109. if ((radx -x) < 2){
  1110. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1111. earthblock(lowerblock(pos));
  1112. }else{
  1113. createblock(lowerblock(pos));
  1114. }
  1115. }
  1116. else{
  1117. createblock(lowerblock(pos));
  1118. } newy--;
  1119. }
  1120. newx--;
  1121. }
  1122. newx = x;
  1123. while(newx <= xpos) {
  1124. float newy = y;
  1125. while(newy <= ypos){
  1126. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1127. if ((radx -x) < 2){
  1128. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1129. earthblock(lowerblock(pos));
  1130. }else{
  1131. createblock(lowerblock(pos));
  1132. }
  1133. }
  1134. else{
  1135. createblock(lowerblock(pos));
  1136. } newy++;
  1137. }
  1138. newx++;
  1139. }
  1140. while(newx >= xneg) {
  1141. float newy = y;
  1142. while(newy <= ypos){
  1143. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1144. if ((radx -x) < 2){
  1145. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1146. earthblock(lowerblock(pos));
  1147. }
  1148. else{
  1149. createblock(lowerblock(pos));
  1150. }
  1151.  
  1152.  
  1153. }
  1154. else{
  1155. createblock(lowerblock(pos));
  1156. } newy++;
  1157. }
  1158. newx--;
  1159. }
  1160. newx = x;
  1161. while(newx <= xpos+1) {
  1162. float newy = y;
  1163. while(newy >= yneg){
  1164. pos = new Point ( Math.abs(newx), Math.abs(zplus+1), Math.abs(newy) );
  1165. if ((radx -x) < 2){
  1166. if ((zplus+1+Math.round(Math.random()*3)) < 10){
  1167. earthblock(lowerblock(pos));
  1168. }
  1169. else{createblock(lowerblock(pos));
  1170.  
  1171. }
  1172. }
  1173. else{
  1174. createblock(lowerblock(pos));
  1175. }
  1176. newy--;
  1177. }
  1178. newx++;
  1179. }
  1180. }
  1181. radx--;
  1182. counter++;
  1183. }
  1184. height--;
  1185. zplus++;
  1186. if (Math.round(Math.random()*100) > 15)
  1187. {
  1188. radx= x + (radius -1);
  1189. }
  1190. else
  1191. radx = x + radius;
  1192. radius--;
  1193. counter= 0;
  1194. }
  1195. else{
  1196. t++;
  1197. break;
  1198. }
  1199.  
  1200. }
  1201. System.out.println("Added a Mountain!");
  1202. }
  1203. System.out.println("End of addHighMountains!");
  1204. }
  1205.  
  1206. public int[][][] gravity(int[][][]world){
  1207. for(int x = 0; x < 255; x ++)//loop de hele array door
  1208. {
  1209. for(int y = 0; y < 255; y++){
  1210. for(int z = 0 ; z < 51 ; z++){
  1211. if (z > 1){
  1212. if (y > 1){
  1213. if (x > 1){
  1214. 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)){
  1215. //zoalng er eennee leuk blokje schuin onder of onder staat is het goed
  1216. }
  1217. else{
  1218. int temp = world[x][y][z];
  1219. world[x][y][z]=0;
  1220. world[x][y][z-1]= temp;
  1221. System.out.println("LOWERED A BLOCK" + temp);
  1222. return world;
  1223. //fix het doro het bloje 1 nnaar onder te zetten
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. }
  1231. return world;
  1232. }
  1233.  
  1234. /*public void earthblockadd(Point pos ){
  1235. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1236. world [(int) pos.x][(int) pos.z][(int) pos.y] = 1;
  1237. //System.out.println("Placed a block on "+ pos.x +" " + pos.z +" "+ pos.y );
  1238. }
  1239. }
  1240. public void grassblockadd(Point pos ){
  1241. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1242. world [(int) pos.x][(int) pos.z][(int) pos.y] = 2 ;
  1243. }
  1244. }
  1245. public void waterblockadd(Point pos ){
  1246. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1247. world [(int) pos.x][(int) pos.z][(int) pos.y] = 3;
  1248. }
  1249. }
  1250. public void stoneblockadd(Point pos ){
  1251. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1252. world [(int) pos.x][(int) pos.z][(int) pos.y] = 4;
  1253. }
  1254. }
  1255.  
  1256. */
  1257. public void createblock( Point pos )
  1258. {
  1259. if (pos.y+ 1 < 10){
  1260.  
  1261. earthblock(lowerblock(pos));
  1262. }
  1263. else
  1264. stoneBlock(lowerblock(pos));
  1265. }
  1266.  
  1267.  
  1268.  
  1269. private void HideBlock(double xp1, double zp1,double yp1)
  1270. {
  1271. int xp = (int) (xp1/2);
  1272. int yp = (int) (yp1/2);
  1273. int zp = (int) (zp1/2);
  1274. if(xp-10 > 0 && yp-10 > 0 && xp+10 < 255 && yp+10 < 255){
  1275. for (int x1 = (int) (xp-7); x1 > (xp-10); x1-- ){
  1276. for (int y1 = (int) (yp-7); y1 > (yp-10); y1-- ){
  1277. for(int z1 = 0; z1 < 51; z1++ )
  1278. {
  1279.  
  1280. int x = x1;
  1281. int y = z1;
  1282. int z = y1;
  1283. if( exposedBlock( x, y, z ) == 1 )
  1284. {
  1285. if( world[x][y][z] > 0)
  1286. {
  1287. box = Boxes[x][y][z];
  1288. if (box.drawed() == true)
  1289. {
  1290. scene.detachChild(box);
  1291. rootNode.attachChild(scene);
  1292. scene.updateWorldBound();
  1293. box.setDraw(false);
  1294. System.out.println("HIDING ");
  1295. box.updateRenderState();
  1296. }
  1297. }
  1298. rootNode.updateRenderState();
  1299. }
  1300. }
  1301. }
  1302. }
  1303. for( int x2 = (int)(xp+7); x2 < xp+10; x2++ ){
  1304. for (int y2 = (int) (yp+7); y2 < yp+10; y2++ ){
  1305. for(int z1 = 0; z1 < 51; z1++ )
  1306. {
  1307.  
  1308. int x3 = x2;
  1309. int y3 = z1;
  1310. int z3 = y2;
  1311. if( exposedBlock( x3, y3, z3 ) == 1 )
  1312. {
  1313. if( world[x3][y3][z3] > 0)
  1314. {
  1315. box = Boxes[x3][y3][z3];
  1316. if (box.drawed() == true)
  1317. {
  1318. scene.detachChild(box);
  1319. rootNode.attachChild(scene);
  1320. scene.updateWorldBound();
  1321. box.setDraw(false);
  1322. box.updateRenderState();
  1323. System.out.println("HIDING ");
  1324. }
  1325. }
  1326. rootNode.updateRenderState();
  1327. }
  1328. }
  1329. }
  1330. }
  1331. }
  1332. }
  1333.  
  1334.  
  1335. public void earthblock(Point pos ){
  1336. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1337. world [(int) pos.x][(int) pos.z][(int) pos.y] = 1;
  1338. String name = "earth "+ pos.x + " " + pos.z + " " + pos.y; //earth 0.0 0.0 0.0
  1339. //System.out.println( name);
  1340. box = new Box2( name, new Vector3f(0,0,0),1, 1,1, false );
  1341. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1342. box.setModelBound(new BoundingBox());
  1343. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1344. box.updateModelBound();
  1345. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/Rock.png");
  1346. // Get my TextureState
  1347. TextureState ts=display.getRenderer().createTextureState();
  1348. // Get my Texture
  1349. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1350. // Set the texture to the TextureState
  1351. ts.setTexture(t);
  1352.  
  1353. // Assign the TextureState to the box
  1354. box.setRenderState(ts);
  1355. //scene.attachChild(box);
  1356. //rootNode.attachChild(scene);
  1357. //scene.updateWorldBound();
  1358.  
  1359. // add array vector/array
  1360. //add elke box in een vector, add ze onder naam als box + pos ? dan kan je ze terugvinden in de vector.
  1361. //Box box
  1362. // box = vector element xxx
  1363. //box.getname() = earth 0.0 0.0 0.0
  1364. //scene.attachChild(box);
  1365. //scene.DetachChild(box);
  1366. //rootNode.updateRenderState();
  1367. // Line of sight algoritme + "foggy" rand van zichtveld?
  1368. boxes.add(box);
  1369. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1370.  
  1371.  
  1372. }
  1373. }
  1374.  
  1375.  
  1376. public void grassblock(Point pos ){
  1377.  
  1378. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1379. world [(int) pos.x][(int) pos.z][(int) pos.y] = 2;
  1380. String name = "grass "+ pos.x + " " + pos.z + " " + pos.y;
  1381. box = new Box2(name, new Vector3f(0,0,0),1, 1,1, false );
  1382. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1383. box.setModelBound(new BoundingBox());
  1384. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1385. box.updateModelBound();
  1386. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/Grass.png");
  1387. // Get my TextureState
  1388. TextureState ts=display.getRenderer().createTextureState();
  1389. // Get my Texture
  1390. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1391. // Set the texture to the TextureState
  1392. ts.setTexture(t);
  1393. // Assign the TextureState to the box
  1394. box.setRenderState(ts);
  1395. //scene.attachChild(box);
  1396. //rootNode.attachChild(scene);
  1397. //scene.updateWorldBound();
  1398.  
  1399. boxes.add(box);
  1400. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1401. }
  1402. }
  1403.  
  1404.  
  1405. public void lavaBlock(Point pos ){
  1406. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1407. world [(int) pos.x][(int) pos.z][(int) pos.y] = 6;
  1408. String name = "lava "+ pos.x + " " + pos.z + " " + pos.y;
  1409. box = new Box2(name, new Vector3f(0,0,0),.999f, 0.999f,.999f, false );
  1410. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1411. box.setModelBound(new BoundingBox());
  1412. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1413. box.updateModelBound();
  1414. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/lava.jpg");
  1415. // Get my TextureState
  1416. TextureState ts=display.getRenderer().createTextureState();
  1417. // Get my Texture
  1418. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1419. // Set the texture to the TextureState
  1420. ts.setTexture(t);
  1421. // Assign the TextureState to the box
  1422. box.setRenderState(ts);
  1423. display.getRenderer();
  1424. //box.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
  1425. //scene.attachChild(box);
  1426. //rootNode.attachChild(scene);
  1427. //scene.updateWorldBound();
  1428.  
  1429. //dit maakt hem transparant!
  1430.  
  1431.  
  1432. boxes.add(box);
  1433. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1434. }
  1435. }
  1436.  
  1437. public void waterBlock(Point pos ){
  1438. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0){
  1439. world [(int) pos.x][(int) pos.z][(int) pos.y] = 3;
  1440. String name = "water "+ pos.x + " " + pos.z + " " + pos.y;
  1441. box = new Box2(name, new Vector3f(0,0,0),.999f, 0.999f,.999f, false );
  1442. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1443. box.setModelBound(new BoundingBox());
  1444. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1445. box.updateModelBound();
  1446. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/water.png");
  1447. // Get my TextureState
  1448. TextureState ts=display.getRenderer().createTextureState();
  1449. // Get my Texture
  1450. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1451. // Set the texture to the TextureState
  1452. ts.setTexture(t);
  1453. // Assign the TextureState to the box
  1454. box.setRenderState(ts);
  1455. display.getRenderer();
  1456. //box.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
  1457. //scene.attachChild(box);
  1458. //rootNode.attachChild(scene);
  1459. //scene.updateWorldBound();
  1460.  
  1461. //dit maakt hem transparant!
  1462. box.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
  1463. BlendState tempBlendState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
  1464. tempBlendState.setBlendEnabled(true);
  1465. tempBlendState.setSourceFunction(BlendState.SourceFunction.SourceAlpha );
  1466. tempBlendState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
  1467. tempBlendState.setTestEnabled(true);
  1468. tempBlendState.setTestFunction(BlendState.TestFunction.Always);
  1469. tempBlendState.setEnabled(true);
  1470.  
  1471. ZBufferState tempZBuffer = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
  1472. tempZBuffer.setEnabled(true);
  1473. tempZBuffer.setWritable(false);
  1474. tempZBuffer.setFunction(ZBufferState.TestFunction.EqualTo);
  1475. box.setRenderState(tempZBuffer);
  1476. box.setRenderState(tempBlendState);
  1477. box.updateRenderState();
  1478. Water.add(pos);
  1479. boxes.add(box);
  1480. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1481. //
  1482. }
  1483. }
  1484.  
  1485.  
  1486.  
  1487. public void stoneBlock(Point pos ){
  1488. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0) {
  1489. world [(int) pos.x][(int) pos.z][(int) pos.y] = 4;
  1490. String name = "stone "+ pos.x + " " + pos.z + " " + pos.y;
  1491. box = new Box2(name, new Vector3f(0,0,0),1, 1,1, false );
  1492. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1493. box.setModelBound(new BoundingBox());
  1494. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1495. box.updateModelBound();
  1496. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/stone.png");
  1497. // Get my TextureState
  1498. TextureState ts=display.getRenderer().createTextureState();
  1499. // Get my Texture
  1500. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1501. // Set the texture to the TextureState
  1502. ts.setTexture(t);
  1503. // Assign the TextureState to the box
  1504. box.setRenderState(ts);
  1505. //scene.attachChild(box);
  1506. //rootNode.attachChild(scene);
  1507. //scene.updateWorldBound();
  1508. boxes.add(box);
  1509. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1510. }
  1511. }
  1512.  
  1513.  
  1514. public void sandBlock(Point pos ){
  1515. if (world [(int) pos.x][(int) pos.z][(int) pos.y] == 0) {
  1516. world [(int) pos.x][(int) pos.z][(int) pos.y] = 5;
  1517. String name = "sand "+ pos.x + " " + pos.z + " " + pos.y;
  1518. box = new Box2(name, new Vector3f(0,0,0),.999f, .999f,.999f, false );
  1519. box.setLocalTranslation((float)pos.x*2,(float)pos.y*2,(float)pos.z*2);
  1520. box.setModelBound(new BoundingBox());
  1521. //CollisionResults results = null;(new Vector3f(0,0,0), 0,0,0)
  1522. box.updateModelBound();
  1523. URL monkeyLoc=HelloKeyInput.class.getClassLoader().getResource("jmetest/data/images/sand.png");
  1524. // Get my TextureState
  1525. TextureState ts=display.getRenderer().createTextureState();
  1526. // Get my Texture
  1527. Texture t=TextureManager.loadTexture(monkeyLoc,Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear);
  1528. // Set the texture to the TextureState
  1529. ts.setTexture(t);
  1530. // Assign the TextureState to the box
  1531. box.setRenderState(ts);
  1532. //scene.attachChild(box);
  1533. //rootNode.attachChild(scene);
  1534. //scene.updateWorldBound();
  1535. boxes.add(box);
  1536. Boxes [(int) pos.x][(int) pos.z][(int) pos.y] = box;
  1537. }
  1538. }
  1539.  
  1540. private void setupSky() {
  1541. sb = new Skybox("skybox", 200, 200, 200);
  1542. try {
  1543. ResourceLocatorTool.addResourceLocator(
  1544. ResourceLocatorTool.TYPE_TEXTURE,
  1545. new SimpleResourceLocator(getClass().getResource(
  1546. "/jmetest/data/texture/")));
  1547. } catch (Exception e) {
  1548. logger.warning("Unable to access texture directory.");
  1549. e.printStackTrace();
  1550. }
  1551. sb.setTexture(Skybox.Face.North, TextureManager.loadTexture(
  1552. "north.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
  1553. Texture.MagnificationFilter.Bilinear));
  1554. sb.setTexture(Skybox.Face.West, TextureManager.loadTexture("west.jpg",
  1555. Texture.MinificationFilter.BilinearNearestMipMap,
  1556. Texture.MagnificationFilter.Bilinear));
  1557. sb.setTexture(Skybox.Face.South, TextureManager.loadTexture(
  1558. "south.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
  1559. Texture.MagnificationFilter.Bilinear));
  1560. sb.setTexture(Skybox.Face.East, TextureManager.loadTexture("east.jpg",
  1561. Texture.MinificationFilter.BilinearNearestMipMap,
  1562. Texture.MagnificationFilter.Bilinear));
  1563. sb.setTexture(Skybox.Face.Up, TextureManager.loadTexture("top.jpg",
  1564. Texture.MinificationFilter.BilinearNearestMipMap,
  1565. Texture.MagnificationFilter.Bilinear));
  1566. sb.setTexture(Skybox.Face.Down, TextureManager.loadTexture(
  1567. "bottom.jpg", Texture.MinificationFilter.BilinearNearestMipMap,
  1568. Texture.MagnificationFilter.Bilinear));
  1569. sb.preloadTextures();
  1570. CullState cullState = display.getRenderer().createCullState();
  1571. cullState.setCullFace(CullState.Face.None);
  1572. cullState.setEnabled(true);
  1573. sb.setRenderState(cullState);
  1574. sb.updateRenderState();
  1575. }
  1576.  
  1577. private void buildPlayer() {
  1578. //box stand in
  1579. Box b = new Box("box", new Vector3f(), 0.35f,0.25f,0.5f);
  1580. b.setModelBound(new BoundingBox());
  1581. b.updateModelBound();
  1582.  
  1583. player = new Node("Player Node");
  1584. player.setLocalTranslation(new Vector3f(8, 10, 8));
  1585. scene.attachChild(player);
  1586. player.attachChild(b);
  1587. //player.attachChild(s);
  1588. player.updateWorldBound();
  1589. }
  1590. private void buildAi() {
  1591. //box stand in
  1592. Box c = new Box("box", new Vector3f(), 0.5f,0.25f,0.35f);
  1593. c.setModelBound(new BoundingBox());
  1594. c.updateModelBound();
  1595.  
  1596. Ai = new Node("Ai Node");
  1597. Ai.setLocalTranslation(new Vector3f(0, 5.25f, 9)); //x, z, y
  1598. scene.attachChild(Ai);
  1599. Ai.attachChild(c);
  1600. Ai.updateWorldBound();
  1601.  
  1602. }
  1603.  
  1604. @SuppressWarnings("unchecked")
  1605. private void buildChaseCamera()
  1606. {
  1607. Vector3f targetOffset = new Vector3f();
  1608. targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;
  1609. HashMap props = new HashMap();
  1610. props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "3");
  1611. props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "0");
  1612. props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
  1613. props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+45 * FastMath.DEG_TO_RAD);
  1614. props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
  1615. props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
  1616. chaser = new ChaseCamera(cam, player, props);
  1617. chaser.setMaxDistance(20);
  1618. chaser.setMinDistance(0);
  1619.  
  1620. }
  1621. private void buildInput() {
  1622. input = new FlagRushHandler(player, settings.getRenderer());
  1623. @SuppressWarnings("unused")
  1624. KeyBinds keybind = new KeyBinds( player, settings.getRenderer() );
  1625.  
  1626. }
  1627. @SuppressWarnings("unused")
  1628. private void Aireload(Vector3f pos, int counter){
  1629.  
  1630. Aiunderling AI= new Aiunderling(pos, counter);
  1631.  
  1632. }
  1633.  
  1634. protected static float highestBlock( float xcoord, float ycoord, float zcoord )
  1635. {
  1636. int x = Math.round( xcoord );
  1637. int y = Math.round( ycoord );
  1638. float height = 0;
  1639. for( int z = 0; z < zcoord; z++)
  1640. {
  1641. 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 )
  1642. height =(float) z;
  1643. }
  1644. return height;
  1645. }
  1646.  
  1647. protected static float highestBlockP( float xcoord, float ycoord, float zcoord )
  1648. {
  1649. int x = Math.round( xcoord );
  1650. int y = Math.round( ycoord );
  1651. float height = 0;
  1652. for( int z = 0; z < zcoord; z++)
  1653. {
  1654. if( world [x][y][z] == 1 || world [x][y][z] == 2|| world [x][y][z] == 4|| world [x][y][z] == 5 )
  1655. height =(float) z;
  1656. }
  1657. return height;
  1658. }
  1659. protected static int exposedBlock(int xcoord, int ycoord, int zcoord ){
  1660. int return1 = 0;
  1661. //if( xcoord > 0 && ycoord > 0 && zcoord > 0 && xcoord <255 && ycoord <255 && zcoord < 51)
  1662. if (xcoord< 255)
  1663. {
  1664. //System.out.println("x + y + z "+ xcoord + " " + ycoord + " " + zcoord);
  1665. if( world[xcoord+1][ycoord][zcoord] == 0 || world[xcoord+1][ycoord][zcoord] == 3 )
  1666. return1 = 1;
  1667. }
  1668. if (xcoord > 0){
  1669. if( world[xcoord-1][ycoord][zcoord] == 0 || world[xcoord-1][ycoord][zcoord] == 3 )
  1670. return1 = 1;
  1671. }
  1672. if (ycoord < 255){
  1673. if( world[xcoord][ycoord+1][zcoord] == 0 || world[xcoord][ycoord+1][zcoord] == 3 )
  1674. return1 = 1;
  1675. }
  1676. if (ycoord > 0){
  1677. if( world[xcoord][ycoord-1][zcoord] == 0 || world[xcoord][ycoord-1][zcoord] == 3 )
  1678. return1 = 1;
  1679. }
  1680. if (zcoord < 51){
  1681. if( world[xcoord][ycoord][zcoord+1] == 0 || world[xcoord][ycoord][zcoord+1] == 3 )
  1682. return1 = 1;
  1683. }
  1684. if (zcoord > 0){
  1685. if( world[xcoord][ycoord][zcoord-1] == 0 || world[xcoord][ycoord][zcoord-1] == 3 )
  1686. return1 = 1;
  1687. }
  1688.  
  1689. return return1;
  1690. }
  1691. protected static int waterexposedBlock(int xcoord, int ycoord, int zcoord ){
  1692. int return1 = 0;
  1693. //if( xcoord > 0 && ycoord > 0 && zcoord > 0 && xcoord <255 && ycoord <255 && zcoord < 51)
  1694. if (xcoord< 51)
  1695. {
  1696. //System.out.println("x + y + z "+ xcoord + " " + ycoord + " " + zcoord);
  1697. if( world[xcoord+1][ycoord][zcoord] == 0 )
  1698. return1 = 1;
  1699. }
  1700. if (xcoord > 0){
  1701. if( world[xcoord-1][ycoord][zcoord] == 0 )
  1702. return1 = 1;
  1703. }
  1704. if (ycoord < 51){
  1705. if( world[xcoord][ycoord+1][zcoord] == 0 )
  1706. return1 = 1;
  1707. }
  1708. if (ycoord > 0){
  1709. if( world[xcoord][ycoord-1][zcoord] == 0 )
  1710. return1 = 1;
  1711. }
  1712. if (zcoord > 0){
  1713. if( world[xcoord][ycoord][zcoord-1] == 0 )
  1714. return1 = 1;
  1715. }
  1716.  
  1717. return return1;
  1718. }
  1719.  
  1720. protected void beach()
  1721. {
  1722. Vector< Point> sandbox = new Vector<Point>();
  1723. for( int x = 0; x < Water.size(); x++ )
  1724. {
  1725. int xcoord = (int) Water.get(x).x;
  1726. int hoogte = (int) Water.get(x).y;
  1727. int zcoord = (int) Water.get(x).z;
  1728. Point replacepos = new Point (xcoord, hoogte,zcoord);
  1729. if (xcoord<255 && zcoord < 255){
  1730. if( world[xcoord+1][zcoord+1][hoogte] == 1 || world[xcoord+1][zcoord+1][hoogte] == 5 )
  1731. {
  1732. for (int c = 0; c < boxes.size() ; c++ ){
  1733. box = boxes.get(c);
  1734. String name ="earth "+ (xcoord+1) + " " +(zcoord+1) + " " +hoogte;
  1735. String name2 = box.getName();
  1736. //System.out.println(name);
  1737. //System.out.println(box.getName());
  1738. if (name2.equals(name) )
  1739. {
  1740. boxes.removeElement(box);
  1741. //System.out.println(box.drawed());
  1742. break;
  1743. }
  1744. }
  1745. world[xcoord+1][zcoord+1][hoogte] = 0;
  1746. replacepos = new Point (xcoord+1, hoogte, zcoord+1);
  1747. sandBlock(replacepos);
  1748. sandbox.add(replacepos);
  1749. }
  1750. }
  1751. if (xcoord>0 && zcoord < 255){
  1752. if( world[xcoord-1][zcoord+1][hoogte] == 1 || world[xcoord-1][zcoord+1][hoogte] == 5 )
  1753. {
  1754. for (int c = 0; c < boxes.size() ; c++ ){
  1755. box = boxes.get(c);
  1756. String name ="earth "+ (xcoord-1) + " " +(zcoord+1) + " " +hoogte;
  1757. String name2 = box.getName();
  1758. //System.out.println(name);
  1759. //System.out.println(box.getName());
  1760. if (name2.equals(name) )
  1761. {
  1762. boxes.removeElement(box);
  1763. //System.out.println(box.drawed());
  1764. break;
  1765. }
  1766. }
  1767. world[xcoord-1][zcoord+1][hoogte] = 0;
  1768. replacepos = new Point (xcoord-1, hoogte, zcoord+1);
  1769. sandBlock(replacepos);
  1770. sandbox.add(replacepos);
  1771. }
  1772. }
  1773. if (xcoord> 0 && zcoord > 0){
  1774. if( world[xcoord-1][zcoord-1][hoogte] == 1 || world[xcoord-1][zcoord-1][hoogte] == 5 )
  1775. {
  1776. for (int c = 0; c < boxes.size() ; c++ ){
  1777. box = boxes.get(c);
  1778. String name ="earth "+ (xcoord-1) + " " +(zcoord-1) + " " +hoogte;
  1779. String name2 = box.getName();
  1780. //System.out.println(name);
  1781. //System.out.println(box.getName());
  1782. if (name2.equals(name) )
  1783. {
  1784. boxes.removeElement(box);
  1785. //System.out.println(box.drawed());
  1786. break;
  1787. }
  1788. }
  1789. world[xcoord-1][zcoord-1][hoogte] = 0;
  1790. replacepos = new Point (xcoord-1, hoogte, zcoord-1);
  1791. sandBlock(replacepos);
  1792. sandbox.add(replacepos);
  1793. }
  1794. }
  1795. if (xcoord<255 && zcoord > 0){
  1796. if( world[xcoord+1][zcoord-1][hoogte] == 1 || world[xcoord+1][zcoord-1][hoogte] == 5 )
  1797. {
  1798. for (int c = 0; c < boxes.size() ; c++ ){
  1799. box = boxes.get(c);
  1800. String name ="earth "+ (xcoord+1) + " " +(zcoord-1) + " " +hoogte;
  1801. String name2 = box.getName();
  1802. //System.out.println(name);
  1803. //System.out.println(box.getName());
  1804. if (name2.equals(name) )
  1805. {
  1806. boxes.removeElement(box);
  1807. //System.out.println(box.drawed());
  1808. break;
  1809. }
  1810. }
  1811. world[xcoord+1][zcoord-1][hoogte] = 0;
  1812. replacepos = new Point (xcoord+1, hoogte, zcoord-1);
  1813. sandBlock(replacepos);
  1814. sandbox.add(replacepos);
  1815. }
  1816. }
  1817. if( world[xcoord+1][zcoord][hoogte] == 1 || world[xcoord+1][zcoord][hoogte] == 5 )
  1818. {
  1819. for (int c = 0; c < boxes.size() ; c++ ){
  1820. box = boxes.get(c);
  1821. String name ="earth "+ (xcoord+1) + " " +zcoord + " " +hoogte;
  1822. String name2 = box.getName();
  1823. //System.out.println(name);
  1824. //System.out.println(box.getName());
  1825. if (name2.equals(name) )
  1826. {
  1827. boxes.removeElement(box);
  1828. //System.out.println(box.drawed());
  1829. break;
  1830. }
  1831. }
  1832.  
  1833. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  1834.  
  1835. for(int g = 4; g > 0; g--)
  1836. {
  1837. if(world [xcoord+g][zcoord+1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1838. {
  1839. beachlength1 = g;
  1840. break;
  1841. }
  1842. }
  1843. for(int g = 4; g > 0; g--)
  1844. {
  1845. if (xcoord+ g < 255 && zcoord-1 > 0)
  1846. if(world [xcoord+g][zcoord-1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1847. {
  1848. beachlength2 = g;
  1849. break;
  1850. }
  1851. }
  1852. if(beachlength1 > beachlength2)
  1853. beachlength = beachlength1;
  1854. else
  1855. beachlength = beachlength2;
  1856. //System.out.println(beachlength);
  1857. double R = (double) (Math.random() * 4);
  1858. if ( R > 2 ){
  1859. beachlength= beachlength + 1;
  1860. //System.out.println("adding sum beach");
  1861. }
  1862. else if ( R > 1 ){
  1863. beachlength= beachlength ;
  1864. }
  1865. else{
  1866. beachlength= beachlength - 1;
  1867.  
  1868. }
  1869. if(beachlength < 1){
  1870. beachlength = 1;
  1871. }
  1872. for( int h = 0; h < beachlength; h ++)
  1873. {
  1874. world[xcoord+h+1][zcoord][hoogte] = 0 ;
  1875. replacepos = new Point (xcoord+h+1, hoogte, zcoord);
  1876. sandBlock(replacepos);
  1877. //sandbox.add(replacepos);
  1878. }
  1879. }
  1880.  
  1881. if (xcoord > 0){
  1882. if( world[xcoord-1][zcoord][hoogte] == 1 || world[xcoord-1][zcoord][hoogte] == 5 ){
  1883. for (int c = 0; c < boxes.size() ; c++ ){
  1884. box = boxes.get(c);
  1885. String name ="earth "+ (xcoord-1) + " " +zcoord + " " +hoogte;
  1886. String name2 = box.getName();
  1887. //System.out.println(name);
  1888. //System.out.println(box.getName());
  1889. if (name2.equals(name) )
  1890. {
  1891. boxes.removeElement(box);
  1892. //System.out.println(box.drawed());
  1893. break;
  1894. }
  1895. }
  1896. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  1897.  
  1898. for(int g = 4; g > 0; g--)
  1899. {
  1900. if (xcoord-g > 0 && zcoord+1 < 255)
  1901. if(world [xcoord-g][zcoord+1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1902. {
  1903. beachlength1 = g;
  1904. break;
  1905. }
  1906. }
  1907. for(int g = 4; g > 0; g--)
  1908. {
  1909. if (xcoord-g > 0 && zcoord-1 > 0)
  1910. if(world [xcoord-g][zcoord-1][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1911. {
  1912. beachlength2 = g;
  1913. break;
  1914. }
  1915. }
  1916. if(beachlength1 > beachlength2)
  1917. beachlength = beachlength1;
  1918. else
  1919. beachlength = beachlength2;
  1920. //System.out.println(beachlength);
  1921. double R = (double) (Math.random() * 4);
  1922. if ( R > 2 ){
  1923. beachlength= beachlength + 1;
  1924. //System.out.println("adding sum beach");
  1925. }
  1926. else if ( R > 1 ){
  1927. beachlength= beachlength ;
  1928. }
  1929. else{
  1930. beachlength= beachlength - 1;
  1931.  
  1932. }
  1933. if(beachlength < 1){
  1934. beachlength = 1;
  1935. }
  1936. for( int h = 0; h < beachlength; h ++)
  1937. {
  1938. world[xcoord-h-1][zcoord][hoogte] = 0 ;
  1939. replacepos = new Point (xcoord-h-1, hoogte, zcoord);
  1940. sandBlock(replacepos);
  1941. //sandbox.add(replacepos);
  1942. }
  1943. }
  1944.  
  1945. }
  1946. if (zcoord < 51){
  1947. if( world[xcoord][zcoord+1][hoogte] == 1 || world[xcoord][zcoord+1][hoogte] == 5 ){
  1948. for (int c = 0; c < boxes.size() ; c++ ){
  1949. box = boxes.get(c);
  1950. String name ="earth "+ xcoord + " " +(zcoord+1) + " " +hoogte;
  1951. String name2 = box.getName();
  1952. //System.out.println(name);
  1953. //System.out.println(box.getName());
  1954. if (name2.equals(name) )
  1955. {
  1956. boxes.removeElement(box);
  1957. //System.out.println(box.drawed());
  1958. break;
  1959. }
  1960. }
  1961. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  1962.  
  1963. for(int g = 4; g > 0; g--)
  1964. {
  1965. if(world [xcoord+1][zcoord+g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1966. {
  1967. beachlength1 = g;
  1968. break;
  1969. }
  1970. }
  1971. for(int g = 4; g > 0; g--)
  1972. {
  1973. if(xcoord > 0 ){
  1974. if(world [xcoord-1][zcoord+g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  1975. {
  1976. beachlength2 = g;
  1977. break;
  1978. }}
  1979. }
  1980. if(beachlength1 > beachlength2)
  1981. beachlength = beachlength1;
  1982. else
  1983. beachlength = beachlength2;
  1984. //System.out.println(beachlength);
  1985. double R = (double) (Math.random() * 4);
  1986. if ( R > 2 ){
  1987. beachlength= beachlength + 1;
  1988. //System.out.println("adding sum beach");
  1989. }
  1990. else if ( R > 1 ){
  1991. beachlength= beachlength ;
  1992. }
  1993. else{
  1994. beachlength= beachlength - 1;
  1995.  
  1996. }
  1997. if(beachlength < 1){
  1998. beachlength = 1;
  1999. }
  2000. for( int h = 0; h < beachlength; h ++)
  2001. {
  2002. world[xcoord][zcoord+h+1][hoogte] = 0 ;
  2003. replacepos = new Point (xcoord, hoogte, zcoord+h+1);
  2004. sandBlock(replacepos);
  2005. //sandbox.add(replacepos);
  2006. }
  2007. }
  2008.  
  2009. }
  2010. if (zcoord > 0){
  2011. if( world[xcoord][zcoord-1][hoogte] == 1 || world[xcoord][zcoord-1][hoogte] == 5 ){
  2012. for (int c = 0; c < boxes.size() ; c++ ){
  2013. box = boxes.get(c);
  2014. String name ="earth "+ xcoord + " " +(zcoord-1) + " " +hoogte;
  2015. String name2 = box.getName();
  2016. //System.out.println(name);
  2017. //System.out.println(box.getName());
  2018. if (name2.equals(name) )
  2019. {
  2020. boxes.removeElement(box);
  2021. //System.out.println(box.drawed());
  2022. break;
  2023. }
  2024. }
  2025. int beachlength = 0, beachlength1 = 0, beachlength2 = 0;
  2026.  
  2027. for(int g = 4; g > 0; g--)
  2028. {
  2029. if(zcoord-g>0){
  2030. if(world [xcoord+1][zcoord-g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  2031. {
  2032. beachlength1 = g;
  2033. break;
  2034. }}
  2035. }
  2036. for(int g = 4; g > 0; g--)
  2037. {
  2038. if(zcoord-g > 0 && xcoord > 0){
  2039. if(world [xcoord-1][zcoord-g][hoogte] == 5 )//ook aan andere kant(zcoord -1) kijken, neem de grootste
  2040. {
  2041. beachlength2 = g;
  2042. break;
  2043. }}
  2044. }
  2045. if(beachlength1 > beachlength2)
  2046. beachlength = beachlength1;
  2047. else
  2048. beachlength = beachlength2;
  2049. //System.out.println(beachlength);
  2050. double R = (double) (Math.random() * 4);
  2051. if ( R > 2 ){
  2052. beachlength= beachlength + 1;
  2053. //System.out.println("adding sum beach");
  2054. }
  2055. else if ( R > 1 ){
  2056. beachlength= beachlength ;
  2057. }
  2058. else{
  2059. beachlength= beachlength - 1;
  2060.  
  2061. }
  2062. if(beachlength < 1){
  2063. beachlength = 1;
  2064. }
  2065. for( int h = 0; h < beachlength; h ++)
  2066. {
  2067. if(zcoord-h > 0)
  2068. world[xcoord][zcoord-h-1][hoogte] = 0 ;
  2069. replacepos = new Point (xcoord, hoogte, zcoord-h-1);
  2070. sandBlock(replacepos);
  2071. //sandbox.add(replacepos);
  2072. }
  2073. }
  2074.  
  2075. }
  2076. if (hoogte > 0){
  2077. if( world[xcoord][zcoord][hoogte-1] == 1 )
  2078. {
  2079. for (int c = 0; c < boxes.size() ; c++ ){
  2080. box = boxes.get(c);
  2081. String name ="earth "+ xcoord+1 + " " +zcoord + " " +(hoogte-1);
  2082. String name2 = box.getName();
  2083. //System.out.println(name);
  2084. //System.out.println(box.getName());
  2085. if (name2.equals(name) )
  2086. {
  2087. boxes.removeElement(box);
  2088. //System.out.println(box.drawed());
  2089. break;
  2090. }
  2091. }
  2092. world[xcoord][zcoord][hoogte-1] = 0;
  2093. replacepos = new Point (xcoord, hoogte-1, zcoord);
  2094. sandBlock(replacepos);
  2095. sandbox.add(replacepos);
  2096. }
  2097.  
  2098.  
  2099. }
  2100. }
  2101. }
  2102.  
  2103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement