var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.MovingAnimal = function() { EHDI.aka.Container.call(this); this.animalRandomizer = (Math.random() > 0.49) ? "lion" : "bear"; this.sprite = new EHDI.aka.Sprite(EHDI.Assets.images[this.animalRandomizer + "_front"]); this.sprite.anchor.x = 0.5; this.sprite.anchor.y = 1; this.addChild(this.sprite); this.collider = EHDI.displays.FillRectangle(0xAA0000, 0, 0, 100, 100, 0); this.collider.anchor.set(0.5, 1); this.collider.y -= 35.5; this.collider.visible = false; this.addChild(this.collider); this.moveSpeed = 96; if(this.animalRandomizer === "bear") this.moveSpeed /= 2; this.distanceTraveled = 0; }; EHDI.components.MovingAnimal.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.MovingAnimal.prototype.move = function(dt) { this.y += dt / 1000 * this.moveSpeed; this.distanceTraveled += dt / 1000 * this.moveSpeed; if(this.distanceTraveled >= this.moveSpeed * 0.5) { this.distanceTraveled = 0; this.sprite.scale.x *= -1; } this.zIndex = this.y - 50; }; EHDI.components.MovingAnimal.prototype.checkIfPlaySFX = function() { if(this.x > 0 && this.x< EHDI.GAME.sceneManager.getStageWidth() && !this.haveIPlaySFX) { this.haveIPlaySFX = true; EHDI.GAME.soundManager.playSFX(this.animalRandomizer + "_spawn"); } };