class Frog extends GameObject { facing = { left: [4,5,6], right: [0,1,2] }; speed = 200; currentFacing = this.facing.right; idle = true; currentIndex = 0; frame = 0; constructor(x,y,sprite,layer) { super(x,y,sprite,layer); } update(deltaTime) { super.update(deltaTime); this.idle = true; if(GameInput.isHeld(GameInput.keys.ArrowRight)) { this.transform.position.x += this.speed * deltaTime; if(this.currentFacing != this.facing.right) { this.changeImageDirection(); this.currentFacing = this.facing.right; } CookieManager.setCookie("arrow", "right"); this.idle = false; this.cycleImage(deltaTime); } if(GameInput.isHeld(GameInput.keys.ArrowLeft)) { this.transform.position.x -= this.speed * deltaTime; if(this.currentFacing != this.facing.left) { this.changeImageDirection(); this.currentFacing = this.facing.left; } CookieManager.setCookie("arrow", "left") this.idle = false; this.cycleImage(deltaTime); } if(this.idle) { this.currentIndex = 0; this.resolveToIdleImage(); } } changeImageDirection() { if(this.renderer.subImage > 3) { this.renderer.subImage -= 4; } else { this.renderer.subImage += 4; } } resolveToIdleImage() { if(this.renderer.subImage > 3) { if(this.renderer.subImage != 4) { this.renderer.subImage = 4; } } else { if(this.renderer.subImage != 0) { this.renderer.subImage = 0; } } } cycleImage(deltaTime) { this.frame+= deltaTime; if(this.frame > .05) { this.frame = 0; this.currentIndex++; this.renderer.subImage = this.currentFacing[this.currentIndex % this.currentFacing.length]; } } }