Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
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
/****
* Classes
****/
/**
* config {
* x : Number || 0,
* y : Number || 0,
* rotation : Number || 0,
* }
**/
var ConfigContainer = Container.expand(function (config) {
var self = Container.call(this);
config = config || {};
;
self.x = config.x || 0;
self.y = config.y || 0;
self.rotation = config.rotation || 0;
if (config.scale !== undefined || config.scaleX !== undefined || config.scaleY !== undefined) {
var scaleX = config.scaleX !== undefined ? config.scaleX : config.scale !== undefined ? config.scale : 1;
var scaleY = config.scaleY !== undefined ? config.scaleY : config.scale !== undefined ? config.scale : 1;
self.scale.set(scaleX, scaleY);
}
;
return self;
});
var Lilypad = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var stalk = self.attachAsset('stalk', {
anchorX: 0.5,
y: LILYPAD_STALK_OFFSET,
width: 15,
height: -(self.y + LILYPAD_STALK_OFFSET) * LILYPAD_HEIGHT_FACTOR,
rotation: LILYPAD_ANGLE * (1 - 2 * Math.random()),
tint: 0x90ee90 // light green
});
var lilypad = self.attachAsset('lilypad', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Hook = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var highlightContainer = self.addChild(new Container());
var hook = self.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0.5
});
self.highlightContainer = highlightContainer;
return self;
});
var Highlight = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var highlight = self.attachAsset('highlight', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.rotation += 0.01;
};
return self;
});
var FrogTongue = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
;
var tongueBody = self.attachAsset('shapeBox', {
anchorX: 0,
anchorY: 0.5,
height: 10,
width: config.length,
tint: 0xffc0cb // pink
});
var tongueTip = self.attachAsset('shapeEllipse', {
anchorX: 0.5,
anchorY: 0.5,
height: 15,
width: 20,
x: config.length,
tint: 0xffc0cb // pink
});
;
return self;
});
var Frog = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var tongueContainer = self.addChild(new Container());
var frog = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 0.5
});
;
self.attach = function (hook) {
if (hook) {
// Calculate the angle between the frog and the hook
var dx = hook.x - self.x;
var dy = hook.y - self.y;
var length = Math.sqrt(dx * dx + dy * dy);
self.rotation = Math.atan2(dy, dx);
self.tongue = tongueContainer.addChild(new FrogTongue({
length: length
}));
LK.getSound('frogTongue').play();
} else {
LK.getSound('noTarget').play();
}
};
self.release = function () {
if (self.tongue) {
self.tongue.destroy();
self.tongue = null;
}
};
;
return self;
});
var Foreground = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var foreground1 = self.attachAsset('foreground', {
anchorX: 0.0,
anchorY: 1.0,
tint: 0x808080 // 50% grey
});
var foreground2 = self.attachAsset('foreground', {
anchorX: 1.0,
anchorY: 1.0,
scaleX: -1,
x: foreground1.width,
tint: 0x808080 // 50% grey
});
return self;
});
var Firewall = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var speed = FIREWALL_SPEED;
var columns = [];
var columnCount = config.columns || 0;
var firewallBase = self.attachAsset('firewallBase', {
anchorX: 0.5,
anchorY: 1.0
});
columns.push(firewallBase);
for (var i = 0; i < columnCount; i++) {
var firewallColumn = LK.getAsset('firewallColumn', {});
var column = self.attachAsset('firewallColumn', {
anchorX: 0.5,
anchorY: 1.0,
y: -firewallBase.height * FIREWALL_OFFSET - i * firewallColumn.height * FIREWALL_OFFSET,
scaleX: Math.random() > 0.5 ? 1 : -1
});
columns.push(column);
}
self.update = function () {
var randomColumn = columns[Math.floor(Math.random() * columns.length)];
randomColumn.scale.x *= -1;
speed += FIREWALL_SPEED_INC;
self.x += speed;
};
return self;
});
var Camera = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var zoom = 1.0;
self.update = function () {
self.scale.set(zoom);
moon.scale.set(zoom);
};
});
/****
* Initialize Game
****/
//<Assets used in the game will automatically appear here>
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
;
//==============================================================================
// Global Constants & Settings
//==============================================================================
;
// Game Constants
var GAME_TICKS = 60;
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
;
// Firewall Settings
var FIREWALL_OFFSET = 0.7;
var FIREWALL_SPEED = 0; // 2;
var FIREWALL_SPEED_INC = 0; // 0.1 / GAME_TICKS;
var FIREWALL_START_X = -GAME_WIDTH / 2;
;
// Lilypad Settings
var LILYPAD_ANGLE = 10 * Math.PI / 180;
var LILYPAD_HEIGHT_FACTOR = 1.025;
var LILYPAD_STALK_OFFSET = -5;
;
// Player Settings
var PLAYER_START_X = -300;
var PLAYER_START_Y = -1000;
var PLAYER_RANGE = 650;
var PLAYER_GRAVITY = 0.2;
;
//==============================================================================
// Game Instances & Variables
//==============================================================================
;
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 1.0,
x: GAME_WIDTH / 2,
y: GAME_HEIGHT
}));
var moon = game.addChild(LK.getAsset('moon', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH / 2,
y: GAME_HEIGHT / 2
}));
var foreground = game.addChild(new Foreground({
y: GAME_HEIGHT
}));
var camera = game.addChild(new Camera({
x: GAME_WIDTH / 2,
y: GAME_HEIGHT
}));
var hookContainer = camera.addChild(new Container());
var lillypadContainer = camera.addChild(new Container());
var pickupContainer = camera.addChild(new Container());
var defaultPad = lillypadContainer.addChild(new Lilypad({
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({
x: FIREWALL_START_X,
columns: 10
}));
var targetHook = hookContainer.addChild(new Hook({
x: defaultPad.x + 400,
y: defaultPad.y + 100
}));
var highlight = targetHook.highlightContainer.addChild(new Highlight());
// Decor lilypads
lillypadContainer.addChild(new Lilypad({
x: PLAYER_START_X - 50,
y: -500
}));
lillypadContainer.addChild(new Lilypad({
x: PLAYER_START_X + 100,
y: -300
}));
;
//==============================================================================
// Global events
//==============================================================================
;
game.up = frog.release;
game.down = function () {
frog.attach(targetHook);
};
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