Exemplo n.º 1
0
  public void loadTerrain() {
    try {
      long start = System.currentTimeMillis();
      // remove the existing terrain and detach it from the root node.
      if (terrain != null) {
        Node existingTerrain = (Node) terrain;
        existingTerrain.removeFromParent();
        existingTerrain.removeControl(TerrainLodControl.class);
        existingTerrain.detachAllChildren();
        terrain = null;
      }

      InputStream fis =
          game.getGameApplication()
              .getAssetManager()
              .locateAsset(new AssetKey("Scenes/" + map + "/terrainsave.jme"))
              .openStream();
      BinaryImporter imp = BinaryImporter.getInstance();
      imp.setAssetManager(assetManager);

      terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
      terrain.setShadowMode(ShadowMode.CastAndReceive);

      clickableNode.attachChild((Node) terrain);

      float duration = (System.currentTimeMillis() - start) / 1000.0f;
      System.out.println("Load took " + duration + " seconds");
    } catch (Exception e) {
    }
  }
Exemplo n.º 2
0
  public GameApplication(
      Game game,
      boolean multiplayer,
      String joinAdress,
      String playerId,
      int playerNumber,
      String map) {
    this.game = game;
    this.map = map;

    setPauseOnLostFocus(false);
    setShowSettings(false);

    if (joinAdress.isEmpty()) {
      server = new GameServer();
      if (server.isStarted() == false) {
        System.out.println("Error cannot start server");
        System.exit(0);
      }

      joinAdress = "localhost";
    }

    if (multiplayer) {
      try {
        client = new GameClient(game, joinAdress, playerId, playerNumber);
      } catch (Exception e) {
        if (server != null) {
          server.close();
          System.out.println("Client error " + e.getMessage());
          System.exit(0);
        }
      }
    }

    try {
      FileInputStream fis = new FileInputStream(new File("settings.txt"));
      AppSettings settings = new AppSettings(true);
      settings.load(new BufferedInputStream(fis));
      setSettings(settings);
    } catch (Exception e) {
      AppSettings settings = new AppSettings(true);
      settings.setResolution(1024, 768);
      settings.setFrameRate(50);
      settings.setFullscreen(false);
      settings.setTitle("JPenguin");

      setSettings(settings);
    }
  }
Exemplo n.º 3
0
  @Override
  public void simpleUpdate(float tpf) {
    if (loading) {
      if (loading_frames == 0) {
        if (game.isMultiplayer() && client.allConnected() == false) {
          return;
        }
      }

      if (loading_frames == 5) {
        if (game.isMultiplayer() && client.allLoaded() == false) {
          return;
        }
      }

      loading(loading_frames);
      loading_frames++;
    } else {

      loops = 0;

      while (System.currentTimeMillis() > next_game_tick
          && loops < MAX_FRAMESKIP
          && (game.isMultiplayer() == false || client.canContinue())) {

        if (game.isMultiplayer()) {
          client.update();
        }

        Timer.update(GAME_TPF);
        game.update(GAME_TPF);

        next_game_tick += SKIP_TICKS;
        loops++;
      }

      camera.update(tpf);
      listener.setLocation(cam.getLocation());
      listener.setRotation(cam.getRotation());
      gui.update(tpf); // nur wegen Kamera auf Minimap
    }
  }
Exemplo n.º 4
0
  public void loading(int pos) {
    if (pos == 0) {
      camera = new RTSCamera(getCamera());
      camera.registerWithInput(inputManager);

      loadingScreen.setProgress(0.1f, "Making Light");
    } else if (pos == 1) {

      loadShadow();
      loadLight();

      loadingScreen.setProgress(0.2f, "Loading Terrain");

    } else if (pos == 2) {
      reflectNode = new Node("reflect");
      rootNode.attachChild(reflectNode);
      nonreflectNode = new Node("non reflect");
      rootNode.attachChild(nonreflectNode);

      clickableNode = new Node("clickable");
      reflectNode.attachChild(clickableNode);
      //  clickableNode.attachChild(createTerrain());
      loadTerrain();
      loadWater();

      camera.addTerrain(terrain);
      camera.addWater(water);

      loadingScreen.setProgress(0.6f, "Loading Doodads");
    } else if (pos == 3) {
      loadDoodads();
      loadingScreen.setProgress(0.8f, "Init Game");
    } else if (pos == 4) {

      game.init();

      // gui=new GUI(game);

      game.getMyGame().init(game);

      if (game.isMultiplayer()) {
        client.finishedLoading();
      }

      loadingScreen.setProgress(1f, "Finished Loading");
    } else if (pos == 5) {
      loadingScreen.clear();
      camera.enable();

      gui = new GUI(game);
      gui.init();

      playerInput = new PlayerInput(game);
      // important input after nifty

      next_game_tick = System.currentTimeMillis();

      Timer.init();
      loading = false;
    }
  }