| 1 | class Frog extends GameObject { |
| 2 | |
| 3 | speed = 200; |
| 4 | |
| 5 | facing = |
| 6 | { |
| 7 | left: 1, |
| 8 | right: 2 |
| 9 | }; |
| 10 | |
| 11 | currentFacing = this.facing.right; |
| 12 | idle = true; |
| 13 | |
| 14 | constructor(x,y,sprite,layer) |
| 15 | { |
| 16 | super(x,y,sprite,layer); |
| 17 | } |
| 18 | |
| 19 | update(deltaTime) |
| 20 | { |
| 21 | super.update(deltaTime); |
| 22 | this.idle = true; |
| 23 | |
| 24 | if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft))) |
| 25 | { |
| 26 | if(GameInput.isHeld(GameInput.keys.ArrowRight)) |
| 27 | { |
| 28 | this.arrowCounter++; |
| 29 | this.transform.position.x += this.speed * deltaTime; |
| 30 | |
| 31 | if(this.currentFacing != this.facing.right) |
| 32 | { |
| 33 | this.renderer.mirrorX = !this.renderer.mirrorX; |
| 34 | this.currentFacing = this.facing.right; |
| 35 | } |
| 36 | |
| 37 | CookieManager.setCookie("arrow", "right"); |
| 38 | this.idle = false; |
| 39 | this.renderer.setAnimation("walk", 0, .2); |
| 40 | } |
| 41 | |
| 42 | if(GameInput.isHeld(GameInput.keys.ArrowLeft)) |
| 43 | { |
| 44 | this.arrowCounter++; |
| 45 | this.transform.position.x -= this.speed * deltaTime; |
| 46 | |
| 47 | if(this.currentFacing != this.facing.left) |
| 48 | { |
| 49 | |
| 50 | this.renderer.mirrorX = !this.renderer.mirrorX; |
| 51 | this.currentFacing = this.facing.left; |
| 52 | } |
| 53 | |
| 54 | CookieManager.setCookie("arrow", "left") |
| 55 | this.idle = false; |
| 56 | this.renderer.setAnimation("walk", 0, .2); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if(this.idle) |
| 61 | { |
| 62 | this.renderer.setAnimationCycleSpeed(-1); |
| 63 | } |
| 64 | } |
| 65 | } |