class Chao extends GameObject { speed = 40; scenePadding = 50; targetDestination = null; minTimeBetweenBehaviour = 3; //in seconds maxTimeBetweenbehaviour = 10; // in seconds behaviourTimer = 10; behaviourList = []; currentBehaviour = null; static Instance; get busyWithBehaviour() { return this.currentBehaviour != null; } constructor(x, y, sprite, layer) { super(x, y, sprite, layer); this.wasHeld = {} this.collider.enabled = true; Chao.Instance = this; } registerBehaviour(behaviour) { this.behaviourList.push(behaviour); } endBehaviour() { this.currentBehaviour = null; this.behaviourTimer = Math.randomRange(this.minTimeBetweenBehaviour, this.maxTimeBetweenbehaviour); } addedToScene() { this.renderer.sprite = this.scene.game.chaoImages.random(); this.renderer.defaultAnimationSpeed = 0.2; this.registerBehaviour(new BehaviourSneeze()); } onClick(btn) { console.log(btn); } anyHeld() { return this.wasHeld.right || this.wasHeld.left || this.wasHeld.up || this.wasHeld.down; } update(deltaTime) { super.update(deltaTime); if(this.busyWithBehaviour) this.currentBehaviour.update(deltaTime); else { this.behaviourTimer -= deltaTime; if(this.behaviourTimer <= 0) { this.currentBehaviour = this.behaviourList.random(); this.currentBehaviour.startBehaviour(); } } } }