Merge remote-tracking branch 'origin/master'
@@ -27,6 +27,8 @@ class FrogScene extends Scene
27
27
28
28
destructing = false;
29
29
30
externalFruitCurrentPos = null;
31
30
32
constructor (x, y, width, height, displayMode = 0)
31
33
{
32
34
super(x, y, width, height, displayMode);
@@ -42,6 +44,14 @@ class FrogScene extends Scene
42
44
this.doSpaceBarTweenIn();
43
45
}
44
46
47
onLoad ()
48
{
49
this.externalFruitCurrentPos = new vector(this.real_position.x - this.game.images.fruit.width / 2, this.real_position.y - this.game.images.fruit.height / 2);
50
51
this.maxPerXAxis = Math.ceil(this.real_size.x / this.game.images.fruit.width) + 2;
52
this.maxPerYAxis = Math.ceil(this.real_size.y / this.game.images.fruit.height) + 2;
53
}
54
45
55
update (deltaTime)
46
56
{
47
57
super.update(deltaTime);
@@ -67,6 +77,10 @@ class FrogScene extends Scene
67
77
68
78
gameOver ()
69
79
{
80
if (this.spaceBarTween)
81
TWEEN.remove(this.spaceBarTween);
82
if (this.screenTween)
83
TWEEN.remove(this.screenTween);
70
84
this.start = false;
71
85
this.activeObjects.forEach(ao => ao.destroy());
72
86
@@ -137,7 +151,7 @@ class FrogScene extends Scene
137
151
138
152
consumeFruit (fruit)
139
153
{
140
let currFruit = { scaleX: .5, scaleY: .5, image: fruit.renderer.subImage };
154
let currFruit = { position: this.getNextExternalFruitPosition(), scaleX: .5, scaleY: .5, image: fruit.renderer.subImage };
141
155
this.eatenFruit.push(currFruit);
142
156
143
157
new TWEEN.Tween(currFruit)
@@ -150,6 +164,31 @@ class FrogScene extends Scene
150
164
this.increaseDifficulty();
151
165
}
152
166
167
getNextExternalFruitPosition ()
168
{
169
if (this.eatenFruit.length == 0)
170
{
171
return this.externalFruitCurrentPos;
172
}
173
174
if (this.eatenFruit.length < this.maxPerXAxis)
175
{
176
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.add(new vector(this.game.images.fruit.width, 0));
177
}
178
else if (this.eatenFruit.length - this.maxPerXAxis < this.maxPerYAxis)
179
{
180
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.add(new vector(0, this.game.images.fruit.height));
181
}
182
else if (this.eatenFruit.length - this.maxPerYAxis < this.maxPerXAxis * 2)
183
{
184
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.subtract(new vector(this.game.images.fruit.width, 0));
185
}
186
else if (this.eatenFruit.length - this.maxPerYAxis < this.maxPerYAxis * 2)
187
{
188
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.subtract(new vector(0, this.game.images.fruit.height));
189
}
190
}
191
153
192
destroyFruit (fruit)
154
193
{
155
194
if (this.fruits.contains(fruit))
@@ -202,52 +241,18 @@ class FrogScene extends Scene
202
241
203
242
drawExternalFruit ()
204
243
{
205
206
244
if (this.eatenFruit.length > 0)
207
245
{
208
let offX = this.game.images.fruit.width;
209
let offY = this.game.images.fruit.height;
210
211
let startingX = this.real_position.x - offX / 2;
212
let startingY = this.real_position.y - offY / 2;
213
214
let maxPerXAxis = Math.ceil(this.real_size.x / offX) + 1;
215
let xAxisCount = 0;
216
217
let maxPerYAxis = Math.ceil(this.real_size.y / offY) + 1;
218
let yAxisCount = 0;
219
220
let currentPos = new vector(startingX, startingY);
221
222
246
for (let i = 0; i < this.eatenFruit.length; i++)
223
247
{
224
248
//draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)
225
249
226
250
this.game.images.fruit.draw(this.parentScene,
227
currentPos.x, currentPos.y,
228
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,
251
this.eatenFruit[i].position.x, this.eatenFruit[i].position.y,
252
this.game.images.fruit.width * this.eatenFruit[i].scaleX, this.game.images.fruit.height * this.eatenFruit[i].scaleY,
229
253
0, 0, 0, 1, this.eatenFruit[i].image);
230
254
231
if (xAxisCount < maxPerXAxis)
232
{
233
xAxisCount++;
234
currentPos = currentPos.add(new vector(offX, 0));
235
}
236
else if (yAxisCount < maxPerYAxis)
237
{
238
yAxisCount++;
239
currentPos = currentPos.add(new vector(0, offY));
240
}
241
else if (xAxisCount < maxPerXAxis * 2)
242
{
243
xAxisCount++;
244
currentPos = currentPos.subtract(new vector(offX, 0));
245
}
246
else if (yAxisCount < maxPerYAxis * 2)
247
{
248
yAxisCount++;
249
currentPos = currentPos.subtract(new vector(0, offY));
250
}
255
251
256
}
252
257
}
253
258
}
@@ -27,6 +27,8 @@ class FrogScene extends Scene27
27
28
destructing = false;28
destructing = false;29
29
30
externalFruitCurrentPos = null;31
30
constructor (x, y, width, height, displayMode = 0)32
constructor (x, y, width, height, displayMode = 0)31
{33
{32
super(x, y, width, height, displayMode);34
super(x, y, width, height, displayMode);@@ -42,6 +44,14 @@ class FrogScene extends Scene42
this.doSpaceBarTweenIn();44
this.doSpaceBarTweenIn();43
}45
}44
46
47
onLoad ()48
{49
this.externalFruitCurrentPos = new vector(this.real_position.x - this.game.images.fruit.width / 2, this.real_position.y - this.game.images.fruit.height / 2);50
51
this.maxPerXAxis = Math.ceil(this.real_size.x / this.game.images.fruit.width) + 2;52
this.maxPerYAxis = Math.ceil(this.real_size.y / this.game.images.fruit.height) + 2;53
}54
45
update (deltaTime)55
update (deltaTime)46
{56
{47
super.update(deltaTime);57
super.update(deltaTime);@@ -67,6 +77,10 @@ class FrogScene extends Scene67
77
68
gameOver ()78
gameOver ()69
{79
{80
if (this.spaceBarTween)81
TWEEN.remove(this.spaceBarTween);82
if (this.screenTween)83
TWEEN.remove(this.screenTween);70
this.start = false;84
this.start = false;71
this.activeObjects.forEach(ao => ao.destroy());85
this.activeObjects.forEach(ao => ao.destroy());72
86
@@ -137,7 +151,7 @@ class FrogScene extends Scene137
151
138
consumeFruit (fruit)152
consumeFruit (fruit)139
{153
{140
let currFruit = { scaleX: .5, scaleY: .5, image: fruit.renderer.subImage };154
let currFruit = { position: this.getNextExternalFruitPosition(), scaleX: .5, scaleY: .5, image: fruit.renderer.subImage };141
this.eatenFruit.push(currFruit);155
this.eatenFruit.push(currFruit);142
156
143
new TWEEN.Tween(currFruit)157
new TWEEN.Tween(currFruit)@@ -150,6 +164,31 @@ class FrogScene extends Scene150
this.increaseDifficulty();164
this.increaseDifficulty();151
}165
}152
166
167
getNextExternalFruitPosition ()168
{169
if (this.eatenFruit.length == 0)170
{171
return this.externalFruitCurrentPos;172
}173
174
if (this.eatenFruit.length < this.maxPerXAxis)175
{176
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.add(new vector(this.game.images.fruit.width, 0));177
}178
else if (this.eatenFruit.length - this.maxPerXAxis < this.maxPerYAxis)179
{180
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.add(new vector(0, this.game.images.fruit.height));181
}182
else if (this.eatenFruit.length - this.maxPerYAxis < this.maxPerXAxis * 2)183
{184
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.subtract(new vector(this.game.images.fruit.width, 0));185
}186
else if (this.eatenFruit.length - this.maxPerYAxis < this.maxPerYAxis * 2)187
{188
return this.externalFruitCurrentPos = this.externalFruitCurrentPos.subtract(new vector(0, this.game.images.fruit.height));189
}190
}191
153
destroyFruit (fruit)192
destroyFruit (fruit)154
{193
{155
if (this.fruits.contains(fruit))194
if (this.fruits.contains(fruit))@@ -202,52 +241,18 @@ class FrogScene extends Scene202
241
203
drawExternalFruit ()242
drawExternalFruit ()204
{243
{205
206
if (this.eatenFruit.length > 0)244
if (this.eatenFruit.length > 0)207
{245
{208
let offX = this.game.images.fruit.width;209
let offY = this.game.images.fruit.height;210
211
let startingX = this.real_position.x - offX / 2;212
let startingY = this.real_position.y - offY / 2;213
214
let maxPerXAxis = Math.ceil(this.real_size.x / offX) + 1;215
let xAxisCount = 0;216
217
let maxPerYAxis = Math.ceil(this.real_size.y / offY) + 1;218
let yAxisCount = 0;219
220
let currentPos = new vector(startingX, startingY);221
222
for (let i = 0; i < this.eatenFruit.length; i++)246
for (let i = 0; i < this.eatenFruit.length; i++)223
{247
{224
//draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)248
//draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)225
249
226
this.game.images.fruit.draw(this.parentScene,250
this.game.images.fruit.draw(this.parentScene,227
currentPos.x, currentPos.y,251
this.eatenFruit[i].position.x, this.eatenFruit[i].position.y,228
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,252
this.game.images.fruit.width * this.eatenFruit[i].scaleX, this.game.images.fruit.height * this.eatenFruit[i].scaleY,229
0, 0, 0, 1, this.eatenFruit[i].image);253
0, 0, 0, 1, this.eatenFruit[i].image);230
254
231
if (xAxisCount < maxPerXAxis)255
232
{233
xAxisCount++;234
currentPos = currentPos.add(new vector(offX, 0));235
}236
else if (yAxisCount < maxPerYAxis)237
{238
yAxisCount++;239
currentPos = currentPos.add(new vector(0, offY));240
}241
else if (xAxisCount < maxPerXAxis * 2)242
{243
xAxisCount++;244
currentPos = currentPos.subtract(new vector(offX, 0));245
}246
else if (yAxisCount < maxPerYAxis * 2)247
{248
yAxisCount++;249
currentPos = currentPos.subtract(new vector(0, offY));250
}251
}256
}252
}257
}253
}258
}