/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> //<Write entity 'classes' with empty functions for important behavior here> var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('characterShape', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Character movement has been removed }; }); var Floor = Container.expand(function () { var self = Container.call(this); self.levels = []; self.addLevel = function (level) { self.levels.push(level); self.addChild(level); }; self.update = function () { for (var i = 0; i < self.levels.length; i++) { self.levels[i].update(); } }; }); var Level = Container.expand(function (difficulty, levelNumber) { var self = Container.call(this); self.obstacles = []; self.character = new Character(); self.character.x = 2048 / 2; self.character.y = 2732 / 2; self.addChild(self.character); self.initializeObstacles = function () { for (var i = 0; i < difficulty; i++) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; self.obstacles.push(obstacle); self.addChild(obstacle); } }; self.initializeObstacles(); self.levelText = new Text2(levelNumber.toString(), { size: 150, fill: 0xFFFFFF }); self.levelText.anchor.set(0.5, 0); self.levelText.x = 2048 / 2; self.levelText.y = 100; self.addChild(self.levelText); self.update = function () { for (var i = 0; i < self.obstacles.length; i++) { if (self.character.intersects(self.obstacles[i])) { LK.showGameOver(); break; } } }; self.removeLevelText = function () { self.removeChild(self.levelText); }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacleShape', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 2; if (self.y > 2732) { self.y = -100; self.x = Math.random() * 2048; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000, //Init game with black background gradientBackground: { colors: [0x000000, 0x1a1a1a, 0x333333, 0x4d4d4d, 0x666666], direction: 'vertical' } }); /**** * Game Code ****/ //<Write game logic code here, including initializing arrays and variables> // Function to create a star function createStar() { var star = new Container(); var starGraphics = star.attachAsset('starShape', { anchorX: 0.5, anchorY: 0.5, shape: 'star' // Use star shape for the graphics }); star.x = Math.random() * 2048; star.y = Math.random() * 2732; starGraphics.alpha = Math.random() * 0.5 + 0.5; // Random transparency return star; } // Add stars to the background var stars = []; for (var i = 0; i < 100; i++) { // Create 100 stars var star = createStar(); stars.push(star); game.addChild(star); } var UI = { Menu: function Menu(options) { this.title = options.title; this.items = options.items; this.show = function () { console.log("Showing menu:", this.title); }; } }; LK.UI = UI; var settingsMenu = new LK.UI.Menu({ title: "Settings", items: [{ label: "Sound", action: function action() {/* Toggle sound */} }, { label: "Music", action: function action() {/* Toggle music */} }, { label: "Graphics", action: function action() {/* Adjust graphics settings */} }] }); LK.on('pause', function () { settingsMenu.show(); // Add additional settings options here if needed var settingsButton = new LK.UI.Button({ label: "Settings", action: function action() { settingsMenu.show(); } }); LK.gui.topRight.addChild(settingsButton); // Add a resume button to unpause the game var resumeButton = new LK.UI.Button({ label: "Resume", action: function action() { LK.resumeGame(); // Unpause the game } }); LK.gui.topRight.addChild(resumeButton); }); var floors = []; var currentLevel = 0; for (var i = 0; i < 25; i++) { var floor = new Floor(); var levelNumber = i + 1; var difficulty = Math.min(levelNumber, 15); // Difficulty increases up to level 15 var level = new Level(difficulty, levelNumber); floor.addLevel(level); floors.push(floor); if (i == currentLevel) { game.addChild(floor); } } game.update = function () { floors[currentLevel].update(); if (floors[currentLevel].levels[0].character.y < 0) { floors[currentLevel].levels[0].removeLevelText(); game.removeChild(floors[currentLevel]); currentLevel++; if (currentLevel < floors.length) { var currentLevelObj = floors[currentLevel].levels[0]; currentLevelObj.character.x = 2048 / 2; // Reset character x position to the middle of the screen currentLevelObj.character.y = 2732 / 2; // Reset character y position to the middle of the screen currentLevelObj.initializeObstacles(); // Randomize obstacle positions game.addChild(floors[currentLevel]); } else { LK.showYouWin(); } } // Add border to the game to prevent the character from going out of the screen view for (var i = 0; i < floors.length; i++) { for (var j = 0; j < floors[i].levels.length; j++) { if (floors[i].levels[j].character.x < 0) { floors[i].levels[j].character.x = 0; } if (floors[i].levels[j].character.x > 2048) { floors[i].levels[j].character.x = 2048; } if (floors[i].levels[j].character.y < 0) { floors[i].levels[j].character.y = 0; } if (floors[i].levels[j].character.y > 2732) { floors[i].levels[j].character.y = 2732; } } } // Level progression if (floors[currentLevel].levels[0].character.y > 2732) { floors[currentLevel].levels[0].removeLevelText(); game.removeChild(floors[currentLevel]); currentLevel++; if (currentLevel < floors.length) { game.addChild(floors[currentLevel]); } else { LK.showYouWin(); } } }; game.down = function (x, y, obj) { // Intentionally left empty to prevent unpausing by clicking the background }; game.move = function (x, y, obj) { var character = floors[currentLevel].levels[0].character; var distance = Math.sqrt(Math.pow(character.x - x, 2) + Math.pow(character.y - y, 2)); if (distance < 150) { // Allow character to follow mouse when within 150 pixels character.x = x; character.y = y; } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
//<Write entity 'classes' with empty functions for important behavior here>
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('characterShape', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Character movement has been removed
};
});
var Floor = Container.expand(function () {
var self = Container.call(this);
self.levels = [];
self.addLevel = function (level) {
self.levels.push(level);
self.addChild(level);
};
self.update = function () {
for (var i = 0; i < self.levels.length; i++) {
self.levels[i].update();
}
};
});
var Level = Container.expand(function (difficulty, levelNumber) {
var self = Container.call(this);
self.obstacles = [];
self.character = new Character();
self.character.x = 2048 / 2;
self.character.y = 2732 / 2;
self.addChild(self.character);
self.initializeObstacles = function () {
for (var i = 0; i < difficulty; i++) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
self.obstacles.push(obstacle);
self.addChild(obstacle);
}
};
self.initializeObstacles();
self.levelText = new Text2(levelNumber.toString(), {
size: 150,
fill: 0xFFFFFF
});
self.levelText.anchor.set(0.5, 0);
self.levelText.x = 2048 / 2;
self.levelText.y = 100;
self.addChild(self.levelText);
self.update = function () {
for (var i = 0; i < self.obstacles.length; i++) {
if (self.character.intersects(self.obstacles[i])) {
LK.showGameOver();
break;
}
}
};
self.removeLevelText = function () {
self.removeChild(self.levelText);
};
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacleShape', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 2;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
//Init game with black background
gradientBackground: {
colors: [0x000000, 0x1a1a1a, 0x333333, 0x4d4d4d, 0x666666],
direction: 'vertical'
}
});
/****
* Game Code
****/
//<Write game logic code here, including initializing arrays and variables>
// Function to create a star
function createStar() {
var star = new Container();
var starGraphics = star.attachAsset('starShape', {
anchorX: 0.5,
anchorY: 0.5,
shape: 'star' // Use star shape for the graphics
});
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
starGraphics.alpha = Math.random() * 0.5 + 0.5; // Random transparency
return star;
}
// Add stars to the background
var stars = [];
for (var i = 0; i < 100; i++) {
// Create 100 stars
var star = createStar();
stars.push(star);
game.addChild(star);
}
var UI = {
Menu: function Menu(options) {
this.title = options.title;
this.items = options.items;
this.show = function () {
console.log("Showing menu:", this.title);
};
}
};
LK.UI = UI;
var settingsMenu = new LK.UI.Menu({
title: "Settings",
items: [{
label: "Sound",
action: function action() {/* Toggle sound */}
}, {
label: "Music",
action: function action() {/* Toggle music */}
}, {
label: "Graphics",
action: function action() {/* Adjust graphics settings */}
}]
});
LK.on('pause', function () {
settingsMenu.show();
// Add additional settings options here if needed
var settingsButton = new LK.UI.Button({
label: "Settings",
action: function action() {
settingsMenu.show();
}
});
LK.gui.topRight.addChild(settingsButton);
// Add a resume button to unpause the game
var resumeButton = new LK.UI.Button({
label: "Resume",
action: function action() {
LK.resumeGame(); // Unpause the game
}
});
LK.gui.topRight.addChild(resumeButton);
});
var floors = [];
var currentLevel = 0;
for (var i = 0; i < 25; i++) {
var floor = new Floor();
var levelNumber = i + 1;
var difficulty = Math.min(levelNumber, 15); // Difficulty increases up to level 15
var level = new Level(difficulty, levelNumber);
floor.addLevel(level);
floors.push(floor);
if (i == currentLevel) {
game.addChild(floor);
}
}
game.update = function () {
floors[currentLevel].update();
if (floors[currentLevel].levels[0].character.y < 0) {
floors[currentLevel].levels[0].removeLevelText();
game.removeChild(floors[currentLevel]);
currentLevel++;
if (currentLevel < floors.length) {
var currentLevelObj = floors[currentLevel].levels[0];
currentLevelObj.character.x = 2048 / 2; // Reset character x position to the middle of the screen
currentLevelObj.character.y = 2732 / 2; // Reset character y position to the middle of the screen
currentLevelObj.initializeObstacles(); // Randomize obstacle positions
game.addChild(floors[currentLevel]);
} else {
LK.showYouWin();
}
}
// Add border to the game to prevent the character from going out of the screen view
for (var i = 0; i < floors.length; i++) {
for (var j = 0; j < floors[i].levels.length; j++) {
if (floors[i].levels[j].character.x < 0) {
floors[i].levels[j].character.x = 0;
}
if (floors[i].levels[j].character.x > 2048) {
floors[i].levels[j].character.x = 2048;
}
if (floors[i].levels[j].character.y < 0) {
floors[i].levels[j].character.y = 0;
}
if (floors[i].levels[j].character.y > 2732) {
floors[i].levels[j].character.y = 2732;
}
}
}
// Level progression
if (floors[currentLevel].levels[0].character.y > 2732) {
floors[currentLevel].levels[0].removeLevelText();
game.removeChild(floors[currentLevel]);
currentLevel++;
if (currentLevel < floors.length) {
game.addChild(floors[currentLevel]);
} else {
LK.showYouWin();
}
}
};
game.down = function (x, y, obj) {
// Intentionally left empty to prevent unpausing by clicking the background
};
game.move = function (x, y, obj) {
var character = floors[currentLevel].levels[0].character;
var distance = Math.sqrt(Math.pow(character.x - x, 2) + Math.pow(character.y - y, 2));
if (distance < 150) {
// Allow character to follow mouse when within 150 pixels
character.x = x;
character.y = y;
}
};