Code edit (17 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: childInstance is undefined' in or related to this line: 'childInstance.x += x;' Line Number: 234
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'self.shift = function (x, y) {' Line Number: 348
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'self.shift = function (x, y) {' Line Number: 342
User prompt
add a "shift" function to the camera which takes in an x and y value. When called, iterate through all the camera's children and increase their x-position by the x value. Additionally increase the Frog instance's y-position by the y value.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please implement this in the frog class for TODO 1,2 and 3 respectively
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: r is not defined' in or related to this line: 'var vt = self.angularVelocity * r;' Line Number: 161
User prompt
Please implement this for the frog class. The TODO 1 is when the frog instance attaches to the hook, the TODO 2 is when the frog releases itself from the hook, and the TODO 3 is the angular momentum update while attached to the hook point
User prompt
Please fix the bug: 'ReferenceError: distance is not defined' in or related to this line: 'var angle = self.angularMomentum / distance;' Line Number: 148
User prompt
Please complete TODO 1, 2 and 3. TODO 1 should convert the current velocity into angular momentum, TODO 2 should convert the current angular momentum into velocity, and TODO 3 should update the position based on the angular momentum and also be influenced by player gravity.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
When releasing, convert the tangential velocity into the new vx and vy
User prompt
Similarly apply the tangential velocity solution while the frog is attached to the hook, and revert it once the release function is called
User prompt
Assuming the frog is the body in this example, please add a vx, vy to it, and allow it to be affected by gravity.
User prompt
make the pink tongue a slightly darker pink
Code edit (1 edits merged)
Please save this source code
User prompt
tint the tongue body and tip pink
Code edit (1 edits merged)
Please save this source code
User prompt
In the Frog's attach function, if hook is defined, create a new FrogTongue with the length calculated from dx and dy. In the Frog's release function, destroy the tongue
===================================================================
--- original.js
+++ change.js
@@ -85,79 +85,59 @@
var self = ConfigContainer.call(this, config);
var tongueContainer = self.addChild(new Container());
var sitting = true;
var hooked = false;
+ var velocityX = 0;
+ var velocityY = 0;
var frog = self.attachAsset('frog', {
- rotation: Math.PI / 2,
anchorX: 0.5,
anchorY: 0.5
});
;
- var velocityX = 0;
- var velocityY = 0;
- var angularVelocity = 0;
- var tangentialVelocity = 0;
- var hookX = 0;
- var hookY = 0;
- var hookLength = 0;
- ;
self.attach = function (hook) {
if (hook) {
sitting = false;
hooked = true;
+ // Calculate the distance between the frog and the hook
+ var dx = hook.x - self.x;
+ var dy = hook.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
// Calculate the angle between the frog and the hook
- hookX = hook.x;
- hookY = hook.y;
- var dx = hookX - self.x;
- var dy = hookY - self.y;
- hookLength = Math.sqrt(dx * dx + dy * dy);
- self.rotation = Math.atan2(dy, dx);
- // Calculate the tangential velocity
- tangentialVelocity = Math.sqrt(velocityX * velocityX + velocityY * velocityY);
- // Calculate the initial angular velocity
- angularVelocity = tangentialVelocity / hookLength;
- // self.tongue = tongueContainer.addChild(new FrogTongue({
- // length: length
- // }));
+ var angle = Math.atan2(dy, dx);
+ // Calculate the angular momentum
+ self.angularMomentum = distance * angle;
LK.getSound('frogTongue').play();
} else {
LK.getSound('noTarget').play();
}
};
self.release = function () {
if (hooked) {
- // self.tongue.destroy();
- // self.tongue = null;
hooked = false;
- // Convert tangential velocity into new vx and vy
- velocityX = angularVelocity * hookLength * Math.cos(self.rotation);
- velocityY = angularVelocity * hookLength * Math.sin(self.rotation);
- tangentialVelocity = 0;
- angularVelocity = 0;
- hookLength = 0;
+ // Calculate the velocity from the angular momentum
+ var angle = self.angularMomentum / distance;
+ velocityX = Math.cos(angle) * distance;
+ velocityY = Math.sin(angle) * distance;
}
};
self.update = function () {
if (!sitting) {
if (hooked) {
- // Update the angular velocity based on gravity
- var angle = Math.atan2(self.y - hookY, self.x - hookX);
- var perpendicularAcceleration = PLAYER_GRAVITY * Math.sin(angle);
- self.angularVelocity += perpendicularAcceleration / hookLength;
- // Update the frog's rotation and position
- self.rotation += angularVelocity;
- self.x = hookY + hookLength * Math.cos(self.rotation);
- self.y = hookX + hookLength * Math.sin(self.rotation);
- velocityX = -angularVelocity * hookLength * Math.sin(self.rotation);
- velocityY = angularVelocity * hookLength * Math.cos(self.rotation);
+ // Calculate the new position based on the angular momentum
+ var angle = self.angularMomentum / distance;
+ self.x += Math.cos(angle) * distance;
+ self.y += Math.sin(angle) * distance;
+ // Apply gravity
+ velocityY += PLAYER_GRAVITY;
+ self.x += velocityX;
+ self.y += velocityY;
} else {
velocityY += PLAYER_GRAVITY;
self.x += velocityX;
self.y += velocityY;
}
}
};
- ;
return self;
});
var Foreground = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
@@ -222,11 +202,8 @@
/****
* Game Code
****/
-game.update = function () {
- frog.update();
-};
;
//==============================================================================
// Global Constants & Settings
//==============================================================================
@@ -250,9 +227,9 @@
// Player Settings
var PLAYER_START_X = -300;
var PLAYER_START_Y = -1000;
var PLAYER_RANGE = 650;
-var PLAYER_GRAVITY = 0.1;
+var PLAYER_GRAVITY = 0.2;
;
//==============================================================================
// Game Instances & Variables
//==============================================================================
@@ -283,8 +260,9 @@
x: PLAYER_START_X,
y: PLAYER_START_Y
}));
var frog = camera.addChild(new Frog({
+ rotation: Math.PI / 2,
x: PLAYER_START_X,
y: PLAYER_START_Y
}));
var firewall = camera.addChild(new Firewall({
fireCrackle
Sound effect
frogTongue
Sound effect
frogDeath
Sound effect
lilypadBounce
Sound effect
noTarget
Sound effect
backgroundAmbient
Sound effect
fireCrackling1
Sound effect
fireCrackling2
Sound effect
fireCrackling3
Sound effect
fireCrackling4
Sound effect
frogBounce
Sound effect
pickupCaught
Sound effect