/**** * Classes ****/ var Toy = Container.expand(function () { var self = Container.call(this); var toyGraphics; var toyVariants = ['puppyToy', 'puppyToy2', 'puppyToy3', 'puppyToy4']; var randomToyIndex = Math.floor(Math.random() * toyVariants.length); var fading = false; toyGraphics = self.attachAsset(toyVariants[randomToyIndex], { anchorX: 0.5, anchorY: 0.5 }); self.reset = function () { self.x = Math.random() < 0.5 ? 512 : 2048 - 512; // Left or right side of the screen self.y = 2732 / 1.5 + 32; // Fixed position in the bottom 2/3 of the screen if (!gameStarted) { gameStarted = true; // Set the game as started on the first click } if (clickCount > 3) { var newBug = new Bug(); newBug.reset(self.x); game.addChild(newBug); currentBug = newBug; } }; self.on('down', function () { if (!fading) { self.fadeAway(); } var additionalScore = countdownValue; LK.setScore(LK.getScore() + additionalScore); // Add remaining countdown time to score scoreTxt.setText(LK.getScore()); // Update score display clickCount++; // Increment click count if (clickCount > 5) { instructionTxt.visible = false; } clickCountTxt.setText('Clicks: ' + clickCount); // Update click count display if (clickCount % 5 === 0) { countdownResetValue = Math.max(60, countdownResetValue - 10); // Reduce countdown reset value by 10, not going below 99 } countdownValue = countdownResetValue; // Reset countdown timer to the current reset value countdownTxt.setText(countdownValue.toString()); // Update countdown display if (currentBug) { currentBug.destroy(); // Destroy the bug when the toy is clicked } }); self.fadeAway = function () { fading = true; self.fadeDuration = self.fadeDuration || 50; // Initialize fadeDuration if not set self.fadeDuration *= 0.9; // Make fadeAway duration 10% faster each click var alphaDecrement = 0.1; var interval = 50; // Interval for the fade effect var steps = self.fadeDuration / interval; var alphaStep = alphaDecrement / steps; var fadeInterval = LK.setInterval(function () { toyGraphics.alpha -= alphaStep; if (toyGraphics.alpha <= 0) { LK.clearInterval(fadeInterval); self.destroy(); initializeToy(); // Call the function to add a new toy to the game } }, interval); }; self.reset(); // Initialize toy position }); var Puppy = Container.expand(function () { var self = Container.call(this); var puppyGraphic = self.attachAsset('puppyHappy', { anchorX: 0.5, anchorY: 0.5 }); self.changeGraphic = function () { if (bugClickCount == 2) { game.setBackgroundColor(0x437AA6); puppyGraphic.destroy(); // Destroy the current graphic puppyGraphic = self.attachAsset('puppyCrying', { anchorX: 0.5, anchorY: 0.5 }); } else if (bugClickCount == 1) { game.setBackgroundColor(0x65ACC9); puppyGraphic.destroy(); // Destroy the current graphic puppyGraphic = self.attachAsset('sadPuppy', { anchorX: 0.5, anchorY: 0.5 }); } else { game.setBackgroundColor(0x215884); puppyGraphic.destroy(); // Destroy the current graphic puppyGraphic = self.attachAsset('puppySkeleton', { anchorX: 0.5, anchorY: 0.5 }); LK.showGameOver(); } }; self.x = 2048 / 2; self.y = 2732 / 4; }); var Bug = Container.expand(function () { var self = Container.call(this); var bugGraphics; var bugVariants = ['bug1', 'bug2', 'bug3']; var randomBugIndex = Math.floor(Math.random() * bugVariants.length); var fading = false; bugGraphics = self.attachAsset(bugVariants[randomBugIndex], { anchorX: 0.5, anchorY: 0.5 }); self.reset = function (toyX) { // Spawn on the opposite side of where Toy is spawned self.x = toyX < 1024 ? 2048 - 512 : 512; self.y = 2732 / 1.5 + 32; }; self.on('down', function () { bugClickCount++; // Increment bug click count countdownValue = countdownResetValue; // Reset countdown timer to the current reset value currentToy.fadeAway(); puppy.changeGraphic(); self.destroy(); }); self.reset(); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to represent the sky }); /**** * Game Code ****/ puppy = new Puppy(); game.addChild(puppy); var scoreTxt = new Text2('0', { size: 100, fill: "#ffffff" }); // Countdown timer in the middle of the screen var countdownTxt = new Text2('199', { size: 150, fill: "#ffffff" }); // Click count display text on the top right var clickCountTxt = new Text2('Clicks: 0', { size: 100, fill: "#ffffff" }); clickCountTxt.anchor.set(1, 0.5); clickCountTxt.x = 0; clickCountTxt.y = 50; LK.gui.topRight.addChild(clickCountTxt); countdownTxt.anchor.set(0.5, 0.5); countdownTxt.x = 0; countdownTxt.y = 0; LK.gui.center.addChild(countdownTxt); scoreTxt.anchor.set(0.5, 0.5); scoreTxt.x = 0; scoreTxt.y = 50; LK.gui.top.addChild(scoreTxt); var currentToy = null; // Initialize the first toy function initializeToy() { if (currentToy) { currentToy.destroy(); // Ensure the previous toy is destroyed } currentToy = new Toy(); // Create a new toy instance game.addChild(currentToy); // Add the new toy to the game } initializeToy(); // Call the function to add the first toy to the game var currentBug = null; var gameStarted = false; // Track if the game has been started var countdownResetValue = 199; var countdownValue = countdownResetValue; // Initialize countdown reset value var clickCount = 0; // Initialize click count as a game variable var bugClickCount = 0; // Initialize bug click count as a game variable LK.on('tick', function () { if (gameStarted && countdownValue > 0 && LK.ticks % 1 == 0) { countdownValue--; countdownTxt.setText(countdownValue.toString()); } else if (!gameStarted) { return; // Do not start countdown or change graphics until game has started } else { bugClickCount = 3; puppy.changeGraphic(); LK.showGameOver(); } }); var instructionTxt = new Text2('Click the toy before the timer runs out to keep Puppy happy.\nBut beware of the bugs!', { size: 50, fill: "#ffffff", align: 'center' }); instructionTxt.anchor.set(0.5, 1); instructionTxt.x = 0; instructionTxt.y = -80; LK.gui.bottom.addChild(instructionTxt); // No need for additional event listeners as the toys handle their own 'down' events
/****
* Classes
****/
var Toy = Container.expand(function () {
var self = Container.call(this);
var toyGraphics;
var toyVariants = ['puppyToy', 'puppyToy2', 'puppyToy3', 'puppyToy4'];
var randomToyIndex = Math.floor(Math.random() * toyVariants.length);
var fading = false;
toyGraphics = self.attachAsset(toyVariants[randomToyIndex], {
anchorX: 0.5,
anchorY: 0.5
});
self.reset = function () {
self.x = Math.random() < 0.5 ? 512 : 2048 - 512; // Left or right side of the screen
self.y = 2732 / 1.5 + 32; // Fixed position in the bottom 2/3 of the screen
if (!gameStarted) {
gameStarted = true; // Set the game as started on the first click
}
if (clickCount > 3) {
var newBug = new Bug();
newBug.reset(self.x);
game.addChild(newBug);
currentBug = newBug;
}
};
self.on('down', function () {
if (!fading) {
self.fadeAway();
}
var additionalScore = countdownValue;
LK.setScore(LK.getScore() + additionalScore); // Add remaining countdown time to score
scoreTxt.setText(LK.getScore()); // Update score display
clickCount++; // Increment click count
if (clickCount > 5) {
instructionTxt.visible = false;
}
clickCountTxt.setText('Clicks: ' + clickCount); // Update click count display
if (clickCount % 5 === 0) {
countdownResetValue = Math.max(60, countdownResetValue - 10); // Reduce countdown reset value by 10, not going below 99
}
countdownValue = countdownResetValue; // Reset countdown timer to the current reset value
countdownTxt.setText(countdownValue.toString()); // Update countdown display
if (currentBug) {
currentBug.destroy(); // Destroy the bug when the toy is clicked
}
});
self.fadeAway = function () {
fading = true;
self.fadeDuration = self.fadeDuration || 50; // Initialize fadeDuration if not set
self.fadeDuration *= 0.9; // Make fadeAway duration 10% faster each click
var alphaDecrement = 0.1;
var interval = 50; // Interval for the fade effect
var steps = self.fadeDuration / interval;
var alphaStep = alphaDecrement / steps;
var fadeInterval = LK.setInterval(function () {
toyGraphics.alpha -= alphaStep;
if (toyGraphics.alpha <= 0) {
LK.clearInterval(fadeInterval);
self.destroy();
initializeToy(); // Call the function to add a new toy to the game
}
}, interval);
};
self.reset(); // Initialize toy position
});
var Puppy = Container.expand(function () {
var self = Container.call(this);
var puppyGraphic = self.attachAsset('puppyHappy', {
anchorX: 0.5,
anchorY: 0.5
});
self.changeGraphic = function () {
if (bugClickCount == 2) {
game.setBackgroundColor(0x437AA6);
puppyGraphic.destroy(); // Destroy the current graphic
puppyGraphic = self.attachAsset('puppyCrying', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (bugClickCount == 1) {
game.setBackgroundColor(0x65ACC9);
puppyGraphic.destroy(); // Destroy the current graphic
puppyGraphic = self.attachAsset('sadPuppy', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
game.setBackgroundColor(0x215884);
puppyGraphic.destroy(); // Destroy the current graphic
puppyGraphic = self.attachAsset('puppySkeleton', {
anchorX: 0.5,
anchorY: 0.5
});
LK.showGameOver();
}
};
self.x = 2048 / 2;
self.y = 2732 / 4;
});
var Bug = Container.expand(function () {
var self = Container.call(this);
var bugGraphics;
var bugVariants = ['bug1', 'bug2', 'bug3'];
var randomBugIndex = Math.floor(Math.random() * bugVariants.length);
var fading = false;
bugGraphics = self.attachAsset(bugVariants[randomBugIndex], {
anchorX: 0.5,
anchorY: 0.5
});
self.reset = function (toyX) {
// Spawn on the opposite side of where Toy is spawned
self.x = toyX < 1024 ? 2048 - 512 : 512;
self.y = 2732 / 1.5 + 32;
};
self.on('down', function () {
bugClickCount++; // Increment bug click count
countdownValue = countdownResetValue; // Reset countdown timer to the current reset value
currentToy.fadeAway();
puppy.changeGraphic();
self.destroy();
});
self.reset();
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the sky
});
/****
* Game Code
****/
puppy = new Puppy();
game.addChild(puppy);
var scoreTxt = new Text2('0', {
size: 100,
fill: "#ffffff"
});
// Countdown timer in the middle of the screen
var countdownTxt = new Text2('199', {
size: 150,
fill: "#ffffff"
});
// Click count display text on the top right
var clickCountTxt = new Text2('Clicks: 0', {
size: 100,
fill: "#ffffff"
});
clickCountTxt.anchor.set(1, 0.5);
clickCountTxt.x = 0;
clickCountTxt.y = 50;
LK.gui.topRight.addChild(clickCountTxt);
countdownTxt.anchor.set(0.5, 0.5);
countdownTxt.x = 0;
countdownTxt.y = 0;
LK.gui.center.addChild(countdownTxt);
scoreTxt.anchor.set(0.5, 0.5);
scoreTxt.x = 0;
scoreTxt.y = 50;
LK.gui.top.addChild(scoreTxt);
var currentToy = null;
// Initialize the first toy
function initializeToy() {
if (currentToy) {
currentToy.destroy(); // Ensure the previous toy is destroyed
}
currentToy = new Toy(); // Create a new toy instance
game.addChild(currentToy); // Add the new toy to the game
}
initializeToy(); // Call the function to add the first toy to the game
var currentBug = null;
var gameStarted = false; // Track if the game has been started
var countdownResetValue = 199;
var countdownValue = countdownResetValue; // Initialize countdown reset value
var clickCount = 0; // Initialize click count as a game variable
var bugClickCount = 0; // Initialize bug click count as a game variable
LK.on('tick', function () {
if (gameStarted && countdownValue > 0 && LK.ticks % 1 == 0) {
countdownValue--;
countdownTxt.setText(countdownValue.toString());
} else if (!gameStarted) {
return; // Do not start countdown or change graphics until game has started
} else {
bugClickCount = 3;
puppy.changeGraphic();
LK.showGameOver();
}
});
var instructionTxt = new Text2('Click the toy before the timer runs out to keep Puppy happy.\nBut beware of the bugs!', {
size: 50,
fill: "#ffffff",
align: 'center'
});
instructionTxt.anchor.set(0.5, 1);
instructionTxt.x = 0;
instructionTxt.y = -80;
LK.gui.bottom.addChild(instructionTxt);
// No need for additional event listeners as the toys handle their own 'down' events
A happy golder retriever puppy. tongue hanging out in happiness. sitting down and looking at the viewer.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sad golden retriever puppy. Single Game Texture. In-Game asset. 2d.
a sad crying golden retriever puppy. lying down. face on front paws. looking at viewer.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute looking dog toy shaped like a bone.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute looking dog toy shaped like a bone.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute looking dog toy shaped like a bone.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cartoon bug. evil looking. red and brown color.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cartoon bug. evil looking. dark blue and red color.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cartoon skeleton puppy. lying down. head between paws.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.