/**
   * For internal use only callback for collisionevent
   *
   * @param event
   */
  public void collision(PhysicsCollisionEvent event) {
    PhysicsCollisionObject objA = event.getObjectA();
    PhysicsCollisionObject objB = event.getObjectB();

    // excluding collisions that involve 2 parts of the ragdoll
    if (event.getNodeA() == null && event.getNodeB() == null) {
      return;
    }

    // discarding low impulse collision
    if (event.getAppliedImpulse() < eventDispatchImpulseThreshold) {
      return;
    }

    boolean hit = false;
    Bone hitBone = null;
    PhysicsCollisionObject hitObject = null;

    // Computing which bone has been hit
    if (objA.getUserObject() instanceof PhysicsBoneLink) {
      PhysicsBoneLink link = (PhysicsBoneLink) objA.getUserObject();
      if (link != null) {
        hit = true;
        hitBone = link.bone;
        hitObject = objB;
      }
    }

    if (objB.getUserObject() instanceof PhysicsBoneLink) {
      PhysicsBoneLink link = (PhysicsBoneLink) objB.getUserObject();
      if (link != null) {
        hit = true;
        hitBone = link.bone;
        hitObject = objA;
      }
    }

    // dispatching the event if the ragdoll has been hit
    if (hit && listeners != null) {
      for (RagdollCollisionListener listener : listeners) {
        listener.collide(hitBone, hitObject, event);
      }
    }
  }
Ejemplo n.º 2
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();
    }
  }