frog cleanup
@@ -41,139 +41,208 @@ class Frog extends GameObject {
41
41
42
42
this.idle = true;
43
43
44
if(this.tongue_retracted && !this.retracting)
44
if(this.tongue_retracted)
45
45
{
46
if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft)))
46
if(GameInput.isHeld(GameInput.keys.ArrowLeft) || GameInput.isHeld(GameInput.keys.ArrowRight))
47
47
{
48
if(GameInput.isHeld(GameInput.keys.ArrowRight))
49
{
50
this.arrowCounter++;
51
if(this.canMove(this.transform.position.x + this.speed * deltaTime)) {
52
this.transform.position.x += this.speed * deltaTime;
53
}
54
55
if(this.currentFacing != this.facing.right)
56
{
57
this.renderer.mirrorX = !this.renderer.mirrorX;
58
this.currentFacing = this.facing.right;
59
}
60
61
CookieManager.setCookie("arrow", "right");
62
this.idle = false;
63
this.renderer.setAnimation("walk", 0, .2);
64
}
65
66
if(GameInput.isHeld(GameInput.keys.ArrowLeft))
67
{
68
this.arrowCounter++;
69
if(this.canMove(this.transform.position.x - this.speed * deltaTime)) {
70
this.transform.position.x -= this.speed * deltaTime;
71
}
72
73
if(this.currentFacing != this.facing.left)
74
{
75
this.renderer.mirrorX = !this.renderer.mirrorX;
76
this.currentFacing = this.facing.left;
77
}
78
79
CookieManager.setCookie("arrow", "left")
80
this.idle = false;
81
this.renderer.setAnimation("walk", 0, .2);
82
}
48
this.move(deltaTime);
83
49
}
84
50
}
85
51
86
52
if(GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)
87
53
{
88
this.renderer.setSubImage(3);
89
this.idle = false;
90
this.tongueLength += deltaTime * this.tongue_speed;
54
this.extendTongueLength(deltaTime);
91
55
}
92
56
else
93
57
{
94
58
if(!this.tongue_retracted)
95
59
{
96
if(this.tongueLengthBounce > 0) {
97
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;
98
}
99
this.tongueLength -= deltaTime * this.tongue_speed * 2;
100
this.retracting = true;
60
this.retractTongueLength(deltaTime);
101
61
}
102
62
else
103
63
{
104
64
this.retracting = false;
105
65
}
106
66
}
67
68
if(!this.tongue_retracted)
69
{
70
this.calculateTongueVectors();
71
}
107
72
108
73
if(this.idle && this.tongue_retracted && !this.retracting)
109
74
{
110
75
this.renderer.setAnimation("walk", 0, -1);
111
76
}
112
77
113
if(!this.tongue_retracted && !this.retracting)
78
79
}
80
81
calculateTongueVectors()
82
{
83
84
let dir = new vector(this.currentFacing, -1);
85
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength)).add(new vector(this.getXOffset(this.currentFacing), 0));
86
87
if(!this.isVectorWithinSceneY(this.tongueVector, this.scene)) {
88
this.retracting = true;
89
return;
90
}
91
92
if(this.should_bounce)
114
93
{
115
this.doTongueStuff(deltaTime);
94
if(!(this.tongueLengthBounce > 0))
95
{
96
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();
97
}
98
99
dir = new vector(this.opposite_facing, -1);
100
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));
101
102
if(this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y) {
103
this.retracting = true;
104
return;
105
}
116
106
}
117
107
}
118
108
119
get tongue_retracted() {
109
draw(context)
110
{
111
super.draw(context);
112
113
if(!this.tongue_retracted)
114
{
115
this.drawTongue();
116
}
117
}
118
119
get tongue_retracted()
120
{
120
121
return this.tongueLength <= 0;
121
122
}
122
123
123
get tongue_speed() {
124
get tongue_speed()
125
{
124
126
return 150 * this.scene.gameSpeed;
125
127
}
126
128
127
get opposite_facing() {
129
get opposite_facing()
130
{
128
131
return this.currentFacing == this.facing.left ? this.facing.right : this.facing.left;
129
132
}
133
134
get should_bounce()
135
{
136
return this.tongueVector && (!this.isVectorWithinSceneX(this.tongueVector, this.scene));
137
}
138
139
getXOffset(facing)
140
{
141
return facing > 0 ? 8 : -8;
142
}
130
143
131
144
canMove(nextPos)
132
145
{
133
146
return nextPos + this.transform.size.x / 2 < this.scene.real_size.x && nextPos - this.transform.size.x / 2 > 0
134
147
}
135
148
136
doTongueStuff(deltaTime)
149
isVectorWithinSceneX(vector, scene)
137
150
{
138
let dir = new vector(this.currentFacing, -1);
139
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength));
151
return vector.x >= 0 && vector.x <= scene.real_size.x;
152
}
140
153
141
if(this.tongueVector.y <= 0 || this.tongueVector.y >= this.scene.size.y) {
142
this.retracting = true;
143
return;
144
}
154
isVectorWithinSceneY(vector, scene)
155
{
156
return vector.y >= 0 && vector.y <= scene.real_size.y;
157
}
145
158
146
if(this.tongueVector.x <= 0 || this.tongueVector.x >= this.scene.size.x )
147
{
148
if(!(this.tongueLengthBounce > 1))
149
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();
159
move(deltaTime)
160
{
161
if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft)))
162
{
163
if(GameInput.isHeld(GameInput.keys.ArrowRight))
164
{
165
if(this.canMove(this.transform.position.x + this.speed * deltaTime))
166
{
167
this.transform.position.x += this.speed * deltaTime;
168
}
150
169
151
this.tongueLengthBounce += deltaTime * this.tongue_speed;
152
dir = new vector(this.opposite_facing, -1);
153
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));
170
if(this.currentFacing != this.facing.right)
171
{
172
this.renderer.mirrorX = !this.renderer.mirrorX;
173
this.currentFacing = this.facing.right;
174
}
175
}
154
176
155
if(this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y) {
156
this.retracting = true;
157
return;
177
if(GameInput.isHeld(GameInput.keys.ArrowLeft))
178
{
179
if(this.canMove(this.transform.position.x - this.speed * deltaTime))
180
{
181
this.transform.position.x -= this.speed * deltaTime;
182
}
183
184
if(this.currentFacing != this.facing.left)
185
{
186
this.renderer.mirrorX = !this.renderer.mirrorX;
187
this.currentFacing = this.facing.left;
188
}
189
}
190
191
this.idle = false;
192
this.renderer.setAnimation("walk", 0, .2);
158
193
}
194
}
195
196
extendTongueLength(deltaTime)
197
{
198
this.renderer.setSubImage(3);
199
this.idle = false;
200
this.tongueLength += deltaTime * this.tongue_speed;
201
202
if(this.should_bounce)
203
{
204
this.tongueLengthBounce += deltaTime * this.tongue_speed;
159
205
}
160
206
}
161
207
162
draw(context)
208
retractTongueLength(deltaTime)
163
209
{
164
super.draw(context);
210
this.tongueLength -= deltaTime * this.tongue_speed * 2;
211
this.retracting = true;
165
212
166
if(!this.tongue_retracted) {
167
168
let dir = new vector(this.currentFacing, -1);
213
if(this.should_bounce)
214
{
215
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;
216
}
217
}
169
218
170
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength));
171
let xOffset = this.currentFacing > 0 ? 5 : -5;
219
drawTongue()
220
{
221
let dir = new vector(this.currentFacing, -1);
222
223
this.frog_tongue_tip.draw(this.scene,
224
0, 0,
225
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
226
this.tongueVector.x, this.tongueVector.y,
227
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
228
dir.toAngle() -90, 0, 0, 1)
229
230
this.frog_tongue_base.draw(
231
this.scene,
232
0, 0,
233
this.frog_tongue_base.width, this.frog_tongue_base.height,
234
(this.transform.position.x + this.tongueVector.x + this.getXOffset(this.currentFacing)) / 2, (this.transform.position.y + this.tongueVector.y) / 2,
235
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
236
dir.toAngle() -90, 0, 0, 1)
237
238
if(this.should_bounce)
239
{
240
dir = new vector(this.opposite_facing, -1);
172
241
173
242
this.frog_tongue_tip.draw(this.scene,
174
243
0, 0,
175
244
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
176
this.tongueVector.x + xOffset, this.tongueVector.y,
245
this.tongueVectorBounce.x, this.tongueVectorBounce.y,
177
246
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
178
247
dir.toAngle() -90, 0, 0, 1)
179
248
@@ -181,30 +250,9 @@ class Frog extends GameObject {
181
250
this.scene,
182
251
0, 0,
183
252
this.frog_tongue_base.width, this.frog_tongue_base.height,
184
(this.transform.position.x + this.tongueVector.x) / 2 + xOffset, (this.transform.position.y + this.tongueVector.y) / 2,
185
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height,
253
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2,
254
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height,
186
255
dir.toAngle() -90, 0, 0, 1)
187
188
if(this.tongueLengthBounce > 0) {
189
dir = new vector(this.opposite_facing, -1);
190
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));
191
xOffset = this.opposite_facing > 0 ? 5 : -5;
192
193
this.frog_tongue_tip.draw(this.scene,
194
0, 0,
195
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
196
this.tongueVectorBounce.x + xOffset, this.tongueVectorBounce.y,
197
this.frog_tongue_tip.width, this.frog_tongue_tip.height,
198
dir.toAngle() -90, 0, 0, 1)
199
200
this.frog_tongue_base.draw(
201
this.scene,
202
0, 0,
203
this.frog_tongue_base.width, this.frog_tongue_base.height,
204
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2 + xOffset, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2,
205
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height,
206
dir.toAngle() -90, 0, 0, 1)
207
}
208
256
}
209
257
}
210
258
}
@@ -41,139 +41,208 @@ class Frog extends GameObject {41
41
42
this.idle = true;42
this.idle = true;43
43
44
if(this.tongue_retracted && !this.retracting) 44
if(this.tongue_retracted) 45
{45
{46
if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft))) 46
if(GameInput.isHeld(GameInput.keys.ArrowLeft) || GameInput.isHeld(GameInput.keys.ArrowRight))47
{47
{48
if(GameInput.isHeld(GameInput.keys.ArrowRight))48
this.move(deltaTime);49
{50
this.arrowCounter++;51
if(this.canMove(this.transform.position.x + this.speed * deltaTime)) {52
this.transform.position.x += this.speed * deltaTime;53
}54
55
if(this.currentFacing != this.facing.right) 56
{57
this.renderer.mirrorX = !this.renderer.mirrorX;58
this.currentFacing = this.facing.right;59
}60
61
CookieManager.setCookie("arrow", "right");62
this.idle = false;63
this.renderer.setAnimation("walk", 0, .2);64
}65
66
if(GameInput.isHeld(GameInput.keys.ArrowLeft))67
{68
this.arrowCounter++;69
if(this.canMove(this.transform.position.x - this.speed * deltaTime)) {70
this.transform.position.x -= this.speed * deltaTime;71
}72
73
if(this.currentFacing != this.facing.left) 74
{75
this.renderer.mirrorX = !this.renderer.mirrorX;76
this.currentFacing = this.facing.left;77
}78
79
CookieManager.setCookie("arrow", "left")80
this.idle = false;81
this.renderer.setAnimation("walk", 0, .2);82
}83
}49
}84
}50
}85
51
86
if(GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)52
if(GameInput.isHeld(GameInput.keys[" "]) && !this.retracting)87
{53
{88
this.renderer.setSubImage(3);54
this.extendTongueLength(deltaTime);89
this.idle = false;90
this.tongueLength += deltaTime * this.tongue_speed;91
} 55
} 92
else56
else93
{57
{94
if(!this.tongue_retracted) 58
if(!this.tongue_retracted) 95
{59
{96
if(this.tongueLengthBounce > 0) {60
this.retractTongueLength(deltaTime);97
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;98
}99
this.tongueLength -= deltaTime * this.tongue_speed * 2;100
this.retracting = true;101
}61
}102
else62
else103
{63
{104
this.retracting = false;64
this.retracting = false;105
}65
}106
}66
}67
68
if(!this.tongue_retracted) 69
{70
this.calculateTongueVectors();71
}107
72
108
if(this.idle && this.tongue_retracted && !this.retracting) 73
if(this.idle && this.tongue_retracted && !this.retracting) 109
{74
{110
this.renderer.setAnimation("walk", 0, -1);75
this.renderer.setAnimation("walk", 0, -1);111
}76
}112
77
113
if(!this.tongue_retracted && !this.retracting) 78
79
}80
81
calculateTongueVectors() 82
{83
84
let dir = new vector(this.currentFacing, -1);85
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength)).add(new vector(this.getXOffset(this.currentFacing), 0));86
87
if(!this.isVectorWithinSceneY(this.tongueVector, this.scene)) {88
this.retracting = true;89
return;90
}91
92
if(this.should_bounce) 114
{93
{115
this.doTongueStuff(deltaTime);94
if(!(this.tongueLengthBounce > 0)) 95
{96
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();97
} 98
99
dir = new vector(this.opposite_facing, -1);100
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));101
102
if(this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y) {103
this.retracting = true;104
return;105
}116
}106
}117
}107
}118
108
119
get tongue_retracted() {109
draw(context)110
{111
super.draw(context); 112
113
if(!this.tongue_retracted) 114
{115
this.drawTongue();116
}117
}118
119
get tongue_retracted() 120
{120
return this.tongueLength <= 0;121
return this.tongueLength <= 0;121
}122
}122
123
123
get tongue_speed() {124
get tongue_speed() 125
{124
return 150 * this.scene.gameSpeed;126
return 150 * this.scene.gameSpeed;125
}127
}126
128
127
get opposite_facing() {129
get opposite_facing() 130
{128
return this.currentFacing == this.facing.left ? this.facing.right : this.facing.left;131
return this.currentFacing == this.facing.left ? this.facing.right : this.facing.left;129
}132
}133
134
get should_bounce() 135
{136
return this.tongueVector && (!this.isVectorWithinSceneX(this.tongueVector, this.scene));137
}138
139
getXOffset(facing) 140
{141
return facing > 0 ? 8 : -8;142
}130
143
131
canMove(nextPos) 144
canMove(nextPos) 132
{145
{133
return nextPos + this.transform.size.x / 2 < this.scene.real_size.x && nextPos - this.transform.size.x / 2 > 0146
return nextPos + this.transform.size.x / 2 < this.scene.real_size.x && nextPos - this.transform.size.x / 2 > 0134
}147
}135
148
136
doTongueStuff(deltaTime) 149
isVectorWithinSceneX(vector, scene) 137
{150
{138
let dir = new vector(this.currentFacing, -1);151
return vector.x >= 0 && vector.x <= scene.real_size.x;139
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength));152
}140
153
141
if(this.tongueVector.y <= 0 || this.tongueVector.y >= this.scene.size.y) {154
isVectorWithinSceneY(vector, scene) 142
this.retracting = true;155
{143
return;156
return vector.y >= 0 && vector.y <= scene.real_size.y;144
}157
}145
158
146
if(this.tongueVector.x <= 0 || this.tongueVector.x >= this.scene.size.x ) 159
move(deltaTime) 147
{160
{148
if(!(this.tongueLengthBounce > 1))161
if(! (GameInput.isHeld(GameInput.keys.ArrowRight) && GameInput.isHeld(GameInput.keys.ArrowLeft))) 149
this.tongueVectorBounceOrigin = this.tongueVector.getCopy();162
{163
if(GameInput.isHeld(GameInput.keys.ArrowRight))164
{165
if(this.canMove(this.transform.position.x + this.speed * deltaTime)) 166
{167
this.transform.position.x += this.speed * deltaTime;168
}150
169
151
this.tongueLengthBounce += deltaTime * this.tongue_speed;170
if(this.currentFacing != this.facing.right) 152
dir = new vector(this.opposite_facing, -1);171
{153
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));172
this.renderer.mirrorX = !this.renderer.mirrorX;173
this.currentFacing = this.facing.right;174
}175
}154
176
155
if(this.tongueVectorBounce.y <= 0 || this.tongueVectorBounce.y >= this.scene.size.y) {177
if(GameInput.isHeld(GameInput.keys.ArrowLeft))156
this.retracting = true;178
{157
return;179
if(this.canMove(this.transform.position.x - this.speed * deltaTime)) 180
{181
this.transform.position.x -= this.speed * deltaTime;182
}183
184
if(this.currentFacing != this.facing.left) 185
{186
this.renderer.mirrorX = !this.renderer.mirrorX;187
this.currentFacing = this.facing.left;188
}189
}190
191
this.idle = false;192
this.renderer.setAnimation("walk", 0, .2);158
}193
}194
}195
196
extendTongueLength(deltaTime) 197
{198
this.renderer.setSubImage(3);199
this.idle = false;200
this.tongueLength += deltaTime * this.tongue_speed;201
202
if(this.should_bounce) 203
{204
this.tongueLengthBounce += deltaTime * this.tongue_speed;159
}205
}160
}206
}161
207
162
draw(context)208
retractTongueLength(deltaTime) 163
{209
{164
super.draw(context); 210
this.tongueLength -= deltaTime * this.tongue_speed * 2;211
this.retracting = true;165
212
166
if(!this.tongue_retracted) {213
if(this.should_bounce) 167
214
{168
let dir = new vector(this.currentFacing, -1);215
this.tongueLengthBounce -= deltaTime * this.tongue_speed * 2;216
}217
}169
218
170
this.tongueVector = this.transform.position.add(dir.stretch(this.tongueLength));219
drawTongue() 171
let xOffset = this.currentFacing > 0 ? 5 : -5;220
{221
let dir = new vector(this.currentFacing, -1);222
223
this.frog_tongue_tip.draw(this.scene, 224
0, 0, 225
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 226
this.tongueVector.x, this.tongueVector.y, 227
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 228
dir.toAngle() -90, 0, 0, 1) 229
230
this.frog_tongue_base.draw(231
this.scene, 232
0, 0, 233
this.frog_tongue_base.width, this.frog_tongue_base.height, 234
(this.transform.position.x + this.tongueVector.x + this.getXOffset(this.currentFacing)) / 2, (this.transform.position.y + this.tongueVector.y) / 2, 235
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height, 236
dir.toAngle() -90, 0, 0, 1)237
238
if(this.should_bounce) 239
{240
dir = new vector(this.opposite_facing, -1);172
241
173
this.frog_tongue_tip.draw(this.scene, 242
this.frog_tongue_tip.draw(this.scene, 174
0, 0, 243
0, 0, 175
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 244
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 176
this.tongueVector.x + xOffset, this.tongueVector.y, 245
this.tongueVectorBounce.x, this.tongueVectorBounce.y, 177
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 246
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 178
dir.toAngle() -90, 0, 0, 1) 247
dir.toAngle() -90, 0, 0, 1) 179
248
@@ -181,30 +250,9 @@ class Frog extends GameObject {181
this.scene, 250
this.scene, 182
0, 0, 251
0, 0, 183
this.frog_tongue_base.width, this.frog_tongue_base.height, 252
this.frog_tongue_base.width, this.frog_tongue_base.height, 184
(this.transform.position.x + this.tongueVector.x) / 2 + xOffset, (this.transform.position.y + this.tongueVector.y) / 2, 253
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2, 185
this.frog_tongue_base.width * (this.tongueLength / 12.5), this.frog_tongue_base.height, 254
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height, 186
dir.toAngle() -90, 0, 0, 1)255
dir.toAngle() -90, 0, 0, 1)187
188
if(this.tongueLengthBounce > 0) {189
dir = new vector(this.opposite_facing, -1);190
this.tongueVectorBounce = this.tongueVectorBounceOrigin.add(dir.stretch(this.tongueLengthBounce));191
xOffset = this.opposite_facing > 0 ? 5 : -5;192
193
this.frog_tongue_tip.draw(this.scene, 194
0, 0, 195
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 196
this.tongueVectorBounce.x + xOffset, this.tongueVectorBounce.y, 197
this.frog_tongue_tip.width, this.frog_tongue_tip.height, 198
dir.toAngle() -90, 0, 0, 1) 199
200
this.frog_tongue_base.draw(201
this.scene, 202
0, 0, 203
this.frog_tongue_base.width, this.frog_tongue_base.height, 204
(this.tongueVectorBounceOrigin.x + this.tongueVectorBounce.x) / 2 + xOffset, (this.tongueVectorBounceOrigin.y + this.tongueVectorBounce.y) / 2, 205
this.frog_tongue_base.width * (this.tongueLengthBounce / 12.5), this.frog_tongue_base.height, 206
dir.toAngle() -90, 0, 0, 1)207
}208
}256
}209
}257
}210
}258
}