Merge remote-tracking branch 'origin/master'
@@ -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:
@@ -812,10 +842,17 @@ class Scene
812
842
813
843
destroy ()
814
844
{
815
this.destroyed = true;
816
for (var i = 0; i < this.activeObjects.length; i++)
845
if (!this.destroyed)
817
846
{
818
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;
819
856
}
820
857
}
821
858
@@ -6,6 +6,8 @@6
class Game6
class Game7
{7
{8
activeScenes = [];8
activeScenes = [];9
pendingRemoval = [];10
9
previousStep = 0; //used for calculating deltaTime11
previousStep = 0; //used for calculating deltaTime10
12
11
images = {};13
images = {};@@ -98,6 +100,16 @@ class Game98
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 Game115
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:@@ -812,10 +842,17 @@ class Scene812
842
813
destroy ()843
destroy ()814
{844
{815
this.destroyed = true;845
if (!this.destroyed)816
for (var i = 0; i < this.activeObjects.length; i++)817
{846
{818
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;819
}856
}820
}857
}821
858
@@ -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 GameObject322
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