Merge remote-tracking branch 'origin/master'
timfa Tim · pushed by timfa
Authored 2022-10-22 · 4 years ago
- Hash
7a2717b45fb980885d8fac11438de094cef0a9f4
3 files changed
+147
−17
@@ -39,6 +39,7 @@ window.onload = function ()
39
39
{ name: "btnToys", url: "images/buttons/menubutton_toys.png", subImgTotal: 1, perRow: 1 },
40
40
{ name: "btnGames", url: "images/buttons/menubutton_games.png", subImgTotal: 1, perRow: 1 },
41
41
{ name: "btnPlants", url: "images/buttons/menubutton_plants.png", subImgTotal: 1, perRow: 1 },
42
{ name: "btnFrog", url: "images/buttons/menubutton_frog.png" },
42
43
{ name: "closeButton", url: "images/buttons/closeMenuBtn.png", subImgTotal: 1, perRow: 1 },
43
44
{ name: "fruitInventory", url: "images/buttons/fruitInventory.png", subImgTotal: 1, perRow: 1 }
44
45
]
@@ -39,6 +39,7 @@ window.onload = function ()39
{ name: "btnToys", url: "images/buttons/menubutton_toys.png", subImgTotal: 1, perRow: 1 },39
{ name: "btnToys", url: "images/buttons/menubutton_toys.png", subImgTotal: 1, perRow: 1 },40
{ name: "btnGames", url: "images/buttons/menubutton_games.png", subImgTotal: 1, perRow: 1 },40
{ name: "btnGames", url: "images/buttons/menubutton_games.png", subImgTotal: 1, perRow: 1 },41
{ name: "btnPlants", url: "images/buttons/menubutton_plants.png", subImgTotal: 1, perRow: 1 },41
{ name: "btnPlants", url: "images/buttons/menubutton_plants.png", subImgTotal: 1, perRow: 1 },42
{ name: "btnFrog", url: "images/buttons/menubutton_frog.png" },42
{ name: "closeButton", url: "images/buttons/closeMenuBtn.png", subImgTotal: 1, perRow: 1 },43
{ name: "closeButton", url: "images/buttons/closeMenuBtn.png", subImgTotal: 1, perRow: 1 },43
{ name: "fruitInventory", url: "images/buttons/fruitInventory.png", subImgTotal: 1, perRow: 1 }44
{ name: "fruitInventory", url: "images/buttons/fruitInventory.png", subImgTotal: 1, perRow: 1 }44
]45
]@@ -1,4 +1,115 @@
1
1
class BtnGames extends GameObject
2
2
{
3
buttons = [];
4
buttonPadding = 10;
5
state = 0;
6
prevState = 0;
3
7
8
constructor (x, y, sprite, layer)
9
{
10
super(x, y, sprite, layer);
11
}
12
13
addedToScene ()
14
{
15
MenuManager.Instance.isLoaded.add(() => this.initializeButtons(), this);
16
MenuManager.Instance.isClosed.add(() => this.moveToClose(), this);
17
}
18
19
initializeButtons ()
20
{
21
let frogButton = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);
22
this.scene.addObject(frogButton);
23
frogButton.startPos = new vector(-32, this.transform.position.y);
24
frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy
25
frogButton.onUpdate = function () { console.log(this.transform.position); };
26
27
let frogButton2 = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);
28
this.scene.addObject(frogButton2);
29
frogButton2.startPos = new vector(-32, this.transform.position.y);
30
frogButton2.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy
31
frogButton2.onUpdate = function () { console.log(this.transform.position); };
32
33
let frogButton3 = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);
34
this.scene.addObject(frogButton3);
35
frogButton3.startPos = new vector(-32, this.transform.position.y);
36
frogButton3.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy
37
frogButton3.onUpdate = function () { console.log(this.transform.position); };
38
39
this.buttons =
40
[
41
this.scene.addObject(frogButton),
42
this.scene.addObject(frogButton2),
43
this.scene.addObject(frogButton3)
44
45
46
];
47
48
for (let i = 0; i < this.buttons.length; i++)
49
{
50
if (i == 0)
51
{
52
this.buttons[i].endPos = new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
53
}
54
else
55
{
56
this.buttons[i].endPos = new vector(
57
this.buttons[i - 1].endPos.x,
58
this.buttons[i - 1].endPos.y + this.buttons[i - 1].transform.size.y + this.buttonPadding);
59
}
60
}
61
}
62
63
onClick (btn)
64
{
65
this.state == MenuManager.States.closed ?
66
this.moveToOpen() :
67
this.moveToClose();
68
}
69
70
moveToOpen ()
71
{
72
if (this.state == MenuManager.States.open)
73
return;
74
75
this.state = MenuManager.States.open;
76
this.buttons.forEach(e => this.createOpenTween(e.transform.position, { x: [e.endPos.x], y: [e.startPos.y, e.startPos.y, e.endPos.y] }, 1000).start());
77
}
78
79
moveToClose ()
80
{
81
if (this.state == MenuManager.States.closed)
82
return;
83
this.state = MenuManager.States.closed;
84
this.buttons.forEach(e => this.createCloseTween(e.transform.position, { x: [e.endPos.x, e.endPos.x, e.startPos.x], y: [e.startPos.y] }, 1000).start());
85
}
86
87
createOpenTween (target, newTarget, length)
88
{
89
return new TWEEN.Tween(target)
90
.to(newTarget, length)
91
.onUpdate(() =>
92
{
93
this.updateButtonPosition && this.updateButtonPosition();
94
this.buttons.forEach(e => e.onUpdate && e.onUpdate());
95
})
96
.easing(TWEEN.Easing.Bounce.Out);
97
}
98
99
createCloseTween (target, newTarget, length)
100
{
101
return new TWEEN.Tween(target)
102
.to(newTarget, length)
103
.onUpdate(() =>
104
{
105
this.updateButtonPosition && this.updateButtonPosition();
106
this.buttons.forEach(e => e.onUpdate && e.onUpdate());
107
})
108
.easing(TWEEN.Easing.Quintic.Out);
109
}
110
111
update (deltaTime)
112
{
113
super.update(deltaTime);
114
}
4
115
}
@@ -1,4 +1,115 @@1
class BtnGames extends GameObject1
class BtnGames extends GameObject2
{2
{3
buttons = [];4
buttonPadding = 10;5
state = 0;6
prevState = 0;3
7
8
constructor (x, y, sprite, layer)9
{10
super(x, y, sprite, layer);11
}12
13
addedToScene ()14
{15
MenuManager.Instance.isLoaded.add(() => this.initializeButtons(), this);16
MenuManager.Instance.isClosed.add(() => this.moveToClose(), this);17
}18
19
initializeButtons ()20
{21
let frogButton = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);22
this.scene.addObject(frogButton);23
frogButton.startPos = new vector(-32, this.transform.position.y);24
frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy25
frogButton.onUpdate = function () { console.log(this.transform.position); };26
27
let frogButton2 = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);28
this.scene.addObject(frogButton2);29
frogButton2.startPos = new vector(-32, this.transform.position.y);30
frogButton2.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy31
frogButton2.onUpdate = function () { console.log(this.transform.position); };32
33
let frogButton3 = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);34
this.scene.addObject(frogButton3);35
frogButton3.startPos = new vector(-32, this.transform.position.y);36
frogButton3.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy37
frogButton3.onUpdate = function () { console.log(this.transform.position); };38
39
this.buttons =40
[41
this.scene.addObject(frogButton),42
this.scene.addObject(frogButton2),43
this.scene.addObject(frogButton3)44
45
46
];47
48
for (let i = 0; i < this.buttons.length; i++)49
{50
if (i == 0)51
{52
this.buttons[i].endPos = new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);53
}54
else55
{56
this.buttons[i].endPos = new vector(57
this.buttons[i - 1].endPos.x,58
this.buttons[i - 1].endPos.y + this.buttons[i - 1].transform.size.y + this.buttonPadding);59
}60
}61
}62
63
onClick (btn)64
{65
this.state == MenuManager.States.closed ?66
this.moveToOpen() :67
this.moveToClose();68
}69
70
moveToOpen ()71
{72
if (this.state == MenuManager.States.open)73
return;74
75
this.state = MenuManager.States.open;76
this.buttons.forEach(e => this.createOpenTween(e.transform.position, { x: [e.endPos.x], y: [e.startPos.y, e.startPos.y, e.endPos.y] }, 1000).start());77
}78
79
moveToClose ()80
{81
if (this.state == MenuManager.States.closed)82
return;83
this.state = MenuManager.States.closed;84
this.buttons.forEach(e => this.createCloseTween(e.transform.position, { x: [e.endPos.x, e.endPos.x, e.startPos.x], y: [e.startPos.y] }, 1000).start());85
}86
87
createOpenTween (target, newTarget, length)88
{89
return new TWEEN.Tween(target)90
.to(newTarget, length)91
.onUpdate(() => 92
{93
this.updateButtonPosition && this.updateButtonPosition();94
this.buttons.forEach(e => e.onUpdate && e.onUpdate());95
})96
.easing(TWEEN.Easing.Bounce.Out);97
}98
99
createCloseTween (target, newTarget, length)100
{101
return new TWEEN.Tween(target)102
.to(newTarget, length)103
.onUpdate(() =>104
{105
this.updateButtonPosition && this.updateButtonPosition();106
this.buttons.forEach(e => e.onUpdate && e.onUpdate());107
})108
.easing(TWEEN.Easing.Quintic.Out);109
}110
111
update (deltaTime)112
{113
super.update(deltaTime);114
}4
}115
}@@ -17,6 +17,8 @@ class MenuManager extends GameObject
17
17
tweenTimer = 0;
18
18
timeDiffPercent = 1;
19
19
isOpened = null;
20
isClosed = null;
21
isLoaded = null;
20
22
21
23
static States = { closed: 0, open: 1, moving: 2 };
22
24
@@ -32,6 +34,8 @@ class MenuManager extends GameObject
32
34
addedToScene ()
33
35
{
34
36
this.isOpened = new Signal();
37
this.isClosed = new Signal();
38
this.isLoaded = new Signal();
35
39
36
40
this.moveToOpen(() => this.moveToClose());
37
41
this.buttons =
@@ -41,6 +45,10 @@ class MenuManager extends GameObject
41
45
this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames)),
42
46
this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants))
43
47
];
48
49
this.updateButtonPosition();
50
51
this.isLoaded.dispatch();
44
52
}
45
53
46
54
onClick (btn)
@@ -59,7 +67,6 @@ class MenuManager extends GameObject
59
67
this.closeTween.stop();
60
68
61
69
this.openTween.to({ x: 60 }, this.openTweenTime * this.timeDiffPercent);
62
console.log("open " + this.openTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);
63
70
64
71
this.state = MenuManager.States.moving;
65
72
@@ -71,6 +78,7 @@ class MenuManager extends GameObject
71
78
72
79
moveToClose (onDone)
73
80
{
81
this.isClosed.dispatch();
74
82
this.prevState = MenuManager.States.open;
75
83
76
84
if (this.state == MenuManager.States.moving)
@@ -78,8 +86,6 @@ class MenuManager extends GameObject
78
86
79
87
this.closeTween.to({ x: -15 }, this.closeTweenTime * this.timeDiffPercent);
80
88
81
console.log("close " + this.closeTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);
82
83
89
this.state = MenuManager.States.moving;
84
90
85
91
let context = this;
@@ -93,6 +99,11 @@ class MenuManager extends GameObject
93
99
return new TWEEN.Tween(target)
94
100
.to(newTarget, length)
95
101
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.openTweenTime); this.tweenTimer = 0; })
102
.onUpdate(() =>
103
{
104
this.updateButtonPosition();
105
this.buttons.forEach(e => e.onUpdate && e.onUpdate());
106
})
96
107
.easing(TWEEN.Easing.Bounce.Out);
97
108
}
98
109
@@ -101,6 +112,10 @@ class MenuManager extends GameObject
101
112
return new TWEEN.Tween(target)
102
113
.to(newTarget, length)
103
114
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.closeTweenTime); this.tweenTimer = 0; })
115
.onUpdate(() =>
116
{
117
this.updateButtonPosition();
118
})
104
119
.easing(TWEEN.Easing.Elastic.Out);
105
120
}
106
121
@@ -114,6 +129,23 @@ class MenuManager extends GameObject
114
129
return 1;
115
130
}
116
131
132
updateButtonPosition ()
133
{
134
for (let i = 0; i < this.buttons.length; i++)
135
{
136
if (i == 0)
137
{
138
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
139
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;
140
}
141
else
142
{
143
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
144
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
145
}
146
}
147
}
148
117
149
update (deltaTime)
118
150
{
119
151
super.update(deltaTime);
@@ -130,19 +162,5 @@ class MenuManager extends GameObject
130
162
this.timeDiffPercent = 1;
131
163
}
132
164
}
133
134
for (let i = 0; i < this.buttons.length; i++)
135
{
136
if (i == 0)
137
{
138
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
139
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;
140
}
141
else
142
{
143
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
144
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
145
}
146
}
147
165
}
148
166
}
@@ -17,6 +17,8 @@ class MenuManager extends GameObject17
tweenTimer = 0;17
tweenTimer = 0;18
timeDiffPercent = 1;18
timeDiffPercent = 1;19
isOpened = null;19
isOpened = null;20
isClosed = null;21
isLoaded = null;20
22
21
static States = { closed: 0, open: 1, moving: 2 };23
static States = { closed: 0, open: 1, moving: 2 };22
24
@@ -32,6 +34,8 @@ class MenuManager extends GameObject32
addedToScene ()34
addedToScene ()33
{35
{34
this.isOpened = new Signal();36
this.isOpened = new Signal();37
this.isClosed = new Signal();38
this.isLoaded = new Signal();35
39
36
this.moveToOpen(() => this.moveToClose());40
this.moveToOpen(() => this.moveToClose());37
this.buttons =41
this.buttons =@@ -41,6 +45,10 @@ class MenuManager extends GameObject41
this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames)),45
this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames)),42
this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants))46
this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants))43
];47
];48
49
this.updateButtonPosition();50
51
this.isLoaded.dispatch();44
}52
}45
53
46
onClick (btn)54
onClick (btn)@@ -59,7 +67,6 @@ class MenuManager extends GameObject59
this.closeTween.stop();67
this.closeTween.stop();60
68
61
this.openTween.to({ x: 60 }, this.openTweenTime * this.timeDiffPercent);69
this.openTween.to({ x: 60 }, this.openTweenTime * this.timeDiffPercent);62
console.log("open " + this.openTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);63
70
64
this.state = MenuManager.States.moving;71
this.state = MenuManager.States.moving;65
72
@@ -71,6 +78,7 @@ class MenuManager extends GameObject71
78
72
moveToClose (onDone)79
moveToClose (onDone)73
{80
{81
this.isClosed.dispatch();74
this.prevState = MenuManager.States.open;82
this.prevState = MenuManager.States.open;75
83
76
if (this.state == MenuManager.States.moving)84
if (this.state == MenuManager.States.moving)@@ -78,8 +86,6 @@ class MenuManager extends GameObject78
86
79
this.closeTween.to({ x: -15 }, this.closeTweenTime * this.timeDiffPercent);87
this.closeTween.to({ x: -15 }, this.closeTweenTime * this.timeDiffPercent);80
88
81
console.log("close " + this.closeTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);82
83
this.state = MenuManager.States.moving;89
this.state = MenuManager.States.moving;84
90
85
let context = this;91
let context = this;@@ -93,6 +99,11 @@ class MenuManager extends GameObject93
return new TWEEN.Tween(target)99
return new TWEEN.Tween(target)94
.to(newTarget, length)100
.to(newTarget, length)95
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.openTweenTime); this.tweenTimer = 0; })101
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.openTweenTime); this.tweenTimer = 0; })102
.onUpdate(() => 103
{104
this.updateButtonPosition();105
this.buttons.forEach(e => e.onUpdate && e.onUpdate());106
})96
.easing(TWEEN.Easing.Bounce.Out);107
.easing(TWEEN.Easing.Bounce.Out);97
}108
}98
109
@@ -101,6 +112,10 @@ class MenuManager extends GameObject101
return new TWEEN.Tween(target)112
return new TWEEN.Tween(target)102
.to(newTarget, length)113
.to(newTarget, length)103
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.closeTweenTime); this.tweenTimer = 0; })114
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.closeTweenTime); this.tweenTimer = 0; })115
.onUpdate(() =>116
{117
this.updateButtonPosition();118
})104
.easing(TWEEN.Easing.Elastic.Out);119
.easing(TWEEN.Easing.Elastic.Out);105
}120
}106
121
@@ -114,6 +129,23 @@ class MenuManager extends GameObject114
return 1;129
return 1;115
}130
}116
131
132
updateButtonPosition ()133
{134
for (let i = 0; i < this.buttons.length; i++)135
{136
if (i == 0)137
{138
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;139
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;140
}141
else142
{143
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;144
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;145
}146
}147
}148
117
update (deltaTime)149
update (deltaTime)118
{150
{119
super.update(deltaTime);151
super.update(deltaTime);@@ -130,19 +162,5 @@ class MenuManager extends GameObject130
this.timeDiffPercent = 1;162
this.timeDiffPercent = 1;131
}163
}132
}164
}133
134
for (let i = 0; i < this.buttons.length; i++)135
{136
if (i == 0)137
{138
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;139
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;140
}141
else142
{143
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;144
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;145
}146
}147
}165
}148
}166
}