Merge remote-tracking branch 'origin/master'
The contents of this binary file are not shown.
@@ -32,6 +32,7 @@ window.onload = function ()
32
32
{ name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },
33
33
{ name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },
34
34
{ name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },
35
{ name: "spacebar", url: "images/spacebar.png" },
35
36
36
37
{ name: "menuButton", url: "images/buttons/menubutton.png", subImgTotal: 1, perRow: 1 },
37
38
{ name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },
@@ -137,11 +138,4 @@ createSubScene = function (scene)
137
138
subScene.gameSpeed = 1;
138
139
139
140
scene.loadChildScene(subScene);
140
141
frog = new Frog(60, subScene.real_size.y - 50, game.images.frog_basic, 0);
142
for (tx = 10; tx < subScene.real_size.x - 10; tx += 15)
143
{
144
subScene.addObject(new FloorTile(tx, subScene.real_size.y - 30, game.images.tile_floor_brown, 0));
145
}
146
subScene.addObject(frog);
147
141
};
@@ -32,6 +32,7 @@ window.onload = function ()32
{ name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },32
{ name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },33
{ name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },33
{ name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },34
{ name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },34
{ name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },35
{ name: "spacebar", url: "images/spacebar.png" },35
36
36
{ name: "menuButton", url: "images/buttons/menubutton.png", subImgTotal: 1, perRow: 1 },37
{ name: "menuButton", url: "images/buttons/menubutton.png", subImgTotal: 1, perRow: 1 },37
{ name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },38
{ name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },@@ -137,11 +138,4 @@ createSubScene = function (scene)137
subScene.gameSpeed = 1;138
subScene.gameSpeed = 1;138
139
139
scene.loadChildScene(subScene);140
scene.loadChildScene(subScene);140
141
frog = new Frog(60, subScene.real_size.y - 50, game.images.frog_basic, 0);142
for (tx = 10; tx < subScene.real_size.x - 10; tx += 15) 143
{144
subScene.addObject(new FloorTile(tx, subScene.real_size.y - 30, game.images.tile_floor_brown, 0));145
}146
subScene.addObject(frog);147
};141
};@@ -1,14 +1,40 @@
1
1
class FloorTile extends GameObject
2
2
{
3
g_target_y = 0;
3
4
4
5
constructor (x, y, sprite, layer)
5
6
{
6
7
super(x, y, sprite, layer);
7
this.collider.enabled = true;
8
this.collider.enabled = false;
9
10
this.transform.position.y = 0;
11
this.g_target_y = y;
12
this.posScaleY = 0;
13
14
new TWEEN.Tween(this)
15
.to({ posScaleY: 1 }, 800)
16
.easing(TWEEN.Easing.Elastic.Out)
17
.start()
18
.onComplete(() => this.collider.enabled = true);
19
}
20
21
update (deltaTime)
22
{
23
super.update(deltaTime);
24
25
this.animate();
8
26
}
9
27
10
28
onDestroy ()
11
29
{
12
30
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));
13
31
}
32
33
animate ()
34
{
35
if (this.transform.position.y != this.g_target_y)
36
{
37
this.transform.position.y = this.g_target_y * this.posScaleY;
38
}
39
}
14
40
}
@@ -1,14 +1,40 @@1
class FloorTile extends GameObject1
class FloorTile extends GameObject2
{2
{3
g_target_y = 0;3
4
4
constructor (x, y, sprite, layer) 5
constructor (x, y, sprite, layer) 5
{6
{6
super(x, y, sprite, layer);7
super(x, y, sprite, layer);7
this.collider.enabled = true;8
this.collider.enabled = false;9
10
this.transform.position.y = 0;11
this.g_target_y = y;12
this.posScaleY = 0;13
14
new TWEEN.Tween(this)15
.to({ posScaleY: 1 }, 800)16
.easing(TWEEN.Easing.Elastic.Out)17
.start()18
.onComplete(() => this.collider.enabled = true);19
}20
21
update (deltaTime)22
{23
super.update(deltaTime);24
25
this.animate();8
}26
}9
27
10
onDestroy ()28
onDestroy ()11
{29
{12
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));30
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));13
}31
}32
33
animate ()34
{35
if (this.transform.position.y != this.g_target_y)36
{37
this.transform.position.y = this.g_target_y * this.posScaleY;38
}39
}14
}40
}@@ -28,10 +28,22 @@ class Frog extends GameObject
28
28
29
29
tongue_obj_ref = null;
30
30
31
g_target_y = 0;
32
31
33
constructor (x, y, sprite, layer)
32
34
{
33
35
super(x, y, sprite, layer);
34
this.collider.enabled = true;
36
this.collider.enabled = false;
37
38
this.transform.position.y = 0;
39
this.g_target_y = y;
40
this.posScaleY = 0;
41
42
new TWEEN.Tween(this)
43
.to({ posScaleY: 1 }, 800)
44
.easing(TWEEN.Easing.Elastic.Out)
45
.start()
46
.onComplete(() => this.collider.enabled = true);
35
47
}
36
48
37
49
addedToScene ()
@@ -42,7 +54,10 @@ class Frog extends GameObject
42
54
43
55
onCollision (obj)
44
56
{
45
// todo: todo
57
if (obj instanceof Fruit)
58
{
59
this.scene.gameOver();
60
}
46
61
}
47
62
48
63
isFloor ()
@@ -59,6 +74,7 @@ class Frog extends GameObject
59
74
{
60
75
super.update(deltaTime);
61
76
77
this.animate();
62
78
this.idle = true;
63
79
64
80
if (this.tongue_retracted)
@@ -322,4 +338,12 @@ class Frog extends GameObject
322
338
dir.toAngle() - 90, 0, 0, 1, 0);
323
339
}
324
340
}
341
342
animate ()
343
{
344
if (this.transform.position.y != this.g_target_y)
345
{
346
this.transform.position.y = this.g_target_y * this.posScaleY;
347
}
348
}
325
349
}
@@ -28,10 +28,22 @@ class Frog extends GameObject28
28
29
tongue_obj_ref = null;29
tongue_obj_ref = null;30
30
31
g_target_y = 0;32
31
constructor (x, y, sprite, layer) 33
constructor (x, y, sprite, layer) 32
{34
{33
super(x, y, sprite, layer);35
super(x, y, sprite, layer);34
this.collider.enabled = true;36
this.collider.enabled = false;37
38
this.transform.position.y = 0;39
this.g_target_y = y;40
this.posScaleY = 0;41
42
new TWEEN.Tween(this)43
.to({ posScaleY: 1 }, 800)44
.easing(TWEEN.Easing.Elastic.Out)45
.start()46
.onComplete(() => this.collider.enabled = true);35
}47
}36
48
37
addedToScene ()49
addedToScene ()@@ -42,7 +54,10 @@ class Frog extends GameObject42
54
43
onCollision (obj) 55
onCollision (obj) 44
{56
{45
// todo: todo57
if (obj instanceof Fruit)58
{59
this.scene.gameOver();60
}46
}61
}47
62
48
isFloor () 63
isFloor () @@ -59,6 +74,7 @@ class Frog extends GameObject59
{74
{60
super.update(deltaTime);75
super.update(deltaTime);61
76
77
this.animate();62
this.idle = true;78
this.idle = true;63
79
64
if (this.tongue_retracted) 80
if (this.tongue_retracted) @@ -322,4 +338,12 @@ class Frog extends GameObject322
dir.toAngle() - 90, 0, 0, 1, 0);338
dir.toAngle() - 90, 0, 0, 1, 0);323
}339
}324
}340
}341
342
animate ()343
{344
if (this.transform.position.y != this.g_target_y)345
{346
this.transform.position.y = this.g_target_y * this.posScaleY;347
}348
}325
}349
}@@ -13,18 +13,66 @@ class FrogScene extends Scene
13
13
14
14
gameSpeed = 1;
15
15
16
start = false;
17
18
posScaleY = 0;
19
text_1_target_y;
20
text_2_target_y;
21
22
image_1_target_y;
23
image_1_rotation = -1;
24
25
spaceBarTween = null;
26
screenTween = null;
27
28
destructing = false;
29
16
30
constructor (x, y, width, height, displayMode = 0)
17
31
{
18
32
super(x, y, width, height, displayMode);
19
33
20
34
this.fruitSpawnTimer = this.fruitSpawnRateMax;
35
36
this.text_1_target_y = this.real_size.y * .3;
37
this.text_2_target_y = this.real_size.y * .62;
38
this.image_1_target_y = this.real_size.y * .45;
39
40
this.doMenuScreenTween();
41
42
this.doSpaceBarTweenIn();
21
43
}
22
44
23
45
update (deltaTime)
24
46
{
25
47
super.update(deltaTime);
26
48
27
this.spawnFruits(deltaTime);
49
if (this.start && !this.destructing)
50
{
51
this.spawnFruits(deltaTime);
52
}
53
else if (!this.start && !this.destructing)
54
{
55
this.checkSpacebar();
56
}
57
58
if (this.destructing)
59
{
60
if (this.activeObjects.length > 0)
61
{
62
return;
63
}
64
this.destroy();
65
}
66
}
67
68
gameOver ()
69
{
70
this.start = false;
71
this.activeObjects.forEach(ao => ao.destroy());
72
73
// pass over fruits array to parent scene
74
75
this.destructing = true; // finish animations first
28
76
}
29
77
30
78
increaseDifficulty ()
@@ -45,6 +93,29 @@ class FrogScene extends Scene
45
93
}
46
94
}
47
95
96
startGame ()
97
{
98
if (this.spaceBarTween)
99
{
100
this.spaceBarTween.stop();
101
TWEEN.removeAll();
102
}
103
104
this.doAwayMenuScreenTween();
105
106
let frog = new Frog(60, this.real_size.y - 50, this.game.images.frog_basic, 0);
107
108
let tileWidth = this.game.images.tile_floor_brown.width - 2;
109
let tileWidthHalf = tileWidth / 2;
110
111
for (let tx = tileWidthHalf - 4; tx < this.real_size.x; tx += tileWidth)
112
{
113
this.addObject(new FloorTile(tx, this.real_size.y - 30, this.game.images.tile_floor_brown, 0));
114
}
115
this.addObject(frog);
116
117
this.start = true;
118
}
48
119
49
120
spawnFruits (deltaTime)
50
121
{
@@ -104,6 +175,35 @@ class FrogScene extends Scene
104
175
{
105
176
super.draw();
106
177
178
this.drawExternalFruit();
179
this.drawMenu();
180
}
181
182
getRandomVectorPosition ()
183
{
184
return new vector
185
(
186
Math.floor(Math.randomRange(0, this.real_size.x)),
187
0
188
);
189
}
190
191
shouldSpawn ()
192
{
193
return Math.random() < this.fruitSpawnChance;
194
}
195
196
checkSpacebar ()
197
{
198
if (GameInput.isHeld(GameInput.keys[" "]))
199
{
200
this.startGame();
201
}
202
}
203
204
drawExternalFruit ()
205
{
206
107
207
if (this.eatenFruit.length > 0)
108
208
{
109
209
let offX = this.game.images.fruit.width;
@@ -129,8 +229,6 @@ class FrogScene extends Scene
129
229
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,
130
230
0, 0, 0, 1, this.eatenFruit[i].image);
131
231
132
console.log(this.eatenFruit[i].scaleX);
133
134
232
if (xAxisCount < maxPerXAxis)
135
233
{
136
234
xAxisCount++;
@@ -151,23 +249,52 @@ class FrogScene extends Scene
151
249
yAxisCount++;
152
250
currentPos = currentPos.subtract(new vector(0, offY));
153
251
}
252
}
253
}
254
}
255
256
drawMenu ()
257
{
258
if (this.posScaleY < 2)
259
{
260
this.context.font = "20px Monospace";
261
this.context.fillStyle = "black"; // sets the color to fill in the rectangle with
154
262
155
263
156
}
264
let textData = this.context.measureText("Press");
265
this.context.fillText("Press", this.real_size.x * .5 - (textData.width / 2), this.text_1_target_y * this.posScaleY, 72);
266
267
textData = this.context.measureText("To Start");
268
this.context.fillText("To Lick", this.real_size.x * .5 - (textData.width / 2) + 5, this.text_2_target_y * this.posScaleY, 72);
269
270
let space = this.game.images.spacebar;
271
space.draw(this, this.real_size.x * .5, this.image_1_target_y * this.posScaleY, space.width, space.height, this.image_1_rotation * 3, 0, 0, 1, 0);
157
272
}
158
273
}
159
274
160
getRandomVectorPosition ()
275
doMenuScreenTween ()
161
276
{
162
return new vector
163
(
164
Math.floor(Math.randomRange(0, this.real_size.x)),
165
0
166
);
277
this.screenTween = new TWEEN.Tween(this)
278
.to({ posScaleY: 1 }, 800)
279
.easing(TWEEN.Easing.Elastic.Out)
280
.start();
167
281
}
168
282
169
shouldSpawn ()
283
doSpaceBarTweenIn ()
170
284
{
171
return Math.random() < this.fruitSpawnChance;
285
this.spaceBarTween = new TWEEN.Tween(this)
286
.to({ image_1_rotation: 1 }, 500)
287
.easing(TWEEN.Easing.Sinusoidal.InOut)
288
.yoyo(true)
289
.repeat(Infinity)
290
.start();
291
}
292
293
doAwayMenuScreenTween ()
294
{
295
this.screenTween
296
.to({ posScaleY: 2.5 }, 800)
297
.easing(TWEEN.Easing.Elastic.InOut)
298
.start();
172
299
}
173
300
}
@@ -13,18 +13,66 @@ class FrogScene extends Scene13
13
14
gameSpeed = 1;14
gameSpeed = 1;15
15
16
start = false;17
18
posScaleY = 0;19
text_1_target_y;20
text_2_target_y;21
22
image_1_target_y;23
image_1_rotation = -1;24
25
spaceBarTween = null;26
screenTween = null;27
28
destructing = false;29
16
constructor (x, y, width, height, displayMode = 0)30
constructor (x, y, width, height, displayMode = 0)17
{31
{18
super(x, y, width, height, displayMode);32
super(x, y, width, height, displayMode);19
33
20
this.fruitSpawnTimer = this.fruitSpawnRateMax;34
this.fruitSpawnTimer = this.fruitSpawnRateMax;35
36
this.text_1_target_y = this.real_size.y * .3;37
this.text_2_target_y = this.real_size.y * .62;38
this.image_1_target_y = this.real_size.y * .45;39
40
this.doMenuScreenTween();41
42
this.doSpaceBarTweenIn();21
}43
}22
44
23
update (deltaTime)45
update (deltaTime)24
{46
{25
super.update(deltaTime);47
super.update(deltaTime);26
48
27
this.spawnFruits(deltaTime);49
if (this.start && !this.destructing)50
{51
this.spawnFruits(deltaTime);52
}53
else if (!this.start && !this.destructing)54
{55
this.checkSpacebar();56
}57
58
if (this.destructing)59
{60
if (this.activeObjects.length > 0)61
{62
return;63
}64
this.destroy();65
}66
}67
68
gameOver ()69
{70
this.start = false;71
this.activeObjects.forEach(ao => ao.destroy());72
73
// pass over fruits array to parent scene74
75
this.destructing = true; // finish animations first28
}76
}29
77
30
increaseDifficulty ()78
increaseDifficulty ()@@ -45,6 +93,29 @@ class FrogScene extends Scene45
}93
}46
}94
}47
95
96
startGame ()97
{98
if (this.spaceBarTween)99
{100
this.spaceBarTween.stop();101
TWEEN.removeAll();102
}103
104
this.doAwayMenuScreenTween();105
106
let frog = new Frog(60, this.real_size.y - 50, this.game.images.frog_basic, 0);107
108
let tileWidth = this.game.images.tile_floor_brown.width - 2;109
let tileWidthHalf = tileWidth / 2;110
111
for (let tx = tileWidthHalf - 4; tx < this.real_size.x; tx += tileWidth) 112
{113
this.addObject(new FloorTile(tx, this.real_size.y - 30, this.game.images.tile_floor_brown, 0));114
}115
this.addObject(frog);116
117
this.start = true;118
}48
119
49
spawnFruits (deltaTime)120
spawnFruits (deltaTime)50
{121
{@@ -104,6 +175,35 @@ class FrogScene extends Scene104
{175
{105
super.draw();176
super.draw();106
177
178
this.drawExternalFruit();179
this.drawMenu();180
}181
182
getRandomVectorPosition ()183
{184
return new vector185
(186
Math.floor(Math.randomRange(0, this.real_size.x)),187
0188
);189
}190
191
shouldSpawn ()192
{193
return Math.random() < this.fruitSpawnChance;194
}195
196
checkSpacebar ()197
{198
if (GameInput.isHeld(GameInput.keys[" "]))199
{200
this.startGame();201
}202
}203
204
drawExternalFruit ()205
{206
107
if (this.eatenFruit.length > 0)207
if (this.eatenFruit.length > 0)108
{208
{109
let offX = this.game.images.fruit.width;209
let offX = this.game.images.fruit.width;@@ -129,8 +229,6 @@ class FrogScene extends Scene129
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,229
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,130
0, 0, 0, 1, this.eatenFruit[i].image);230
0, 0, 0, 1, this.eatenFruit[i].image);131
231
132
console.log(this.eatenFruit[i].scaleX);133
134
if (xAxisCount < maxPerXAxis)232
if (xAxisCount < maxPerXAxis)135
{233
{136
xAxisCount++;234
xAxisCount++;@@ -151,23 +249,52 @@ class FrogScene extends Scene151
yAxisCount++;249
yAxisCount++;152
currentPos = currentPos.subtract(new vector(0, offY));250
currentPos = currentPos.subtract(new vector(0, offY));153
}251
}252
}253
}254
}255
256
drawMenu ()257
{258
if (this.posScaleY < 2)259
{260
this.context.font = "20px Monospace";261
this.context.fillStyle = "black"; // sets the color to fill in the rectangle with154
262
155
263
156
}264
let textData = this.context.measureText("Press");265
this.context.fillText("Press", this.real_size.x * .5 - (textData.width / 2), this.text_1_target_y * this.posScaleY, 72);266
267
textData = this.context.measureText("To Start");268
this.context.fillText("To Lick", this.real_size.x * .5 - (textData.width / 2) + 5, this.text_2_target_y * this.posScaleY, 72);269
270
let space = this.game.images.spacebar;271
space.draw(this, this.real_size.x * .5, this.image_1_target_y * this.posScaleY, space.width, space.height, this.image_1_rotation * 3, 0, 0, 1, 0);157
}272
}158
}273
}159
274
160
getRandomVectorPosition ()275
doMenuScreenTween ()161
{276
{162
return new vector277
this.screenTween = new TWEEN.Tween(this)163
(278
.to({ posScaleY: 1 }, 800)164
Math.floor(Math.randomRange(0, this.real_size.x)),279
.easing(TWEEN.Easing.Elastic.Out)165
0280
.start();166
);167
}281
}168
282
169
shouldSpawn ()283
doSpaceBarTweenIn ()170
{284
{171
return Math.random() < this.fruitSpawnChance;285
this.spaceBarTween = new TWEEN.Tween(this)286
.to({ image_1_rotation: 1 }, 500)287
.easing(TWEEN.Easing.Sinusoidal.InOut)288
.yoyo(true)289
.repeat(Infinity)290
.start();291
}292
293
doAwayMenuScreenTween ()294
{295
this.screenTween296
.to({ posScaleY: 2.5 }, 800)297
.easing(TWEEN.Easing.Elastic.InOut)298
.start();172
}299
}173
}300
}@@ -21,6 +21,11 @@ class Fruit extends GameObject
21
21
}
22
22
}
23
23
24
onDestroy ()
25
{
26
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));
27
}
28
24
29
update (deltaTime)
25
30
{
26
31
super.update(deltaTime);
@@ -21,6 +21,11 @@ class Fruit extends GameObject21
}21
}22
}22
}23
23
24
onDestroy ()25
{26
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));27
}28
24
update (deltaTime)29
update (deltaTime)25
{30
{26
super.update(deltaTime);31
super.update(deltaTime);