BlueGit

blue-star speeltuin

removal of stuff

timfa wsadhelios · pushed by timfa

Authored 2022-10-21 · 4 years ago

Hash
635965692118cfd145cbedf83afdb0e741ddbad3
Parent
2405113e
2 files changed +108 −18
build/framework.js +107 −17
@@ -6,6 +6,8 @@
6 6 class Game
7 7 {
8 8 activeScenes = [];
9 pendingRemoval = [];
10
9 11 previousStep = 0; //used for calculating deltaTime
10 12
11 13 images = {};
@@ -98,6 +100,16 @@ class Game
98 100 scene.onLoad();
99 101 }
100 102
103 removeScene (scene)
104 {
105 let index = this.activeScenes.indexOf(scene);
106 if (index >= 0 && !scene.destroyed)
107 {
108 if (!this.pendingRemoval.contains(index))
109 this.pendingRemoval.push(index);
110 }
111 }
112
101 113 update ()
102 114 {
103 115 this.previousStep = this.previousStep || 0;
@@ -115,12 +127,30 @@ class Game
115 127 this.activeScenes[i].draw();
116 128 }
117 129
130 this.cleanActiveScenes();
131
118 132 this.previousStep = stepTime;
119 133
120 134 TWEEN.update();
121 135
122 136 requestAnimationFrame(this.update);
123 137 }
138
139 cleanActiveScenes ()
140 {
141 if (this.pendingRemoval.length > 0)
142 {
143 this.pendingRemoval.sort((a, b) => a - b);
144
145 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
146 {
147 if (this.activeScenes[this.pendingRemoval[i]].destroyed)
148 this.activeScenes.removeAt(this.pendingRemoval[i]);
149
150 this.pendingRemoval.splice(i, 1);
151 }
152 }
153 }
124 154 }
125 155 /*
126 156 * End File:
@@ -320,19 +350,20 @@ class Collider
320 350 {
321 351 if (this.enabled)
322 352 {
323 let pressed = GameInput.mousePressed();
324 let held = GameInput.mouseHeld();
325 if (pressed.left || pressed.middle || pressed.right)
326 {
327 this.checkClick(true, pressed);
328 }
353 this.checkCollisions();
354 }
329 355
330 if (held.left || held.middle || held.right)
331 {
332 this.checkClick(false, held);
333 }
356 let pressed = GameInput.mousePressed();
357 let held = GameInput.mouseHeld();
334 358
335 this.checkCollisions();
359 if (pressed.left || pressed.middle || pressed.right)
360 {
361 this.checkClick(true, pressed);
362 }
363
364 if (held.left || held.middle || held.right)
365 {
366 this.checkClick(false, held);
336 367 }
337 368 }
338 369
@@ -614,12 +645,64 @@ class Renderer
614 645 */
615 646 class Transform
616 647 {
617 position = null;
618 scale = null;
648 get position ()
649 {
650 if (!this.g_position)
651 this.g_position = new vector(0, 0);
652
653 return this.g_position;
654 }
655
656 set position (v)
657 {
658 if (!this.g_position)
659 this.g_position = new vector(v.x, v.y);
660
661 this.g_position.x = v.x;
662 this.g_position.y = v.y;
663 }
664
665 get scale ()
666 {
667 if (!this.g_scale)
668 this.g_scale = new vector(0, 0);
669
670 return this.g_scale;
671 }
672
673 set scale (v)
674 {
675 if (!this.g_scale)
676 this.g_scale = new vector(v.x, v.y);
677
678 this.g_scale.x = v.x;
679 this.g_scale.y = v.y;
680 }
681
682 get velocity ()
683 {
684 if (!this.g_velocity)
685 this.g_velocity = new vector(0, 0);
686
687 return this.g_velocity;
688 }
689
690 set velocity (v)
691 {
692 if (!this.g_velocity)
693 this.g_velocity = new vector(v.x, v.y);
694
695 this.g_velocity.x = v.x;
696 this.g_velocity.y = v.y;
697 }
698
699 g_position = null;
700
701 g_scale = null;
619 702 rotation = 0;
620 703 gameObject = null;
621 704
622 velocity = null;
705 g_velocity = null;
623 706 angularVelocity = 0;
624 707
625 708 get size ()
@@ -759,10 +842,17 @@ class Scene
759 842
760 843 destroy ()
761 844 {
762 this.destroyed = true;
763 for (var i = 0; i < this.activeObjects.length; i++)
845 if (!this.destroyed)
764 846 {
765 this.activeObjects[i].destroy();
847 for (var i = 0; i < this.activeObjects.length; i++)
848 {
849 this.activeObjects[i].destroy();
850 }
851 this.game.removeScene(this);
852
853 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
854
855 this.destroyed = true;
766 856 }
767 857 }
768 858
@@ -6,6 +6,8 @@
6class Game
6class Game
7{
7{
8 activeScenes = [];
8 activeScenes = [];
9 pendingRemoval = [];
10
9 previousStep = 0; //used for calculating deltaTime
11 previousStep = 0; //used for calculating deltaTime
10
12
11 images = {};
13 images = {};
@@ -98,6 +100,16 @@ class Game
98 scene.onLoad();
100 scene.onLoad();
99 }
101 }
100
102
103 removeScene (scene)
104 {
105 let index = this.activeScenes.indexOf(scene);
106 if (index >= 0 && !scene.destroyed)
107 {
108 if (!this.pendingRemoval.contains(index))
109 this.pendingRemoval.push(index);
110 }
111 }
112
101 update ()
113 update ()
102 {
114 {
103 this.previousStep = this.previousStep || 0;
115 this.previousStep = this.previousStep || 0;
@@ -115,12 +127,30 @@ class Game
115 this.activeScenes[i].draw();
127 this.activeScenes[i].draw();
116 }
128 }
117
129
130 this.cleanActiveScenes();
131
118 this.previousStep = stepTime;
132 this.previousStep = stepTime;
119
133
120 TWEEN.update();
134 TWEEN.update();
121
135
122 requestAnimationFrame(this.update);
136 requestAnimationFrame(this.update);
123 }
137 }
138
139 cleanActiveScenes ()
140 {
141 if (this.pendingRemoval.length > 0)
142 {
143 this.pendingRemoval.sort((a, b) => a - b);
144
145 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
146 {
147 if (this.activeScenes[this.pendingRemoval[i]].destroyed)
148 this.activeScenes.removeAt(this.pendingRemoval[i]);
149
150 this.pendingRemoval.splice(i, 1);
151 }
152 }
153 }
124}
154}
125/*
155/*
126 * End File:
156 * End File:
@@ -320,19 +350,20 @@ class Collider
320 {
350 {
321 if (this.enabled)
351 if (this.enabled)
322 {
352 {
323 let pressed = GameInput.mousePressed();
353 this.checkCollisions();
324 let held = GameInput.mouseHeld();
354 }
325 if (pressed.left || pressed.middle || pressed.right)
326 {
327 this.checkClick(true, pressed);
328 }
329
355
330 if (held.left || held.middle || held.right)
356 let pressed = GameInput.mousePressed();
331 {
357 let held = GameInput.mouseHeld();
332 this.checkClick(false, held);
333 }
334
358
335 this.checkCollisions();
359 if (pressed.left || pressed.middle || pressed.right)
360 {
361 this.checkClick(true, pressed);
362 }
363
364 if (held.left || held.middle || held.right)
365 {
366 this.checkClick(false, held);
336 }
367 }
337 }
368 }
338
369
@@ -614,12 +645,64 @@ class Renderer
614 */
645 */
615class Transform
646class Transform
616{
647{
617 position = null;
648 get position ()
618 scale = null;
649 {
650 if (!this.g_position)
651 this.g_position = new vector(0, 0);
652
653 return this.g_position;
654 }
655
656 set position (v)
657 {
658 if (!this.g_position)
659 this.g_position = new vector(v.x, v.y);
660
661 this.g_position.x = v.x;
662 this.g_position.y = v.y;
663 }
664
665 get scale ()
666 {
667 if (!this.g_scale)
668 this.g_scale = new vector(0, 0);
669
670 return this.g_scale;
671 }
672
673 set scale (v)
674 {
675 if (!this.g_scale)
676 this.g_scale = new vector(v.x, v.y);
677
678 this.g_scale.x = v.x;
679 this.g_scale.y = v.y;
680 }
681
682 get velocity ()
683 {
684 if (!this.g_velocity)
685 this.g_velocity = new vector(0, 0);
686
687 return this.g_velocity;
688 }
689
690 set velocity (v)
691 {
692 if (!this.g_velocity)
693 this.g_velocity = new vector(v.x, v.y);
694
695 this.g_velocity.x = v.x;
696 this.g_velocity.y = v.y;
697 }
698
699 g_position = null;
700
701 g_scale = null;
619 rotation = 0;
702 rotation = 0;
620 gameObject = null;
703 gameObject = null;
621
704
622 velocity = null;
705 g_velocity = null;
623 angularVelocity = 0;
706 angularVelocity = 0;
624
707
625 get size ()
708 get size ()
@@ -759,10 +842,17 @@ class Scene
759
842
760 destroy ()
843 destroy ()
761 {
844 {
762 this.destroyed = true;
845 if (!this.destroyed)
763 for (var i = 0; i < this.activeObjects.length; i++)
764 {
846 {
765 this.activeObjects[i].destroy();
847 for (var i = 0; i < this.activeObjects.length; i++)
848 {
849 this.activeObjects[i].destroy();
850 }
851 this.game.removeScene(this);
852
853 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
854
855 this.destroyed = true;
766 }
856 }
767 }
857 }
768
858
src/minigame/frog/frog.js +1 −1
@@ -322,7 +322,7 @@ class Frog extends GameObject
322 322 this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
323 323 dir.toAngle() - 90, 0, 0, 1, 0);
324 324
325 if (this.should_bounce)
325 if (this.should_bounce && this.tongueVectorBounce)
326 326 {
327 327 dir = new vector(this.opposite_facing, -1);
328 328
@@ -322,7 +322,7 @@ class Frog extends GameObject
322 this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
322 this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
323 dir.toAngle() - 90, 0, 0, 1, 0);
323 dir.toAngle() - 90, 0, 0, 1, 0);
324
324
325 if (this.should_bounce)
325 if (this.should_bounce && this.tongueVectorBounce)
326 {
326 {
327 dir = new vector(this.opposite_facing, -1);
327 dir = new vector(this.opposite_facing, -1);
328
328