BlueGit

blue-star speeltuin

Merge remote-tracking branch 'origin/master'

timfa Tim · pushed by timfa

Authored 2022-10-22 · 4 years ago

Hash
980e68d2a2d86efec212d812e3bb77009ea0ae98
5 files changed +71 −45
build/framework.js +12 −2
@@ -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);
@@ -853,12 +853,20 @@ class Scene
853 853 }
854 854 this.game.removeScene(this);
855 855
856 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
856 //this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
857
858 this.removeCanvas();
857 859
858 860 this.destroyed = true;
859 861 }
860 862 }
861 863
864 removeCanvas ()
865 {
866 var elem = document.getElementById(this.id);
867 return elem.parentNode.removeChild(elem);
868 }
869
862 870 backgroundColor =
863 871 {
864 872 r: 255,
@@ -981,6 +989,8 @@ class Scene
981 989 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
982 990 }
983 991
992 this.activeObjects.sort((a, b) => a.layer - b.layer);
993
984 994 for (var i = 0; i < this.activeObjects.length; i++)
985 995 {
986 996 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);
@@ -853,12 +853,20 @@ class Scene
853 }
853 }
854 this.game.removeScene(this);
854 this.game.removeScene(this);
855
855
856 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
856 //this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
857
858 this.removeCanvas();
857
859
858 this.destroyed = true;
860 this.destroyed = true;
859 }
861 }
860 }
862 }
861
863
864 removeCanvas ()
865 {
866 var elem = document.getElementById(this.id);
867 return elem.parentNode.removeChild(elem);
868 }
869
862 backgroundColor =
870 backgroundColor =
863 {
871 {
864 r: 255,
872 r: 255,
@@ -981,6 +989,8 @@ class Scene
981 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
989 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
982 }
990 }
983
991
992 this.activeObjects.sort((a, b) => a.layer - b.layer);
993
984 for (var i = 0; i < this.activeObjects.length; i++)
994 for (var i = 0; i < this.activeObjects.length; i++)
985 {
995 {
986 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
996 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
src/game.js +1 −11
@@ -129,17 +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 //createSubScene(scene);
136 135 };
137
138 createSubScene = function (scene)
139 {
140 var subScene = new FrogScene(200, 200, 416, 512, Scene.DisplayModes.absolute);
141
142 subScene.gameSpeed = 1;
143
144 scene.loadChildScene(subScene);
145 };
@@ -129,17 +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);
136};
135};
137
138createSubScene = function (scene)
139{
140 var subScene = new FrogScene(200, 200, 416, 512, Scene.DisplayModes.absolute);
141
142 subScene.gameSpeed = 1;
143
144 scene.loadChildScene(subScene);
145};
src/minigame/minigameInitialiser.js added +34 −0
@@ -0,0 +1,34 @@
1 class MinigameInitialiser
2 {
3 static StartFrogGame (parentScene, originVector, originSize)
4 {
5 let subScene = new FrogScene(144, 64, 416, 512, Scene.DisplayModes.absolute);
6
7 let endPos = subScene.real_position.getCopy();
8 let endSize = subScene.real_size.getCopy();
9
10 subScene.position = originVector.getCopy();
11 subScene.size = originSize.getCopy();
12
13 this.WindowTween(subScene, endPos, endSize, 1000);
14
15 subScene.gameSpeed = 1;
16
17 parentScene.loadChildScene(subScene);
18 }
19
20 static WindowTween (scene, endPosition, endSize, length)
21 {
22 new TWEEN.Tween(scene.position)
23 .to({ x: endPosition.x, y: endPosition.y }, length)
24 .easing(TWEEN.Easing.Elastic.Out)
25 .onUpdate((s) => console.log(scene.position))
26 .start();
27
28 new TWEEN.Tween(scene.size)
29 .to({ x: endSize.x, y: endSize.y }, length)
30 .easing(TWEEN.Easing.Elastic.Out)
31 .onUpdate((s) => console.log(scene.position))
32 .start();
33 }
34 }
@@ -0,0 +1,34 @@
1class MinigameInitialiser
2{
3 static StartFrogGame (parentScene, originVector, originSize)
4 {
5 let subScene = new FrogScene(144, 64, 416, 512, Scene.DisplayModes.absolute);
6
7 let endPos = subScene.real_position.getCopy();
8 let endSize = subScene.real_size.getCopy();
9
10 subScene.position = originVector.getCopy();
11 subScene.size = originSize.getCopy();
12
13 this.WindowTween(subScene, endPos, endSize, 1000);
14
15 subScene.gameSpeed = 1;
16
17 parentScene.loadChildScene(subScene);
18 }
19
20 static WindowTween (scene, endPosition, endSize, length)
21 {
22 new TWEEN.Tween(scene.position)
23 .to({ x: endPosition.x, y: endPosition.y }, length)
24 .easing(TWEEN.Easing.Elastic.Out)
25 .onUpdate((s) => console.log(scene.position))
26 .start();
27
28 new TWEEN.Tween(scene.size)
29 .to({ x: endSize.x, y: endSize.y }, length)
30 .easing(TWEEN.Easing.Elastic.Out)
31 .onUpdate((s) => console.log(scene.position))
32 .start();
33 }
34}
src/objects/menus/btnGames.js +20 −28
@@ -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,12 @@ 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
23 this.createSubButton(this.scene.game.images.btnFrog, function ()
24 {
25 MinigameInitialiser.StartFrogGame(this.scene, this.transform.position, this.transform.size);
26 MenuManager.Instance.moveToClose();
45 27
46 ];
28 });
47 29
48 30 for (let i = 0; i < this.buttons.length; i++)
49 31 {
@@ -60,6 +42,16 @@ class BtnGames extends GameObject
60 42 }
61 43 }
62 44
45 createSubButton (image, onClick)
46 {
47 let button = new GameObject(this.subBtnStartPosX, this.transform.position.y, image, 3);
48 this.scene.addObject(button);
49 button.startPos = new vector(-32, this.transform.position.y);
50 button.onClick = onClick;
51
52 this.buttons.push(button);
53 }
54
63 55 onClick (btn)
64 56 {
65 57 this.state == MenuManager.States.closed ?
@@ -73,7 +65,7 @@ class BtnGames extends GameObject
73 65 return;
74 66
75 67 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());
68 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 69 }
78 70
79 71 moveToClose ()
@@ -81,7 +73,7 @@ class BtnGames extends GameObject
81 73 if (this.state == MenuManager.States.closed)
82 74 return;
83 75 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());
76 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 77 }
86 78
87 79 createOpenTween (target, newTarget, length)
@@ -93,7 +85,7 @@ class BtnGames extends GameObject
93 85 this.updateButtonPosition && this.updateButtonPosition();
94 86 this.buttons.forEach(e => e.onUpdate && e.onUpdate());
95 87 })
96 .easing(TWEEN.Easing.Bounce.Out);
88 .easing(TWEEN.Easing.Back.Out);
97 89 }
98 90
99 91 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,12 @@ 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 ()
22 this.scene.addObject(frogButton);
24 {
23 frogButton.startPos = new vector(-32, this.transform.position.y);
25 MinigameInitialiser.StartFrogGame(this.scene, this.transform.position, this.transform.size);
24 frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy
26 MenuManager.Instance.moveToClose();
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
27
46 ];
28 });
47
29
48 for (let i = 0; i < this.buttons.length; i++)
30 for (let i = 0; i < this.buttons.length; i++)
49 {
31 {
@@ -60,6 +42,16 @@ class BtnGames extends GameObject
60 }
42 }
61 }
43 }
62
44
45 createSubButton (image, onClick)
46 {
47 let button = new GameObject(this.subBtnStartPosX, this.transform.position.y, image, 3);
48 this.scene.addObject(button);
49 button.startPos = new vector(-32, this.transform.position.y);
50 button.onClick = onClick;
51
52 this.buttons.push(button);
53 }
54
63 onClick (btn)
55 onClick (btn)
64 {
56 {
65 this.state == MenuManager.States.closed ?
57 this.state == MenuManager.States.closed ?
@@ -73,7 +65,7 @@ class BtnGames extends GameObject
73 return;
65 return;
74
66
75 this.state = MenuManager.States.open;
67 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());
68 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 }
69 }
78
70
79 moveToClose ()
71 moveToClose ()
@@ -81,7 +73,7 @@ class BtnGames extends GameObject
81 if (this.state == MenuManager.States.closed)
73 if (this.state == MenuManager.States.closed)
82 return;
74 return;
83 this.state = MenuManager.States.closed;
75 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());
76 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 }
77 }
86
78
87 createOpenTween (target, newTarget, length)
79 createOpenTween (target, newTarget, length)
@@ -93,7 +85,7 @@ class BtnGames extends GameObject
93 this.updateButtonPosition && this.updateButtonPosition();
85 this.updateButtonPosition && this.updateButtonPosition();
94 this.buttons.forEach(e => e.onUpdate && e.onUpdate());
86 this.buttons.forEach(e => e.onUpdate && e.onUpdate());
95 })
87 })
96 .easing(TWEEN.Easing.Bounce.Out);
88 .easing(TWEEN.Easing.Back.Out);
97 }
89 }
98
90
99 createCloseTween (target, newTarget, length)
91 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();