a
timfa wsadhelios · pushed by timfa
Authored 2022-10-21 · 4 years ago
- Hash
622cbaad339998df7de3c33561c6b1d833a26aea- Parent
ce69466f
3 files changed
+83
−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,59 @@
1
1
class BtnGames extends GameObject
2
2
{
3
buttons = [];
4
buttonPadding = 10;
5
buttonXOffset = -32;
6
state = 0;
7
prevState = 0;
3
8
9
menuAnchor = null;
10
11
static States = { closed: 0, open: 1, moving: 2 };
12
13
constructor (x, y, sprite, layer)
14
{
15
super(x, y, sprite, layer);
16
17
this.menuAnchor = this.transform.position.getCopy();
18
}
19
20
addedToScene ()
21
{
22
let frogButton = this.scene.addObject(new GameObject(0, 0, this.scene.game.images.btnFrog));
23
frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy
24
25
this.buttons =
26
[
27
this.scene.addObject(frogButton)
28
];
29
}
30
31
onClick (btn)
32
{
33
console.log("clicked games btn");
34
}
35
36
onUpdate ()
37
{
38
39
}
40
41
update (deltaTime)
42
{
43
super.update(deltaTime);
44
45
for (let i = 0; i < this.buttons.length; i++)
46
{
47
if (i == 0)
48
{
49
this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset;
50
this.buttons[i].transform.position.y = this.menuAnchor.y + this.transform.size.y + this.buttonPadding;
51
}
52
else
53
{
54
this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset;
55
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
56
}
57
}
58
}
4
59
}
@@ -1,4 +1,59 @@1
class BtnGames extends GameObject1
class BtnGames extends GameObject2
{2
{3
buttons = [];4
buttonPadding = 10;5
buttonXOffset = -32;6
state = 0;7
prevState = 0;3
8
9
menuAnchor = null;10
11
static States = { closed: 0, open: 1, moving: 2 };12
13
constructor (x, y, sprite, layer)14
{15
super(x, y, sprite, layer);16
17
this.menuAnchor = this.transform.position.getCopy();18
}19
20
addedToScene ()21
{22
let frogButton = this.scene.addObject(new GameObject(0, 0, this.scene.game.images.btnFrog));23
frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy24
25
this.buttons =26
[27
this.scene.addObject(frogButton)28
];29
}30
31
onClick (btn)32
{33
console.log("clicked games btn");34
}35
36
onUpdate ()37
{38
39
}40
41
update (deltaTime)42
{43
super.update(deltaTime);44
45
for (let i = 0; i < this.buttons.length; i++)46
{47
if (i == 0)48
{49
this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset;50
this.buttons[i].transform.position.y = this.menuAnchor.y + this.transform.size.y + this.buttonPadding;51
}52
else53
{54
this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset;55
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;56
}57
}58
}4
}59
}@@ -55,7 +55,6 @@ class MenuManager extends GameObject
55
55
this.closeTween.stop();
56
56
57
57
this.openTween.to({ x: 60 }, this.openTweenTime * this.timeDiffPercent);
58
console.log("open " + this.openTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);
59
58
60
59
this.state = MenuManager.States.moving;
61
60
@@ -74,8 +73,6 @@ class MenuManager extends GameObject
74
73
75
74
this.closeTween.to({ x: -15 }, this.closeTweenTime * this.timeDiffPercent);
76
75
77
console.log("close " + this.closeTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);
78
79
76
this.state = MenuManager.States.moving;
80
77
81
78
let context = this;
@@ -89,6 +86,11 @@ class MenuManager extends GameObject
89
86
return new TWEEN.Tween(target)
90
87
.to(newTarget, length)
91
88
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.openTweenTime); this.tweenTimer = 0; })
89
.onUpdate(() =>
90
{
91
this.updateButtonPosition();
92
this.buttons.forEach(e => e.onUpdate && e.onUpdate());
93
})
92
94
.easing(TWEEN.Easing.Bounce.Out);
93
95
}
94
96
@@ -97,6 +99,11 @@ class MenuManager extends GameObject
97
99
return new TWEEN.Tween(target)
98
100
.to(newTarget, length)
99
101
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.closeTweenTime); this.tweenTimer = 0; })
102
.onUpdate(() =>
103
{
104
this.updateButtonPosition();
105
this.buttons.forEach(e => e.onUpdate && e.onUpdate());
106
})
100
107
.easing(TWEEN.Easing.Elastic.Out);
101
108
}
102
109
@@ -110,6 +117,23 @@ class MenuManager extends GameObject
110
117
return 1;
111
118
}
112
119
120
updateButtonPosition ()
121
{
122
for (let i = 0; i < this.buttons.length; i++)
123
{
124
if (i == 0)
125
{
126
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
127
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;
128
}
129
else
130
{
131
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
132
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
133
}
134
}
135
}
136
113
137
update (deltaTime)
114
138
{
115
139
super.update(deltaTime);
@@ -126,19 +150,5 @@ class MenuManager extends GameObject
126
150
this.timeDiffPercent = 1;
127
151
}
128
152
}
129
130
for (let i = 0; i < this.buttons.length; i++)
131
{
132
if (i == 0)
133
{
134
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
135
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;
136
}
137
else
138
{
139
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
140
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
141
}
142
}
143
153
}
144
154
}
@@ -55,7 +55,6 @@ class MenuManager extends GameObject55
this.closeTween.stop();55
this.closeTween.stop();56
56
57
this.openTween.to({ x: 60 }, this.openTweenTime * this.timeDiffPercent);57
this.openTween.to({ x: 60 }, this.openTweenTime * this.timeDiffPercent);58
console.log("open " + this.openTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);59
58
60
this.state = MenuManager.States.moving;59
this.state = MenuManager.States.moving;61
60
@@ -74,8 +73,6 @@ class MenuManager extends GameObject74
73
75
this.closeTween.to({ x: -15 }, this.closeTweenTime * this.timeDiffPercent);74
this.closeTween.to({ x: -15 }, this.closeTweenTime * this.timeDiffPercent);76
75
77
console.log("close " + this.closeTweenTime * this.timeDiffPercent + " time diff : " + this.timeDiffPercent);78
79
this.state = MenuManager.States.moving;76
this.state = MenuManager.States.moving;80
77
81
let context = this;78
let context = this;@@ -89,6 +86,11 @@ class MenuManager extends GameObject89
return new TWEEN.Tween(target)86
return new TWEEN.Tween(target)90
.to(newTarget, length)87
.to(newTarget, length)91
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.openTweenTime); this.tweenTimer = 0; })88
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.openTweenTime); this.tweenTimer = 0; })89
.onUpdate(() => 90
{91
this.updateButtonPosition();92
this.buttons.forEach(e => e.onUpdate && e.onUpdate());93
})92
.easing(TWEEN.Easing.Bounce.Out);94
.easing(TWEEN.Easing.Bounce.Out);93
}95
}94
96
@@ -97,6 +99,11 @@ class MenuManager extends GameObject97
return new TWEEN.Tween(target)99
return new TWEEN.Tween(target)98
.to(newTarget, length)100
.to(newTarget, length)99
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.closeTweenTime); this.tweenTimer = 0; })101
.onStop(() => { this.timeDiffPercent = this.calculateTimeLeftPercent(this.closeTweenTime); this.tweenTimer = 0; })102
.onUpdate(() =>103
{104
this.updateButtonPosition();105
this.buttons.forEach(e => e.onUpdate && e.onUpdate());106
})100
.easing(TWEEN.Easing.Elastic.Out);107
.easing(TWEEN.Easing.Elastic.Out);101
}108
}102
109
@@ -110,6 +117,23 @@ class MenuManager extends GameObject110
return 1;117
return 1;111
}118
}112
119
120
updateButtonPosition ()121
{122
for (let i = 0; i < this.buttons.length; i++)123
{124
if (i == 0)125
{126
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;127
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;128
}129
else130
{131
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;132
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;133
}134
}135
}136
113
update (deltaTime)137
update (deltaTime)114
{138
{115
super.update(deltaTime);139
super.update(deltaTime);@@ -126,19 +150,5 @@ class MenuManager extends GameObject126
this.timeDiffPercent = 1;150
this.timeDiffPercent = 1;127
}151
}128
}152
}129
130
for (let i = 0; i < this.buttons.length; i++)131
{132
if (i == 0)133
{134
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;135
this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;136
}137
else138
{139
this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;140
this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;141
}142
}143
}153
}144
}154
}