/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Opponent.js :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: edbernar start + (end - start) * t; const thisClass = this; const speedFactor = 0.5; if (thisClass.animationFrame) cancelAnimationFrame(thisClass.animationFrame); const animate = () => { this.object.position.x = lerp(this.object.position.x, content.pos, speedFactor); if (Math.abs(this.object.position.x - content.pos) < 0.01) this.object.position.x = content.pos; else thisClass.animationFrame = requestAnimationFrame(animate); }; thisClass.animationFrame = requestAnimationFrame(animate); if (content.up && thisClass.object.position.y < thisClass.limits.up) { if (this.interval) clearInterval(this.interval); thisClass.interval = setInterval(() => { thisClass.object.position.y += thisClass.speed / 40; if (thisClass.object.position.y >= thisClass.limits.up) { clearInterval(thisClass.interval); thisClass.interval = null; } }, 5); } else if (!content.up && thisClass.object.position.y > thisClass.limits.down) { if (this.interval) clearInterval(this.interval); this.interval = setInterval(() => { thisClass.object.position.y -= thisClass.speed / 40; if (thisClass.object.position.y <= thisClass.limits.down) { clearInterval(thisClass.interval); thisClass.interval = null; thisClass.object.position.y = thisClass.limits.down; } }, 5); } } } export { Opponent };