| 1 | class Fruit extends GameObject |
| 2 | { |
| 3 | speed = 10; |
| 4 | |
| 5 | constructor (x, y, sprite, layer) |
| 6 | { |
| 7 | super(x, y, sprite, layer); |
| 8 | |
| 9 | this.transform.scale = new vector(0.7, 0.7); |
| 10 | this.renderer.subImage = Math.floor(Math.randomRange(0, 15)); |
| 11 | |
| 12 | this.collider.enabled = true; |
| 13 | } |
| 14 | |
| 15 | onCollision (obj) |
| 16 | { |
| 17 | if (obj instanceof FloorTile) |
| 18 | { |
| 19 | obj.destroy(); |
| 20 | this.scene.destroyFruit(this); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | update (deltaTime) |
| 25 | { |
| 26 | super.update(deltaTime); |
| 27 | |
| 28 | this.transform.position.y += this.speed * this.scene.gameSpeed * this.scene.gameSpeed * deltaTime; |
| 29 | |
| 30 | if (this.transform.position.y > this.scene.real_size.y) |
| 31 | { |
| 32 | this.scene.destroyFruit(this); |
| 33 | } |
| 34 | } |
| 35 | } |