/****
* Classes
****/
// Create a BlueTarget class to represent the targets that the player has to click
var BlueTarget = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0xff0000 // Set color to red
});
// Set a timeout to destroy the target after 7 seconds
LK.setTimeout(function () {
self.destroy();
}, 7000);
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 1);
};
});
// Create a Button class to represent the button that awards points every 5 clicks
var Button = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the button
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Variable to track the number of clicks
self.clickCount = 0;
// Event listener for when the button is pressed
self.down = function (x, y, obj) {
// Increment the click count
self.clickCount++;
// Toggle point awarding on every second click
if (self.clickCount % 2 === 1) {
// Set a timer to award 5 points every 3 seconds
if (!self.awardPointsInterval) {
self.awardPointsInterval = LK.setInterval(function () {
LK.setScore(LK.getScore() + 5);
}, 3000);
}
} else {
// Clear the interval to stop awarding points
if (self.awardPointsInterval) {
LK.clearInterval(self.awardPointsInterval);
self.awardPointsInterval = null;
}
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Duck class to represent the player character
var Duck = Container.expand(function () {
var self = Container.call(this);
// Attach duck asset
var duckGraphics = self.attachAsset('duckey', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
});
// Method to update duck's position
self.update = function () {
// Duck movement logic can be added here if needed
};
});
// Create a OrangeTarget class to represent the targets that the player has to click
var OrangeTarget = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('orangeTarget', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Set a timeout to destroy the target after 7 seconds
LK.setTimeout(function () {
self.destroy();
}, 7000);
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 5);
};
});
// Create a RedTarget class to represent the targets that the player has to avoid
var RedTarget = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0xff0000 // Set color to red
});
// Set a timeout to destroy the target after 7 seconds
LK.setTimeout(function () {
self.destroy();
}, 7000);
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 1);
};
});
// Create a ShopButton class to represent the shop button
var ShopButton = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the button
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0x0000ff // Set color to blue
});
// Event listener for when the button is pressed
self.down = function (x, y, obj) {
// Open the shop when the button is clicked
openShop();
};
});
// Create a ShopOption class to represent the shop options
var ShopOption = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the shop option
var optionGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0x0000ff // Set color to blue
});
// Event listener for when the shop option is pressed
self.down = function (x, y, obj) {
// Implement the functionality of the shop option when it is clicked
};
});
// Create a Target class to represent the targets that the player has to click
var Target = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Method to update target's state
self.update = function () {
// Target state update logic can be added here if needed
};
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 1);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the pond
});
/****
* Game Code
****/
// Initialize the button and add it to the game
var pointButton = game.addChild(new Button());
// Set initial position of the button to the bottom-right corner of the screen
pointButton.x = 2048 - 100;
pointButton.y = 2732 - 100;
// Variable to track if the shop is open
var shopOpen = false;
// Declare autoPointerOption in the global scope
var autoPointerOption;
// Declare levelOption in the global scope
var levelOption = null;
function openShop() {
// Set shopOpen to true
shopOpen = true;
// Change the background color to green
game.setBackgroundColor(0x008000);
// Create shop options
autoPointerOption = game.addChild(new ShopOption());
autoPointerOption.x = 2048 / 2;
autoPointerOption.y = 2732 / 2 - 200;
var levelOption = game.addChild(new ShopOption());
// Create an exit button for the shop
var exitButton = game.addChild(new ShopOption());
exitButton.x = 2048 / 2;
exitButton.y = 2732 / 2 + 400;
exitButton.down = function (x, y, obj) {
// Close the shop when the exit button is clicked
shopOpen = false;
game.setBackgroundColor(0x87CEEB);
autoPointerOption.destroy();
if (levelOption) {
levelOption.destroy();
}
exitButton.destroy();
// Remove all targets from the game when exiting the shop
game.children.forEach(function (child) {
if (child instanceof BlueTarget || child instanceof OrangeTarget || child instanceof RedTarget) {
child.destroy();
}
});
};
levelOption.x = 2048 / 2;
levelOption.y = 2732 / 2 + 200;
levelOption.down = function (x, y, obj) {
// Implement the functionality of the level
};
}
// Initialize the duck and add it to the game
var duck = game.addChild(new Duck());
// Initialize the shop button and add it to the game
var shopButton = game.addChild(new ShopButton());
// Set initial position of the shop button to the top-right corner of the screen
shopButton.x = 2048 - 50;
shopButton.y = 50;
// Set initial position of the duck to the center of the screen
duck.x = 2048 / 2;
duck.y = 2732 / 2;
// Variable to track the node being dragged
var dragNode = null;
// Function to handle movement of the duck
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
// Event listener for when the game is pressed
game.down = function (x, y, obj) {
// Check if the shop is open
if (shopOpen) {
// Destroy the shop options
autoPointerOption.destroy();
if (levelOption) {
levelOption.destroy();
}
// Close the shop
shopOpen = false;
// Change the background color back to light blue
game.setBackgroundColor(0x87CEEB);
// Remove all targets from the game
game.children.forEach(function (child) {
if (child instanceof BlueTarget || child instanceof OrangeTarget || child instanceof RedTarget) {
child.destroy();
}
});
} else {
// Set the drag node to the duck
dragNode = duck;
// Call move handler immediately
handleMove(x, y, obj);
}
};
// Event listener for when the game is released
game.up = function (x, y, obj) {
dragNode = null;
};
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
// Add the score text to the GUI overlay at the top-center of the screen
LK.gui.top.addChild(scoreTxt);
// Function to spawn points every 7 seconds
function spawnPoints() {
var point = game.addChild(new BlueTarget());
do {
point.x = Math.random() * 2048;
point.y = Math.random() * 2732;
} while (point.x > 1948 && point.x < 2048 && point.y > 2632 && point.y < 2732);
}
// Set an interval to spawn points every 5 seconds
LK.setInterval(spawnPoints, 5000);
// Update function called every game tick
game.update = function () {
// Update the score text
scoreTxt.setText(LK.getScore());
// Spawn a red target every 120 ticks and an orange target every 50 ticks if the shop is not open
if (!shopOpen) {
if (LK.ticks % 240 == 0) {
var redTarget = game.addChild(new RedTarget());
do {
redTarget.x = Math.random() * 2048;
redTarget.y = Math.random() * 2732;
} while (redTarget.x > 800 && redTarget.x < 1248 && redTarget.y > 1132 && redTarget.y < 1600);
}
if (LK.ticks % 4800 == 0) {
var orangeTarget = game.addChild(new OrangeTarget());
do {
orangeTarget.x = Math.random() * 2048;
orangeTarget.y = Math.random() * 2732;
} while (orangeTarget.x > 800 && orangeTarget.x < 1248 && orangeTarget.y > 1132 && orangeTarget.y < 1600);
}
}
}; /****
* Classes
****/
// Create a BlueTarget class to represent the targets that the player has to click
var BlueTarget = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0xff0000 // Set color to red
});
// Set a timeout to destroy the target after 7 seconds
LK.setTimeout(function () {
self.destroy();
}, 7000);
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 1);
};
});
// Create a Button class to represent the button that awards points every 5 clicks
var Button = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the button
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Variable to track the number of clicks
self.clickCount = 0;
// Event listener for when the button is pressed
self.down = function (x, y, obj) {
// Increment the click count
self.clickCount++;
// Toggle point awarding on every second click
if (self.clickCount % 2 === 1) {
// Set a timer to award 5 points every 3 seconds
if (!self.awardPointsInterval) {
self.awardPointsInterval = LK.setInterval(function () {
LK.setScore(LK.getScore() + 5);
}, 3000);
}
} else {
// Clear the interval to stop awarding points
if (self.awardPointsInterval) {
LK.clearInterval(self.awardPointsInterval);
self.awardPointsInterval = null;
}
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Duck class to represent the player character
var Duck = Container.expand(function () {
var self = Container.call(this);
// Attach duck asset
var duckGraphics = self.attachAsset('duckey', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
});
// Method to update duck's position
self.update = function () {
// Duck movement logic can be added here if needed
};
});
// Create a OrangeTarget class to represent the targets that the player has to click
var OrangeTarget = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('orangeTarget', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Set a timeout to destroy the target after 7 seconds
LK.setTimeout(function () {
self.destroy();
}, 7000);
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 5);
};
});
// Create a RedTarget class to represent the targets that the player has to avoid
var RedTarget = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0xff0000 // Set color to red
});
// Set a timeout to destroy the target after 7 seconds
LK.setTimeout(function () {
self.destroy();
}, 7000);
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 1);
};
});
// Create a ShopButton class to represent the shop button
var ShopButton = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the button
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0x0000ff // Set color to blue
});
// Event listener for when the button is pressed
self.down = function (x, y, obj) {
// Open the shop when the button is clicked
openShop();
};
});
// Create a ShopOption class to represent the shop options
var ShopOption = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the shop option
var optionGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4,
color: 0x0000ff // Set color to blue
});
// Event listener for when the shop option is pressed
self.down = function (x, y, obj) {
// Implement the functionality of the shop option when it is clicked
};
});
// Create a Target class to represent the targets that the player has to click
var Target = Container.expand(function () {
var self = Container.call(this);
// Attach a shape asset to represent the target
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Method to update target's state
self.update = function () {
// Target state update logic can be added here if needed
};
// Event listener for when the target is pressed
self.down = function (x, y, obj) {
// Destroy the target when it is clicked
self.destroy();
// Add points when a target is clicked
LK.setScore(LK.getScore() + 1);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the pond
});
/****
* Game Code
****/
// Initialize the button and add it to the game
var pointButton = game.addChild(new Button());
// Set initial position of the button to the bottom-right corner of the screen
pointButton.x = 2048 - 100;
pointButton.y = 2732 - 100;
// Variable to track if the shop is open
var shopOpen = false;
// Declare autoPointerOption in the global scope
var autoPointerOption;
// Declare levelOption in the global scope
var levelOption = null;
function openShop() {
// Set shopOpen to true
shopOpen = true;
// Change the background color to green
game.setBackgroundColor(0x008000);
// Create shop options
autoPointerOption = game.addChild(new ShopOption());
autoPointerOption.x = 2048 / 2;
autoPointerOption.y = 2732 / 2 - 200;
var levelOption = game.addChild(new ShopOption());
// Create an exit button for the shop
var exitButton = game.addChild(new ShopOption());
exitButton.x = 2048 / 2;
exitButton.y = 2732 / 2 + 400;
exitButton.down = function (x, y, obj) {
// Close the shop when the exit button is clicked
shopOpen = false;
game.setBackgroundColor(0x87CEEB);
autoPointerOption.destroy();
if (levelOption) {
levelOption.destroy();
}
exitButton.destroy();
// Remove all targets from the game when exiting the shop
game.children.forEach(function (child) {
if (child instanceof BlueTarget || child instanceof OrangeTarget || child instanceof RedTarget) {
child.destroy();
}
});
};
levelOption.x = 2048 / 2;
levelOption.y = 2732 / 2 + 200;
levelOption.down = function (x, y, obj) {
// Implement the functionality of the level
};
}
// Initialize the duck and add it to the game
var duck = game.addChild(new Duck());
// Initialize the shop button and add it to the game
var shopButton = game.addChild(new ShopButton());
// Set initial position of the shop button to the top-right corner of the screen
shopButton.x = 2048 - 50;
shopButton.y = 50;
// Set initial position of the duck to the center of the screen
duck.x = 2048 / 2;
duck.y = 2732 / 2;
// Variable to track the node being dragged
var dragNode = null;
// Function to handle movement of the duck
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
// Event listener for when the game is pressed
game.down = function (x, y, obj) {
// Check if the shop is open
if (shopOpen) {
// Destroy the shop options
autoPointerOption.destroy();
if (levelOption) {
levelOption.destroy();
}
// Close the shop
shopOpen = false;
// Change the background color back to light blue
game.setBackgroundColor(0x87CEEB);
// Remove all targets from the game
game.children.forEach(function (child) {
if (child instanceof BlueTarget || child instanceof OrangeTarget || child instanceof RedTarget) {
child.destroy();
}
});
} else {
// Set the drag node to the duck
dragNode = duck;
// Call move handler immediately
handleMove(x, y, obj);
}
};
// Event listener for when the game is released
game.up = function (x, y, obj) {
dragNode = null;
};
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
// Add the score text to the GUI overlay at the top-center of the screen
LK.gui.top.addChild(scoreTxt);
// Function to spawn points every 7 seconds
function spawnPoints() {
var point = game.addChild(new BlueTarget());
do {
point.x = Math.random() * 2048;
point.y = Math.random() * 2732;
} while (point.x > 1948 && point.x < 2048 && point.y > 2632 && point.y < 2732);
}
// Set an interval to spawn points every 5 seconds
LK.setInterval(spawnPoints, 5000);
// Update function called every game tick
game.update = function () {
// Update the score text
scoreTxt.setText(LK.getScore());
// Spawn a red target every 120 ticks and an orange target every 50 ticks if the shop is not open
if (!shopOpen) {
if (LK.ticks % 240 == 0) {
var redTarget = game.addChild(new RedTarget());
do {
redTarget.x = Math.random() * 2048;
redTarget.y = Math.random() * 2732;
} while (redTarget.x > 800 && redTarget.x < 1248 && redTarget.y > 1132 && redTarget.y < 1600);
}
if (LK.ticks % 4800 == 0) {
var orangeTarget = game.addChild(new OrangeTarget());
do {
orangeTarget.x = Math.random() * 2048;
orangeTarget.y = Math.random() * 2732;
} while (orangeTarget.x > 800 && orangeTarget.x < 1248 && orangeTarget.y > 1132 && orangeTarget.y < 1600);
}
}
};