BlueGit

blue-star speeltuin

layering

timfa wsadhelios · pushed by timfa

Authored 2022-10-22 · 4 years ago

Hash
2c04abef615558e524508d4c1ca9d336476a7cad
Parent
fbb32e05
4 files changed +24 −35
build/framework.js +3 −1
@@ -172,7 +172,7 @@ class GameObject
172 172
173 173 destroyed = false;
174 174
175 constructor (x, y, sprite, layer)
175 constructor (x, y, sprite, layer = 0)
176 176 {
177 177 this.transform = new Transform(this, x, y, 1, 1, 0);
178 178 this.renderer = new Renderer(this, sprite);
@@ -981,6 +981,8 @@ class Scene
981 981 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
982 982 }
983 983
984 this.activeObjects.sort((a, b) => a.layer - b.layer);
985
984 986 for (var i = 0; i < this.activeObjects.length; i++)
985 987 {
986 988 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
@@ -172,7 +172,7 @@ class GameObject
172
172
173 destroyed = false;
173 destroyed = false;
174
174
175 constructor (x, y, sprite, layer)
175 constructor (x, y, sprite, layer = 0)
176 {
176 {
177 this.transform = new Transform(this, x, y, 1, 1, 0);
177 this.transform = new Transform(this, x, y, 1, 1, 0);
178 this.renderer = new Renderer(this, sprite);
178 this.renderer = new Renderer(this, sprite);
@@ -981,6 +981,8 @@ class Scene
981 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
981 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
982 }
982 }
983
983
984 this.activeObjects.sort((a, b) => a.layer - b.layer);
985
984 for (var i = 0; i < this.activeObjects.length; i++)
986 for (var i = 0; i < this.activeObjects.length; i++)
985 {
987 {
986 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
988 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
src/game.js +1 −1
@@ -129,7 +129,7 @@ createMainScene = function (game)
129 129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
130 130 scene.addObject(chao);
131 131
132 scene.addObject(new MenuManager(0, 50, game.images.menuButton, 0));
132 scene.addObject(new MenuManager(0, 50, game.images.menuButton, 5));
133 133
134 134 WorldObjectTracker.Load(scene);
135 135 //createSubScene(scene);
@@ -129,7 +129,7 @@ createMainScene = function (game)
129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
130 scene.addObject(chao);
130 scene.addObject(chao);
131
131
132 scene.addObject(new MenuManager(0, 50, game.images.menuButton, 0));
132 scene.addObject(new MenuManager(0, 50, game.images.menuButton, 5));
133
133
134 WorldObjectTracker.Load(scene);
134 WorldObjectTracker.Load(scene);
135 //createSubScene(scene);
135 //createSubScene(scene);
src/objects/menus/btnGames.js +16 −29
@@ -5,6 +5,8 @@ class BtnGames extends GameObject
5 5 state = 0;
6 6 prevState = 0;
7 7
8 subBtnStartPosX = -32;
9
8 10 constructor (x, y, sprite, layer)
9 11 {
10 12 super(x, y, sprite, layer);
@@ -18,32 +20,7 @@ class BtnGames extends GameObject
18 20
19 21 initializeButtons ()
20 22 {
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 ];
23 this.createSubButton(this.scene.game.images.btnFrog, function () { console.log("clicked frog btn", this); });
47 24
48 25 for (let i = 0; i < this.buttons.length; i++)
49 26 {
@@ -60,6 +37,16 @@ class BtnGames extends GameObject
60 37 }
61 38 }
62 39
40 createSubButton (image, onClick)
41 {
42 let button = new GameObject(this.subBtnStartPosX, this.transform.position.y, image, 3);
43 this.scene.addObject(button);
44 button.startPos = new vector(-32, this.transform.position.y);
45 button.onClick = onClick;
46
47 this.buttons.push(button);
48 }
49
63 50 onClick (btn)
64 51 {
65 52 this.state == MenuManager.States.closed ?
@@ -73,7 +60,7 @@ class BtnGames extends GameObject
73 60 return;
74 61
75 62 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());
63 this.buttons.forEach(e => this.createOpenTween(e.transform.position, { x: [e.endPos.x], y: [e.startPos.y, e.startPos.y, e.startPos.y, e.endPos.y] }, 500).start());
77 64 }
78 65
79 66 moveToClose ()
@@ -81,7 +68,7 @@ class BtnGames extends GameObject
81 68 if (this.state == MenuManager.States.closed)
82 69 return;
83 70 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());
71 this.buttons.forEach(e => this.createCloseTween(e.transform.position, { x: [e.endPos.x, e.endPos.x, e.endPos.x, e.endPos.x, e.startPos.x], y: [e.startPos.y] }, 1000).start());
85 72 }
86 73
87 74 createOpenTween (target, newTarget, length)
@@ -93,7 +80,7 @@ class BtnGames extends GameObject
93 80 this.updateButtonPosition && this.updateButtonPosition();
94 81 this.buttons.forEach(e => e.onUpdate && e.onUpdate());
95 82 })
96 .easing(TWEEN.Easing.Bounce.Out);
83 .easing(TWEEN.Easing.Back.Out);
97 84 }
98 85
99 86 createCloseTween (target, newTarget, length)
@@ -5,6 +5,8 @@ class BtnGames extends GameObject
5 state = 0;
5 state = 0;
6 prevState = 0;
6 prevState = 0;
7
7
8 subBtnStartPosX = -32;
9
8 constructor (x, y, sprite, layer)
10 constructor (x, y, sprite, layer)
9 {
11 {
10 super(x, y, sprite, layer);
12 super(x, y, sprite, layer);
@@ -18,32 +20,7 @@ class BtnGames extends GameObject
18
20
19 initializeButtons ()
21 initializeButtons ()
20 {
22 {
21 let frogButton = new GameObject(-32, this.transform.position.y, this.scene.game.images.btnFrog);
23 this.createSubButton(this.scene.game.images.btnFrog, function () { console.log("clicked frog btn", this); });
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
24
48 for (let i = 0; i < this.buttons.length; i++)
25 for (let i = 0; i < this.buttons.length; i++)
49 {
26 {
@@ -60,6 +37,16 @@ class BtnGames extends GameObject
60 }
37 }
61 }
38 }
62
39
40 createSubButton (image, onClick)
41 {
42 let button = new GameObject(this.subBtnStartPosX, this.transform.position.y, image, 3);
43 this.scene.addObject(button);
44 button.startPos = new vector(-32, this.transform.position.y);
45 button.onClick = onClick;
46
47 this.buttons.push(button);
48 }
49
63 onClick (btn)
50 onClick (btn)
64 {
51 {
65 this.state == MenuManager.States.closed ?
52 this.state == MenuManager.States.closed ?
@@ -73,7 +60,7 @@ class BtnGames extends GameObject
73 return;
60 return;
74
61
75 this.state = MenuManager.States.open;
62 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());
63 this.buttons.forEach(e => this.createOpenTween(e.transform.position, { x: [e.endPos.x], y: [e.startPos.y, e.startPos.y, e.startPos.y, e.endPos.y] }, 500).start());
77 }
64 }
78
65
79 moveToClose ()
66 moveToClose ()
@@ -81,7 +68,7 @@ class BtnGames extends GameObject
81 if (this.state == MenuManager.States.closed)
68 if (this.state == MenuManager.States.closed)
82 return;
69 return;
83 this.state = MenuManager.States.closed;
70 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());
71 this.buttons.forEach(e => this.createCloseTween(e.transform.position, { x: [e.endPos.x, e.endPos.x, e.endPos.x, e.endPos.x, e.startPos.x], y: [e.startPos.y] }, 1000).start());
85 }
72 }
86
73
87 createOpenTween (target, newTarget, length)
74 createOpenTween (target, newTarget, length)
@@ -93,7 +80,7 @@ class BtnGames extends GameObject
93 this.updateButtonPosition && this.updateButtonPosition();
80 this.updateButtonPosition && this.updateButtonPosition();
94 this.buttons.forEach(e => e.onUpdate && e.onUpdate());
81 this.buttons.forEach(e => e.onUpdate && e.onUpdate());
95 })
82 })
96 .easing(TWEEN.Easing.Bounce.Out);
83 .easing(TWEEN.Easing.Back.Out);
97 }
84 }
98
85
99 createCloseTween (target, newTarget, length)
86 createCloseTween (target, newTarget, length)
src/objects/menus/menuManager.js +4 −4
@@ -40,10 +40,10 @@ class MenuManager extends GameObject
40 40 this.moveToOpen(() => this.moveToClose());
41 41 this.buttons =
42 42 [
43 this.scene.addObject(new BtnFruit(0, 0, this.scene.game.images.btnFruit)),
44 this.scene.addObject(new BtnToys(0, 0, this.scene.game.images.btnToys)),
45 this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames)),
46 this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants))
43 this.scene.addObject(new BtnFruit(0, 0, this.scene.game.images.btnFruit, 4)),
44 this.scene.addObject(new BtnToys(0, 0, this.scene.game.images.btnToys, 4)),
45 this.scene.addObject(new BtnGames(0, 0, this.scene.game.images.btnGames, 4)),
46 this.scene.addObject(new BtnPlants(0, 0, this.scene.game.images.btnPlants, 4))
47 47 ];
48 48
49 49 this.updateButtonPosition();
@@ -40,10 +40,10 @@ class MenuManager extends GameObject
40 this.moveToOpen(() => this.moveToClose());
40 this.moveToOpen(() => this.moveToClose());
41 this.buttons =
41 this.buttons =
42 [
42 [
43 this.scene.addObject(new BtnFruit(0, 0, this.scene.game.images.btnFruit)),
43 this.scene.addObject(new BtnFruit(0, 0, this.scene.game.images.btnFruit, 4)),
44 this.scene.addObject(new BtnToys(0, 0, this.scene.game.images.btnToys)),
44 this.scene.addObject(new BtnToys(0, 0, this.scene.game.images.btnToys, 4)),
45 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, 4)),
46 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, 4))
47 ];
47 ];
48
48
49 this.updateButtonPosition();
49 this.updateButtonPosition();