Exemplo n.º 1
0
  // Received damages
  receiveDamage(dmg) {
    if (this.invincibleTimer > 0) return;

    this.health = clamp(this.health - dmg, 0, this.MaxHealth);

    if (this.health === 0) {
      this.entity.events.emit('kill');
      return;
    }

    this.invincibleTimer = this.DamageInvincibleTime;

    this.entity.events.emit('receiveDamage', dmg);
  }
  fixedUpdate(_, dt) {
    if (this.UseKeyboard) {
      this.entity.coll.force.set(0);
      this.turning = 0;
      if (keyboard.down(this.ForwardKey)) this.pushForward();
      if (keyboard.down(this.BackwardKey)) this.pushBackward();
      if (keyboard.down(this.LeftKey)) this.turning -= 1;
      if (keyboard.down(this.RightKey)) this.turning += 1;
    }

    // Update turning
    if (this.turning !== 0) {
      this.turnSpeed = clamp(this.turnSpeed + this.turning * this.Torque * dt, -this.MaxTurnSpeed, this.MaxTurnSpeed);
    }
    if (this.AngularDamping !== 0) {
      this.turnSpeed *= Math.pow(1 - this.AngularDamping, dt);
    }
    this.entity.rotation += this.turnSpeed * dt;
    this.dir.set(1, 0).rotate(this.entity.rotation);
  }
Exemplo n.º 3
0
  // Actions
  // Recover some health
  heal(v) {
    this.health = clamp(this.health + v, 1, this.MaxHealth);

    this.entity.events.emit('heal', v);
  }