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 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)) { self.destroy(); gameInterface.increaseMultiplier(); } }; return self; }); var Lilypad = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); config = config || {}; var destroying = false; var active = config.active !== undefined ? config.active : true; 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 }); ; 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 () { score = Math.round(score); LK.saveScore(score); }; self.updateScore = function (newScore) { score = newScore; scoreText.setText(score); }; self.increaseMultiplier = function () { self.updateMultiplier(multiplier + 0.1); }; 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; 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); }; }); /** * 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; ; // 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; ; //============================================================================== // 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 })); pickupContainer.addChild(new Pickup({ x: Math.random() * GAME_WIDTH, y: Math.random() * GAME_HEIGHT })); ; //============================================================================== // 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(); } // 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; } };
===================================================================
--- original.js
+++ change.js
@@ -33,10 +33,9 @@
});
self.update = function () {
if (collectable.intersects(frog)) {
self.destroy();
- var currentMultiplier = parseFloat(gameInterface.multiplierText.text);
- gameInterface.updateMultiplier(currentMultiplier + 0.1);
+ gameInterface.increaseMultiplier();
}
};
return self;
});
@@ -80,8 +79,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
@@ -91,14 +92,23 @@
anchorX: 0.5,
anchorY: 0.5
}));
;
- self.updateScore = function (score) {
+ self.finalize = function () {
+ score = Math.round(score);
+ LK.saveScore(score);
+ };
+ self.updateScore = function (newScore) {
+ score = newScore;
scoreText.setText(score);
};
- self.updateMultiplier = function (multiplier) {
- multiplierText.setText(multiplier.toFixed(1) + 'x');
+ self.increaseMultiplier = function () {
+ self.updateMultiplier(multiplier + 0.1);
};
+ self.updateMultiplier = function (newMultiplier) {
+ multiplier = newMultiplier;
+ multiplierText.setText(newMultiplier.toFixed(1) + 'x');
+ };
;
return self;
});
var Hook = ConfigContainer.expand(function (config) {
@@ -561,16 +571,13 @@
frog.attach(targetHook);
if (paused) {
paused = false;
defaultPad.launch();
- // Example of updating score and multiplier
- // gameInterface.updateScore(LK.getScore());
- // gameInterface.updateMultiplier(1.0); // Replace with actual multiplier logic
}
- ;
};
game.update = function () {
if (gameOver) {
+ gameInterface.finalize();
LK.showGameOver();
}
// Dynamically loop the fire crackling effect based on distance
if (LK.ticks % (GAME_TICKS * 1) === 0) {
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