Code edit (22 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var countdownInterval = setInterval(function () {' Line Number: 55
User prompt
Add a new countdown class to the game, which goes "Ready" "Set" "Go" to start the game
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
In BonusIndicator update the call to rgbToHsv to correctly calculate the R,g,b values from color
Code edit (6 edits merged)
Please save this source code
User prompt
the hsv calculation on BonusIndicator seems in correct, add a RGB to HSV method in the game code
Code edit (4 edits merged)
Please save this source code
User prompt
Update outlineColor in BonusIndicator such that it's a 180degrees rotated HSV color from the color parsed to BonusIndicator
Code edit (2 edits merged)
Please save this source code
User prompt
In bonus indicator add white drop shadow to scoreLabel
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Add drop shadow to scoreLabel
Code edit (7 edits merged)
Please save this source code
User prompt
Add white stroke outline to BonusIndicator label
User prompt
in BonusIndicator, use color for the color of the text. Note you have to convert from int color to string color with the format #xxxxx
Code edit (3 edits merged)
Please save this source code
User prompt
Add a label to OverhangPlate which shows the value of score.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Insert place sound at //Play sound here
Code edit (1 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
===================================================================
--- original.js
+++ change.js
@@ -4,13 +4,9 @@
var BonusIndicator = Container.expand(function (score, color) {
var self = Container.call(this);
color = Math.round(color);
var hsv = rgbToHsv(color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF);
- hsv[0] = hsv[0] + .6;
- if (hsv[0] > 1) {
- hsv[0] -= 1;
- }
- var outlineColor = hsvToRgb(hsv[0], hsv[1], hsv[2] / 3);
+ var outlineColor = hsv[0] > .08 && hsv[0] < .55 ? 0x0 : 0xffffff;
var scoreLabel = new Text2(score.toString(), {
size: 150,
fill: '#' + color.toString(16).padStart(6, '0'),
font: 'Impact',
@@ -18,9 +14,9 @@
strokeThickness: 15
});
scoreLabel.anchor.set(.5, 0);
self.addChild(scoreLabel);
- self.speedX = Math.random() * 10 - 5;
+ self.speedX = Math.random() * 16 - 8;
self.speedY = -20;
self.rotationSpeed = self.speedX > 0 ? 0.01 : -0.01;
self._move_migrated = function () {
self.x += self.speedX;
@@ -32,8 +28,32 @@
self.destroy();
}
};
});
+var Countdown = Container.expand(function () {
+ var self = Container.call(this);
+ var countdownLabel = new Text2('', {
+ size: 150,
+ fill: '#ffffff',
+ font: 'Impact'
+ });
+ countdownLabel.anchor.set(.5, .5);
+ self.addChild(countdownLabel);
+ self.x = 2048 / 2;
+ self.y = 2732 / 2;
+ self.countdown = function () {
+ var countdownTexts = ['Ready', 'Set', 'Go'];
+ var index = 0;
+ var countdownInterval = setInterval(function () {
+ countdownLabel.setText(countdownTexts[index]);
+ index++;
+ if (index >= countdownTexts.length) {
+ clearInterval(countdownInterval);
+ self.destroy();
+ }
+ }, 1000);
+ };
+});
var OverhangPlate = Container.expand(function (width, direction, color) {
var self = Container.call(this);
var plateGraphics = self.attachAsset('plate', {
anchorX: 0.5,
@@ -95,9 +115,9 @@
var v = 1;
self.color = hsvToRgb(h, s, v);
plateGraphics.tint = self.color;
self.colorIndex = (self.colorIndex + 1) % 32;
- var bgColor = self.hsvToRgb(h, s, v / 3);
+ var bgColor = self.hsvToRgb(h, s, v / 4);
game.setBackgroundColor(bgColor);
};
self.updateColor();
self.speed = 22.5;
@@ -209,16 +229,18 @@
plates.push(newPlate);
plateContainer.addChild(newPlate);
var bonusCount = 1;
game.on('down', function (x, y, obj) {
+ if (!gameStarted || countdown.parent) {
+ return;
+ }
var topPlate = plates[plates.length - 2];
if (newPlate.x < topPlate.x + topPlate.width && newPlate.x + newPlate.width > topPlate.x) {
var overhang = newPlate.x + newPlate.width / 2 - (topPlate.x + topPlate.width / 2);
var overhangSide = overhang > 0 ? 'right' : 'left';
overhang = Math.abs(overhang);
- console.log(overhang);
newPlate.stack();
- if (overhang > 50) {
+ if (overhang > 21) {
bonusCount = 1;
LK.getSound('place').play();
currentPlateWidth -= overhang;
var overhangPlate = new OverhangPlate(overhang, overhangSide, newPlate.color);
@@ -241,9 +263,9 @@
plateColorIndex++;
nextPlate.colorIndex = plateColorIndex;
nextPlate.updateColor();
plates.push(nextPlate);
- if (overhang <= 50) {
+ if (overhang <= 21) {
newPlate.x = topPlate.x;
LK.getSound('perfect').play();
bonusCount++;
var bonusIndicator = new BonusIndicator('+' + bonusCount, newPlate.color);
@@ -259,11 +281,19 @@
LK.setScore(newScore);
newPlate = nextPlate;
} else {
LK.showGameOver();
+ LK.getSound('gameover').play();
}
});
+var countdown = new Countdown();
+game.addChild(countdown);
+countdown.countdown();
+var gameStarted = false;
LK.on('tick', function () {
+ if (!gameStarted) {
+ return;
+ }
for (var i = 0; i < plateContainer.children.length; i++) {
var plate = plateContainer.children[i];
plate._move_migrated();
if (plate instanceof OverhangPlate && (plate.x < -plate.width / 2 || plate.x > 2048 + plate.width / 2 || plate.y > 2732 + plate.height / 2)) {
@@ -274,9 +304,8 @@
}
var topPlate = plates[plates.length - 2];
if (newPlate.x < topPlate.x + topPlate.width && !newPlate.hasOverlapped) {
LK.getSound('slide').play();
- console.log("now");
newPlate.hasOverlapped = true;
}
}
if (plateContainer.y !== plateContainer.targetY) {