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").
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: soundFireCrackling is undefined' in or related to this line: 'soundFireCrackling.volume = volume;' Line Number: 438
User prompt
Please fix the bug: 'ReferenceError: volume is not defined' in or related to this line: 'soundFireCrackling.volume = volume;' Line Number: 438
Code edit (1 edits merged)
Please save this source code
User prompt
Add a slightly transparent black tinted shapeBox to the firewall. It should have a width of 2 * GAME_WIDTH, a height of 2 * GAME_HEIGHT and an anchor of 1,1
Code edit (2 edits merged)
Please save this source code
User prompt
In the game.update function add an empty if statement, checking if the tick counter is at 10s
Code edit (2 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: 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
});
console.log({
x: foregroundRight.x,
anchorX: foregroundRight.anchor.x,
scaleX: foregroundRight.scale.x
});
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 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);
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 / 2;
shadowground.x += x / 3;
frog.x += x;
frog.y += y;
};
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);
};
});
/****
* 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 = -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;
;
// Other Settings
var MOON_SCALING = 0.25;
var FOREGROUND_COVERAGE = 6 * GAME_WIDTH;
var FOREGROUND_SCALE = 1.0;
var SHADOWGROUND_SCALE = 0.65;
var SHADOWGROUND_OFFSET = 200;
;
//==============================================================================
// 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
}));
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,
y: -SHADOWGROUND_OFFSET,
tint: 0x111111,
coverage: FOREGROUND_COVERAGE,
scale: SHADOWGROUND_SCALE
}));
var foreground = foregroundContainer.addChild(new Foreground({
x: PLAYER_START_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());
var backgroundAmbientTimer = LK.setInterval(function () {
LK.getSound('backgroundAmbient').play();
}, 10000);
// 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);
if (paused) {
paused = false;
defaultPad.destroy();
}
};
game.update = function () {
if (gameOver) {
LK.showGameOver();
LK.clearInterval(backgroundAmbientTimer);
}
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