Fix vibration bug

This commit is contained in:
schmelczerandras 2020-10-26 16:08:47 +01:00
parent b8ef90c100
commit 4dd90b9860
2 changed files with 7 additions and 4 deletions

View file

@ -25,6 +25,7 @@ export class GameObjectContainer extends CommandReceiver {
} }
this.player = c.character as PlayerCharacterView; this.player = c.character as PlayerCharacterView;
this.player.isMainCharacter = true;
this.camera = new Camera(this.game); this.camera = new Camera(this.game);

View file

@ -14,6 +14,8 @@ export class PlayerCharacterView extends PlayerCharacterBase implements ViewObje
private healthElement: HTMLElement = document.createElement('div'); private healthElement: HTMLElement = document.createElement('div');
private previousHealth; private previousHealth;
public isMainCharacter = false;
constructor( constructor(
id: Id, id: Id,
name: string, name: string,
@ -50,12 +52,12 @@ export class PlayerCharacterView extends PlayerCharacterBase implements ViewObje
public step(deltaTimeInSeconds: number): void { public step(deltaTimeInSeconds: number): void {
if (this.previousHealth > this.health) { if (this.previousHealth > this.health) {
this.previousHealth = this.health; if (this.isMainCharacter && OptionsHandler.options.vibrationEnabled) {
if (OptionsHandler.options.vibrationEnabled) { navigator.vibrate(Math.min(200, (this.previousHealth - this.health) * 4));
navigator.vibrate(75);
} }
this.previousHealth = this.health;
} }
this.previousHealth = this.health;
} }
public onShoot(strength: number) { public onShoot(strength: number) {