@Override public void onAction(final String name, final boolean keyPressed, final float tpf) { if (name.equals("Lefts")) { if (keyPressed) { TerrainGridTileLoaderTest.this.left = true; } else { TerrainGridTileLoaderTest.this.left = false; } } else if (name.equals("Rights")) { if (keyPressed) { TerrainGridTileLoaderTest.this.right = true; } else { TerrainGridTileLoaderTest.this.right = false; } } else if (name.equals("Ups")) { if (keyPressed) { TerrainGridTileLoaderTest.this.up = true; } else { TerrainGridTileLoaderTest.this.up = false; } } else if (name.equals("Downs")) { if (keyPressed) { TerrainGridTileLoaderTest.this.down = true; } else { TerrainGridTileLoaderTest.this.down = false; } } else if (name.equals("Jumps")) { TerrainGridTileLoaderTest.this.player3.jump(); } else if (name.equals("pick") && keyPressed) { // Terrain picked = terrain.getTerrainAt(player3.getPhysicsLocation()); Terrain picked = terrain.getTerrainAtCell(terrain.getCurrentCell()); System.out.println( "** cell " + player3.getPhysicsLocation() + " picked terrain: " + picked); } }
/** * This is the main event loop--walking happens here. We check in which direction the player is * walking by interpreting the camera direction forward (camDir) and to the side (camLeft). The * setWalkDirection() command is what lets a physics-controlled player walk. We also make sure * here that the camera moves with player. */ @Override public void simpleUpdate(float tpf) { camDir.set(cam.getDirection()).multLocal(0.6f); camLeft.set(cam.getLeft()).multLocal(0.4f); walkDirection.set(0, 0, 0); if (left) { walkDirection.addLocal(camLeft); } if (right) { walkDirection.addLocal(camLeft.negate()); } if (up) { walkDirection.addLocal(camDir); } if (down) { walkDirection.addLocal(camDir.negate()); } player.setWalkDirection(walkDirection); cam.setLocation(player.getPhysicsLocation()); }
@Override public void simpleUpdate(float lastTimePerFrame) { float playerMoveSpeed = ((cubesSettings.getBlockSize() * 6.5f) * lastTimePerFrame); Vector3f camDir = cam.getDirection().mult(playerMoveSpeed); Vector3f camLeft = cam.getLeft().mult(playerMoveSpeed); walkDirection.set(0, 0, 0); if (arrowKeys[0]) { walkDirection.addLocal(camDir); } if (arrowKeys[1]) { walkDirection.addLocal(camLeft.negate()); } if (arrowKeys[2]) { walkDirection.addLocal(camDir.negate()); } if (arrowKeys[3]) { walkDirection.addLocal(camLeft); } walkDirection.setY(0); walkDirection.normalize(); walkDirection.multLocal(lastTimePerFrame * 10); playerControl.setWalkDirection(walkDirection); cam.setLocation(playerControl.getPhysicsLocation()); }