protected void shutdown() {
    super.shutdown();

    backgroundMusic.release(audioMgr);
    splatSound.release(audioMgr);
    resource1.unload();
    audioMgr.shutdown();

    if (gameClient != null) {
      gameClient.sendByeMessage();
      try {
        gameClient.shutdown();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    display.close();
  }
 protected void render() {
   renderer.setCamera(camera1);
   super.render();
 }
  private void initGameObjects() {
    // group1 = new Group();
    // group2 = new Group();
    // group1.addChild(group2);
    arrow = new Arrow();
    addGameWorldObject(arrow);
    Matrix3D tempM;
    TriMesh otherCube;
    Random rand = new Random();
    for (int i = 0; i < cubeList.length; i++) {
      otherCube = objLoader.loadModel("src/Models/car.obj");
      tempM = otherCube.getLocalTranslation();
      if (i > 10) {
        tempM.translate(rand.nextInt(30) * 1, 30, rand.nextInt(30) * 1);
      }
      tempM.translate(rand.nextInt(30) + 1, 30, rand.nextInt(30) + 1);
      otherCube.setLocalTranslation(tempM);
      otherCube.updateWorldBound();
      otherCube.updateGeometricState(1.0f, true);
      float angVeloc[] = {rand.nextInt(10), rand.nextInt(10), rand.nextInt(10)};
      carPArray[i] =
          physicsEngine.addSphereObject(
              physicsEngine.nextUID(), ballMass, otherCube.getWorldTransform().getValues(), 1.0f);
      carPArray[i].setBounciness(1.0f);
      carPArray[i].setAngularVelocity(angVeloc);
      otherCube.setPhysicsObject(carPArray[i]);
      addGameWorldObject(otherCube);
      // group2.addChild(otherCube);
      cubeList[i] = otherCube;
    }

    TriMesh otherCylinder;
    for (int i = 0; i < cylinderList.length; i++) {
      otherCylinder = objLoader.loadModel("src/Models/truck.obj");
      tempM = otherCylinder.getLocalTranslation();
      // if(i > 10){
      // tempM.translate(rand.nextInt(30)*1, 30, rand.nextInt(30)*1);
      // }
      tempM.translate(rand.nextInt(90), 90, rand.nextInt(90));
      otherCylinder.setLocalTranslation(tempM);
      otherCylinder.updateWorldBound();
      truckPArray[i] =
          physicsEngine.addSphereObject(
              physicsEngine.nextUID(),
              ballMass,
              otherCylinder.getWorldTransform().getValues(),
              1.0f);
      truckPArray[i].setBounciness(0.5f);
      otherCylinder.setPhysicsObject(truckPArray[i]);
      addGameWorldObject(otherCylinder);
      // group2.addChild(otherCylinder);
      cylinderList[i] = otherCylinder;
    }

    MyPyramid otherPyramid;
    for (int i = 0; i < pyramidList.length; i++) {
      otherPyramid = new MyPyramid();
      tempM = otherPyramid.getLocalTranslation();
      // if(i > 10){
      // tempM.translate(rand.nextInt(30)*-1, 0, rand.nextInt(45)*-1);
      // }
      // tempM.translate(rand.nextInt(30), 0, rand.nextInt(45)*-1);
      if (i > 10) {
        tempM.translate(rand.nextInt(30) * 1, 30, rand.nextInt(30) * 1);
      }
      tempM.translate(rand.nextInt(30) + 1, 30, rand.nextInt(30) + 1);
      otherPyramid.setLocalTranslation(tempM);
      otherPyramid.updateWorldBound();
      addGameWorldObject(otherPyramid);
      // group2.addChild(otherPyramid);
      pyramidList[i] = otherPyramid;
    }

    // MyTranslateController transController = new MyTranslateController();
    // spinController = new MySpinController();

    // group1.addController(transController);
    // transController.addControlledNode(group1);

    // group2.addController(spinController);
    // spinController.addControlledNode(group2);

    // ballP = physicsEngine.addSphereObject(physicsEngine.nextUID(),
    // ballMass, group1.getWorldTransform().getValues(),1.0f);
    // ballP.setBounciness(1.0f);
    // group1.setPhysicsObject(ballP);

    // addGameWorldObject(group1);
    super.update(0);
  }
  public void update(float elapsedTimeMS) {
    super.update(elapsedTimeMS);
    player1.updateAnimation(elapsedTimeMS);

    if (!isGPOn) {
      cam1Controller.update(elapsedTimeMS);
    } else {
      cam1GPController.update(elapsedTimeMS);
    }

    if (gameClient != null) {
      gameClient.sendUpdate(getPlayerPosition());
      gameClient.processPackets();
    }
    physicsEngine.update(20.0f);
    Matrix3D mat;
    Vector3D translateVec;

    for (SceneNode s : getGameWorld()) {

      if (s.getPhysicsObject() != null) {
        if (s.getWorldBound().intersects(player1.getWorldBound())
            && (s.getName().equals("src/Models/car.obj")
                || s.getName().equals("src/Models/truck.obj"))) {
          playerHit = true;

          s.setLocalTranslation(new Matrix3D());
          s.translate(0, 10, 0);
        }
        if (s.getName().equals(player1.getName())) {
          mat = s.getLocalTranslation();
          translateVec = mat.getCol(3);
          s.getLocalTranslation().setCol(3, translateVec);

        } else {
          mat = new Matrix3D(s.getPhysicsObject().getTransform());
          translateVec = mat.getCol(3);
          s.getLocalTranslation().setCol(3, translateVec);
        }
      } else if (s instanceof TriMesh
          && s.getWorldBound().intersects(player1.getWorldBound())
          && (s.getName().equals("src/Models/car.obj")
              || s.getName().equals("src/Models/truck.obj"))) {
        playerHit = true;
      }
    }
    player1ScoreString.setText("Score = " + player1Score);
    player1HPString.setText("HP: " + player1HP);

    Matrix3D camTranslation = new Matrix3D();
    camTranslation.translate(
        camera1.getLocation().getX(), camera1.getLocation().getY(), camera1.getLocation().getZ());
    skybox.setLocalTranslation(camTranslation);

    if (playerHit) {
      splatSound.play(100, false);
      player1.translate(133f, 13f, 123f);
      playerHit = false;
    }

    if (gameOver) {
      player1GameOverString.setText("LOOOOOOOSER!");
    } else if (!player1Won) {
      if (checkWin()) {
        gameClient.sendWonMessage();
        player1Won = true;
        player1GameOverString.setText("WINNER!");
      }
    }
  }
 public void start() {
   super.start();
 }