Beispiel #1
0
  public void collision(PhysicsCollisionEvent event) {
    String nodeA = event.getNodeA().getName();
    String nodeB = event.getNodeB().getName();
    if (nodeA.equals("Spaceship") || nodeB.equals("Spaceship")) {
      lives = -1;

      /*if(nodeB.equals("Sun") || nodeA.equals("Sun")) {
          lives -= 3;
      } else {
          lives--;
      }*/
      if (lives >= 0) {
        // guiNode.detachChild(livespic[lives]);
        Vector3f movement = new Vector3f(0, 0, 0);
        spaceship.getWorldRotation().mult(new Vector3f(0, 0, 10), movement);
        spaceship.getControl().setLinearVelocity(movement);
      } else {
        speed = 0.2f;
        generateExplosion(spaceship.getWorldTranslation());
        generateDebris(spaceship.getWorldTranslation());
        spaceship.getSound("Accelerate").stop();
        bap.getPhysicsSpace().remove(spaceship.getControl());
        spaceship.removeFromParent();
        lives = 0;
        guiNode.detachAllChildren();
        guiNode.detachChild(showText);
        showText.setText("GAME OVER");
        guiNode.attachChild(showText);
        guiNode.attachChild(scoreText);
        inputManager.removeListener(actionListener);
      }
    } else if (nodeA.equals("Laser") || nodeB.equals("Laser")) {
      if (nodeB.equals("Asteroid") || nodeA.equals("Asteroid")) {
        final Asteroid asteroid;
        if (nodeA.equals("Asteroid")) {
          asteroid = (Asteroid) event.getNodeA();
        } else {
          asteroid = (Asteroid) event.getNodeB();
        }
        if (asteroid.isComet()) {
          score += 500;
        } else {
          score += 100;
        }
        generateDebris(asteroid.getWorldTranslation());
        bap.getPhysicsSpace().remove(asteroid.getControl());
        asteroid.removeFromParent();
      } else {
        score -= 50;
      }
      Laser laser;
      if (nodeA.equals("Laser")) {
        laser = (Laser) event.getNodeA();
      } else {
        laser = (Laser) event.getNodeB();
      }
      generateExplosion(laser.getWorldTranslation());
      bap.getPhysicsSpace().remove(laser.getControl());
      laser.removeFromParent();
    }
  }
Beispiel #2
0
  public void generateRandomAsteroid() {
    Material asteroidMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    asteroidMaterial.setTexture(
        "DiffuseMap", assetManager.loadTexture("Textures/Asteroid/Solid.png"));
    asteroidMaterial.setTexture(
        "NormalMap", assetManager.loadTexture("Textures/Asteroid/Normal.png"));

    Asteroid asteroid =
        new Asteroid("Asteroid", assetManager.loadModel("Models/Asteroid.j3o"), asteroidMaterial);

    asteroid.getModel().scale((float) Math.random() / 2);

    if (Math.random() * noComet < 0.05) {
      asteroid.getModel().scale((float) Math.random() / 2);
      asteroid.addTrail(
          new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"),
          assetManager.loadTexture("Effects/Explosion/flame.png"));
      asteroid.setSpeed((int) (Math.random() * 4) + 10);
      noComet = 1;
    } else {
      asteroid.setSpeed((int) (Math.random() * 4) + 4);
      noComet -= 0.05;
    }

    rootNode.attachChild(asteroid);

    float theta = (float) (2 * FastMath.PI * Math.random());
    float phi = (float) (2 * FastMath.PI * Math.random());
    float r = 120;

    float x = r * FastMath.cos(theta) * FastMath.sin(phi);
    float y = r * FastMath.sin(theta) * FastMath.cos(phi);
    float z = r * FastMath.cos(phi);

    asteroid.setLocalTranslation(x, y, z);
    asteroid.setDirection(
        planets[2]
            .getGeom()
            .getWorldTranslation()
            .subtract(asteroid.getLocalTranslation())
            .normalize());
    asteroid.setRotation(
        new Vector3f((float) Math.random(), (float) Math.random(), (float) Math.random())
            .normalize());
    asteroid.registerPhysics(bap.getPhysicsSpace());
    asteroids.attachChild(asteroid);
  }