Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (22 edits merged)
Please save this source code
User prompt
Add a label to platforms at the top center
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (15 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'np.y')' in or related to this line: 'var npTargetY = np.y;' Line Number: 112
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Can't find variable: right' in or related to this line: 'var debugLabel = new Text2('Volume: 0\n Pitch: 0', {' Line Number: 279
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.setHeight is not a function. (In 'self.setHeight(currentBridge.height - (currentBridge.height - targetHeight) / 10)', 'self.setHeight' is undefined)' in or related to this line: 'self.setHeight(currentBridge.height - (currentBridge.height - targetHeight) / 10);' Line Number: 156
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Add a debug label to top right corner showing volume and pitch
User prompt
Create a tutorial class for the game.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Add a drop indicator class
Code edit (14 edits merged)
Please save this source code
User prompt
Insert Thumb sound @ //Insert "thump" sound here.
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var facekit = LK.import("@upit/facekit.v1"); var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Bridge class to represent the bridge being built var Bridge = Container.expand(function () { var self = Container.call(this); var bridgeGraphicsBG = self.attachAsset('bridge', { anchorX: .5, anchorY: 1 }); bridgeGraphicsBG.tint = 0x949494; var bridgeGraphics = self.attachAsset('bridge', { anchorX: .5, anchorY: 1, scaleY: 0 }); var bridgeShadow = shadowContainer.attachAsset('shadow', { anchorX: .5, anchorY: 1 }); self.setHeight = function (height) { self.height = height; bridgeShadow.width = self.width + 40; bridgeShadow.height = self.height + 40; }; self.update = function () { bridgeShadow.rotation = self.rotation; bridgeShadow.x = self.x - Math.sin(bridgeShadow.rotation) * 20; bridgeShadow.y = self.y + Math.cos(bridgeShadow.rotation) * 20; }; self.remove = function () { bridgeShadow.destroy(); self.destroy(); }; self.setProgress = function (progress) { bridgeGraphics.scale.y = progress; }; // Method to update the bridge's width based on voice pitch }); // Character class to represent the character in the game var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 1 }); characterGraphics.rotation = .02; self.currentPlatform = undefined; self.state = 'walking'; var mouseIsDown = false; game.down = function () { mouseIsDown = true; }; function dropBridge() { if (self.state == 'bridge') { self.state = 'dropping'; if (isFirst) { isFirst = false; tutorial.hide(); } var nextPlatform = platforms[currentPlatformOffset + 1]; var platformGap = nextPlatform.x - self.currentPlatform.x - self.currentPlatform.width + 26; var platformOffset = currentBridge.height - platformGap; if (platformOffset < 0) { //die due to short bridge tween(currentBridge, { rotation: Math.PI }, { duration: 1000, easing: tween.bounceOut }); LK.setTimeout(function () { self.state = 'dieshort'; }, 550); LK.setTimeout(function () { LK.getSound('thump').play(); }, 200); return; } else if (platformOffset > nextPlatform.width) { //die due to large bridge LK.setTimeout(function () { self.state = 'dielong'; }, 550); } else { //you survive ticksToDrop -= 2; LK.setTimeout(function () { currentPlatformOffset++; self.currentPlatform = nextPlatform; self.state = 'walking'; }, 520); if (!nextPlatform.finish) { var nwidth = 20; //100 + Math.random() * 50; var _short = platforms.length % 2 == 0; var targetPitch = pitches[currentPlatformOffset]; var np = addPlatform(platforms[platforms.length - 1].x + platforms[platforms.length - 1].realWidth + targetPitch - nwidth / 2 + 25, nwidth); var npTargetY = np.y; np.y = 3500; tween(np, { y: npTargetY }, { duration: 500, easing: tween.easeOut }); } } tween(currentBridge, { rotation: Math.PI / 2 }, { duration: 500, easing: tween.bounceOut }); LK.setTimeout(function () { LK.getSound('thump').play(); }, 50); //currentBridge.height = platformGap + nextPlatform.width; } } game.up = function () { if (mouseIsDown) { // dropBridge(); } mouseIsDown = false; }; var ticksToDrop = 80; var curentTicksToDrop = 0; var isFirst = true; self.update = function () { switch (self.state) { case 'walking': { var targetX = self.currentPlatform.x + self.currentPlatform.width - self.width / 2 - 15; self.x += 25; if (self.x >= targetX) { if (self.currentPlatform.finish) { LK.showYouWin(); self.state = "won"; return; } self.x = targetX; self.state = 'bridge'; addNewBridge(self.x + self.width / 2 - 10); curentTicksToDrop = 0; } break; } case 'bridge': { var targetHeight = Math.max(facekit.pitch * 2, 50); var newHeight = currentBridge.height - (currentBridge.height - targetHeight) / 10; if (facekit.volume > .1 && facekit.pitch < 1000) { currentBridge.setHeight(newHeight); debugLabel.setText("Volume: ".concat(facekit.volume.toFixed(2), "\nPitch: ").concat(facekit.pitch.toFixed(2))); } /*if (mouseIsDown) { currentBridge.height += 15; }*/ if (!isFirst || Math.abs(facekit.pitch - pitches[0] / 2) < 50) { curentTicksToDrop++; currentBridge.setProgress(curentTicksToDrop / ticksToDrop); } if (curentTicksToDrop >= ticksToDrop) { currentBridge.setHeight(pitches[currentPlatformOffset]); dropBridge(); } break; } case 'dielong': case 'dieshort': { self.x += 20; var targetX = self.currentPlatform.x + self.currentPlatform.width + self.width / 2 + 50; if (self.state == 'dielong') { targetX = self.currentPlatform.x + self.currentPlatform.width + currentBridge.height + self.width / 2 + 50; } if (self.x > targetX) { self.state = 'died'; tween(self, { x: self.x + 150, y: 3500 }, { duration: 500, easing: tween.easeIn }); LK.setTimeout(function () { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); }, 500); } break; } } var targetX = -character.x + 400 - container.x; if (targetX <= 0) { container.x += targetX / 15; shadowContainer.x = container.x; } }; }); // Platform class to represent the platform in the game var Platform = Container.expand(function (width, finish, x, y, name) { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0, anchorY: 0 }); // Add a label to the platform at the top center var platformLabel = new Text2(name, { size: 60, weight: 800, fill: 0x000000, align: 'center' }); platformLabel.anchor.set(0.5, 0); // Center the label horizontally at the top platformLabel.x = width / 2; // Position label at the center of the platform platformLabel.y = 20; // Slightly above the platform self.addChild(platformLabel); var platformShadow = shadowContainer.attachAsset('shadow', { anchorX: 0, anchorY: 0 }); self.finish = finish; if (finish) { var trophy = shadowContainer.attachAsset('trophy', { anchorX: .5, anchorY: 1, x: x + width / 2, y: y - 10 }); trophy.alpha = 0; trophy.scale.set(0, 0); tween(trophy, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 100, delay: 500 }); } platformGraphics.height = 500; platformGraphics.width = width; platformShadow.width = width + 40; platformShadow.height = platformGraphics.height + 40; self.realWidth = width; this.update = function () { platformShadow.x = self.x - 20; platformShadow.y = self.y - 20; }; this.remove = function () { platformShadow.destroy(); self.destroy(); }; }); // Tutorial class to represent the tutorial in the game var Tutorial = Container.expand(function () { var self = Container.call(this); var dashContainer = self.addChild(new Container()); var dashes = []; for (var a = 0; a < 21; a++) { var shadow = dashContainer.attachAsset('shadow', { anchorX: 0.5, anchorY: 0.5, x: -2048 / 2 + a * ((2048 - 100) / 20) + 50, width: 50 + 30, height: 10 + 30 }); var dash = dashContainer.attachAsset('dash', { anchorX: 0.5, anchorY: 0.5, x: -2048 / 2 + a * ((2048 - 100) / 20) + 50 }); dashes.push(dash); } dashContainer.y = 780; var tutorialGraphics = self.attachAsset('mic', { anchorX: 0.5, anchorY: 0.5, y: -100 }); var tutorialGraphics = self.attachAsset('tutorial', { anchorX: 0.5, anchorY: 0.5, y: 300 }); self.hide = function () { tween(self, { y: self.y - 400, alpha: 0 }, { easing: tween.easeIn, duration: 500 }); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Platform class to represent the platform in the game var pitches = [261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 261.63 * 2, 293.66 * 2, 329.63 * 2, 349.23 * 2, 392.00 * 2, 440.00 * 2, 493.88 * 2]; var names = ["Do", "Re", "Mi", "Fa", "Sol", "La", "Ti"]; var tutorial = game.addChild(new Tutorial()); tutorial.x = 2048 / 2; tutorial.y = 2732 / 2; var shadowContainer = game.addChild(new Container()); // Create a debug label to display volume and pitch var debugLabel = new Text2('', { size: 30, weight: 600, fill: 0xFFFFFF, align: 'right' }); debugLabel.alpha = .5; debugLabel.anchor.set(1, 0); // Anchor to the top-right corner LK.gui.topRight.addChild(debugLabel); var container = game.addChild(new Container()); var platforms = []; var bridges = []; function addPlatform(x, width) { var platform = container.addChild(new Platform(width, platforms.length >= pitches.length, x, 2400, names[(platforms.length - 1) % names.length])); platform.y = 2400; platform.x = x; platforms.push(platform); for (var a = 0; a < platforms.length - 4; a++) { if (platforms[a]) { platforms[a].remove(); platforms[a] = undefined; } } return platform; } addPlatform(0, 500); addPlatform(pitches[0] + 500 - 75 + 25, 150); var character = container.addChild(new Character()); var currentPlatformOffset = 0; character.currentPlatform = platforms[currentPlatformOffset]; character.y = 2402 - 5; character.x = -200; var currentBridge; function addNewBridge(x) { currentBridge = container.addChildAt(new Bridge(), 0); currentBridge.scale.set(0, 0); tween(currentBridge, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeIn }); currentBridge.y = 2400 + 25; currentBridge.x = x; bridges.push(currentBridge); for (var a = 0; a < bridges.length - 4; a++) { if (bridges[a]) { bridges[a].remove(); bridges[a] = undefined; } } }
===================================================================
--- original.js
+++ change.js
@@ -88,18 +88,19 @@
self.state = 'dielong';
}, 550);
} else {
//you survive
+ ticksToDrop -= 2;
LK.setTimeout(function () {
currentPlatformOffset++;
self.currentPlatform = nextPlatform;
self.state = 'walking';
}, 520);
if (!nextPlatform.finish) {
- var nwidth = 100 + Math.random() * 50;
+ var nwidth = 20; //100 + Math.random() * 50;
var _short = platforms.length % 2 == 0;
- var targetPitch = pitches[platforms.length - 1];
- var np = addPlatform(platforms[platforms.length - 1].x + platforms[platforms.length - 1].width + 50 - nwidth / 2 + targetPitch, nwidth);
+ var targetPitch = pitches[currentPlatformOffset];
+ var np = addPlatform(platforms[platforms.length - 1].x + platforms[platforms.length - 1].realWidth + targetPitch - nwidth / 2 + 25, nwidth);
var npTargetY = np.y;
np.y = 3500;
tween(np, {
y: npTargetY
@@ -134,9 +135,9 @@
switch (self.state) {
case 'walking':
{
var targetX = self.currentPlatform.x + self.currentPlatform.width - self.width / 2 - 15;
- self.x += 20;
+ self.x += 25;
if (self.x >= targetX) {
if (self.currentPlatform.finish) {
LK.showYouWin();
self.state = "won";
@@ -164,8 +165,9 @@
curentTicksToDrop++;
currentBridge.setProgress(curentTicksToDrop / ticksToDrop);
}
if (curentTicksToDrop >= ticksToDrop) {
+ currentBridge.setHeight(pitches[currentPlatformOffset]);
dropBridge();
}
break;
}
@@ -209,16 +211,16 @@
anchorY: 0
});
// Add a label to the platform at the top center
var platformLabel = new Text2(name, {
- size: 40,
+ size: 60,
weight: 800,
fill: 0x000000,
align: 'center'
});
platformLabel.anchor.set(0.5, 0); // Center the label horizontally at the top
platformLabel.x = width / 2; // Position label at the center of the platform
- platformLabel.y = 0; // Slightly above the platform
+ platformLabel.y = 20; // Slightly above the platform
self.addChild(platformLabel);
var platformShadow = shadowContainer.attachAsset('shadow', {
anchorX: 0,
anchorY: 0
@@ -245,8 +247,9 @@
platformGraphics.height = 500;
platformGraphics.width = width;
platformShadow.width = width + 40;
platformShadow.height = platformGraphics.height + 40;
+ self.realWidth = width;
this.update = function () {
platformShadow.x = self.x - 20;
platformShadow.y = self.y - 20;
};
@@ -340,9 +343,9 @@
}
return platform;
}
addPlatform(0, 500);
-addPlatform(pitches[0] + 500 - 75, 150);
+addPlatform(pitches[0] + 500 - 75 + 25, 150);
var character = container.addChild(new Character());
var currentPlatformOffset = 0;
character.currentPlatform = platforms[currentPlatformOffset];
character.y = 2402 - 5;
White gameplay character, black outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
White ribbon banner with text "Hit this pitch with your voice". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Fast white up arrow. Simple design. Black background.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows