/**** * Classes ****/ // Coin class representing the collectible items var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Hero class representing the player character var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Hero movement logic self.x += self.speed; if (self.x > 2048) { self.x = 0; // Wrap around } }; }); // Obstacle class for parkour elements var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Obstacle logic }; }); // Spider class representing the enemy var Spider = Container.expand(function () { var self = Container.call(this); var spiderGraphics = self.attachAsset('spider', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { // Spider movement logic self.y += self.speed; if (self.y > 2732) { self.y = 0; // Wrap around } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x008000 // Init game with a green background }); /**** * Game Code ****/ var mazeBackground = game.attachAsset('mazeBackground', { anchorX: 0.0, anchorY: 0.0, x: 0, y: 0 }); // Initialize hero var hero = game.addChild(new Hero()); hero.x = 100; hero.y = 1366; // Centered vertically // Initialize spiders var spiders = []; for (var i = 0; i < 5; i++) { var spider = new Spider(); spider.x = Math.random() * 2048; spider.y = Math.random() * 2732; spiders.push(spider); game.addChild(spider); } // Initialize coins var coins = []; for (var k = 0; k < 10; k++) { var coin = new Coin(); coin.x = Math.random() * 2048; coin.y = Math.random() * 2732; coins.push(coin); game.addChild(coin); } // Initialize obstacles var obstacles = []; for (var j = 0; j < 10; j++) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; obstacles.push(obstacle); game.addChild(obstacle); } // Game update logic // Add timer text to the top right corner of the game var timerText = new Text2('1:30', { size: 50, fill: '#ffffff', anchorX: 1.0, // Right anchor anchorY: 0.0, // Top anchor x: 2048, // Position x-coordinate y: 0 // Position y-coordinate }); LK.gui.topRight.addChild(timerText); game.update = function () { hero.update(); spiders.forEach(function (spider) { spider.update(); if (hero.intersects(spider)) { // Handle collision with spider LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); coins.forEach(function (coin, index) { if (hero.intersects(coin)) { // Handle collision with coin coins.splice(index, 1); coin.destroy(); LK.setScore(LK.getScore() + 1); if (LK.getScore() >= 10 && coins.length == 0) { // Add 20 more coins for (var k = 0; k < 20; k++) { var coin = new Coin(); coin.x = Math.random() * 2048; coin.y = Math.random() * 2732; coins.push(coin); game.addChild(coin); } } else if (LK.getScore() >= 20 && coins.length == 0) { // Add 30 more coins for (var k = 0; k < 30; k++) { var coin = new Coin(); coin.x = Math.random() * 2048; coin.y = Math.random() * 2732; coins.push(coin); game.addChild(coin); } } else if (LK.getScore() >= 30) { // End game after 30 coins have been collected LK.showYouWin(); } } }); obstacles.forEach(function (obstacle) { if (hero.intersects(obstacle)) { // Handle collision with obstacle hero.speed = 0; // Stop hero movement } }); }; // Handle touch events for hero movement game.down = function (x, y, obj) { hero.x = x; hero.y = y; }; game.move = function (x, y, obj) { hero.x = x; hero.y = y; }; game.up = function (x, y, obj) { // Reset hero speed after touch release hero.speed = 5; }; // Initialize timer var timer = 90; // 1 minute and 30 seconds // Create interval to update the timer every second var timerInterval = LK.setInterval(function () { timer--; var minutes = Math.floor(timer / 60); var seconds = timer % 60; timerText.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); if (timer <= 0) { // End the game when the timer reaches 0 LK.clearInterval(timerInterval); LK.showGameOver(); } }, 1000); // Initialize timer text asset var timerText = new Text2('1:30', { size: 50, fill: '#ffffff', anchorX: 1.0, anchorY: 0.0, x: 2048, y: 0 }); // Add timer text to the game GUI LK.gui.topRight.addChild(timerText);
/****
* Classes
****/
// Coin class representing the collectible items
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Hero class representing the player character
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Hero movement logic
self.x += self.speed;
if (self.x > 2048) {
self.x = 0; // Wrap around
}
};
});
// Obstacle class for parkour elements
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Obstacle logic
};
});
// Spider class representing the enemy
var Spider = Container.expand(function () {
var self = Container.call(this);
var spiderGraphics = self.attachAsset('spider', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Spider movement logic
self.y += self.speed;
if (self.y > 2732) {
self.y = 0; // Wrap around
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x008000 // Init game with a green background
});
/****
* Game Code
****/
var mazeBackground = game.attachAsset('mazeBackground', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
});
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 100;
hero.y = 1366; // Centered vertically
// Initialize spiders
var spiders = [];
for (var i = 0; i < 5; i++) {
var spider = new Spider();
spider.x = Math.random() * 2048;
spider.y = Math.random() * 2732;
spiders.push(spider);
game.addChild(spider);
}
// Initialize coins
var coins = [];
for (var k = 0; k < 10; k++) {
var coin = new Coin();
coin.x = Math.random() * 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
// Initialize obstacles
var obstacles = [];
for (var j = 0; j < 10; j++) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Game update logic
// Add timer text to the top right corner of the game
var timerText = new Text2('1:30', {
size: 50,
fill: '#ffffff',
anchorX: 1.0,
// Right anchor
anchorY: 0.0,
// Top anchor
x: 2048,
// Position x-coordinate
y: 0 // Position y-coordinate
});
LK.gui.topRight.addChild(timerText);
game.update = function () {
hero.update();
spiders.forEach(function (spider) {
spider.update();
if (hero.intersects(spider)) {
// Handle collision with spider
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
coins.forEach(function (coin, index) {
if (hero.intersects(coin)) {
// Handle collision with coin
coins.splice(index, 1);
coin.destroy();
LK.setScore(LK.getScore() + 1);
if (LK.getScore() >= 10 && coins.length == 0) {
// Add 20 more coins
for (var k = 0; k < 20; k++) {
var coin = new Coin();
coin.x = Math.random() * 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
} else if (LK.getScore() >= 20 && coins.length == 0) {
// Add 30 more coins
for (var k = 0; k < 30; k++) {
var coin = new Coin();
coin.x = Math.random() * 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
} else if (LK.getScore() >= 30) {
// End game after 30 coins have been collected
LK.showYouWin();
}
}
});
obstacles.forEach(function (obstacle) {
if (hero.intersects(obstacle)) {
// Handle collision with obstacle
hero.speed = 0; // Stop hero movement
}
});
};
// Handle touch events for hero movement
game.down = function (x, y, obj) {
hero.x = x;
hero.y = y;
};
game.move = function (x, y, obj) {
hero.x = x;
hero.y = y;
};
game.up = function (x, y, obj) {
// Reset hero speed after touch release
hero.speed = 5;
};
// Initialize timer
var timer = 90; // 1 minute and 30 seconds
// Create interval to update the timer every second
var timerInterval = LK.setInterval(function () {
timer--;
var minutes = Math.floor(timer / 60);
var seconds = timer % 60;
timerText.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
if (timer <= 0) {
// End the game when the timer reaches 0
LK.clearInterval(timerInterval);
LK.showGameOver();
}
}, 1000);
// Initialize timer text asset
var timerText = new Text2('1:30', {
size: 50,
fill: '#ffffff',
anchorX: 1.0,
anchorY: 0.0,
x: 2048,
y: 0
});
// Add timer text to the game GUI
LK.gui.topRight.addChild(timerText);