コード例 #1
0
  @ReceiveEvent(components = {HealthComponent.class})
  public void onCrash(HorizontalCollisionEvent event, EntityRef entity) {
    HealthComponent health = entity.getComponent(HealthComponent.class);

    Vector3f vel = new Vector3f(event.getVelocity());
    vel.y = 0;
    float speed = vel.length();

    if (speed > health.horizontalDamageSpeedThreshold) {
      int damage =
          (int)
              ((speed - health.horizontalDamageSpeedThreshold)
                  * health.excessSpeedDamageMultiplier);
      if (damage > 0) {
        checkDamage(
            entity, damage, EngineDamageTypes.PHYSICAL.get(), EntityRef.NULL, EntityRef.NULL);
      }
    }
  }
コード例 #2
0
  @ReceiveEvent
  public void onCrash(
      HorizontalCollisionEvent event,
      EntityRef entity,
      CharacterSoundComponent characterSounds,
      HealthComponent healthComponent) {
    Vector3f horizVelocity = new Vector3f(event.getVelocity());
    horizVelocity.y = 0;
    float velocity = horizVelocity.length();

    if (velocity > healthComponent.horizontalDamageSpeedThreshold) {
      if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = random.nextItem(characterSounds.landingSounds);
        if (sound != null) {
          entity.send(new PlaySoundEvent(sound, characterSounds.landingVolume));
          characterSounds.lastSoundTime = time.getGameTimeInMs();
          entity.saveComponent(characterSounds);
        }
      }
    }
  }