class Chao extends GameObject { speed = 30; constructor(x, y, sprite, layer) { super(x, y, sprite, layer); this.wasHeld = {} this.collider.enabled = true; } onClick(btn) { console.log(btn); } anyHeld() { return this.wasHeld.right || this.wasHeld.left || this.wasHeld.up || this.wasHeld.down; } update(deltaTime) { super.update(deltaTime); this.wasHeld = this.wasHeld || {} if(this.wasHeld.right && !GameInput.isHeld(GameInput.keys.ArrowRight)) { this.wasHeld.right = false; if(!this.anyHeld()) this.renderer.setAnimation("standLeft", 0, .2); } if(this.wasHeld.left && !GameInput.isHeld(GameInput.keys.ArrowLeft)) { this.wasHeld.left = false; if(!this.anyHeld()) this.renderer.setAnimation("standLeft", 0, .2); } if(this.wasHeld.up && !GameInput.isHeld(GameInput.keys.ArrowUp)) { this.wasHeld.up = false; if(!this.anyHeld()) this.renderer.setAnimation("standUp", 0, .2); } if(this.wasHeld.down && !GameInput.isHeld(GameInput.keys.ArrowDown)) { this.wasHeld.down = false; if(!this.anyHeld()) this.renderer.setAnimation("standDown", 0, .2); } if(GameInput.isHeld(GameInput.keys.ArrowRight) && !this.wasHeld.left && !this.wasHeld.up && !this.wasHeld.down) { this.transform.position.x += this.speed * deltaTime; CookieManager.setCookie("arrow", "right"); if(!this.wasHeld.right) this.renderer.setAnimation("walkLeft", 0, .2); this.renderer.mirrorX = true; this.wasHeld.right = true; } else if(GameInput.isHeld(GameInput.keys.ArrowLeft) && !this.wasHeld.right && !this.wasHeld.up && !this.wasHeld.down) { this.transform.position.x -= this.speed * deltaTime; CookieManager.setCookie("arrow", "left") if(!this.wasHeld.left) this.renderer.setAnimation("walkLeft", 0, .2); this.renderer.mirrorX = false; this.wasHeld.left = true; } else if(GameInput.isHeld(GameInput.keys.ArrowUp) && !this.wasHeld.left && !this.wasHeld.right && !this.wasHeld.down) { this.transform.position.y -= this.speed * deltaTime; CookieManager.setCookie("arrow", "up") if(!this.wasHeld.up) this.renderer.setAnimation("walkUp", 0, .2); this.renderer.mirrorX = false; this.wasHeld.up = true; } else if(GameInput.isHeld(GameInput.keys.ArrowDown) && !this.wasHeld.left && !this.wasHeld.up && !this.wasHeld.right) { this.transform.position.y += this.speed * deltaTime; CookieManager.setCookie("arrow", "down") if(!this.wasHeld.down) this.renderer.setAnimation("walkDown", 0, .2); this.renderer.mirrorX = false; this.wasHeld.down = true; } else { if(GameInput.isPressed(GameInput.keys["1"])) { this.renderer.setAnimation("tripDown", 0, .2) } if(GameInput.isPressed(GameInput.keys["2"])) { this.renderer.setAnimation("tripLeft", 0, .2) } if(GameInput.isPressed(GameInput.keys["3"])) { this.renderer.setAnimation("tripUp", 0, .2) } if(GameInput.isPressed(GameInput.keys["4"])) { this.renderer.setAnimation("sitDown", 0, .2) } if(GameInput.isPressed(GameInput.keys["5"])) { this.renderer.setAnimation("sitLeft", 0, .2) } if(GameInput.isPressed(GameInput.keys["6"])) { this.renderer.setAnimation("tantrum", 0, .2) } if(GameInput.isPressed(GameInput.keys["7"])) { this.renderer.setAnimation("swimStruggle", 0, .2) } if(GameInput.isPressed(GameInput.keys["8"])) { this.renderer.setAnimation("swim", 0, .2) } if(GameInput.isPressed(GameInput.keys["9"])) { this.renderer.setAnimation("eatStart", 0, .2) } if(GameInput.isPressed(GameInput.keys["0"])) { this.renderer.setAnimation("cheer", 0, .2) } if(GameInput.isPressed(GameInput.keys["q"])) { this.renderer.setAnimation("wave", 0, .2) } if(GameInput.isPressed(GameInput.keys["w"])) { this.renderer.setAnimation("hungry", 0, .2) } if(GameInput.isPressed(GameInput.keys["e"])) { this.renderer.setAnimation("no", 0, .2) } if(GameInput.isPressed(GameInput.keys["r"])) { this.renderer.setAnimation("think", 0, .2) } if(GameInput.isPressed(GameInput.keys["t"])) { this.renderer.setAnimation("happy", 0, .2) } if(GameInput.isPressed(GameInput.keys["y"])) { this.renderer.setAnimation("sad", 0, .2) } if(GameInput.isPressed(GameInput.keys["u"])) { this.renderer.setAnimation("sleep", 0, .2) } if(GameInput.isPressed(GameInput.keys["i"])) { this.renderer.setAnimation("eatBig", 0, .2) } if(GameInput.isPressed(GameInput.keys["o"])) { this.renderer.setAnimation("sneeze", 0, .2) } if(GameInput.isPressed(GameInput.keys["p"])) { this.renderer.setAnimation("cry", 0, .2) } if(GameInput.isPressed(GameInput.keys["["])) { this.renderer.setAnimation("think2", 0, .2) } } } }