fruit border
@@ -117,6 +117,8 @@ class Game
117
117
118
118
this.previousStep = stepTime;
119
119
120
TWEEN.update();
121
120
122
requestAnimationFrame(this.update);
121
123
}
122
124
}
@@ -117,6 +117,8 @@ class Game117
117
118
this.previousStep = stepTime;118
this.previousStep = stepTime;119
119
120
TWEEN.update();121
120
requestAnimationFrame(this.update);122
requestAnimationFrame(this.update);121
}123
}122
}124
}@@ -120,14 +120,14 @@ createMainScene = function (game)
120
120
121
121
createSubScene = function (scene)
122
122
{
123
var subScene = new FrogScene(200, 200, 400, 500, Scene.DisplayModes.absolute);
123
var subScene = new FrogScene(200, 200, 416, 512, Scene.DisplayModes.absolute);
124
124
125
subScene.gameSpeed = 2;
125
subScene.gameSpeed = 1;
126
126
127
127
scene.loadChildScene(subScene);
128
128
129
129
frog = new Frog(60, subScene.real_size.y - 50, game.images.frog_basic, 0);
130
for (tx = 10; tx < subScene.real_size.x; tx += 15)
130
for (tx = 10; tx < subScene.real_size.x - 10; tx += 15)
131
131
{
132
132
subScene.addObject(new FloorTile(tx, subScene.real_size.y - 30, game.images.tile_floor_brown, 0));
133
133
}
@@ -120,14 +120,14 @@ createMainScene = function (game)120
120
121
createSubScene = function (scene) 121
createSubScene = function (scene) 122
{122
{123
var subScene = new FrogScene(200, 200, 400, 500, Scene.DisplayModes.absolute);123
var subScene = new FrogScene(200, 200, 416, 512, Scene.DisplayModes.absolute);124
124
125
subScene.gameSpeed = 2;125
subScene.gameSpeed = 1;126
126
127
scene.loadChildScene(subScene);127
scene.loadChildScene(subScene);128
128
129
frog = new Frog(60, subScene.real_size.y - 50, game.images.frog_basic, 0);129
frog = new Frog(60, subScene.real_size.y - 50, game.images.frog_basic, 0);130
for (tx = 10; tx < subScene.real_size.x; tx += 15) 130
for (tx = 10; tx < subScene.real_size.x - 10; tx += 15) 131
{131
{132
subScene.addObject(new FloorTile(tx, subScene.real_size.y - 30, game.images.tile_floor_brown, 0));132
subScene.addObject(new FloorTile(tx, subScene.real_size.y - 30, game.images.tile_floor_brown, 0));133
}133
}@@ -67,7 +67,13 @@ class FrogScene extends Scene
67
67
68
68
consumeFruit (fruit)
69
69
{
70
this.eatenFruit.push(fruit.renderer.subImage);
70
let currFruit = { scaleX: .5, scaleY: .5, image: fruit.renderer.subImage };
71
this.eatenFruit.push(currFruit);
72
73
new TWEEN.Tween(currFruit)
74
.to({ scaleX: 1, scaleY: 1 }, 400)
75
.easing(TWEEN.Easing.Elastic.Out)
76
.start();
71
77
72
78
this.destroyFruit(fruit);
73
79
@@ -94,6 +100,63 @@ class FrogScene extends Scene
94
100
fruit.renderer.subImage = Math.floor(Math.randomRange(0, fruit.renderer.sprite.subImages));
95
101
}
96
102
103
draw ()
104
{
105
super.draw();
106
107
if (this.eatenFruit.length > 0)
108
{
109
let offX = this.game.images.fruit.width;
110
let offY = this.game.images.fruit.height;
111
112
let startingX = this.real_position.x - offX / 2;
113
let startingY = this.real_position.y - offY / 2;
114
115
let maxPerXAxis = Math.ceil(this.real_size.x / offX) + 1;
116
let xAxisCount = 0;
117
118
let maxPerYAxis = Math.ceil(this.real_size.y / offY) + 1;
119
let yAxisCount = 0;
120
121
let currentPos = new vector(startingX, startingY);
122
123
for (let i = 0; i < this.eatenFruit.length; i++)
124
{
125
//draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)
126
127
this.game.images.fruit.draw(this.parentScene,
128
currentPos.x, currentPos.y,
129
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,
130
0, 0, 0, 1, this.eatenFruit[i].image);
131
132
console.log(this.eatenFruit[i].scaleX);
133
134
if (xAxisCount < maxPerXAxis)
135
{
136
xAxisCount++;
137
currentPos = currentPos.add(new vector(offX, 0));
138
}
139
else if (yAxisCount < maxPerYAxis)
140
{
141
yAxisCount++;
142
currentPos = currentPos.add(new vector(0, offY));
143
}
144
else if (xAxisCount < maxPerXAxis * 2)
145
{
146
xAxisCount++;
147
currentPos = currentPos.subtract(new vector(offX, 0));
148
}
149
else if (yAxisCount < maxPerYAxis * 2)
150
{
151
yAxisCount++;
152
currentPos = currentPos.subtract(new vector(0, offY));
153
}
154
155
156
}
157
}
158
}
159
97
160
getRandomVectorPosition ()
98
161
{
99
162
return new vector
@@ -67,7 +67,13 @@ class FrogScene extends Scene67
67
68
consumeFruit (fruit)68
consumeFruit (fruit)69
{69
{70
this.eatenFruit.push(fruit.renderer.subImage);70
let currFruit = { scaleX: .5, scaleY: .5, image: fruit.renderer.subImage };71
this.eatenFruit.push(currFruit);72
73
new TWEEN.Tween(currFruit)74
.to({ scaleX: 1, scaleY: 1 }, 400)75
.easing(TWEEN.Easing.Elastic.Out)76
.start();71
77
72
this.destroyFruit(fruit);78
this.destroyFruit(fruit);73
79
@@ -94,6 +100,63 @@ class FrogScene extends Scene94
fruit.renderer.subImage = Math.floor(Math.randomRange(0, fruit.renderer.sprite.subImages));100
fruit.renderer.subImage = Math.floor(Math.randomRange(0, fruit.renderer.sprite.subImages));95
}101
}96
102
103
draw ()104
{105
super.draw();106
107
if (this.eatenFruit.length > 0)108
{109
let offX = this.game.images.fruit.width;110
let offY = this.game.images.fruit.height;111
112
let startingX = this.real_position.x - offX / 2;113
let startingY = this.real_position.y - offY / 2;114
115
let maxPerXAxis = Math.ceil(this.real_size.x / offX) + 1;116
let xAxisCount = 0;117
118
let maxPerYAxis = Math.ceil(this.real_size.y / offY) + 1;119
let yAxisCount = 0;120
121
let currentPos = new vector(startingX, startingY);122
123
for (let i = 0; i < this.eatenFruit.length; i++)124
{125
//draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)126
127
this.game.images.fruit.draw(this.parentScene,128
currentPos.x, currentPos.y,129
offX * this.eatenFruit[i].scaleX, offY * this.eatenFruit[i].scaleY,130
0, 0, 0, 1, this.eatenFruit[i].image);131
132
console.log(this.eatenFruit[i].scaleX);133
134
if (xAxisCount < maxPerXAxis)135
{136
xAxisCount++;137
currentPos = currentPos.add(new vector(offX, 0));138
}139
else if (yAxisCount < maxPerYAxis)140
{141
yAxisCount++;142
currentPos = currentPos.add(new vector(0, offY));143
}144
else if (xAxisCount < maxPerXAxis * 2)145
{146
xAxisCount++;147
currentPos = currentPos.subtract(new vector(offX, 0));148
}149
else if (yAxisCount < maxPerYAxis * 2)150
{151
yAxisCount++;152
currentPos = currentPos.subtract(new vector(0, offY));153
}154
155
156
}157
}158
}159
97
getRandomVectorPosition ()160
getRandomVectorPosition ()98
{161
{99
return new vector162
return new vector