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
Code edit (8 edits merged)
Please save this source code
User prompt
When a pickup is destroyed, play the pickupCaught sound
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
In the interface's finalize function, round the score variable and save it using the LK engine
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: pickupContainer is undefined' in or related to this line: 'var pickup = pickupContainer.addChild(new Pickup({' Line Number: 439
User prompt
Add a pickup class, inheriting from ConfigContainer. It has the collectable asset with a random rotation, and an update function that checks for a collision with the frog instance, if so, it is destroyed and the interface score multiplier increased by 0.1
Code edit (6 edits merged)
Please save this source code
User prompt
Play the frogBounce sound in the lilypad's launch function
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: velocityY is not defined' in or related to this line: 'velocityY = -Math.abs(velocityY); // Example: reverse the Y velocity' Line Number: 53
User prompt
add an update statement to the lilypad class that checks for a collision with the frog instance and calls a new bounce function on the frog
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
change the interface text colours to black
Code edit (8 edits merged)
Please save this source code
User prompt
Instead of adding the gameInterface to the game, add it to the middle GUI element
User prompt
Add an Interface class that contains a score (displaying only the score value) and a multiplier below (displayed as the numerical rounded to 1 decimal place, and an "x", eg: "1.0x").
/****
* 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: 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.PI / 2) * PLAYER_RELEASE_MULTIPLIER;
velocityY = angularVelocity * hookLength * Math.sin(velocityAngle + Math.PI / 2) * PLAYER_RELEASE_MULTIPLIER - PLAYER_RELEASE_VY_BONUS;
hookLength = 0;
}
};
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.PI / 2);
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;
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) {
// TODO: Send update to the scoring interface
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);
};
});
var Interface = Container.expand(function () {
var self = Container.call(this);
// Score Text
var scoreText = new Text2('0', {
size: 100,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
scoreText.x = GAME_WIDTH / 2;
scoreText.y = 50;
self.addChild(scoreText);
// Multiplier Text
var multiplierText = new Text2('1.0x', {
size: 50,
fill: "#ffffff"
});
multiplierText.anchor.set(0.5, 0);
multiplierText.x = GAME_WIDTH / 2;
multiplierText.y = 150;
self.addChild(multiplierText);
// Update score
self.updateScore = function (score) {
scoreText.setText(score);
};
// Update multiplier
self.updateMultiplier = function (multiplier) {
multiplierText.setText(multiplier.toFixed(1) + 'x');
};
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;
;
// 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;
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;
;
// 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_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;
;
//==============================================================================
// 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 - 200
}));
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
}));
var frog = forefrontContainer.addChild(new Frog({
rotation: Math.PI / 2,
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
}));
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
}));
var gameInterface = game.addChild(new Interface());
;
//==============================================================================
// Global events
//==============================================================================
;
game.up = frog.release;
game.down = function () {
frog.attach(targetHook);
if (paused) {
paused = false;
defaultPad.destroy();
// Example of updating score and multiplier
gameInterface.updateScore(LK.getScore());
gameInterface.updateMultiplier(1.0); // Replace with actual multiplier logic
}
;
};
game.update = function () {
if (gameOver) {
LK.showGameOver();
}
// 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