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
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
===================================================================
--- original.js
+++ change.js
@@ -6,9 +6,9 @@
* x : Number || 0,
* y : Number || 0,
* rotation : Number || 0,
* }
-**/
+**/
var ConfigContainer = Container.expand(function (config) {
var self = Container.call(this);
config = config || {};
;
@@ -40,21 +40,16 @@
return self;
});
var Interface = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
- var scoreText = self.addChild(new Text2('0', {
- y: -50,
- size: 100,
- fill: "#000000",
- anchorX: 0.5,
- anchorY: 0
+ var scoreText = self.addChild(new BorderedText('0', {
+ y: -100,
+ size: 1.5 * TEXT_DEFAULT_SIZE,
+ anchorX: 0.5
}));
- var multiplierText = self.addChild(new Text2('1.0x', {
- y: 50,
- size: 50,
- fill: "#000000",
- anchorX: 0.5,
- anchorY: 0
+ var multiplierText = self.addChild(new BorderedText('1.0x', {
+ y: 0,
+ anchorX: 0.5
}));
;
self.updateScore = function (score) {
scoreText.setText(score);
@@ -154,18 +149,18 @@
}
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;
+ 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.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);
+ 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;
@@ -285,8 +280,75 @@
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
****/
@@ -307,8 +369,22 @@
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;
@@ -359,10 +435,14 @@
var moon = game.addChild(LK.getAsset('moon', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH / 2,
- y: GAME_HEIGHT / 2 - 200
+ 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
}));
@@ -391,9 +471,9 @@
x: PLAYER_START_X,
y: PLAYER_START_Y
}));
var frog = forefrontContainer.addChild(new Frog({
- rotation: Math.PI / 2,
+ rotation: MATH_HALF_PI,
x: PLAYER_START_X,
y: PLAYER_START_Y
}));
var firewall = forefrontContainer.addChild(new Firewall({
@@ -413,9 +493,8 @@
lillypadContainer.addChild(new Lilypad({
x: PLAYER_START_X + 100,
y: -300
}));
-var gameInterface = moon.addChild(new Interface());
;
//==============================================================================
// Global events
//==============================================================================
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