BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / menus / btnGames.js

btnGames.js

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