BlueGit

blue-star speeltuin

fruit menu

timfa Tim · pushed by timfa

Authored 2022-10-21 · 4 years ago

Hash
8e1c916e9b0c7787041393880a13ec3ecc0310cf
Parent
738c6c74
9 files changed +93 −2
build/framework.js +1 −1
@@ -2355,7 +2355,7 @@ class Ray
2355 2355 */
2356 2356 // Basic event listeners, modeled after Phaser Signals
2357 2357
2358 class signal
2358 class Signal
2359 2359 {
2360 2360 listeners = [];
2361 2361
@@ -2355,7 +2355,7 @@ class Ray
2355 */
2355 */
2356// Basic event listeners, modeled after Phaser Signals
2356// Basic event listeners, modeled after Phaser Signals
2357
2357
2358class signal
2358class Signal
2359{
2359{
2360 listeners = [];
2360 listeners = [];
2361
2361
build/images/buttons/closeMenuBtn.png added Binary file +0 −0

The contents of this binary file are not shown.

build/images/buttons/fruitInventory.png added Binary file +0 −0

The contents of this binary file are not shown.

src/game.js +3 −1
@@ -38,7 +38,9 @@ window.onload = function ()
38 38 { name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },
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 { 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: "closeButton", url: "images/buttons/closeMenuBtn.png", subImgTotal: 1, perRow: 1 },
43 { name: "fruitInventory", url: "images/buttons/fruitInventory.png", subImgTotal: 1, perRow: 1 }
42 44 ]
43 45 , function ()
44 46 {
@@ -38,7 +38,9 @@ window.onload = function ()
38 { name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },
38 { name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },
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: "closeButton", url: "images/buttons/closeMenuBtn.png", subImgTotal: 1, perRow: 1 },
43 { name: "fruitInventory", url: "images/buttons/fruitInventory.png", subImgTotal: 1, perRow: 1 }
42 ]
44 ]
43 , function ()
45 , function ()
44 {
46 {
src/objects/menus/btnFruit.js +12 −0
@@ -1,4 +1,16 @@
1 1 class BtnFruit extends GameObject
2 2 {
3 fruitInventory = null;
3 4
5 addedToScene ()
6 {
7 this.fruitInventory = this.scene.addObject(new FruitInventory(400, -500, this.scene.game.images.fruitInventory));
8 }
9
10 onClick (btns)
11 {
12 console.log("ey");
13 MenuManager.Instance.moveToClose();
14 this.fruitInventory.moveToOpen();
15 }
4 16 }
@@ -1,4 +1,16 @@
1class BtnFruit extends GameObject
1class BtnFruit extends GameObject
2{
2{
3 fruitInventory = null;
3
4
5 addedToScene ()
6 {
7 this.fruitInventory = this.scene.addObject(new FruitInventory(400, -500, this.scene.game.images.fruitInventory));
8 }
9
10 onClick (btns)
11 {
12 console.log("ey");
13 MenuManager.Instance.moveToClose();
14 this.fruitInventory.moveToOpen();
15 }
4}
16}
src/objects/menus/fruitInventory.js added +62 −0
@@ -0,0 +1,62 @@
1 class FruitInventory extends GameObject
2 {
3 closeButton = null;
4 closeBtnX = 120;
5 closeBtnY = -140;
6 state = 0;
7
8 constructor (x, y, sprite, layer)
9 {
10 super(x, y, sprite, layer);
11 }
12
13 addedToScene ()
14 {
15 let pos = this.transform.position.add(new vector(this.closeBtnX, this.closeBtnY));
16 this.closeButton = this.scene.addObject(new SubBtn(pos.x, pos.y, this.scene.game.images.closeButton));
17
18 this.moveToClose();
19
20 this.closeButton.isClicked.add(function ()
21 {
22 this.moveToClose();
23 }, this);
24 }
25
26 update (deltaTime)
27 {
28 super.update(deltaTime);
29 let pos = this.transform.position.add(new vector(this.closeBtnX, this.closeBtnY));
30 this.closeButton.transform.position = pos;
31 }
32
33 moveToOpen (onDone)
34 {
35 if (this.state == MenuManager.States.moving)
36 return;
37
38 this.state = MenuManager.States.moving;
39
40 let context = this;
41 new TWEEN.Tween(this.transform.position)
42 .to({ y: 250 }, 1500)
43 .easing(TWEEN.Easing.Elastic.Out)
44 .onComplete(() => { this.state = MenuManager.States.open; onDone && onDone.call(context); })
45 .start();
46 }
47
48 moveToClose (onDone)
49 {
50 if (this.state == MenuManager.States.moving)
51 return;
52
53 this.state = MenuManager.States.moving;
54
55 let context = this;
56 new TWEEN.Tween(this.transform.position)
57 .to({ y: -500 }, 1500)
58 .easing(TWEEN.Easing.Elastic.Out)
59 .onComplete(() => { this.state = MenuManager.States.closed; onDone && onDone.call(context); })
60 .start();
61 }
62 }
@@ -0,0 +1,62 @@
1class FruitInventory extends GameObject
2{
3 closeButton = null;
4 closeBtnX = 120;
5 closeBtnY = -140;
6 state = 0;
7
8 constructor (x, y, sprite, layer)
9 {
10 super(x, y, sprite, layer);
11 }
12
13 addedToScene ()
14 {
15 let pos = this.transform.position.add(new vector(this.closeBtnX, this.closeBtnY));
16 this.closeButton = this.scene.addObject(new SubBtn(pos.x, pos.y, this.scene.game.images.closeButton));
17
18 this.moveToClose();
19
20 this.closeButton.isClicked.add(function ()
21 {
22 this.moveToClose();
23 }, this);
24 }
25
26 update (deltaTime)
27 {
28 super.update(deltaTime);
29 let pos = this.transform.position.add(new vector(this.closeBtnX, this.closeBtnY));
30 this.closeButton.transform.position = pos;
31 }
32
33 moveToOpen (onDone)
34 {
35 if (this.state == MenuManager.States.moving)
36 return;
37
38 this.state = MenuManager.States.moving;
39
40 let context = this;
41 new TWEEN.Tween(this.transform.position)
42 .to({ y: 250 }, 1500)
43 .easing(TWEEN.Easing.Elastic.Out)
44 .onComplete(() => { this.state = MenuManager.States.open; onDone && onDone.call(context); })
45 .start();
46 }
47
48 moveToClose (onDone)
49 {
50 if (this.state == MenuManager.States.moving)
51 return;
52
53 this.state = MenuManager.States.moving;
54
55 let context = this;
56 new TWEEN.Tween(this.transform.position)
57 .to({ y: -500 }, 1500)
58 .easing(TWEEN.Easing.Elastic.Out)
59 .onComplete(() => { this.state = MenuManager.States.closed; onDone && onDone.call(context); })
60 .start();
61 }
62}
src/objects/menus/subBtn.js added +15 −0
@@ -0,0 +1,15 @@
1 class SubBtn extends GameObject
2 {
3 isClicked = null;
4
5 constructor (x, y, sprite, layer)
6 {
7 super(x, y, sprite, layer);
8 this.isClicked = new Signal();
9 }
10
11 onClick (btns)
12 {
13 this.isClicked.dispatch();
14 }
15 }
@@ -0,0 +1,15 @@
1class SubBtn extends GameObject
2{
3 isClicked = null;
4
5 constructor (x, y, sprite, layer)
6 {
7 super(x, y, sprite, layer);
8 this.isClicked = new Signal();
9 }
10
11 onClick (btns)
12 {
13 this.isClicked.dispatch();
14 }
15}
src/objects/worldItems/worldItem.js src/objects/worldItems/base/aworldItem.js renamed +0 −0
src/objects/worldItems/items/item_fruit.js src/objects/worldItems/item_fruit.js renamed +0 −0