autoformat all
@@ -1,21 +1,21 @@
1
1
class ChaoBehaviour
2
2
{
3
constructor()
3
constructor ()
4
4
{
5
5
6
6
}
7
7
8
startBehaviour()
8
startBehaviour ()
9
9
{
10
10
//override this to allow the Chao to start this behaviour
11
11
}
12
12
13
update(deltaTime)
13
update (deltaTime)
14
14
{
15
15
16
16
}
17
17
18
endBehaviour()
18
endBehaviour ()
19
19
{
20
20
//make sure to call this so the Chao knows it can queue up another thing.
21
21
Chao.Instance.endBehaviour();
@@ -1,21 +1,21 @@1
class ChaoBehaviour1
class ChaoBehaviour2
{2
{3
constructor()3
constructor ()4
{4
{5
5
6
}6
}7
7
8
startBehaviour()8
startBehaviour ()9
{9
{10
//override this to allow the Chao to start this behaviour10
//override this to allow the Chao to start this behaviour11
}11
}12
12
13
update(deltaTime)13
update (deltaTime)14
{14
{15
15
16
}16
}17
17
18
endBehaviour()18
endBehaviour ()19
{19
{20
//make sure to call this so the Chao knows it can queue up another thing.20
//make sure to call this so the Chao knows it can queue up another thing.21
Chao.Instance.endBehaviour();21
Chao.Instance.endBehaviour();@@ -1,13 +1,13 @@
1
1
class BehaviourSneeze extends ChaoBehaviour
2
2
{
3
startBehaviour()
3
startBehaviour ()
4
4
{
5
5
Chao.Instance.renderer.setAnimation("sneeze");
6
6
}
7
7
8
update(deltaTime)
8
update (deltaTime)
9
9
{
10
if(Chao.Instance.renderer.currentAnimationName != "sneeze")
10
if (Chao.Instance.renderer.currentAnimationName != "sneeze")
11
11
this.endBehaviour();
12
12
}
13
13
}
@@ -1,13 +1,13 @@1
class BehaviourSneeze extends ChaoBehaviour1
class BehaviourSneeze extends ChaoBehaviour2
{2
{3
startBehaviour()3
startBehaviour ()4
{4
{5
Chao.Instance.renderer.setAnimation("sneeze");5
Chao.Instance.renderer.setAnimation("sneeze");6
}6
}7
7
8
update(deltaTime)8
update (deltaTime)9
{9
{10
if(Chao.Instance.renderer.currentAnimationName != "sneeze")10
if (Chao.Instance.renderer.currentAnimationName != "sneeze")11
this.endBehaviour();11
this.endBehaviour();12
}12
}13
} 13
} @@ -1,13 +1,13 @@
1
1
class BehaviourWander extends ChaoBehaviour
2
2
{
3
startBehaviour()
3
startBehaviour ()
4
4
{
5
5
Chao.Instance.walkToPosition(new vector(Math.randomRange(0, Chao.Instance.scene.real_size.x), Math.randomRange(0, Chao.Instance.scene.real_size.y)));
6
6
}
7
7
8
update(deltaTime)
8
update (deltaTime)
9
9
{
10
if(!Chao.Instance.walking)
10
if (!Chao.Instance.walking)
11
11
this.endBehaviour();
12
12
}
13
13
}
@@ -1,13 +1,13 @@1
class BehaviourWander extends ChaoBehaviour1
class BehaviourWander extends ChaoBehaviour2
{2
{3
startBehaviour()3
startBehaviour ()4
{4
{5
Chao.Instance.walkToPosition(new vector(Math.randomRange(0, Chao.Instance.scene.real_size.x), Math.randomRange(0, Chao.Instance.scene.real_size.y)));5
Chao.Instance.walkToPosition(new vector(Math.randomRange(0, Chao.Instance.scene.real_size.x), Math.randomRange(0, Chao.Instance.scene.real_size.y)));6
}6
}7
7
8
update(deltaTime)8
update (deltaTime)9
{9
{10
if(!Chao.Instance.walking)10
if (!Chao.Instance.walking)11
this.endBehaviour();11
this.endBehaviour();12
}12
}13
} 13
} @@ -1,13 +1,14 @@
1
class FloorTile extends GameObject{
1
class FloorTile extends GameObject
2
{
2
3
3
constructor(x,y,sprite,layer)
4
constructor (x, y, sprite, layer)
4
5
{
5
super(x,y,sprite,layer);
6
super(x, y, sprite, layer);
6
7
this.collider.enabled = true;
7
8
}
8
9
onDestroy()
9
10
onDestroy ()
10
11
{
11
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion,0, .05, true));
12
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));
12
13
}
13
14
}
@@ -1,13 +1,14 @@1
class FloorTile extends GameObject{1
class FloorTile extends GameObject2
{2
3
3
constructor(x,y,sprite,layer) 4
constructor (x, y, sprite, layer) 4
{5
{5
super(x,y,sprite,layer);6
super(x, y, sprite, layer);6
this.collider.enabled = true;7
this.collider.enabled = true;7
}8
}8
9
9
onDestroy()10
onDestroy ()10
{11
{11
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion,0, .05, true));12
this.scene.addObject(new FloorTileDestroyer(this.transform.position.x, this.transform.position.y, this.scene.game.images.tile_floor_explosion, 0, .05, true));12
}13
}13
}14
}@@ -1,23 +1,24 @@
1
class FloorTileDestroyer extends GameObject{
1
class FloorTileDestroyer extends GameObject
2
{
2
3
3
4
timeOfDestroy = 0;
4
5
timer = 0;
5
6
6
constructor(x,y,sprite,layer, animationLength, destroyAfter)
7
constructor (x, y, sprite, layer, animationLength, destroyAfter)
7
8
{
8
super(x,y,sprite,layer);
9
super(x, y, sprite, layer);
9
10
10
this.renderer.setAnimation("destroy",0 , animationLength);
11
this.renderer.setAnimation("destroy", 0, animationLength);
11
12
12
13
this.timeOfDestroy = this.renderer.cycle.cycleArray.length * animationLength;
13
14
}
14
15
15
update(deltaTime)
16
update (deltaTime)
16
17
{
17
18
super.update(deltaTime);
18
19
19
20
this.timer += deltaTime;
20
if(this.timer > this.timeOfDestroy)
21
if (this.timer > this.timeOfDestroy)
21
22
{
22
23
this.destroy();
23
24
}
@@ -1,23 +1,24 @@1
class FloorTileDestroyer extends GameObject{1
class FloorTileDestroyer extends GameObject2
{2
3
3
timeOfDestroy = 0;4
timeOfDestroy = 0;4
timer = 0;5
timer = 0;5
6
6
constructor(x,y,sprite,layer, animationLength, destroyAfter) 7
constructor (x, y, sprite, layer, animationLength, destroyAfter) 7
{8
{8
super(x,y,sprite,layer);9
super(x, y, sprite, layer);9
10
10
this.renderer.setAnimation("destroy",0 , animationLength);11
this.renderer.setAnimation("destroy", 0, animationLength);11
12
12
this.timeOfDestroy = this.renderer.cycle.cycleArray.length * animationLength;13
this.timeOfDestroy = this.renderer.cycle.cycleArray.length * animationLength;13
}14
}14
15
15
update(deltaTime) 16
update (deltaTime) 16
{17
{17
super.update(deltaTime);18
super.update(deltaTime);18
19
19
this.timer += deltaTime;20
this.timer += deltaTime;20
if(this.timer > this.timeOfDestroy) 21
if (this.timer > this.timeOfDestroy) 21
{22
{22
this.destroy();23
this.destroy();23
}24
}@@ -1,12 +1,13 @@
1
class Frog extends GameObject {
1
class Frog extends GameObject
2
{
2
3
3
4
speed = 100;
4
5
5
facing =
6
{
7
left: -.8,
8
right:.8
9
};
6
facing =
7
{
8
left: -.8,
9
right: .8
10
};
10
11
11
12
currentFacing = this.facing.right;
12
13
idle = true;
@@ -19,64 +20,64 @@ class Frog extends GameObject {
19
20
tongueLength = 0;
20
21
tongueLengthBounce = 0;
21
22
retracting = false;
22
23
23
24
frog_tongue_base = null;
24
25
frog_tongue_tip = null;
25
26
26
27
floorTileConnections = [];
27
28
28
constructor(x,y,sprite,layer)
29
constructor (x, y, sprite, layer)
29
30
{
30
super(x,y,sprite,layer);
31
super(x, y, sprite, layer);
31
32
this.collider.enabled = true;
32
33
}
33
34
34
addedToScene()
35
addedToScene ()
35
36
{
36
37
this.frog_tongue_base = this.scene.game.images.frog_tongue_base;
37
38
this.frog_tongue_tip = this.scene.game.images.frog_tongue_tip;
38
39
}
39
40
40
onCollision(obj)
41
onCollision (obj)
41
42
{
42
43
43
44
}
44
45
45
isFloor()
46
isFloor ()
46
47
{
47
48
let amount = this.renderer.sprite.width / 2;
48
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1;
49
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1;
49
50
50
let obj = Ray.Cast(this.scene, new vector(this.transform.position.x + amount, this.scene.real_size.y), new vector(0,-1),50);
51
let obj = Ray.Cast(this.scene, new vector(this.transform.position.x + amount, this.scene.real_size.y), new vector(0, -1), 50);
51
52
52
53
return obj && obj.hitObj instanceof FloorTile;
53
54
}
54
55
55
update(deltaTime)
56
update (deltaTime)
56
57
{
57
(1/deltaTime < 50) ? console.log(1/deltaTime) : null;
58
(1 / deltaTime < 50) ? console.log(1 / deltaTime) : null;
58
59
super.update(deltaTime);
59
60
60
61
this.idle = true;
61
62
62
if(this.tongue_retracted)
63
if (this.tongue_retracted)
63
64
{
64
if(GameInput.isHeld(GameInput.keys.ArrowLeft) || GameInput.isHeld(GameInput.keys.ArrowRight))
65
if (GameInput.isHeld(GameInput.keys.ArrowLeft) || GameInput.isHeld(GameInput.keys.ArrowRight))
65
66
{
66
67
this.move(deltaTime);
67
68
68
69
}
69
70
}
70
71
71
if(GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)
72
if (GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)
72
73
{
73
74
this.extendTongueLength(deltaTime);
74
75
75
76
this.checkCollision();
76
}
77
}
77
78
else
78
79
{
79
if(!this.tongue_retracted)
80
if (!this.tongue_retracted)
80
81
{
81
82
this.retractTongueLength(deltaTime);
82
83
}
@@ -90,65 +91,67 @@ class Frog extends GameObject {
90
91
}
91
92
}
92
93
93
if(!this.tongue_retracted)
94
if (!this.tongue_retracted)
94
95
{
95
96
this.calculateTongueVectors();
96
97
}
97
98
if(this.idle && this.tongue_retracted && !this.retracting)
98
99
if (this.idle && this.tongue_retracted && !this.retracting)
99
100
{
100
101
this.renderer.setSubImage(0);
101
102
}
102
103
103
104
104
105
}
105
106
106
checkCollision()
107
checkCollision ()
107
108
{
108
109
let collisionVector = this.tongueVectorBounce ? this.tongueVectorBounce : this.tongueVector;
109
110
110
if(!collisionVector)
111
if (!collisionVector)
111
112
{
112
113
return;
113
114
}
114
115
115
let obj = Ray.Cast(this.scene, collisionVector, new vector(this.tongueVectorBounce?this.currentFacing : this.opposite_facing, -1), 5);
116
let obj = Ray.Cast(this.scene, collisionVector, new vector(this.tongueVectorBounce ? this.currentFacing : this.opposite_facing, -1), 5);
116
117
}
117
118
118
calculateTongueVectors()
119
calculateTongueVectors ()
119
120
{
120
121
let dir = new vector(this.currentFacing, -1);
121
122
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength)).add(new vector(this.getXOffset(this.currentFacing), 0));
122
123
123
if(!this.isVectorWithinSceneY(this.tongueVector, this.scene)) {
124
if (!this.isVectorWithinSceneY(this.tongueVector, this.scene))
125
{
124
126
this.retracting = true;
125
127
return;
126
128
}
127
129
128
if(this.should_bounce)
130
if (this.should_bounce)
129
131
{
130
if((this.tongueLengthBounce <= 0))
132
if ((this.tongueLengthBounce <= 0))
131
133
{
132
134
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();
133
}
135
}
134
136
135
137
dir = new vector(this.opposite_facing, -1);
136
138
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));
137
139
138
if(this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y) {
140
if (this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y)
141
{
139
142
this.retracting = true;
140
143
return;
141
144
}
142
145
}
143
146
}
144
147
145
draw(context)
148
draw (context)
146
149
{
147
super.draw(context);
150
super.draw(context);
151
148
152
149
150
153
let amount = this.renderer.sprite.width / 2;
151
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1;
154
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1;
152
155
153
156
let v = new vector(this.transform.position.x + amount, this.scene.real_size.y);
154
157
context.lineWidth = 3;
@@ -156,141 +159,141 @@ class Frog extends GameObject {
156
159
context.lineTo(v.x, v.y - 50);
157
160
context.stroke();
158
161
159
if(!this.tongue_retracted)
162
if (!this.tongue_retracted)
160
163
{
161
164
this.drawTongue();
162
165
}
163
166
}
164
167
165
get tongue_retracted()
168
get tongue_retracted ()
166
169
{
167
170
return this.tongueLength <= 0;
168
171
}
169
172
170
get tongue_speed()
173
get tongue_speed ()
171
174
{
172
175
return 150 * this.scene.gameSpeed;
173
176
}
174
177
175
get opposite_facing()
178
get opposite_facing ()
176
179
{
177
180
return this.currentFacing == this.facing.left ? this.facing.right : this.facing.left;
178
181
}
179
182
180
get should_bounce()
183
get should_bounce ()
181
184
{
182
185
return this.tongueVector && (!this.isVectorWithinSceneX(this.tongueVector, this.scene));
183
186
}
184
187
185
getXOffset(facing)
188
getXOffset (facing)
186
189
{
187
190
return facing > 0 ? 8 : -8;
188
191
}
189
190
canMove(nextPos)
192
193
canMove (nextPos)
191
194
{
192
195
return nextPos + this.transform.size.x / 2 < this.scene.real_size.x && nextPos - this.transform.size.x / 2 > 0 && this.isFloor();
193
196
}
194
197
195
isVectorWithinSceneX(vector, scene)
198
isVectorWithinSceneX (vector, scene)
196
199
{
197
200
return vector.x >= 0 && vector.x <= scene.real_size.x;
198
201
}
199
202
200
isVectorWithinSceneY(vector, scene)
203
isVectorWithinSceneY (vector, scene)
201
204
{
202
return vector.y >= 0 && vector.y <= scene.real_size.y;
205
return vector.y >= 0 && vector.y <= scene.real_size.y;
203
206
}
204
207
205
move(deltaTime)
208
move (deltaTime)
206
209
{
207
if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft)))
210
if (!(GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft)))
211
{
212
if (GameInput.isHeld(GameInput.keys.ArrowRight))
208
213
{
209
if(GameInput.isHeld(GameInput.keys.ArrowRight))
214
if (this.canMove(this.transform.position.x + this.speed * deltaTime))
215
{
216
this.transform.position.x += this.speed * deltaTime;
217
}
218
219
if (this.currentFacing != this.facing.right)
210
220
{
211
if(this.canMove(this.transform.position.x + this.speed * deltaTime))
212
{
213
this.transform.position.x += this.speed * deltaTime;
214
}
215
216
if(this.currentFacing != this.facing.right)
217
{
218
this.renderer.mirrorX = !this.renderer.mirrorX;
219
this.currentFacing = this.facing.right;
220
}
221
this.renderer.mirrorX = !this.renderer.mirrorX;
222
this.currentFacing = this.facing.right;
221
223
}
224
}
222
225
223
if(GameInput.isHeld(GameInput.keys.ArrowLeft))
226
if (GameInput.isHeld(GameInput.keys.ArrowLeft))
227
{
228
if (this.canMove(this.transform.position.x - this.speed * deltaTime))
224
229
{
225
if(this.canMove(this.transform.position.x - this.speed * deltaTime))
226
{
227
this.transform.position.x -= this.speed * deltaTime;
228
}
229
230
if(this.currentFacing != this.facing.left)
231
{
232
this.renderer.mirrorX = !this.renderer.mirrorX;
233
this.currentFacing = this.facing.left;
234
}
230
this.transform.position.x -= this.speed * deltaTime;
235
231
}
236
232
237
this.idle = false;
238
this.renderer.setAnimation("walk", 0, .2);
233
if (this.currentFacing != this.facing.left)
234
{
235
this.renderer.mirrorX = !this.renderer.mirrorX;
236
this.currentFacing = this.facing.left;
237
}
239
238
}
239
240
this.idle = false;
241
this.renderer.setAnimation("walk", 0, .2);
242
}
240
243
}
241
244
242
extendTongueLength(deltaTime)
245
extendTongueLength (deltaTime)
243
246
{
244
247
this.renderer.setSubImage(3);
245
248
this.idle = false;
246
249
this.tongueLength += deltaTime * this.tongue_speed;
247
248
if(this.should_bounce)
250
251
if (this.should_bounce)
249
252
{
250
253
this.tongueLengthBounce += deltaTime * this.tongue_speed;
251
254
}
252
255
}
253
256
254
retractTongueLength(deltaTime)
257
retractTongueLength (deltaTime)
255
258
{
256
259
this.tongueLength -= deltaTime * this.tongue_speed * 2;
257
260
this.retracting = true;
258
261
259
if(this.should_bounce)
262
if (this.should_bounce)
260
263
{
261
264
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;
262
265
}
263
266
}
264
267
265
drawTongue()
268
drawTongue ()
266
269
{
267
270
let dir = new vector(this.currentFacing, -1);
268
271
269
this.frog_tongue_tip.draw(this.scene,
270
this.tongueVector.x, this.tongueVector.y,
271
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
272
dir.toAngle() -90, 0, 0, 1, 0)
272
this.frog_tongue_tip.draw(this.scene,
273
this.tongueVector.x, this.tongueVector.y,
274
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
275
dir.toAngle() - 90, 0, 0, 1, 0);
273
276
274
277
this.frog_tongue_base.draw(
275
278
this.scene,
276
(this.transform.position.x + this.tongueVector.x + this.getXOffset(this.currentFacing)) / 2, (this.transform.position.y + this.tongueVector.y) / 2,
277
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
278
dir.toAngle() -90, 0, 0, 1, 0)
279
(this.transform.position.x + this.tongueVector.x + this.getXOffset(this.currentFacing)) / 2, (this.transform.position.y + this.tongueVector.y) / 2,
280
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
281
dir.toAngle() - 90, 0, 0, 1, 0);
279
282
280
if(this.should_bounce)
283
if (this.should_bounce)
281
284
{
282
285
dir = new vector(this.opposite_facing, -1);
283
286
284
this.frog_tongue_tip.draw(this.scene,
285
this.tongueVectorBounce.x, this.tongueVectorBounce.y,
286
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
287
dir.toAngle() -90, 0, 0, 1, 0)
287
this.frog_tongue_tip.draw(this.scene,
288
this.tongueVectorBounce.x, this.tongueVectorBounce.y,
289
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
290
dir.toAngle() - 90, 0, 0, 1, 0);
288
291
289
292
this.frog_tongue_base.draw(
290
this.scene,
291
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2,
292
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height,
293
dir.toAngle() -90, 0, 0, 1, 0)
293
this.scene,
294
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2,
295
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height,
296
dir.toAngle() - 90, 0, 0, 1, 0);
294
297
}
295
298
}
296
299
}
@@ -1,12 +1,13 @@1
class Frog extends GameObject {1
class Frog extends GameObject2
{2
3
3
speed = 100;4
speed = 100;4
5
5
facing = 6
facing =6
{ 7
{7
left: -.8,8
left: -.8,8
right:.89
right: .89
};10
};10
11
11
currentFacing = this.facing.right;12
currentFacing = this.facing.right;12
idle = true;13
idle = true;@@ -19,64 +20,64 @@ class Frog extends GameObject {19
tongueLength = 0;20
tongueLength = 0;20
tongueLengthBounce = 0;21
tongueLengthBounce = 0;21
retracting = false;22
retracting = false;22
23
23
frog_tongue_base = null;24
frog_tongue_base = null;24
frog_tongue_tip = null;25
frog_tongue_tip = null;25
26
26
floorTileConnections = [];27
floorTileConnections = [];27
28
28
constructor(x,y,sprite,layer) 29
constructor (x, y, sprite, layer) 29
{30
{30
super(x,y,sprite,layer);31
super(x, y, sprite, layer);31
this.collider.enabled = true;32
this.collider.enabled = true;32
}33
}33
34
34
addedToScene()35
addedToScene ()35
{36
{36
this.frog_tongue_base = this.scene.game.images.frog_tongue_base;37
this.frog_tongue_base = this.scene.game.images.frog_tongue_base;37
this.frog_tongue_tip = this.scene.game.images.frog_tongue_tip;38
this.frog_tongue_tip = this.scene.game.images.frog_tongue_tip;38
}39
}39
40
40
onCollision(obj) 41
onCollision (obj) 41
{42
{42
43
43
}44
}44
45
45
isFloor() 46
isFloor () 46
{47
{47
let amount = this.renderer.sprite.width / 2;48
let amount = this.renderer.sprite.width / 2;48
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1; 49
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1;49
50
50
let obj = Ray.Cast(this.scene, new vector(this.transform.position.x + amount, this.scene.real_size.y), new vector(0,-1),50);51
let obj = Ray.Cast(this.scene, new vector(this.transform.position.x + amount, this.scene.real_size.y), new vector(0, -1), 50);51
52
52
return obj && obj.hitObj instanceof FloorTile;53
return obj && obj.hitObj instanceof FloorTile;53
}54
}54
55
55
update(deltaTime)56
update (deltaTime)56
{57
{57
(1/deltaTime < 50) ? console.log(1/deltaTime) : null;58
(1 / deltaTime < 50) ? console.log(1 / deltaTime) : null;58
super.update(deltaTime);59
super.update(deltaTime);59
60
60
this.idle = true;61
this.idle = true;61
62
62
if(this.tongue_retracted) 63
if (this.tongue_retracted) 63
{64
{64
if(GameInput.isHeld(GameInput.keys.ArrowLeft) || GameInput.isHeld(GameInput.keys.ArrowRight))65
if (GameInput.isHeld(GameInput.keys.ArrowLeft) || GameInput.isHeld(GameInput.keys.ArrowRight))65
{66
{66
this.move(deltaTime);67
this.move(deltaTime);67
68
68
}69
}69
}70
}70
71
71
if(GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)72
if (GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)72
{73
{73
this.extendTongueLength(deltaTime);74
this.extendTongueLength(deltaTime);74
75
75
this.checkCollision();76
this.checkCollision();76
} 77
}77
else78
else78
{79
{79
if(!this.tongue_retracted) 80
if (!this.tongue_retracted) 80
{81
{81
this.retractTongueLength(deltaTime);82
this.retractTongueLength(deltaTime);82
}83
}@@ -90,65 +91,67 @@ class Frog extends GameObject {90
}91
}91
}92
}92
93
93
if(!this.tongue_retracted) 94
if (!this.tongue_retracted) 94
{95
{95
this.calculateTongueVectors();96
this.calculateTongueVectors();96
}97
}97
98
98
if(this.idle && this.tongue_retracted && !this.retracting) 99
if (this.idle && this.tongue_retracted && !this.retracting) 99
{100
{100
this.renderer.setSubImage(0);101
this.renderer.setSubImage(0);101
}102
}102
103
103
104
104
}105
}105
106
106
checkCollision()107
checkCollision ()107
{108
{108
let collisionVector = this.tongueVectorBounce ? this.tongueVectorBounce : this.tongueVector;109
let collisionVector = this.tongueVectorBounce ? this.tongueVectorBounce : this.tongueVector;109
110
110
if(!collisionVector)111
if (!collisionVector)111
{112
{112
return;113
return;113
}114
}114
115
115
let obj = Ray.Cast(this.scene, collisionVector, new vector(this.tongueVectorBounce?this.currentFacing : this.opposite_facing, -1), 5);116
let obj = Ray.Cast(this.scene, collisionVector, new vector(this.tongueVectorBounce ? this.currentFacing : this.opposite_facing, -1), 5);116
}117
}117
118
118
calculateTongueVectors() 119
calculateTongueVectors () 119
{120
{120
let dir = new vector(this.currentFacing, -1);121
let dir = new vector(this.currentFacing, -1);121
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength)).add(new vector(this.getXOffset(this.currentFacing), 0));122
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength)).add(new vector(this.getXOffset(this.currentFacing), 0));122
123
123
if(!this.isVectorWithinSceneY(this.tongueVector, this.scene)) {124
if (!this.isVectorWithinSceneY(this.tongueVector, this.scene))125
{124
this.retracting = true;126
this.retracting = true;125
return;127
return;126
}128
}127
129
128
if(this.should_bounce) 130
if (this.should_bounce) 129
{131
{130
if((this.tongueLengthBounce <= 0)) 132
if ((this.tongueLengthBounce <= 0)) 131
{133
{132
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();134
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();133
} 135
}134
136
135
dir = new vector(this.opposite_facing, -1);137
dir = new vector(this.opposite_facing, -1);136
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));138
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));137
139
138
if(this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y) {140
if (this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y)141
{139
this.retracting = true;142
this.retracting = true;140
return;143
return;141
}144
}142
}145
}143
}146
}144
147
145
draw(context)148
draw (context)146
{149
{147
super.draw(context); 150
super.draw(context);151
148
152
149
150
let amount = this.renderer.sprite.width / 2;153
let amount = this.renderer.sprite.width / 2;151
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1; 154
this.currentFacing == this.facing.right ? amount *= 1 : amount *= -1;152
155
153
let v = new vector(this.transform.position.x + amount, this.scene.real_size.y);156
let v = new vector(this.transform.position.x + amount, this.scene.real_size.y);154
context.lineWidth = 3;157
context.lineWidth = 3;@@ -156,141 +159,141 @@ class Frog extends GameObject {156
context.lineTo(v.x, v.y - 50);159
context.lineTo(v.x, v.y - 50);157
context.stroke();160
context.stroke();158
161
159
if(!this.tongue_retracted) 162
if (!this.tongue_retracted) 160
{163
{161
this.drawTongue();164
this.drawTongue();162
}165
}163
}166
}164
167
165
get tongue_retracted() 168
get tongue_retracted () 166
{169
{167
return this.tongueLength <= 0;170
return this.tongueLength <= 0;168
}171
}169
172
170
get tongue_speed() 173
get tongue_speed () 171
{174
{172
return 150 * this.scene.gameSpeed;175
return 150 * this.scene.gameSpeed;173
}176
}174
177
175
get opposite_facing() 178
get opposite_facing () 176
{179
{177
return this.currentFacing == this.facing.left ? this.facing.right : this.facing.left;180
return this.currentFacing == this.facing.left ? this.facing.right : this.facing.left;178
}181
}179
182
180
get should_bounce() 183
get should_bounce () 181
{184
{182
return this.tongueVector && (!this.isVectorWithinSceneX(this.tongueVector, this.scene));185
return this.tongueVector && (!this.isVectorWithinSceneX(this.tongueVector, this.scene));183
}186
}184
187
185
getXOffset(facing) 188
getXOffset (facing) 186
{189
{187
return facing > 0 ? 8 : -8;190
return facing > 0 ? 8 : -8;188
}191
}189
192
190
canMove(nextPos) 193
canMove (nextPos) 191
{194
{192
return nextPos + this.transform.size.x / 2 < this.scene.real_size.x && nextPos - this.transform.size.x / 2 > 0 && this.isFloor();195
return nextPos + this.transform.size.x / 2 < this.scene.real_size.x && nextPos - this.transform.size.x / 2 > 0 && this.isFloor();193
}196
}194
197
195
isVectorWithinSceneX(vector, scene) 198
isVectorWithinSceneX (vector, scene) 196
{199
{197
return vector.x >= 0 && vector.x <= scene.real_size.x;200
return vector.x >= 0 && vector.x <= scene.real_size.x;198
}201
}199
202
200
isVectorWithinSceneY(vector, scene) 203
isVectorWithinSceneY (vector, scene) 201
{204
{202
return vector.y >= 0 && vector.y <= scene.real_size.y;205
return vector.y >= 0 && vector.y <= scene.real_size.y;203
}206
}204
207
205
move(deltaTime) 208
move (deltaTime) 206
{209
{207
if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft))) 210
if (!(GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft))) 211
{212
if (GameInput.isHeld(GameInput.keys.ArrowRight))208
{213
{209
if(GameInput.isHeld(GameInput.keys.ArrowRight))214
if (this.canMove(this.transform.position.x + this.speed * deltaTime)) 215
{216
this.transform.position.x += this.speed * deltaTime;217
}218
219
if (this.currentFacing != this.facing.right) 210
{220
{211
if(this.canMove(this.transform.position.x + this.speed * deltaTime)) 221
this.renderer.mirrorX = !this.renderer.mirrorX;212
{222
this.currentFacing = this.facing.right;213
this.transform.position.x += this.speed * deltaTime;214
}215
216
if(this.currentFacing != this.facing.right) 217
{218
this.renderer.mirrorX = !this.renderer.mirrorX;219
this.currentFacing = this.facing.right;220
}221
}223
}224
}222
225
223
if(GameInput.isHeld(GameInput.keys.ArrowLeft))226
if (GameInput.isHeld(GameInput.keys.ArrowLeft))227
{228
if (this.canMove(this.transform.position.x - this.speed * deltaTime)) 224
{229
{225
if(this.canMove(this.transform.position.x - this.speed * deltaTime)) 230
this.transform.position.x -= this.speed * deltaTime;226
{227
this.transform.position.x -= this.speed * deltaTime;228
}229
230
if(this.currentFacing != this.facing.left) 231
{232
this.renderer.mirrorX = !this.renderer.mirrorX;233
this.currentFacing = this.facing.left;234
}235
}231
}236
232
237
this.idle = false;233
if (this.currentFacing != this.facing.left) 238
this.renderer.setAnimation("walk", 0, .2);234
{235
this.renderer.mirrorX = !this.renderer.mirrorX;236
this.currentFacing = this.facing.left;237
}239
}238
}239
240
this.idle = false;241
this.renderer.setAnimation("walk", 0, .2);242
}240
}243
}241
244
242
extendTongueLength(deltaTime) 245
extendTongueLength (deltaTime) 243
{246
{244
this.renderer.setSubImage(3);247
this.renderer.setSubImage(3);245
this.idle = false;248
this.idle = false;246
this.tongueLength += deltaTime * this.tongue_speed;249
this.tongueLength += deltaTime * this.tongue_speed;247
250
248
if(this.should_bounce) 251
if (this.should_bounce) 249
{252
{250
this.tongueLengthBounce += deltaTime * this.tongue_speed;253
this.tongueLengthBounce += deltaTime * this.tongue_speed;251
}254
}252
}255
}253
256
254
retractTongueLength(deltaTime) 257
retractTongueLength (deltaTime) 255
{258
{256
this.tongueLength -= deltaTime * this.tongue_speed * 2;259
this.tongueLength -= deltaTime * this.tongue_speed * 2;257
this.retracting = true;260
this.retracting = true;258
261
259
if(this.should_bounce) 262
if (this.should_bounce) 260
{263
{261
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;264
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;262
}265
}263
}266
}264
267
265
drawTongue() 268
drawTongue () 266
{269
{267
let dir = new vector(this.currentFacing, -1);270
let dir = new vector(this.currentFacing, -1);268
271
269
this.frog_tongue_tip.draw(this.scene, 272
this.frog_tongue_tip.draw(this.scene,270
this.tongueVector.x, this.tongueVector.y, 273
this.tongueVector.x, this.tongueVector.y,271
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 274
this.frog_tongue_tip.width, this.frog_tongue_tip.height,272
dir.toAngle() -90, 0, 0, 1, 0) 275
dir.toAngle() - 90, 0, 0, 1, 0);273
276
274
this.frog_tongue_base.draw(277
this.frog_tongue_base.draw(275
this.scene,278
this.scene,276
(this.transform.position.x + this.tongueVector.x + this.getXOffset(this.currentFacing)) / 2, (this.transform.position.y + this.tongueVector.y) / 2, 279
(this.transform.position.x + this.tongueVector.x + this.getXOffset(this.currentFacing)) / 2, (this.transform.position.y + this.tongueVector.y) / 2,277
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height, 280
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,278
dir.toAngle() -90, 0, 0, 1, 0)281
dir.toAngle() - 90, 0, 0, 1, 0);279
282
280
if(this.should_bounce) 283
if (this.should_bounce) 281
{284
{282
dir = new vector(this.opposite_facing, -1);285
dir = new vector(this.opposite_facing, -1);283
286
284
this.frog_tongue_tip.draw(this.scene, 287
this.frog_tongue_tip.draw(this.scene,285
this.tongueVectorBounce.x, this.tongueVectorBounce.y, 288
this.tongueVectorBounce.x, this.tongueVectorBounce.y,286
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 289
this.frog_tongue_tip.width, this.frog_tongue_tip.height,287
dir.toAngle() -90, 0, 0, 1, 0) 290
dir.toAngle() - 90, 0, 0, 1, 0);288
291
289
this.frog_tongue_base.draw(292
this.frog_tongue_base.draw(290
this.scene, 293
this.scene,291
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2, 294
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2,292
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height, 295
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height,293
dir.toAngle() -90, 0, 0, 1, 0)296
dir.toAngle() - 90, 0, 0, 1, 0);294
}297
}295
}298
}296
}299
}@@ -13,35 +13,35 @@ class FrogScene extends Scene
13
13
14
14
gameSpeed = 1;
15
15
16
constructor(x, y, width, height, displayMode = 0)
16
constructor (x, y, width, height, displayMode = 0)
17
17
{
18
18
super(x, y, width, height, displayMode);
19
19
20
20
this.fruitSpawnTimer = this.fruitSpawnRateMax;
21
21
}
22
22
23
onLoad()
23
onLoad ()
24
24
{
25
while(this.fruitPool.length < this.fruitMax)
25
while (this.fruitPool.length < this.fruitMax)
26
26
{
27
let fruit = new Fruit(0,0, this.game.images.fruit, 0);
27
let fruit = new Fruit(0, 0, this.game.images.fruit, 0);
28
28
this.fruitPool.push(fruit);
29
29
}
30
30
}
31
31
32
update(deltaTime)
32
update (deltaTime)
33
33
{
34
34
super.update(deltaTime);
35
35
36
36
this.spawnFruits(deltaTime);
37
37
}
38
38
39
spawnFruits(deltaTime)
39
spawnFruits (deltaTime)
40
40
{
41
41
this.fruitSpawnTimer -= deltaTime;
42
if(this.fruitSpawnTimer < this.fruitSpawnRateMin)
42
if (this.fruitSpawnTimer < this.fruitSpawnRateMin)
43
43
{
44
if(this.shouldSpawn() || this.fruitSpawnTimer < 0)
44
if (this.shouldSpawn() || this.fruitSpawnTimer < 0)
45
45
{
46
46
let fruit = this.getFromFruitPoolOrCreate();
47
47
fruit.destroyed = false;
@@ -55,33 +55,33 @@ class FrogScene extends Scene
55
55
}
56
56
}
57
57
58
destroyFruit(fruit)
58
destroyFruit (fruit)
59
59
{
60
60
this.fruits.remove(fruit);
61
61
this.fruitPool.push(fruit);
62
62
fruit.destroy();
63
63
}
64
64
65
getFromFruitPoolOrCreate()
65
getFromFruitPoolOrCreate ()
66
66
{
67
return this.fruitPool.length > 0 ? this.fruitPool.pop() : new Fruit(0,0, this.game.images.fruit, 0);
67
return this.fruitPool.length > 0 ? this.fruitPool.pop() : new Fruit(0, 0, this.game.images.fruit, 0);
68
68
}
69
69
70
setRandomSubImage(fruit)
70
setRandomSubImage (fruit)
71
71
{
72
fruit.renderer.subImage = Math.floor(Math.randomRange(0,fruit.renderer.sprite.subImages));
72
fruit.renderer.subImage = Math.floor(Math.randomRange(0, fruit.renderer.sprite.subImages));
73
73
}
74
74
75
getRandomVectorPosition(fruit)
75
getRandomVectorPosition (fruit)
76
76
{
77
77
return new vector
78
(
79
Math.floor(Math.randomRange(0, this.real_size.x)),
80
0
81
);
78
(
79
Math.floor(Math.randomRange(0, this.real_size.x)),
80
0
81
);
82
82
}
83
83
84
shouldSpawn()
84
shouldSpawn ()
85
85
{
86
86
return this.fruits.length < this.fruitMax && Math.random() < this.fruitSpawnChance;
87
87
}
@@ -13,35 +13,35 @@ class FrogScene extends Scene13
13
14
gameSpeed = 1;14
gameSpeed = 1;15
15
16
constructor(x, y, width, height, displayMode = 0)16
constructor (x, y, width, height, displayMode = 0)17
{17
{18
super(x, y, width, height, displayMode);18
super(x, y, width, height, displayMode);19
19
20
this.fruitSpawnTimer = this.fruitSpawnRateMax;20
this.fruitSpawnTimer = this.fruitSpawnRateMax;21
}21
}22
22
23
onLoad()23
onLoad ()24
{24
{25
while(this.fruitPool.length < this.fruitMax)25
while (this.fruitPool.length < this.fruitMax)26
{26
{27
let fruit = new Fruit(0,0, this.game.images.fruit, 0);27
let fruit = new Fruit(0, 0, this.game.images.fruit, 0);28
this.fruitPool.push(fruit);28
this.fruitPool.push(fruit);29
}29
}30
}30
}31
31
32
update(deltaTime)32
update (deltaTime)33
{33
{34
super.update(deltaTime);34
super.update(deltaTime);35
35
36
this.spawnFruits(deltaTime);36
this.spawnFruits(deltaTime);37
}37
}38
38
39
spawnFruits(deltaTime)39
spawnFruits (deltaTime)40
{40
{41
this.fruitSpawnTimer -= deltaTime;41
this.fruitSpawnTimer -= deltaTime;42
if(this.fruitSpawnTimer < this.fruitSpawnRateMin) 42
if (this.fruitSpawnTimer < this.fruitSpawnRateMin) 43
{43
{44
if(this.shouldSpawn() || this.fruitSpawnTimer < 0)44
if (this.shouldSpawn() || this.fruitSpawnTimer < 0)45
{45
{46
let fruit = this.getFromFruitPoolOrCreate();46
let fruit = this.getFromFruitPoolOrCreate();47
fruit.destroyed = false;47
fruit.destroyed = false;@@ -55,33 +55,33 @@ class FrogScene extends Scene55
}55
}56
}56
}57
57
58
destroyFruit(fruit)58
destroyFruit (fruit)59
{59
{60
this.fruits.remove(fruit);60
this.fruits.remove(fruit);61
this.fruitPool.push(fruit);61
this.fruitPool.push(fruit);62
fruit.destroy();62
fruit.destroy();63
}63
}64
64
65
getFromFruitPoolOrCreate()65
getFromFruitPoolOrCreate ()66
{66
{67
return this.fruitPool.length > 0 ? this.fruitPool.pop() : new Fruit(0,0, this.game.images.fruit, 0);67
return this.fruitPool.length > 0 ? this.fruitPool.pop() : new Fruit(0, 0, this.game.images.fruit, 0);68
}68
}69
69
70
setRandomSubImage(fruit)70
setRandomSubImage (fruit)71
{71
{72
fruit.renderer.subImage = Math.floor(Math.randomRange(0,fruit.renderer.sprite.subImages));72
fruit.renderer.subImage = Math.floor(Math.randomRange(0, fruit.renderer.sprite.subImages));73
}73
}74
74
75
getRandomVectorPosition(fruit)75
getRandomVectorPosition (fruit)76
{76
{77
return new vector77
return new vector78
(78
(79
Math.floor(Math.randomRange(0, this.real_size.x)), 79
Math.floor(Math.randomRange(0, this.real_size.x)),80
080
081
);81
);82
}82
}83
83
84
shouldSpawn()84
shouldSpawn ()85
{85
{86
return this.fruits.length < this.fruitMax && Math.random() < this.fruitSpawnChance;86
return this.fruits.length < this.fruitMax && Math.random() < this.fruitSpawnChance;87
}87
}@@ -2,32 +2,32 @@ class Fruit extends GameObject
2
2
{
3
3
speed = 10;
4
4
5
constructor(x,y,sprite,layer)
5
constructor (x, y, sprite, layer)
6
6
{
7
super(x,y,sprite,layer);
7
super(x, y, sprite, layer);
8
8
9
this.transform.scale = new vector(0.7,0.7);
10
this.renderer.subImage = Math.floor(Math.randomRange(0,15));
9
this.transform.scale = new vector(0.7, 0.7);
10
this.renderer.subImage = Math.floor(Math.randomRange(0, 15));
11
11
12
12
this.collider.enabled = true;
13
13
}
14
14
15
onCollision(obj)
15
onCollision (obj)
16
16
{
17
if(obj instanceof FloorTile)
17
if (obj instanceof FloorTile)
18
18
{
19
19
obj.destroy();
20
20
this.scene.destroyFruit(this);
21
21
}
22
22
}
23
23
24
update(deltaTime)
24
update (deltaTime)
25
25
{
26
26
super.update(deltaTime);
27
27
28
28
this.transform.position.y += this.speed * this.scene.gameSpeed * deltaTime;
29
29
30
if(this.transform.position.y > this.scene.real_size.y)
30
if (this.transform.position.y > this.scene.real_size.y)
31
31
{
32
32
this.scene.destroyFruit(this);
33
33
}
@@ -2,32 +2,32 @@ class Fruit extends GameObject2
{2
{3
speed = 10;3
speed = 10;4
4
5
constructor(x,y,sprite,layer)5
constructor (x, y, sprite, layer)6
{6
{7
super(x,y,sprite,layer);7
super(x, y, sprite, layer);8
8
9
this.transform.scale = new vector(0.7,0.7);9
this.transform.scale = new vector(0.7, 0.7);10
this.renderer.subImage = Math.floor(Math.randomRange(0,15));10
this.renderer.subImage = Math.floor(Math.randomRange(0, 15));11
11
12
this.collider.enabled = true;12
this.collider.enabled = true;13
}13
}14
14
15
onCollision(obj)15
onCollision (obj)16
{16
{17
if(obj instanceof FloorTile)17
if (obj instanceof FloorTile)18
{18
{19
obj.destroy();19
obj.destroy();20
this.scene.destroyFruit(this);20
this.scene.destroyFruit(this);21
}21
}22
}22
}23
23
24
update(deltaTime)24
update (deltaTime)25
{25
{26
super.update(deltaTime);26
super.update(deltaTime);27
27
28
this.transform.position.y += this.speed * this.scene.gameSpeed * deltaTime;28
this.transform.position.y += this.speed * this.scene.gameSpeed * deltaTime;29
29
30
if(this.transform.position.y > this.scene.real_size.y)30
if (this.transform.position.y > this.scene.real_size.y)31
{31
{32
this.scene.destroyFruit(this);32
this.scene.destroyFruit(this);33
}33
}@@ -1,32 +1,32 @@
1
1
class Caster extends GameObject
2
2
{
3
3
lastResult = {};
4
update(deltaTime)
4
update (deltaTime)
5
5
{
6
6
7
if(!GameInput.mousePosition)
8
return;
7
if (!GameInput.mousePosition)
8
return;
9
9
this.collider.enabled = true;
10
if(this.collider.isInBounds(GameInput.mousePosition))
10
if (this.collider.isInBounds(GameInput.mousePosition))
11
11
{
12
console.log("hoverin")
12
console.log("hoverin");
13
13
}
14
14
}
15
15
16
draw(context)
16
draw (context)
17
17
{
18
if(!GameInput.mousePosition)
19
return;
18
if (!GameInput.mousePosition)
19
return;
20
20
21
21
super.draw(context);
22
22
let origin = this.transform.position;
23
let dir = GameInput.mousePosition.subtract(this.transform.position).normalize()
24
let ray = Ray.Cast(this.scene, this.transform.position, dir)
23
let dir = GameInput.mousePosition.subtract(this.transform.position).normalize();
24
let ray = Ray.Cast(this.scene, this.transform.position, dir);
25
25
26
if(ray)
26
if (ray)
27
27
{
28
context.moveTo(this.transform.position.x, this.transform.position.y)
29
context.lineTo(ray.hitPoint.x, ray.hitPoint.y)
28
context.moveTo(this.transform.position.x, this.transform.position.y);
29
context.lineTo(ray.hitPoint.x, ray.hitPoint.y);
30
30
context.stroke();
31
31
this.lastResult = ray;
32
32
}
@@ -1,32 +1,32 @@1
class Caster extends GameObject1
class Caster extends GameObject2
{2
{3
lastResult = {};3
lastResult = {};4
update(deltaTime)4
update (deltaTime)5
{5
{6
6
7
if(!GameInput.mousePosition)7
if (!GameInput.mousePosition)8
return;8
return;9
this.collider.enabled = true;9
this.collider.enabled = true;10
if(this.collider.isInBounds(GameInput.mousePosition))10
if (this.collider.isInBounds(GameInput.mousePosition))11
{11
{12
console.log("hoverin")12
console.log("hoverin");13
}13
}14
}14
}15
15
16
draw(context)16
draw (context)17
{17
{18
if(!GameInput.mousePosition)18
if (!GameInput.mousePosition)19
return;19
return;20
20
21
super.draw(context);21
super.draw(context);22
let origin = this.transform.position;22
let origin = this.transform.position;23
let dir = GameInput.mousePosition.subtract(this.transform.position).normalize()23
let dir = GameInput.mousePosition.subtract(this.transform.position).normalize();24
let ray = Ray.Cast(this.scene, this.transform.position, dir)24
let ray = Ray.Cast(this.scene, this.transform.position, dir);25
25
26
if(ray)26
if (ray)27
{27
{28
context.moveTo(this.transform.position.x, this.transform.position.y)28
context.moveTo(this.transform.position.x, this.transform.position.y);29
context.lineTo(ray.hitPoint.x, ray.hitPoint.y)29
context.lineTo(ray.hitPoint.x, ray.hitPoint.y);30
context.stroke();30
context.stroke();31
this.lastResult = ray;31
this.lastResult = ray;32
}32
}@@ -3,27 +3,27 @@ class GrassTiler extends GameObject
3
3
ground_light = null;
4
4
ground_dark = null;
5
5
6
addedToScene()
6
addedToScene ()
7
7
{
8
8
this.ground_dark = this.scene.game.images.grass_dark;
9
9
this.ground_light = this.scene.game.images.grass_light;
10
10
}
11
11
12
draw(context)
12
draw (context)
13
13
{
14
let width = this.scene.real_size.x + this.ground_dark.width
15
let height = this.scene.real_size.y + this.ground_dark.height
16
let size = 32
14
let width = this.scene.real_size.x + this.ground_dark.width;
15
let height = this.scene.real_size.y + this.ground_dark.height;
16
let size = 32;
17
17
let count = 0;
18
for(let x = 0; x < width; x += size)
18
for (let x = 0; x < width; x += size)
19
19
{
20
for(let y = 0; y < height; y += size)
20
for (let y = 0; y < height; y += size)
21
21
{
22
22
count++;
23
((count) %2 == 1? this.ground_dark : this.ground_light).draw(this.scene, x - (size/2), y, size, size, 0, 0, 0, 1, 0)
23
((count) % 2 == 1 ? this.ground_dark : this.ground_light).draw(this.scene, x - (size / 2), y, size, size, 0, 0, 0, 1, 0);
24
24
}
25
25
26
count = x/size % 2;
26
count = x / size % 2;
27
27
}
28
28
}
29
29
}
@@ -3,27 +3,27 @@ class GrassTiler extends GameObject3
ground_light = null;3
ground_light = null;4
ground_dark = null;4
ground_dark = null;5
5
6
addedToScene()6
addedToScene ()7
{7
{8
this.ground_dark = this.scene.game.images.grass_dark;8
this.ground_dark = this.scene.game.images.grass_dark;9
this.ground_light = this.scene.game.images.grass_light;9
this.ground_light = this.scene.game.images.grass_light;10
}10
}11
11
12
draw(context)12
draw (context)13
{13
{14
let width = this.scene.real_size.x + this.ground_dark.width14
let width = this.scene.real_size.x + this.ground_dark.width;15
let height = this.scene.real_size.y + this.ground_dark.height15
let height = this.scene.real_size.y + this.ground_dark.height;16
let size = 3216
let size = 32;17
let count = 0;17
let count = 0;18
for(let x = 0; x < width; x += size)18
for (let x = 0; x < width; x += size)19
{19
{20
for(let y = 0; y < height; y += size)20
for (let y = 0; y < height; y += size)21
{21
{22
count++;22
count++;23
((count) %2 == 1? this.ground_dark : this.ground_light).draw(this.scene, x - (size/2), y, size, size, 0, 0, 0, 1, 0)23
((count) % 2 == 1 ? this.ground_dark : this.ground_light).draw(this.scene, x - (size / 2), y, size, size, 0, 0, 0, 1, 0);24
}24
}25
25
26
count = x/size % 2;26
count = x / size % 2;27
}27
}28
}28
}29
}29
}