/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { level: 1, coins: 0, antiRejection: 0, dreamBoost: 0, levelSkips: 0 }); /**** * Classes ****/ var Button = Container.expand(function (text, width, height, color) { var self = Container.call(this); var buttonWidth = width || 300; var buttonHeight = height || 100; var buttonColor = color || 0x3498db; var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5, width: buttonWidth, height: buttonHeight, color: buttonColor }); var buttonText = new Text2(text, { size: 50, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.setText = function (newText) { buttonText.setText(newText); }; self.down = function (x, y, obj) { tween(buttonGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeOut }); }; self.up = function (x, y, obj) { tween(buttonGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); }; return self; }); var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { coinGraphics.rotation += 0.05; }; return self; }); var Exit = Container.expand(function () { var self = Container.call(this); var exitGraphics = self.attachAsset('exit', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); // Pulsing animation var pulseDirection = 1; var pulseMin = 0.7; var pulseMax = 1.0; self.update = function () { exitGraphics.alpha += 0.01 * pulseDirection; if (exitGraphics.alpha >= pulseMax) { exitGraphics.alpha = pulseMax; pulseDirection = -1; } else if (exitGraphics.alpha <= pulseMin) { exitGraphics.alpha = pulseMin; pulseDirection = 1; } exitGraphics.rotation += 0.02; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.isMoving = false; self.moveSpeed = 10; self.targetX = 0; self.targetY = 0; self.moveToCell = function (cellX, cellY) { if (self.isMoving) { return false; } // Calculate target position self.targetX = cellX * cellSize + cellSize / 2; self.targetY = cellY * cellSize + cellSize / 2; // If cube has developed a mind of its own (after level 20) and no anti-rejection if (storage.level >= 20 && Math.random() < 0.5 && storage.antiRejection <= 0) { LK.getSound('reject').play(); // Show rejection animation tween(playerGraphics, { rotation: Math.PI * 2 }, { duration: 500, easing: tween.easeInOut }); return false; } if (storage.antiRejection > 0) { storage.antiRejection--; updateShopUI(); } self.isMoving = true; // Animate movement tween(self, { x: self.targetX, y: self.targetY }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { self.isMoving = false; checkCollisions(); } }); LK.getSound('move').play(); return true; }; self.update = function () { // Add subtle idle animation if (!self.isMoving) { playerGraphics.rotation += 0.01; } }; return self; }); var ShopItem = Container.expand(function (name, description, price, count) { var self = Container.call(this); var buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); var titleText = new Text2(name, { size: 36, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); titleText.y = -30; self.addChild(titleText); var descText = new Text2(description, { size: 24, fill: 0xCCCCCC }); descText.anchor.set(0.5, 0); descText.y = 10; self.addChild(descText); var priceText = new Text2(price + " MC", { size: 30, fill: 0xFFCC00 }); priceText.anchor.set(0.5, 0); priceText.y = 40; self.addChild(priceText); var countText = new Text2("Owned: " + count, { size: 24, fill: 0xFFFFFF }); countText.anchor.set(1.0, 0); countText.x = 100; countText.y = -30; self.addChild(countText); self.name = name; self.price = price; self.updateCount = function (newCount) { countText.setText("Owned: " + newCount); }; self.down = function (x, y, obj) { tween(buttonGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeOut }); }; self.up = function (x, y, obj) { tween(buttonGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); // Check if player can afford if (storage.coins >= self.price) { storage.coins -= self.price; if (self.name === "Anti-Rejection") { storage.antiRejection += 60; // 60 seconds of rejection-free swipes } else if (self.name === "Dream Boost") { storage.dreamBoost += 1; // Add uranium ad effect and glow // Implement glow and trail effect player.tint = 0x00FF00; // Example glow effect // Add trail effect logic here } LK.getSound('coin').play(); updateShopUI(); updateCoinsUI(); } }; return self; }); var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ // UI Elements var skipLevelButton = new Button("SKIP LEVEL", 200, 80, 0xE74C3C); // Define skipLevelButton // Clear storage to reset progress on refresh storage = LK.import('@upit/storage.v1', { level: 1, coins: 0, antiRejection: 0, dreamBoost: 0, levelSkips: 0 }); // Reset MindCoins and Level to 1 when the game is first played if (!storage.hasPlayed) { storage.level = 1; storage.coins = 0; storage.hasPlayed = true; skipLevelButton.visible = false; // Hide skip level button on reset } function resetGame() { storage.level = 1; updateLevelUI(); storage.coins = 0; updateLevelUI(); updateCoinsUI(); skipLevelButton.visible = false; // Hide skip level button on reset } var mazeContainer; var playerContainer; var shopContainer; var isShopOpen = false; var cellSize = 120; var mazeWidth = 0; var mazeHeight = 0; var playerCellX = 0; var playerCellY = 0; var maze = []; var lastSwipeDirection = ''; var lastSwipeTime = 0; var coinTimer = 0; var gameInitialized = false; // UI Elements var coinText; var levelText; var gambleButton; var shopButton; var skipLevelButton; var antiRejectionItem; var dreamBoostItem; var levelSkipItem; // Level data generator function generateMaze(level) { // Maze size increases with level, making it harder var size = Math.min(5 + Math.floor(level / 3), 15); mazeWidth = size; mazeHeight = size; // Initialize maze with all walls maze = []; for (var y = 0; y < mazeHeight; y++) { maze[y] = []; for (var x = 0; x < mazeWidth; x++) { maze[y][x] = 1; // 1 = wall } } // Create paths using a simple algorithm var startX = 1; var startY = 1; var exitX = mazeWidth - 2; var exitY = mazeHeight - 2; maze[startY][startX] = 0; // 0 = path // Simple recursive maze generator function carve(x, y) { var directions = [[0, -2], // Up [2, 0], // Right [0, 2], // Down [-2, 0] // Left ]; // Shuffle directions for (var i = directions.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = directions[i]; directions[i] = directions[j]; directions[j] = temp; } // Try each direction for (var i = 0; i < directions.length; i++) { var dx = directions[i][0]; var dy = directions[i][1]; var nx = x + dx; var ny = y + dy; if (nx > 0 && nx < mazeWidth - 1 && ny > 0 && ny < mazeHeight - 1 && maze[ny][nx] === 1) { // Carve path maze[y + dy / 2][x + dx / 2] = 0; maze[ny][nx] = 0; carve(nx, ny); } } } carve(startX, startY); // Ensure exit is accessible maze[exitY][exitX] = 0; // Create an opening next to the exit for all levels maze[exitY][exitX - 1] = 0; // Open path to the left of the exit // Add more random paths for higher levels to increase difficulty if (level > 10) { var extraPaths = Math.min(Math.floor(level / 5), 10); for (var i = 0; i < extraPaths; i++) { var rx = Math.floor(Math.random() * (mazeWidth - 2)) + 1; var ry = Math.floor(Math.random() * (mazeHeight - 2)) + 1; maze[ry][rx] = 0; } } // Set player start position playerCellX = startX; playerCellY = startY; return { startX: startX, startY: startY, exitX: exitX, exitY: exitY }; } function renderMaze() { // Clear existing maze if any if (mazeContainer) { game.removeChild(mazeContainer); } mazeContainer = new Container(); game.addChild(mazeContainer); // Center the maze on screen var mazePixelWidth = mazeWidth * cellSize; var mazePixelHeight = mazeHeight * cellSize; mazeContainer.x = (2048 - mazePixelWidth) / 2; mazeContainer.y = (2732 - mazePixelHeight) / 2; // Create walls for (var y = 0; y < mazeHeight; y++) { for (var x = 0; x < mazeWidth; x++) { if (maze[y][x] === 1) { var wall = new Wall(); wall.x = x * cellSize + cellSize / 2; wall.y = y * cellSize + cellSize / 2; mazeContainer.addChild(wall); } } } // Add exit exit = new Exit(); exit.x = positions.exitX * cellSize + cellSize / 2; exit.y = positions.exitY * cellSize + cellSize / 2; mazeContainer.addChild(exit); // Add player player = new Player(); player.x = positions.startX * cellSize + cellSize / 2; player.y = positions.startY * cellSize + cellSize / 2; mazeContainer.addChild(player); } function movePlayer(dx, dy) { if (player.isMoving) { return; } var newX = playerCellX + dx; var newY = playerCellY + dy; // Check if valid move if (newX >= 0 && newX < mazeWidth && newY >= 0 && newY < mazeHeight && maze[newY][newX] === 0) { if (player.moveToCell(newX, newY)) { playerCellX = newX; playerCellY = newY; } } } function checkCollisions() { // Check if player reached exit if (playerCellX === positions.exitX && playerCellY === positions.exitY) { // Level completed! LK.getSound('win').play(); // Increase level storage.level++; // Check if level is 67 to reset if (storage.level === 67) { storage.level = 1; storage.coins = 0; storage.hasPlayed = false; // Reset hasPlayed to allow reset on next game start } // Update UI after potential reset updateLevelUI(); // Award bonus coins for completion var bonus = Math.floor(5 + storage.level / 2); storage.coins += bonus; updateCoinsUI(); // Show level complete popup and proceed to next level LK.setTimeout(function () { initLevel(); }, 1000); } } function updateCoinsUI() { coinText.setText("MindCoins: " + storage.coins); } function updateLevelUI() { levelText.setText("Level: " + storage.level); } function updateShopUI() { if (antiRejectionItem) { antiRejectionItem.updateCount(storage.antiRejection); } if (dreamBoostItem) { dreamBoostItem.updateCount(storage.dreamBoost); } if (levelSkipItem) { levelSkipItem.updateCount(storage.levelSkips); } if (skipLevelButton) { skipLevelButton.visible = storage.levelSkips > 0; } } function gamble() { if (storage.coins >= 5) { storage.coins -= 5; updateCoinsUI(); LK.getSound('gamble').play(); // 75% chance to win (rigged in player's favor) if (Math.random() < 0.75) { // Win 15 coins (net profit of 10) var winnings = 15; // Bigger wins on higher levels if (storage.level > 20) { winnings = 20; } // Apply dream boost if owned if (storage.dreamBoost > 0) { storage.dreamBoost--; winnings *= 2; updateShopUI(); } storage.coins += winnings; // Show win animation var winText = new Text2("+" + winnings + "!", { size: 80, fill: 0xFFCC00 }); winText.anchor.set(0.5, 0.5); winText.x = gambleButton.x; winText.y = gambleButton.y - 150; game.addChild(winText); tween(winText, { y: winText.y - 100, alpha: 0 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { game.removeChild(winText); } }); } else { // Lose animation var loseText = new Text2("Try Again!", { size: 60, fill: 0xFF5555 }); loseText.anchor.set(0.5, 0.5); loseText.x = gambleButton.x; loseText.y = gambleButton.y - 150; game.addChild(loseText); tween(loseText, { y: loseText.y - 100, alpha: 0 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { game.removeChild(loseText); } }); // Implement 25% chance to lose 90% of coins if (Math.random() < 0.25) { storage.coins = Math.floor(storage.coins * 0.1); updateCoinsUI(); } } updateCoinsUI(); } } function toggleShop() { if (isShopOpen) { // Close shop tween(shopContainer, { alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { shopContainer.visible = false; // Show maze, player, and exit assets mazeContainer.visible = true; player.visible = true; exit.visible = true; } }); } else { // Hide maze, player, and exit assets mazeContainer.visible = false; player.visible = false; exit.visible = false; // Open shop shopContainer.visible = true; tween(shopContainer, { alpha: 1 }, { duration: 300, easing: tween.easeOut }); } isShopOpen = !isShopOpen; } function initUI() { // Create coin counter coinText = new Text2("MindCoins: " + storage.coins, { size: 50, fill: 0xFFCC00 }); coinText.anchor.set(1, 0); LK.gui.topRight.addChild(coinText); // Create level indicator levelText = new Text2("Level: " + storage.level, { size: 50, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); LK.gui.top.addChild(levelText); // Create gamble button gambleButton = new Button("GAMBLE 5 MC", 350, 120, 0xE74C3C); gambleButton.x = 2048 - 200; gambleButton.y = 2732 - 200; game.addChild(gambleButton); gambleButton.up = function () { tween(gambleButton, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); gamble(); }; // Create shop button shopButton = new Button("SHOP", 200, 100, 0x2ECC71); shopButton.x = 150; shopButton.y = 2732 - 200; game.addChild(shopButton); shopButton.up = function () { tween(shopButton, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); toggleShop(); }; // Create shop container shopContainer = new Container(); shopContainer.visible = false; shopContainer.alpha = 0; game.addChild(shopContainer); // Shop background var shopBg = LK.getAsset('shopBackground', { anchorX: 0.5, anchorY: 0.5, alpha: 0.9 }); shopBg.x = 2048 / 2; shopBg.y = 2732 / 2; shopContainer.addChild(shopBg); // Shop title var shopTitle = new Text2("MIND MAZE SHOP", { size: 80, fill: 0xFFFFFF }); shopTitle.anchor.set(0.5, 0); shopTitle.x = 2048 / 2; shopTitle.y = 2732 / 2 - 700; shopContainer.addChild(shopTitle); // Shop items antiRejectionItem = new ShopItem("Anti-Rejection", "Prevent 5 move rejections", 25, storage.antiRejection); antiRejectionItem.x = 2048 / 2; antiRejectionItem.y = 2732 / 2 - 400; shopContainer.addChild(antiRejectionItem); // Add icon for anti-rejection purchase var antiRejectionIcon = LK.getAsset('pickaxeIcon', { anchorX: 0.5, anchorY: 0.5 }); antiRejectionIcon.x = antiRejectionItem.x - 150; antiRejectionIcon.y = antiRejectionItem.y; shopContainer.addChild(antiRejectionIcon); var slashIcon = LK.getAsset('slashIcon', { anchorX: 0.5, anchorY: 0.5 }); slashIcon.x = antiRejectionIcon.x; slashIcon.y = antiRejectionIcon.y; shopContainer.addChild(slashIcon); dreamBoostItem = new ShopItem("Dream Boost", "Double gamble winnings 3 times", 40, storage.dreamBoost); dreamBoostItem.x = 2048 / 2; dreamBoostItem.y = 2732 / 2 - 200; shopContainer.addChild(dreamBoostItem); // Close shop button var closeButton = new Button("CLOSE", 200, 80, 0xE74C3C); closeButton.x = 2048 / 2; closeButton.y = 2732 / 2 + 200; shopContainer.addChild(closeButton); closeButton.up = function () { tween(closeButton, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); toggleShop(); }; // Reset button var resetButton = new Button("RESET", 200, 80, 0xE74C3C); resetButton.x = 2048 / 2; resetButton.y = 250; game.addChild(resetButton); resetButton.up = function () { tween(resetButton, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeOut }); resetGame(); }; } function initSwipeControl() { // Handle swipe gestures for movement var startX = 0; var startY = 0; var isTracking = false; game.down = function (x, y) { if (isShopOpen) { return; } startX = x; startY = y; isTracking = true; }; game.up = function (x, y) { if (isShopOpen || !isTracking) { return; } var dx = x - startX; var dy = y - startY; var threshold = 50; // Determine swipe direction if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > threshold) { // Horizontal swipe if (dx > 0) { movePlayer(1, 0); // Right lastSwipeDirection = 'right'; } else { movePlayer(-1, 0); // Left lastSwipeDirection = 'left'; } } else if (Math.abs(dy) > Math.abs(dx) && Math.abs(dy) > threshold) { // Vertical swipe if (dy > 0) { movePlayer(0, 1); // Down lastSwipeDirection = 'down'; } else { movePlayer(0, -1); // Up lastSwipeDirection = 'up'; } } lastSwipeTime = Date.now(); isTracking = false; }; } function initLevel() { // Generate new level positions = generateMaze(storage.level); renderMaze(); // Update UI to reflect new level updateLevelUI(); updateShopUI(); } function initGame() { if (gameInitialized) { return; } LK.playMusic('bgmusic'); initUI(); initSwipeControl(); initLevel(); gameInitialized = true; } // Main game loop game.update = function () { if (!gameInitialized) { initGame(); } // Award coins every 2 seconds (120 ticks) if (LK.ticks % 120 === 0) { storage.coins += 1; updateCoinsUI(); } // Check if game is in shop mode if (isShopOpen) { return; // Skip other updates when shop is open } }; // Initialize the game initGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
level: 1,
coins: 0,
antiRejection: 0,
dreamBoost: 0,
levelSkips: 0
});
/****
* Classes
****/
var Button = Container.expand(function (text, width, height, color) {
var self = Container.call(this);
var buttonWidth = width || 300;
var buttonHeight = height || 100;
var buttonColor = color || 0x3498db;
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: buttonWidth,
height: buttonHeight,
color: buttonColor
});
var buttonText = new Text2(text, {
size: 50,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setText = function (newText) {
buttonText.setText(newText);
};
self.down = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut
});
};
self.up = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeOut
});
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
coinGraphics.rotation += 0.05;
};
return self;
});
var Exit = Container.expand(function () {
var self = Container.call(this);
var exitGraphics = self.attachAsset('exit', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
// Pulsing animation
var pulseDirection = 1;
var pulseMin = 0.7;
var pulseMax = 1.0;
self.update = function () {
exitGraphics.alpha += 0.01 * pulseDirection;
if (exitGraphics.alpha >= pulseMax) {
exitGraphics.alpha = pulseMax;
pulseDirection = -1;
} else if (exitGraphics.alpha <= pulseMin) {
exitGraphics.alpha = pulseMin;
pulseDirection = 1;
}
exitGraphics.rotation += 0.02;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.moveSpeed = 10;
self.targetX = 0;
self.targetY = 0;
self.moveToCell = function (cellX, cellY) {
if (self.isMoving) {
return false;
}
// Calculate target position
self.targetX = cellX * cellSize + cellSize / 2;
self.targetY = cellY * cellSize + cellSize / 2;
// If cube has developed a mind of its own (after level 20) and no anti-rejection
if (storage.level >= 20 && Math.random() < 0.5 && storage.antiRejection <= 0) {
LK.getSound('reject').play();
// Show rejection animation
tween(playerGraphics, {
rotation: Math.PI * 2
}, {
duration: 500,
easing: tween.easeInOut
});
return false;
}
if (storage.antiRejection > 0) {
storage.antiRejection--;
updateShopUI();
}
self.isMoving = true;
// Animate movement
tween(self, {
x: self.targetX,
y: self.targetY
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
checkCollisions();
}
});
LK.getSound('move').play();
return true;
};
self.update = function () {
// Add subtle idle animation
if (!self.isMoving) {
playerGraphics.rotation += 0.01;
}
};
return self;
});
var ShopItem = Container.expand(function (name, description, price, count) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2(name, {
size: 36,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -30;
self.addChild(titleText);
var descText = new Text2(description, {
size: 24,
fill: 0xCCCCCC
});
descText.anchor.set(0.5, 0);
descText.y = 10;
self.addChild(descText);
var priceText = new Text2(price + " MC", {
size: 30,
fill: 0xFFCC00
});
priceText.anchor.set(0.5, 0);
priceText.y = 40;
self.addChild(priceText);
var countText = new Text2("Owned: " + count, {
size: 24,
fill: 0xFFFFFF
});
countText.anchor.set(1.0, 0);
countText.x = 100;
countText.y = -30;
self.addChild(countText);
self.name = name;
self.price = price;
self.updateCount = function (newCount) {
countText.setText("Owned: " + newCount);
};
self.down = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut
});
};
self.up = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeOut
});
// Check if player can afford
if (storage.coins >= self.price) {
storage.coins -= self.price;
if (self.name === "Anti-Rejection") {
storage.antiRejection += 60; // 60 seconds of rejection-free swipes
} else if (self.name === "Dream Boost") {
storage.dreamBoost += 1; // Add uranium ad effect and glow
// Implement glow and trail effect
player.tint = 0x00FF00; // Example glow effect
// Add trail effect logic here
}
LK.getSound('coin').play();
updateShopUI();
updateCoinsUI();
}
};
return self;
});
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// UI Elements
var skipLevelButton = new Button("SKIP LEVEL", 200, 80, 0xE74C3C); // Define skipLevelButton
// Clear storage to reset progress on refresh
storage = LK.import('@upit/storage.v1', {
level: 1,
coins: 0,
antiRejection: 0,
dreamBoost: 0,
levelSkips: 0
});
// Reset MindCoins and Level to 1 when the game is first played
if (!storage.hasPlayed) {
storage.level = 1;
storage.coins = 0;
storage.hasPlayed = true;
skipLevelButton.visible = false; // Hide skip level button on reset
}
function resetGame() {
storage.level = 1;
updateLevelUI();
storage.coins = 0;
updateLevelUI();
updateCoinsUI();
skipLevelButton.visible = false; // Hide skip level button on reset
}
var mazeContainer;
var playerContainer;
var shopContainer;
var isShopOpen = false;
var cellSize = 120;
var mazeWidth = 0;
var mazeHeight = 0;
var playerCellX = 0;
var playerCellY = 0;
var maze = [];
var lastSwipeDirection = '';
var lastSwipeTime = 0;
var coinTimer = 0;
var gameInitialized = false;
// UI Elements
var coinText;
var levelText;
var gambleButton;
var shopButton;
var skipLevelButton;
var antiRejectionItem;
var dreamBoostItem;
var levelSkipItem;
// Level data generator
function generateMaze(level) {
// Maze size increases with level, making it harder
var size = Math.min(5 + Math.floor(level / 3), 15);
mazeWidth = size;
mazeHeight = size;
// Initialize maze with all walls
maze = [];
for (var y = 0; y < mazeHeight; y++) {
maze[y] = [];
for (var x = 0; x < mazeWidth; x++) {
maze[y][x] = 1; // 1 = wall
}
}
// Create paths using a simple algorithm
var startX = 1;
var startY = 1;
var exitX = mazeWidth - 2;
var exitY = mazeHeight - 2;
maze[startY][startX] = 0; // 0 = path
// Simple recursive maze generator
function carve(x, y) {
var directions = [[0, -2],
// Up
[2, 0],
// Right
[0, 2],
// Down
[-2, 0] // Left
];
// Shuffle directions
for (var i = directions.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = directions[i];
directions[i] = directions[j];
directions[j] = temp;
}
// Try each direction
for (var i = 0; i < directions.length; i++) {
var dx = directions[i][0];
var dy = directions[i][1];
var nx = x + dx;
var ny = y + dy;
if (nx > 0 && nx < mazeWidth - 1 && ny > 0 && ny < mazeHeight - 1 && maze[ny][nx] === 1) {
// Carve path
maze[y + dy / 2][x + dx / 2] = 0;
maze[ny][nx] = 0;
carve(nx, ny);
}
}
}
carve(startX, startY);
// Ensure exit is accessible
maze[exitY][exitX] = 0;
// Create an opening next to the exit for all levels
maze[exitY][exitX - 1] = 0; // Open path to the left of the exit
// Add more random paths for higher levels to increase difficulty
if (level > 10) {
var extraPaths = Math.min(Math.floor(level / 5), 10);
for (var i = 0; i < extraPaths; i++) {
var rx = Math.floor(Math.random() * (mazeWidth - 2)) + 1;
var ry = Math.floor(Math.random() * (mazeHeight - 2)) + 1;
maze[ry][rx] = 0;
}
}
// Set player start position
playerCellX = startX;
playerCellY = startY;
return {
startX: startX,
startY: startY,
exitX: exitX,
exitY: exitY
};
}
function renderMaze() {
// Clear existing maze if any
if (mazeContainer) {
game.removeChild(mazeContainer);
}
mazeContainer = new Container();
game.addChild(mazeContainer);
// Center the maze on screen
var mazePixelWidth = mazeWidth * cellSize;
var mazePixelHeight = mazeHeight * cellSize;
mazeContainer.x = (2048 - mazePixelWidth) / 2;
mazeContainer.y = (2732 - mazePixelHeight) / 2;
// Create walls
for (var y = 0; y < mazeHeight; y++) {
for (var x = 0; x < mazeWidth; x++) {
if (maze[y][x] === 1) {
var wall = new Wall();
wall.x = x * cellSize + cellSize / 2;
wall.y = y * cellSize + cellSize / 2;
mazeContainer.addChild(wall);
}
}
}
// Add exit
exit = new Exit();
exit.x = positions.exitX * cellSize + cellSize / 2;
exit.y = positions.exitY * cellSize + cellSize / 2;
mazeContainer.addChild(exit);
// Add player
player = new Player();
player.x = positions.startX * cellSize + cellSize / 2;
player.y = positions.startY * cellSize + cellSize / 2;
mazeContainer.addChild(player);
}
function movePlayer(dx, dy) {
if (player.isMoving) {
return;
}
var newX = playerCellX + dx;
var newY = playerCellY + dy;
// Check if valid move
if (newX >= 0 && newX < mazeWidth && newY >= 0 && newY < mazeHeight && maze[newY][newX] === 0) {
if (player.moveToCell(newX, newY)) {
playerCellX = newX;
playerCellY = newY;
}
}
}
function checkCollisions() {
// Check if player reached exit
if (playerCellX === positions.exitX && playerCellY === positions.exitY) {
// Level completed!
LK.getSound('win').play();
// Increase level
storage.level++;
// Check if level is 67 to reset
if (storage.level === 67) {
storage.level = 1;
storage.coins = 0;
storage.hasPlayed = false; // Reset hasPlayed to allow reset on next game start
}
// Update UI after potential reset
updateLevelUI();
// Award bonus coins for completion
var bonus = Math.floor(5 + storage.level / 2);
storage.coins += bonus;
updateCoinsUI();
// Show level complete popup and proceed to next level
LK.setTimeout(function () {
initLevel();
}, 1000);
}
}
function updateCoinsUI() {
coinText.setText("MindCoins: " + storage.coins);
}
function updateLevelUI() {
levelText.setText("Level: " + storage.level);
}
function updateShopUI() {
if (antiRejectionItem) {
antiRejectionItem.updateCount(storage.antiRejection);
}
if (dreamBoostItem) {
dreamBoostItem.updateCount(storage.dreamBoost);
}
if (levelSkipItem) {
levelSkipItem.updateCount(storage.levelSkips);
}
if (skipLevelButton) {
skipLevelButton.visible = storage.levelSkips > 0;
}
}
function gamble() {
if (storage.coins >= 5) {
storage.coins -= 5;
updateCoinsUI();
LK.getSound('gamble').play();
// 75% chance to win (rigged in player's favor)
if (Math.random() < 0.75) {
// Win 15 coins (net profit of 10)
var winnings = 15;
// Bigger wins on higher levels
if (storage.level > 20) {
winnings = 20;
}
// Apply dream boost if owned
if (storage.dreamBoost > 0) {
storage.dreamBoost--;
winnings *= 2;
updateShopUI();
}
storage.coins += winnings;
// Show win animation
var winText = new Text2("+" + winnings + "!", {
size: 80,
fill: 0xFFCC00
});
winText.anchor.set(0.5, 0.5);
winText.x = gambleButton.x;
winText.y = gambleButton.y - 150;
game.addChild(winText);
tween(winText, {
y: winText.y - 100,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
game.removeChild(winText);
}
});
} else {
// Lose animation
var loseText = new Text2("Try Again!", {
size: 60,
fill: 0xFF5555
});
loseText.anchor.set(0.5, 0.5);
loseText.x = gambleButton.x;
loseText.y = gambleButton.y - 150;
game.addChild(loseText);
tween(loseText, {
y: loseText.y - 100,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
game.removeChild(loseText);
}
});
// Implement 25% chance to lose 90% of coins
if (Math.random() < 0.25) {
storage.coins = Math.floor(storage.coins * 0.1);
updateCoinsUI();
}
}
updateCoinsUI();
}
}
function toggleShop() {
if (isShopOpen) {
// Close shop
tween(shopContainer, {
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
shopContainer.visible = false;
// Show maze, player, and exit assets
mazeContainer.visible = true;
player.visible = true;
exit.visible = true;
}
});
} else {
// Hide maze, player, and exit assets
mazeContainer.visible = false;
player.visible = false;
exit.visible = false;
// Open shop
shopContainer.visible = true;
tween(shopContainer, {
alpha: 1
}, {
duration: 300,
easing: tween.easeOut
});
}
isShopOpen = !isShopOpen;
}
function initUI() {
// Create coin counter
coinText = new Text2("MindCoins: " + storage.coins, {
size: 50,
fill: 0xFFCC00
});
coinText.anchor.set(1, 0);
LK.gui.topRight.addChild(coinText);
// Create level indicator
levelText = new Text2("Level: " + storage.level, {
size: 50,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
LK.gui.top.addChild(levelText);
// Create gamble button
gambleButton = new Button("GAMBLE 5 MC", 350, 120, 0xE74C3C);
gambleButton.x = 2048 - 200;
gambleButton.y = 2732 - 200;
game.addChild(gambleButton);
gambleButton.up = function () {
tween(gambleButton, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeOut
});
gamble();
};
// Create shop button
shopButton = new Button("SHOP", 200, 100, 0x2ECC71);
shopButton.x = 150;
shopButton.y = 2732 - 200;
game.addChild(shopButton);
shopButton.up = function () {
tween(shopButton, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeOut
});
toggleShop();
};
// Create shop container
shopContainer = new Container();
shopContainer.visible = false;
shopContainer.alpha = 0;
game.addChild(shopContainer);
// Shop background
var shopBg = LK.getAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
shopBg.x = 2048 / 2;
shopBg.y = 2732 / 2;
shopContainer.addChild(shopBg);
// Shop title
var shopTitle = new Text2("MIND MAZE SHOP", {
size: 80,
fill: 0xFFFFFF
});
shopTitle.anchor.set(0.5, 0);
shopTitle.x = 2048 / 2;
shopTitle.y = 2732 / 2 - 700;
shopContainer.addChild(shopTitle);
// Shop items
antiRejectionItem = new ShopItem("Anti-Rejection", "Prevent 5 move rejections", 25, storage.antiRejection);
antiRejectionItem.x = 2048 / 2;
antiRejectionItem.y = 2732 / 2 - 400;
shopContainer.addChild(antiRejectionItem);
// Add icon for anti-rejection purchase
var antiRejectionIcon = LK.getAsset('pickaxeIcon', {
anchorX: 0.5,
anchorY: 0.5
});
antiRejectionIcon.x = antiRejectionItem.x - 150;
antiRejectionIcon.y = antiRejectionItem.y;
shopContainer.addChild(antiRejectionIcon);
var slashIcon = LK.getAsset('slashIcon', {
anchorX: 0.5,
anchorY: 0.5
});
slashIcon.x = antiRejectionIcon.x;
slashIcon.y = antiRejectionIcon.y;
shopContainer.addChild(slashIcon);
dreamBoostItem = new ShopItem("Dream Boost", "Double gamble winnings 3 times", 40, storage.dreamBoost);
dreamBoostItem.x = 2048 / 2;
dreamBoostItem.y = 2732 / 2 - 200;
shopContainer.addChild(dreamBoostItem);
// Close shop button
var closeButton = new Button("CLOSE", 200, 80, 0xE74C3C);
closeButton.x = 2048 / 2;
closeButton.y = 2732 / 2 + 200;
shopContainer.addChild(closeButton);
closeButton.up = function () {
tween(closeButton, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeOut
});
toggleShop();
};
// Reset button
var resetButton = new Button("RESET", 200, 80, 0xE74C3C);
resetButton.x = 2048 / 2;
resetButton.y = 250;
game.addChild(resetButton);
resetButton.up = function () {
tween(resetButton, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeOut
});
resetGame();
};
}
function initSwipeControl() {
// Handle swipe gestures for movement
var startX = 0;
var startY = 0;
var isTracking = false;
game.down = function (x, y) {
if (isShopOpen) {
return;
}
startX = x;
startY = y;
isTracking = true;
};
game.up = function (x, y) {
if (isShopOpen || !isTracking) {
return;
}
var dx = x - startX;
var dy = y - startY;
var threshold = 50;
// Determine swipe direction
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > threshold) {
// Horizontal swipe
if (dx > 0) {
movePlayer(1, 0); // Right
lastSwipeDirection = 'right';
} else {
movePlayer(-1, 0); // Left
lastSwipeDirection = 'left';
}
} else if (Math.abs(dy) > Math.abs(dx) && Math.abs(dy) > threshold) {
// Vertical swipe
if (dy > 0) {
movePlayer(0, 1); // Down
lastSwipeDirection = 'down';
} else {
movePlayer(0, -1); // Up
lastSwipeDirection = 'up';
}
}
lastSwipeTime = Date.now();
isTracking = false;
};
}
function initLevel() {
// Generate new level
positions = generateMaze(storage.level);
renderMaze();
// Update UI to reflect new level
updateLevelUI();
updateShopUI();
}
function initGame() {
if (gameInitialized) {
return;
}
LK.playMusic('bgmusic');
initUI();
initSwipeControl();
initLevel();
gameInitialized = true;
}
// Main game loop
game.update = function () {
if (!gameInitialized) {
initGame();
}
// Award coins every 2 seconds (120 ticks)
if (LK.ticks % 120 === 0) {
storage.coins += 1;
updateCoinsUI();
}
// Check if game is in shop mode
if (isShopOpen) {
return; // Skip other updates when shop is open
}
};
// Initialize the game
initGame();