Code edit (2 edits merged)
Please save this source code
User prompt
Let's decrease the Opacity of the dynamite image and make it 80% opaque.
Code edit (1 edits merged)
Please save this source code
User prompt
Let's increase the size of the dynamite image by three times.
User prompt
the dynamite image should show up behind the stopwatch image but at 500 pixels wide
User prompt
Let's create a new shape called dynamite.
User prompt
Let's create a new graphic that will be placed behind the stopwatch graphic.
User prompt
The player should not receive a point towards their score when they get a hit. They should get a point for every second remaining.
User prompt
For the game over screen, let's show the remaining time.
User prompt
Let's lower the remaining time by 300 pixels.
User prompt
When the player wins, let's show the remaining time in the top of the screen.
User prompt
Let's change the color of the stopwatch shape to red.
User prompt
Let's use the diffuse line shape for the diffuse progress bar.
User prompt
Let's create a new shape that we'll use for the diffuse progress bar. Let's call it diffuse line.
User prompt
The progress bar for diffuse and the progress bar for the timer need to be two separate colors.
User prompt
When the player wins the game, play the sound called win.
User prompt
When the player loses the game, play the sound called Lose.
User prompt
Let's create another sound called exact.
User prompt
Delay the game from ending by two seconds.
User prompt
When the screen flashes green or yellow, play the sound called hit.
User prompt
When the screen flashes red, play the sound called, Miss.
User prompt
Do you know why the hit sound is not playing?
User prompt
Okay, let's take a different approach for the hit sound. Let's play the hit sound every time the screen lights up green.
User prompt
I'm still not hearing it
User prompt
I'm not hearing the hit sound when I hit the target correctly.
/****
* Initialize Game
****/
// No assets are needed for this game
// No classes are needed for this game
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize sound assets
// Initialize variables
var winTxt = null;
var loseTxt = null;
var startTime = null;
var elapsedTime = 0;
var timerTxt = null;
var gameStarted = false;
var progressBar = null;
var progressBarWidth = 2048; // Full width of the screen
var progressBarHeight = 50; // Height of the progress bar
// Add stopwatch image to the game
var stopwatchImage = LK.getAsset('stopwatchImage', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(stopwatchImage);
// Create a progress bar
progressBar = LK.getAsset('stopwatch', {
anchorX: 1.0,
anchorY: 0.0,
x: 2048,
// Start from the right edge
y: 0,
// Top of the screen
width: progressBarWidth,
height: progressBarHeight
});
game.addChild(progressBar);
// Create a defuse bar for points
var defuseBar = LK.getAsset('stopwatch', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
// Start from the left edge
y: 50,
// Just below the top of the screen
width: 0,
// Start with zero width
height: progressBarHeight,
color: 0x00ff00 // Green color for defuse progress
});
game.addChild(defuseBar);
// Create a text object to display the timer
timerTxt = new Text2('0.00', {
size: 150,
fill: "#ffffff",
// Change text color to white
stroke: "#000000",
// Add black stroke
strokeThickness: 10,
// Set stroke thickness to thick
font: "Arial" // Set font to Arial
});
timerTxt.anchor.set(0.5, 0.5);
timerTxt.x = 2048 / 2;
timerTxt.y = 2732 / 2 + 40;
game.addChild(timerTxt);
// Create a text object to display the score
var scoreTxt = new Text2('Defused: 0 of 10', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
startTime = Date.now();
gameStarted = true;
// Check the elapsed time on mouse up
game.down = function (x, y, obj) {
if (gameStarted) {
elapsedTime = 60 - (Date.now() - startTime) / 1000;
timerTxt.setText(elapsedTime.toFixed(2));
if (Math.abs(elapsedTime - Math.round(elapsedTime)) <= 0.01) {
LK.effects.flashScreen(0xffff00, 500); // Flash yellow for exact time
LK.setScore(LK.getScore() + 10); // Increment score by 10
scoreTxt.setText('Fuses: ' + LK.getScore() + ' out of 10'); // Update score display
if (LK.getSound('hit')) {
LK.getSound('hit').play(); // Play hit sound
}
} else if (Math.abs(elapsedTime - Math.round(elapsedTime)) <= 0.1) {
LK.effects.flashScreen(0x00ff00, 500); // Flash green to simulate fireworks
LK.setScore(LK.getScore() + 1); // Increment score
scoreTxt.setText('Fuses: ' + LK.getScore() + ' out of 10'); // Update score display
} else {
startTime -= 5000; // Adjust startTime to deduct five seconds persistently
timerTxt.setText(elapsedTime.toFixed(2)); // Update timer display
LK.effects.flashScreen(0xff0000, 500); // Flash red for negative effect
}
}
};
// Update the timer every game tick
game.update = function () {
if (gameStarted) {
elapsedTime = 60 - (Date.now() - startTime) / 1000;
timerTxt.setText(elapsedTime.toFixed(2));
// Update progress bar width
progressBar.width = progressBarWidth * (1 - elapsedTime / 60);
// Update defuse bar width with 10 segments
defuseBar.width = progressBarWidth * (LK.getScore() / 10);
if (LK.getScore() >= 10) {
// game.setBackgroundColor(0x00ff00); // Removed green background effect
if (!winTxt) {
winTxt = new Text2('You Win!', {
size: 200,
fill: "#ffffff"
});
winTxt.anchor.set(0.5, 0.0);
winTxt.x = 2048 / 2;
winTxt.y = 300; // Position near the top of the screen
game.addChild(winTxt);
}
LK.showGameOver(); // End game
gameStarted = false;
} else if (elapsedTime <= 0) {
if (!loseTxt) {
loseTxt = new Text2('BOOM!', {
size: 200,
fill: "#ffffff"
});
loseTxt.anchor.set(0.5, 0.0);
loseTxt.x = 2048 / 2;
loseTxt.y = 300; // Position near the top of the screen
game.addChild(loseTxt);
}
LK.showGameOver(); // End game
gameStarted = false;
}
}
};
// Initialize stopwatch image asset
cartoon dynamite. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit crowd of police and others cheer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.