class Frog extends GameObject { speed = 200; facing = { left: 1, right: 2 }; currentFacing = this.facing.right; idle = true; constructor(x,y,sprite,layer) { super(x,y,sprite,layer); } update(deltaTime) { super.update(deltaTime); this.idle = true; if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft))) { if(GameInput.isHeld(GameInput.keys.ArrowRight)) { this.arrowCounter++; this.transform.position.x += this.speed * deltaTime; if(this.currentFacing != this.facing.right) { this.renderer.mirrorX = !this.renderer.mirrorX; this.currentFacing = this.facing.right; } CookieManager.setCookie("arrow", "right"); this.idle = false; this.renderer.setAnimation("walk", 0, .2); } if(GameInput.isHeld(GameInput.keys.ArrowLeft)) { this.arrowCounter++; this.transform.position.x -= this.speed * deltaTime; if(this.currentFacing != this.facing.left) { this.renderer.mirrorX = !this.renderer.mirrorX; this.currentFacing = this.facing.left; } CookieManager.setCookie("arrow", "left") this.idle = false; this.renderer.setAnimation("walk", 0, .2); } } if(this.idle) { this.renderer.setAnimationCycleSpeed(-1); } } }