class Chao extends GameObject { speed = 40; scenePadding = 50; targetDestination = null; minTimeBetweenBehaviour = 3; //in seconds maxTimeBetweenbehaviour = 10; // in seconds behaviourTimer = 10; behaviourList = []; currentBehaviour = null; particler = 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()); this.particler = new ParticleEmitter(new vector(100, 100), this.scene.game.images.gem, 0.1, 45, 0, 4, 0, new vector(0, 0.1), 0, new vector(30, 30), new vector(50, 50), 2, 2.5, 0.5, 1, 0) this.particler.start(); } onClick(btn) { console.log(btn); } anyHeld() { return this.wasHeld.right || this.wasHeld.left || this.wasHeld.up || this.wasHeld.down; } update(deltaTime) { super.update(deltaTime); this.particler.emissionAngle = Math.randomRange(10, 60) this.particler.startFrame = Math.floor(Math.randomRange(0, this.scene.game.images.gem.subImages)) this.particler.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(); } } } draw(context) { super.draw(context); this.particler.draw(this.scene) } }