BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / menus / mainMenu.js

mainMenu.js

some cool shtuff
timfa wsadhelios · pushed by timfa · 4 years ago
ed656e16 History
mainMenu.js 3.2 KiB Download Raw
1class MainMenu extends BaseMenu
2{
3 static Instance;
4
5 buttons = [];
6 buttonPadding = 10;
7 buttonXOffset = -32;
8
9 openTargetX = 60;
10
11 closedTargetX = -15;
12
13 constructor (sx, sy, ex, ey, sprite, layer, tOpen, tClose)
14 {
15 super(sx, sy, ex, ey, sprite, layer, tOpen, tClose);
16 MainMenu.Instance = this;
17 }
18
19 addedToScene ()
20 {
21 super.addedToScene();
22
23 this.initialiseChildren();
24
25 this.moveSelfOnOpen();
26 this.moveSelfOnClose();
27
28 this.open(() => this.close(), this);
29 }
30
31 initialiseChildren ()
32 {
33 let vectorOrigin = this.getNextOriginPosition();
34 this.addChildButton("btnFruit", this.scene.addObject(new BtnFruit(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnFruit, 4)));
35
36 vectorOrigin = this.getNextOriginPosition();
37 this.addChildButton("btnToys", this.scene.addObject(new BtnToys(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnToys, 4)));
38
39 vectorOrigin = this.getNextOriginPosition();
40 this.addChildButton("btnGames", this.scene.addObject(new BtnGames(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnGames, 4)));
41
42 vectorOrigin = this.getNextOriginPosition();
43 this.addChildButton("btnPlants", this.scene.addObject(new BtnPlants(vectorOrigin.x, vectorOrigin.y, this.targetPosition.x + this.buttonXOffset, vectorOrigin.y, this.scene.game.images.btnPlants, 4))
44 );
45
46 }
47
48 getNextOriginPosition ()
49 {
50 if (this.children.length == 0)
51 {
52 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
53 }
54 else
55 {
56 return new vector(this.transform.position.x + this.buttonXOffset, this.children[this.children.length - 1].button.transform.position.y + this.children[this.children.length - 1].button.transform.size.y + this.buttonPadding);
57
58 }
59 }
60
61 //override for peekOnHover during closed state
62 peekOnHover ()
63 {
64 if (!GameInput.mousePosition)
65 return;
66 if (this.collider.isInBounds(GameInput.mousePosition))
67 {
68 if (this.activeTween == null && (this.transform.position.x == this.originPosition.x && this.transform.position.y == this.originPosition.y))
69 {
70 this.createHoverTween(400, null, this).easing(TWEEN.Easing.Elastic.Out).start();
71 }
72 }
73 else
74 {
75 if (this.activeTween == null &&
76 (this.transform.position.x != this.originPosition.x || this.transform.position.y != this.originPosition.y) &&
77 this.state == MenuStates.closed)
78 {
79 this.createInactiveStateTween(400, null, this).start();
80 }
81 }
82 }
83
84 //override for small opening from closed state
85 createHoverTween (time, onDone, context)
86 {
87 return super.createHoverTween(time, onDone, context)
88 .to({ x: this.originPosition.x + 10 }, time);
89 }
90}