| 1 | class Arrow extends GameObject |
| 2 | { |
| 3 | speed = 250; |
| 4 | |
| 5 | constructor(x, y, sprite, layer) |
| 6 | { |
| 7 | super(x, y, sprite, layer); |
| 8 | this.transform.angularVelocity = 40; |
| 9 | } |
| 10 | |
| 11 | update(deltaTime) |
| 12 | { |
| 13 | super.update(deltaTime); |
| 14 | |
| 15 | let oldPos = this.transform.position.getCopy(); |
| 16 | |
| 17 | if(GameInput.isHeld(GameInput.keys.ArrowRight)) |
| 18 | { |
| 19 | this.transform.position.x += this.speed * deltaTime; |
| 20 | } |
| 21 | |
| 22 | if(GameInput.isHeld(GameInput.keys.ArrowLeft)) |
| 23 | { |
| 24 | this.transform.position.x -= this.speed * deltaTime; |
| 25 | } |
| 26 | |
| 27 | if(GameInput.isHeld(GameInput.keys.ArrowUp)) |
| 28 | { |
| 29 | this.transform.position.y -= this.speed * deltaTime; |
| 30 | } |
| 31 | |
| 32 | if(GameInput.isHeld(GameInput.keys.ArrowDown)) |
| 33 | { |
| 34 | this.transform.position.y += this.speed * deltaTime; |
| 35 | } |
| 36 | |
| 37 | if(oldPos.distanceTo(this.transform.position) > 1) |
| 38 | { |
| 39 | this.transform.pointTowards(oldPos) |
| 40 | this.transform.rotation += 180; |
| 41 | } |
| 42 | } |
| 43 | } |