User prompt
Rename the global `PLAYER_TONGUE_RANGE` to `PLAYER_TONGUE_RANGE_MAX` and update all its usages. Add a new global under `PLAYER_TONGUE_RANGE_MAX` called `PLAYER_TONGUE_RANGE_MIN`
Code edit (1 edits merged)
Please save this source code
User prompt
the hook should flip it's hook asset's scale.x every 5 to 10 frames
User prompt
Please fix the bug: 'ReferenceError: highlightContainer is not defined' in or related to this line: 'self.highlightContainer = highlightContainer;' Line Number: 183
User prompt
Remove the highlightContainer from the hook and instead attach directly to the highlight instance
User prompt
change the frog's "hookedObj" variable to be "self.hookedObj" instead, and update all references
Code edit (1 edits merged)
Please save this source code
User prompt
change the hook class's disableInterval to be a timeout instead
Code edit (1 edits merged)
Please save this source code
User prompt
Add a disable function to the hook class which sets it's "self.enabled" to false and tints it dark grey for HOOK_OFFLINE ticks, then reverts the changes
User prompt
Please fix the bug: 'TypeError: hookedObj.disable is not a function' in or related to this line: 'hookedObj.disable();' Line Number: 278
User prompt
In the frog release function, if hooked then call a new disable function on the hookedObj and then clear the variable
User prompt
hide the visibility of the frog's collision
Code edit (4 edits merged)
Please save this source code
User prompt
add a 50x50 shapeEllipse to the frog as the collision
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Create an empty Spawner class
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Add an update function to the hook class. If the hook's x position is less than the firewall's x position, destroy the hook
Code edit (1 edits merged)
Please save this source code
User prompt
after the `targetHook = closestHook;` line, check if the targethook is defined, if it is defined, add the highlight instance as a child to its highlightContainer, add the highlight as a child to the game instance, and hide it
Code edit (3 edits merged)
Please save this source code
User prompt
Inside the game.update function, iterate through the hookContainer's children and find the closest child to the frog within PLAYER_TONGUE_RANGE distance (use distance squared for comparison). The closest hook should be set as the targetHook, otherwise it should be set to undefined
/****
* 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 Pickup = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
config = config || {};
var collectable = self.attachAsset('collectable', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.random() * Math.PI * 2
});
self.update = function () {
if (collectable.intersects(frog)) {
LK.getSound('pickupCaught').play();
gameInterface.increaseMultiplier();
self.destroy();
}
};
return self;
});
var Lilypad = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
config = config || {};
;
var inert = config.inert !== undefined ? config.inert : false;
var active = config.active !== undefined ? config.active : true;
var destroying = false;
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
});
if (!inert && Math.random() < LILYPAD_PICKUP_CHANCE) {
pickupContainer.addChild(new Pickup({
x: self.x,
y: self.y - LILYPAD_PICKUP_OFFSET_MIN - LILYPAD_PICKUP_OFFSET_VAR * Math.random()
}));
}
;
self.launch = function () {
active = false;
destroying = true;
LK.getSound('frogBounce').play();
};
self.update = function () {
if (active && lilypad.intersects(frog)) {
frog.bounce();
self.launch();
}
if (destroying) {
if (self.alpha <= 0) {
self.destroy();
}
self.alpha -= 0.1;
self.y += 10;
}
};
;
return self;
});
var Interface = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var score = 0;
var multiplier = 1.0;
var scoreText = self.addChild(new BorderedText('0', {
y: -75,
size: 1.5 * TEXT_DEFAULT_SIZE,
anchorX: 0.5
}));
var multiplierText = self.addChild(new BorderedText('1.0x', {
y: 0,
anchorX: 0.5,
anchorY: 0.5
}));
;
self.finalize = function () {
LK.setScore(Math.floor(score));
};
self.increaseDistance = function (distance) {
self.updateScore(score + distance * SCORE_PER_DISTANCE * multiplier);
};
self.updateScore = function (newScore) {
score = newScore;
scoreText.setText(Math.floor(score));
};
self.increaseMultiplier = function () {
self.updateMultiplier(multiplier + SCORE_PICKUP_MULTIPLER);
};
self.updateMultiplier = function (newMultiplier) {
multiplier = newMultiplier;
multiplierText.setText(newMultiplier.toFixed(1) + 'x');
};
;
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: 0xff69b4 // slightly darker pink
});
var tongueTip = self.attachAsset('shapeEllipse', {
anchorX: 0.5,
anchorY: 0.5,
height: 15,
width: 20,
x: config.length,
tint: 0xff69b4 // slightly darker pink
});
;
return self;
});
var Frog = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
;
var hooked = false;
var sitting = true;
var velocityX = 0;
var velocityY = 0;
var velocityAngle = 0;
var hookedObj = undefined;
var hookLength = 0;
var tangentialVelocity = 0;
var angularVelocity = 0;
var tongue = undefined;
var tongueContainer = self.addChild(new Container());
var frog = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 0.5
});
;
self.attach = function (hook) {
if (hook) {
hooked = true;
sitting = false;
hookedObj = hook;
var dx = self.x - hookedObj.x;
var dy = self.y - hookedObj.y;
hookLength = Math.sqrt(dx * dx + dy * dy);
velocityAngle = Math.atan2(dy, dx);
var direction = Math.atan2(velocityY, velocityX);
var magnitude = Math.sin(direction - velocityAngle) * PLAYER_ATTACH_MULTIPLIER;
angularVelocity = magnitude * Math.sqrt(velocityX * velocityX + velocityY * velocityY) / hookLength;
tongue = tongueContainer.addChild(new FrogTongue({
length: hookLength
}));
self.rotation = velocityAngle + Math.PI;
LK.getSound('frogTongue').play();
} else {
LK.getSound('noTarget').play();
}
};
self.release = function () {
if (tongue) {
tongue.destroy();
tongue = undefined;
}
if (hooked) {
hooked = false;
// Convert tangential velocity into new vx and vy
velocityX = angularVelocity * hookLength * Math.cos(velocityAngle + MATH_HALF_PI) * PLAYER_RELEASE_MULTIPLIER;
velocityY = angularVelocity * hookLength * Math.sin(velocityAngle + MATH_HALF_PI) * PLAYER_RELEASE_MULTIPLIER - PLAYER_RELEASE_VY_BONUS;
hookLength = 0;
}
};
self.bounce = function () {
if (hooked) {
angularVelocity *= PLAYER_BOUNCE_FACTOR;
} else {
velocityY *= PLAYER_BOUNCE_FACTOR;
}
};
self.update = function () {
if (!sitting) {
if (hooked) {
var hookAngle = Math.atan2(self.y - hookedObj.y, self.x - hookedObj.x);
var perpendicularAcceleration = PLAYER_GRAVITY * Math.sin(hookAngle + MATH_HALF_PI);
angularVelocity += perpendicularAcceleration / hookLength;
angularVelocity *= PLAYER_ANGULAR_DAMPENING;
velocityAngle += angularVelocity;
velocityX = hookedObj.x + hookLength * Math.cos(velocityAngle) - self.x;
velocityY = hookedObj.y + hookLength * Math.sin(velocityAngle) - self.y;
camera.shift(velocityX, velocityY);
self.rotation = Math.atan2(self.y - hookedObj.y, self.x - hookedObj.x) + Math.PI;
} else {
velocityY += PLAYER_GRAVITY;
self.rotation += angularVelocity * PLAYER_SPIN_MAGNITUDE;
camera.shift(velocityX, velocityY);
}
}
};
;
return self;
});
var Foreground = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
config = config || {};
var tint = config.tint !== undefined ? config.tint : 0xFFFFFF;
var coverage = config.coverage !== undefined ? config.coverage : 0;
var covered = 0;
var segmentWidth = 0;
var flipX = -1;
var scaleX = self.scale.x;
do {
var foregroundLeft = self.attachAsset('foreground', {
x: -covered / 2,
anchorX: Math.max(0, flipX),
anchorY: 1.0,
scaleX: flipX,
tint: tint
});
var foregroundRight = self.attachAsset('foreground', {
x: covered / 2,
anchorX: Math.max(0, flipX),
anchorY: 1.0,
scaleX: -flipX,
tint: tint
});
covered += segmentWidth || (segmentWidth = foregroundRight.width + foregroundLeft.width);
flipX *= -1;
} while (covered < coverage);
;
self.update = function () {
if (self.x <= -segmentWidth * scaleX) {
self.x += segmentWidth * scaleX;
}
if (self.x >= segmentWidth * scaleX) {
self.x -= segmentWidth * scaleX;
}
};
;
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 firewallOverlay = self.attachAsset('shapeBox', {
anchorX: 1,
anchorY: 1,
width: 2 * GAME_WIDTH,
height: 2 * GAME_HEIGHT,
tint: 0x000000,
alpha: 0.85
});
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 distance = 0;
var distanceMax = 0;
var hookSpawnDist = self.zoom = 1;
self.shift = function (x, y) {
for (var i = 0; i < self.children.length; i++) {
var childContainer = self.children[i];
for (var j = 0; j < childContainer.children.length; j++) {
var childInstance = childContainer.children[j];
childInstance.x -= x;
}
}
foreground.x -= x / FOREGROUND_MOVEMENT;
shadowground.x += x / SHADOWGROUND_MOVEMENT;
frog.x += x;
frog.y += y;
distance += x;
if (distance > distanceMax) {
gameInterface.increaseDistance(distance - distanceMax);
distanceMax = distance;
}
};
self.update = function () {
self.zoom = Math.min(1, GAME_HEIGHT / (Math.abs(frog.y) * PLAYER_SCREEN_MARGIN));
self.scale.set(self.zoom);
moon.scale.set(1 - MOON_SCALING + MOON_SCALING * self.zoom);
};
});
/**
* config {
* x : Number || 0, // See: ConfigContainer
* y : Number || 0, // See: ConfigContainer
* rotation : Number || 0, // See: ConfigContainer
* anchorX : Number || 0,
* anchorY : Number || 1,
* size : Number || TEXT_DEFAULT_SIZE,
* weight : Number || TEXT_DEFAULT_WEIGHT,
* font : String || TEXT_DEFAULT_FONT,
* fill : String || TEXT_DEFAULT_FILL,
* border : String || TEXT_DEFAULT_BORDER,
* }
**/
var BorderedText = ConfigContainer.expand(function (text, config) {
var self = ConfigContainer.call(this, config);
config = config || {};
;
var anchorX = config.anchorX !== undefined ? config.anchorX : 0;
var anchorY = config.anchorY !== undefined ? config.anchorY : 1;
var size = config.size !== undefined ? config.size : TEXT_DEFAULT_SIZE;
var weight = config.weight !== undefined ? config.weight : TEXT_DEFAULT_WEIGHT;
var font = config.font !== undefined ? config.font : TEXT_DEFAULT_FONT;
var textFill = config.fill !== undefined ? config.fill : TEXT_DEFAULT_FILL;
var borderFill = config.border !== undefined ? config.border : TEXT_DEFAULT_BORDER;
var textAssets = [];
var mainAsset;
;
self.setText = setText;
self.setFill = setFill;
;
function setText(newText) {
for (var i = 0; i < textAssets.length; i++) {
textAssets[i].setText(newText);
}
}
function setFill(newFill) {
textFill = newFill;
mainAsset.fill = newFill;
}
function buildTextAssets(newText) {
for (var i = 0; i < TEXT_OFFSETS.length; i++) {
var main = i === TEXT_OFFSETS.length - 1;
var fill = main ? textFill : borderFill;
var textAsset = textAssets[i];
if (textAsset) {
textAsset.destroy();
}
textAsset = self.addChild(new Text2(newText, {
fill: fill,
font: font,
size: size
}));
textAsset.anchor = {
x: anchorX,
y: anchorY
}; // NOTE: Cannot be set in config
textAsset.x = TEXT_OFFSETS[i][0] * weight; // NOTE: Cannot be set in config
textAsset.y = TEXT_OFFSETS[i][1] * weight; // NOTE: Cannot be set in config
textAssets[i] = textAsset;
}
mainAsset = textAssets[TEXT_OFFSETS.length - 1];
}
;
buildTextAssets(text);
return self;
});
/****
* 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;
;
// Math Constants / Pre-calculations
var MATH_4_PI = Math.PI * 4;
var MATH_2_PI = Math.PI * 2;
var MATH_HALF_PI = Math.PI / 2;
var MATH_HALF_ROOT_3 = Math.sqrt(3) / 2; // Required by: TEXT_OFFSETS, BorderedText, BorderedSymbol, BorderedShape, SymbolText
;
// Text Settings
var TEXT_OFFSETS = [[0, 1], [MATH_HALF_ROOT_3, 0.5], [MATH_HALF_ROOT_3, -0.5], [0, -1], [-MATH_HALF_ROOT_3, -0.5], [-MATH_HALF_ROOT_3, 0.5], [0, 0]]; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText
var TEXT_DEFAULT_WEIGHT = 4; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText
var TEXT_DEFAULT_BORDER = '#000000'; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText
var TEXT_DEFAULT_FILL = '#000000'; // Required by: BorderedText, SymbolText
var TEXT_DEFAULT_FONT = 'Courier'; // Required by: BorderedText, SymbolText
var TEXT_DEFAULT_SIZE = 100; // Required by: BorderedText, SymbolText
;
// 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 - 500;
var FIREWALL_SOUND_COUNT = 4;
var FIREWALL_SOUND_DIVDIST = 1000;
;
// Lilypad Settings
var LILYPAD_ANGLE = 10 * Math.PI / 180;
var LILYPAD_HEIGHT_FACTOR = 1.025;
var LILYPAD_STALK_OFFSET = -5;
var LILYPAD_PICKUP_CHANCE = 0.5;
var LILYPAD_PICKUP_OFFSET_MIN = 50;
var LILYPAD_PICKUP_OFFSET_VAR = 100;
;
// Hook Settings
var HOOK_OFFLINE = 1 * GAME_TICKS;
var HOOK_SPAWN_MARGIN = 3000;
var HOOK_SPAWN_X_MIN = 100;
var HOOK_SPAWN_X_VAR = 1000;
var HOOK_SPAWN_Y_MIN = 600;
var HOOK_SPAWN_Y_VAR = 1000;
var HOOK_DOUBLE_CHANCE = 0.1;
;
// Player Settings
var PLAYER_START_X = -400;
var PLAYER_START_Y = -1300;
var PLAYER_GRAVITY = 0.5;
var PLAYER_SPIN_MAGNITUDE = -2.0;
var PLAYER_ANGULAR_DAMPENING = 0.9995;
var PLAYER_TONGUE_RANGE = 650;
var PLAYER_ATTACH_MULTIPLIER = 1.1;
var PLAYER_RELEASE_MULTIPLIER = 1.1;
var PLAYER_RELEASE_VY_BONUS = 2;
var PLAYER_BOUNCE_FACTOR = -1.1;
var PLAYER_SCREEN_MARGIN = 1.25;
;
// Background Settings
var MOON_SCALING = 0.25;
var FOREGROUND_COVERAGE = 6 * GAME_WIDTH;
var FOREGROUND_OFFSET_X = 200;
var FOREGROUND_SCALE = 1.0;
var FOREGROUND_MOVEMENT = 25;
var SHADOWGROUND_OFFSET_X = -50;
var SHADOWGROUND_OFFSET_Y = -200;
var SHADOWGROUND_SCALE = 0.65;
var SHADOWGROUND_MOVEMENT = 3;
;
// Scoring Settings
var SCORE_PER_DISTANCE = 0.01;
var SCORE_PICKUP_MULTIPLER = 0.1;
;
//==============================================================================
// Game Instances & Variables
//==============================================================================
;
var paused = true;
var gameOver = false;
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 - 400
}));
var gameInterface = game.addChild(new Interface({
x: moon.x,
y: moon.y
}));
var camera = game.addChild(new Camera({
x: GAME_WIDTH / 2,
y: GAME_HEIGHT
}));
// Camera containers
var foregroundContainer = camera.addChild(new Container());
var hookContainer = camera.addChild(new Container());
var lillypadContainer = camera.addChild(new Container());
var pickupContainer = camera.addChild(new Container());
var forefrontContainer = camera.addChild(new Container());
// Foreground instances
var shadowground = foregroundContainer.addChild(new Foreground({
x: PLAYER_START_X + SHADOWGROUND_OFFSET_X,
y: SHADOWGROUND_OFFSET_Y,
tint: 0x111111,
coverage: FOREGROUND_COVERAGE,
scale: SHADOWGROUND_SCALE
}));
var foreground = foregroundContainer.addChild(new Foreground({
x: PLAYER_START_X + FOREGROUND_OFFSET_X,
tint: 0x808080,
coverage: FOREGROUND_COVERAGE,
scale: FOREGROUND_SCALE
}));
// Camera instances
var defaultPad = lillypadContainer.addChild(new Lilypad({
x: PLAYER_START_X,
y: PLAYER_START_Y,
active: false,
inert: true
}));
var frog = forefrontContainer.addChild(new Frog({
rotation: MATH_HALF_PI,
x: PLAYER_START_X,
y: PLAYER_START_Y
}));
var firewall = forefrontContainer.addChild(new Firewall({
x: FIREWALL_START_X,
columns: 10
}));
var targetHook = hookContainer.addChild(new Hook({
x: defaultPad.x + 400,
y: defaultPad.y + 200,
inert: true
}));
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,
inert: true
}));
;
//==============================================================================
// Global events
//==============================================================================
;
game.up = frog.release;
game.down = function () {
frog.attach(targetHook);
if (paused) {
paused = false;
defaultPad.launch();
}
};
game.update = function () {
if (gameOver) {
gameInterface.finalize();
LK.showGameOver();
// Find the closest hook to the frog within PLAYER_TONGUE_RANGE
var closestHook = undefined;
var minDistanceSq = PLAYER_TONGUE_RANGE * PLAYER_TONGUE_RANGE;
for (var i = 0; i < hookContainer.children.length; i++) {
var hook = hookContainer.children[i];
var dx = hook.x - frog.x;
var dy = hook.y - frog.y;
var distanceSq = dx * dx + dy * dy;
if (distanceSq < minDistanceSq) {
minDistanceSq = distanceSq;
closestHook = hook;
}
}
targetHook = closestHook;
}
;
// Dynamically loop the fire crackling effect based on distance
if (LK.ticks % (GAME_TICKS * 1) === 0) {
var distance = frog.x - firewall.x;
var volume = Math.pow(1 + distance / FIREWALL_SOUND_DIVDIST, -1);
var index = Math.floor(volume * 5);
if (index) {
LK.getSound('fireCrackling' + index).play();
}
}
// Loop the background music
if (LK.ticks % (GAME_TICKS * 10) === 0) {
LK.getSound('backgroundAmbient').play();
}
// Game over conditions
if (frog.y > 0 || frog.x < firewall.x) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('frogDeath').play();
gameOver = true;
}
};
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