BlueGit

blue-star speeltuin

Merge branch 'master' of https://gitlab.com/spark-imagination/speeltuin

timfa wsadhelios · pushed by timfa

Authored 2022-10-21 · 4 years ago

Hash
181e705accd1c1a3ff58fd2f31557ad63830bac8
13 files changed +108 −1
build/images/buttons/menubutton.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

src/game.js +9 −1
@@ -32,7 +32,13 @@ window.onload = function ()
32 32 { name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },
33 33 { name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },
34 34 { name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },
35 { name: "spacebar", url: "images/spacebar.png" }
35 { name: "spacebar", url: "images/spacebar.png" },
36
37 { name: "menuButton", url: "images/buttons/menubutton.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 },
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 }
36 42 ]
37 43 , function ()
38 44 {
@@ -120,6 +126,8 @@ createMainScene = function (game)
120 126 chao = new Chao(60, 60, game.images.chao_default, 0);
121 127 scene.addObject(chao);
122 128
129 scene.addObject(new MenuManager(0, 150, game.images.menuButton, 0));
130
123 131 createSubScene(scene);
124 132 };
125 133
@@ -32,7 +32,13 @@ window.onload = function ()
32 { name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },
32 { name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },
33 { name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },
33 { name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },
34 { name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },
34 { name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },
35 { name: "spacebar", url: "images/spacebar.png" }
35 { name: "spacebar", url: "images/spacebar.png" },
36
37 { name: "menuButton", url: "images/buttons/menubutton.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 },
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 }
36 ]
42 ]
37 , function ()
43 , function ()
38 {
44 {
@@ -120,6 +126,8 @@ createMainScene = function (game)
120 chao = new Chao(60, 60, game.images.chao_default, 0);
126 chao = new Chao(60, 60, game.images.chao_default, 0);
121 scene.addObject(chao);
127 scene.addObject(chao);
122
128
129 scene.addObject(new MenuManager(0, 150, game.images.menuButton, 0));
130
123 createSubScene(scene);
131 createSubScene(scene);
124};
132};
125
133
src/objects/menus/btnFruit.js added +4 −0
@@ -0,0 +1,4 @@
1 class BtnFruit extends GameObject
2 {
3
4 }
@@ -0,0 +1,4 @@
1class BtnFruit extends GameObject
2{
3
4}
src/objects/menus/btnGames.js added +4 −0
@@ -0,0 +1,4 @@
1 class BtnGames extends GameObject
2 {
3
4 }
@@ -0,0 +1,4 @@
1class BtnGames extends GameObject
2{
3
4}
src/objects/menus/btnPlants.js added +4 −0
@@ -0,0 +1,4 @@
1 class BtnPlants extends GameObject
2 {
3
4 }
@@ -0,0 +1,4 @@
1class BtnPlants extends GameObject
2{
3
4}
src/objects/menus/btnToys.js added +4 −0
@@ -0,0 +1,4 @@
1 class BtnToys extends GameObject
2 {
3
4 }
@@ -0,0 +1,4 @@
1class BtnToys extends GameObject
2{
3
4}
src/objects/menus/menuManager.js added +83 −0
@@ -0,0 +1,83 @@
1 class MenuManager extends GameObject
2 {
3 static Instance;
4
5 buttons = [];
6 buttonPadding = 10;
7 buttonXOffset = -32;
8 state = 0;
9
10 static States = { closed: 0, open: 1, moving: 2 };
11
12 constructor (x, y, sprite, layer)
13 {
14 super(x, y, sprite, layer);
15 MenuManager.Instance = this;
16 }
17
18 addedToScene ()
19 {
20 this.moveToOpen(this.moveToClose);
21 this.buttons =
22 [
23 this.scene.addObject(new BtnFruit(0, 0, this.scene.game.images.btnFruit)),
24 this.scene.addObject(new BtnToys(0, 0, this.scene.game.images.btnToys)),
25 this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames)),
26 this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants))
27 ];
28 }
29
30 onClick (btn)
31 {
32 this.state == MenuManager.States.open ? this.moveToClose() : this.moveToOpen();
33 }
34
35 moveToOpen (onDone)
36 {
37 if (this.state == MenuManager.States.moving)
38 return;
39
40 this.state = MenuManager.States.moving;
41
42 let context = this;
43 new TWEEN.Tween(this.transform.position)
44 .to({ x: 60 }, 800)
45 .easing(TWEEN.Easing.Bounce.Out)
46 .onComplete(() => { this.state = MenuManager.States.open; onDone && onDone.call(context); })
47 .start();
48 }
49
50 moveToClose (onDone)
51 {
52 if (this.state == MenuManager.States.moving)
53 return;
54
55 this.state = MenuManager.States.moving;
56
57 let context = this;
58 new TWEEN.Tween(this.transform.position)
59 .to({ x: -15 }, 1500)
60 .easing(TWEEN.Easing.Elastic.Out)
61 .onComplete(() => { this.state = MenuManager.States.closed; onDone && onDone.call(context); })
62 .start();
63 }
64
65 update (deltaTime)
66 {
67 super.update(deltaTime);
68
69 for (let i = 0; i < this.buttons.length; i++)
70 {
71 if (i == 0)
72 {
73 this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
74 this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;
75 }
76 else
77 {
78 this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
79 this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
80 }
81 }
82 }
83 }
@@ -0,0 +1,83 @@
1class MenuManager extends GameObject
2{
3 static Instance;
4
5 buttons = [];
6 buttonPadding = 10;
7 buttonXOffset = -32;
8 state = 0;
9
10 static States = { closed: 0, open: 1, moving: 2 };
11
12 constructor (x, y, sprite, layer)
13 {
14 super(x, y, sprite, layer);
15 MenuManager.Instance = this;
16 }
17
18 addedToScene ()
19 {
20 this.moveToOpen(this.moveToClose);
21 this.buttons =
22 [
23 this.scene.addObject(new BtnFruit(0, 0, this.scene.game.images.btnFruit)),
24 this.scene.addObject(new BtnToys(0, 0, this.scene.game.images.btnToys)),
25 this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames)),
26 this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants))
27 ];
28 }
29
30 onClick (btn)
31 {
32 this.state == MenuManager.States.open ? this.moveToClose() : this.moveToOpen();
33 }
34
35 moveToOpen (onDone)
36 {
37 if (this.state == MenuManager.States.moving)
38 return;
39
40 this.state = MenuManager.States.moving;
41
42 let context = this;
43 new TWEEN.Tween(this.transform.position)
44 .to({ x: 60 }, 800)
45 .easing(TWEEN.Easing.Bounce.Out)
46 .onComplete(() => { this.state = MenuManager.States.open; onDone && onDone.call(context); })
47 .start();
48 }
49
50 moveToClose (onDone)
51 {
52 if (this.state == MenuManager.States.moving)
53 return;
54
55 this.state = MenuManager.States.moving;
56
57 let context = this;
58 new TWEEN.Tween(this.transform.position)
59 .to({ x: -15 }, 1500)
60 .easing(TWEEN.Easing.Elastic.Out)
61 .onComplete(() => { this.state = MenuManager.States.closed; onDone && onDone.call(context); })
62 .start();
63 }
64
65 update (deltaTime)
66 {
67 super.update(deltaTime);
68
69 for (let i = 0; i < this.buttons.length; i++)
70 {
71 if (i == 0)
72 {
73 this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
74 this.buttons[i].transform.position.y = this.transform.position.y + this.transform.size.y + this.buttonPadding;
75 }
76 else
77 {
78 this.buttons[i].transform.position.x = this.transform.position.x + this.buttonXOffset;
79 this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
80 }
81 }
82 }
83}