| 1 | class BtnGames extends MoveableMenuItem |
| 2 | { |
| 3 | buttons = []; |
| 4 | buttonPadding = 10; |
| 5 | state = 0; |
| 6 | prevState = 1; |
| 7 | |
| 8 | constructor (sx, sy, ex, ey, sprite, layer, isMenu, tOpen = 600, tClose = 800) |
| 9 | { |
| 10 | super(sx, sy, ex, ey, sprite, layer, isMenu, tOpen, tClose); |
| 11 | } |
| 12 | |
| 13 | addedToScene () |
| 14 | { |
| 15 | this.initialiseChildren(); |
| 16 | } |
| 17 | |
| 18 | onClick (btn) |
| 19 | { |
| 20 | this.menu.onClick(btn); |
| 21 | } |
| 22 | |
| 23 | initialiseChildren () |
| 24 | { |
| 25 | let target = this.getNextTargetPosition(); |
| 26 | let buttonFrog = this.scene.addObject(new MoveableMenuItem(this.originPosition.x, this.originPosition.y, target.x, target.y, this.scene.game.images.btnFrog, 3)); |
| 27 | buttonFrog.onClick = function () |
| 28 | { |
| 29 | MinigameInitialiser.StartFrogGame(this.scene, new vector(this.targetPosition.x - this.transform.size.x / 2, this.targetPosition.y - this.transform.size.y / 2), this.transform.size); |
| 30 | MainMenu.Instance.menu.close(); |
| 31 | }; |
| 32 | |
| 33 | buttonFrog.createActiveStateTween = function (time, onDone) |
| 34 | { |
| 35 | return MoveableMenuItem.prototype.createActiveStateTween(time, onDone, this) |
| 36 | .to({ x: [this.targetPosition.x], y: [this.originPosition.y, this.originPosition.y, this.originPosition.y, this.targetPosition.y] }, time) |
| 37 | .easing(TWEEN.Easing.Back.Out); |
| 38 | }; |
| 39 | |
| 40 | buttonFrog.createInactiveStateTween = function (time, onDone) |
| 41 | { |
| 42 | return MoveableMenuItem.prototype.createInactiveStateTween(time, onDone, this) |
| 43 | .to({ x: [this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.targetPosition.x, this.originPosition.x], y: [this.originPosition.y] }, time) |
| 44 | .easing(TWEEN.Easing.Quintic.Out); |
| 45 | }; |
| 46 | |
| 47 | this.menu.addChildItem("btnFrog", buttonFrog); |
| 48 | } |
| 49 | |
| 50 | getNextTargetPosition () |
| 51 | { |
| 52 | let buttonArray = Object.values(this.menu.children); |
| 53 | if (buttonArray == 0) |
| 54 | { |
| 55 | return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding); |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | let previous = buttonArray[buttonArray.length - 1]; |
| 60 | current.endPos = new vector( |
| 61 | previous.targetPosition.x, |
| 62 | previous.targetPosition.y + previous.transform.size.y + this.buttonPadding); |
| 63 | } |
| 64 | } |
| 65 | } |