/**** * Classes ****/ // Class for Doors var Door = Container.expand(function () { var self = Container.call(this); var doorGraphics = self.attachAsset('door', { anchorX: 0.5, anchorY: 0.5 }); self.locked = true; self.unlock = function () { if (self.locked) { self.locked = false; doorGraphics.tint = 0x00ff00; // Change color to indicate unlocked } }; }); // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Example assets: hidden objects, doors, and environment elements. // Class for Hidden Objects var HiddenObject = Container.expand(function () { var self = Container.call(this); var objectGraphics = self.attachAsset('hiddenObject', { anchorX: 0.5, anchorY: 0.5 }); self.found = false; self.reveal = function () { if (!self.found) { self.found = true; objectGraphics.alpha = 1; // Make the object fully visible } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var hiddenObjects = []; var doors = []; var foundObjectsCount = 0; var totalObjectsToFind = 5; // Example number of objects to find // Create hidden objects and doors for (var i = 0; i < totalObjectsToFind; i++) { var hiddenObject = new HiddenObject(); hiddenObject.x = Math.random() * 2048; hiddenObject.y = Math.random() * 2732; hiddenObjects.push(hiddenObject); game.addChild(hiddenObject); } var door = new Door(); door.x = 1024; // Centered horizontally door.y = 1366; // Centered vertically doors.push(door); game.addChild(door); // Event listener for finding hidden objects game.down = function (x, y, obj) { hiddenObjects.forEach(function (hiddenObject) { if (!hiddenObject.found && hiddenObject.intersects(obj)) { hiddenObject.reveal(); foundObjectsCount++; if (foundObjectsCount === totalObjectsToFind) { doors.forEach(function (door) { door.unlock(); }); } } }); }; // Update function called every game tick game.update = function () { // Game logic updates can be added here if needed };
/****
* Classes
****/
// Class for Doors
var Door = Container.expand(function () {
var self = Container.call(this);
var doorGraphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 0.5
});
self.locked = true;
self.unlock = function () {
if (self.locked) {
self.locked = false;
doorGraphics.tint = 0x00ff00; // Change color to indicate unlocked
}
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Example assets: hidden objects, doors, and environment elements.
// Class for Hidden Objects
var HiddenObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('hiddenObject', {
anchorX: 0.5,
anchorY: 0.5
});
self.found = false;
self.reveal = function () {
if (!self.found) {
self.found = true;
objectGraphics.alpha = 1; // Make the object fully visible
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var hiddenObjects = [];
var doors = [];
var foundObjectsCount = 0;
var totalObjectsToFind = 5; // Example number of objects to find
// Create hidden objects and doors
for (var i = 0; i < totalObjectsToFind; i++) {
var hiddenObject = new HiddenObject();
hiddenObject.x = Math.random() * 2048;
hiddenObject.y = Math.random() * 2732;
hiddenObjects.push(hiddenObject);
game.addChild(hiddenObject);
}
var door = new Door();
door.x = 1024; // Centered horizontally
door.y = 1366; // Centered vertically
doors.push(door);
game.addChild(door);
// Event listener for finding hidden objects
game.down = function (x, y, obj) {
hiddenObjects.forEach(function (hiddenObject) {
if (!hiddenObject.found && hiddenObject.intersects(obj)) {
hiddenObject.reveal();
foundObjectsCount++;
if (foundObjectsCount === totalObjectsToFind) {
doors.forEach(function (door) {
door.unlock();
});
}
}
});
};
// Update function called every game tick
game.update = function () {
// Game logic updates can be added here if needed
};