/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { milestones: [] }); /**** * Classes ****/ // On-screen left/right controls for mobile var AsciiButton = Container.expand(function () { var self = Container.call(this); self.txt = self.addChild(new Text2("", { size: 120, fill: 0xFFFFFF, font: "monospace" })); self.txt.anchor.set(0.5, 0.5); self.setLabel = function (label) { self.txt.setText(label); }; return self; }); // ASCII Obstacle var AsciiObstacle = Container.expand(function () { var self = Container.call(this); // Randomly choose an ASCII obstacle shape, now with more funny blocks! var shapes = ["#####", "=====", "-----", "|||||", "oOoOo", // funny bouncy "UwU", // cute face "0v0v0", // zigzag "><(((º>", // fish "LOL", // meme ":-)", // smiley "ZZZZZ", // sleepy "MOO", // cow "BEEP", // robot "!!!", // exclamation "T_T", // sad face "12345", // numbers "abcde" // letters ]; var ascii = shapes[Math.floor(Math.random() * shapes.length)]; var obsText = self.addChild(new Text2(ascii, { size: 90, fill: 0xFF5555, font: "monospace" })); obsText.anchor.set(0.5, 0.5); // For collision, define a bounding box self.getBounds = function () { return { x: self.x - 225, y: self.y - 45, width: 450, height: 90 }; }; // Move down at a variable speed (default 12, can be overridden) self.speed = 12; self.update = function () { if (typeof self.lastY === "undefined") { self.lastY = self.y; } self.y += self.speed; self.lastY = self.y; }; return self; }); // ASCII Player Character var AsciiPlayer = Container.expand(function () { var self = Container.call(this); // ASCII art for the player (simple stick figure) var asciiArt = [" O ", " /|\\ ", " / \\ "].join("\n"); var playerText = self.addChild(new Text2(asciiArt, { size: 90, fill: 0xFFFFFF, font: "monospace" })); playerText.anchor.set(0.5, 0.5); // Cosmetic tag above head (for rewards) self.tagText = self.addChild(new Text2("", { size: 60, fill: 0x00FF99, font: "monospace" })); self.tagText.anchor.set(0.5, 1); self.tagText.x = 0; self.tagText.y = -160; // For collision, define a bounding box self.getBounds = function () { return { x: self.x - 90, y: self.y - 135, width: 180, height: 270 }; }; return self; }); // Power-up: Shield var ShieldPowerup = Container.expand(function () { var self = Container.call(this); var shieldText = self.addChild(new Text2("[SHIELD]", { size: 80, fill: 0x00FFFF, font: "monospace" })); shieldText.anchor.set(0.5, 0.5); self.speed = 10; self.getBounds = function () { return { x: self.x - 120, y: self.y - 40, width: 240, height: 80 }; }; self.update = function () { if (typeof self.lastY === "undefined") self.lastY = self.y; self.y += self.speed; self.lastY = self.y; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181818 }); /**** * Game Code ****/ // Storage for persistent profile/milestones // Tween for possible future use (not used in MVP, but included for extensibility) // Game states var STATE_MENU = 0; var STATE_PLAY = 1; var STATE_PROFILE = 2; var gameState = STATE_MENU; // Main elements var player; var obstacles = []; var powerups = []; // Make powerups globally defined so it is accessible everywhere var score = 0; var bestScore = storage.bestScore || 0; var milestones = storage.milestones || []; var milestoneThresholds = [10, 25, 50, 100, 200, 500, 1000]; // GUI elements var scoreText, bestText, menuTitle, startBtn, profileBtn, profilePanel, profileTitle, profileMilestones, backBtn; var healthText; // Make healthText globally defined so it is accessible everywhere var leftBtn; // Make leftBtn globally defined so it is accessible everywhere var rightBtn; // Make rightBtn globally defined so it is accessible everywhere // Utility: collision detection (AABB) function intersects(a, b) { var ab = a.getBounds(); var bb = b.getBounds(); return ab.x < bb.x + bb.width && ab.x + ab.width > bb.x && ab.y < bb.y + bb.height && ab.y + ab.height > bb.y; } // --- MENU UI --- function showMenu() { gameState = STATE_MENU; clearGame(); clearProfile(); // Title menuTitle = new Text2("ASCII RUNNER", { size: 140, fill: 0xFFFFFF, font: "monospace" }); menuTitle.anchor.set(0.5, 0); menuTitle.x = 2048 / 2; menuTitle.y = 300; game.addChild(menuTitle); // Start Button (always enabled, no username required) startBtn = new Text2("[ START ]", { size: 110, fill: 0x00FF99, font: "monospace" }); startBtn.anchor.set(0.5, 0.5); startBtn.x = 2048 / 2; startBtn.y = 900; startBtn.alpha = 1; startBtn.down = function () { clearMenu(); startGame(); }; game.addChild(startBtn); // Profile Button profileBtn = new Text2("[ PROFILE ]", { size: 90, fill: 0xCCCCCC, font: "monospace" }); profileBtn.anchor.set(0.5, 0.5); profileBtn.x = 2048 / 2; profileBtn.y = 1600; game.addChild(profileBtn); // Best Score bestText = new Text2("Best: " + bestScore, { size: 80, fill: 0xAAAAAA, font: "monospace" }); bestText.anchor.set(0.5, 0.5); bestText.x = 2048 / 2; bestText.y = 1800; game.addChild(bestText); // Button handlers profileBtn.down = function () { showProfile(); }; } // --- PROFILE UI --- function showProfile() { gameState = STATE_PROFILE; clearMenu(); clearGame(); profilePanel = new Container(); // Username at top var uname = typeof username !== "undefined" && username ? username : storage.username || ""; var unameText = new Text2(uname, { size: 90, fill: 0x00FF99, font: "monospace" }); unameText.anchor.set(0.5, 0); unameText.x = 2048 / 2; unameText.y = 180; profilePanel.addChild(unameText); // Title profileTitle = new Text2("PROFILE", { size: 120, fill: 0xFFFFFF, font: "monospace" }); profileTitle.anchor.set(0.5, 0); profileTitle.x = 2048 / 2; profileTitle.y = 300; profilePanel.addChild(profileTitle); // Milestones var milestoneLines = []; for (var i = 0; i < milestoneThresholds.length; i++) { var th = milestoneThresholds[i]; var unlocked = milestones.indexOf(th) !== -1; milestoneLines.push((unlocked ? "[✓] " : "[ ] ") + "Score " + th); } profileMilestones = new Text2(milestoneLines.join("\n"), { size: 90, fill: 0xFFFF99, font: "monospace" }); profileMilestones.anchor.set(0.5, 0); profileMilestones.x = 2048 / 2; profileMilestones.y = 500; profilePanel.addChild(profileMilestones); // Back Button backBtn = new Text2("[ BACK ]", { size: 90, fill: 0x00FF99, font: "monospace" }); backBtn.anchor.set(0.5, 0.5); backBtn.x = 2048 / 2; backBtn.y = 1800; profilePanel.addChild(backBtn); backBtn.down = function () { showMenu(); }; game.addChild(profilePanel); } // --- GAMEPLAY UI --- function startGame() { gameState = STATE_PLAY; clearMenu(); clearProfile(); clearGame(); score = 0; obstacles = []; powerups = []; health = 3; maxHealth = 5; combo = 0; lastCosmetic = -1; cosmeticTags = ["", "★", "ASCII PRO", "RUNNER", "ELITE", "ASCII KING", "GODMODE"]; game._lastShieldScore = -1; // Reset shield drop tracker // Player player = new AsciiPlayer(); player.x = 2048 / 2; player.y = 2200; game.addChild(player); // Cosmetic border container player.borderBox = new Container(); player.addChild(player.borderBox); // Function to update border style player.updateBorder = function (score) { // Remove previous border if (player.borderBox.children.length > 0) { for (var i = 0; i < player.borderBox.children.length; i++) { player.borderBox.children[i].destroy(); } player.borderBox.removeChildren(); } // Choose border style by score var borderStyle = Math.floor(score / 500) % 4; var borderArt = ""; var borderColor = 0xFFFFFF; if (borderStyle === 0) { borderArt = "+-----+\n| |\n| |\n+-----+"; borderColor = 0xAAAAAA; } else if (borderStyle === 1) { borderArt = "☆-----☆\n| |\n| |\n☆-----☆"; borderColor = 0xFFD700; } else if (borderStyle === 2) { borderArt = "🔥-----🔥\n| |\n| |\n🔥-----🔥"; borderColor = 0xFF5500; } else if (borderStyle === 3) { borderArt = "▓▓▓▓▓▓▓\n| |\n| |\n▓▓▓▓▓▓▓"; borderColor = 0x00FFFF; } var borderTxt = new Text2(borderArt, { size: 100, fill: borderColor, font: "monospace" }); borderTxt.anchor.set(0.5, 0.5); borderTxt.x = 0; borderTxt.y = 0; player.borderBox.addChild(borderTxt); }; // Initial border player.updateBorder(0); // Score Text scoreText = new Text2("Score: 0", { size: 100, fill: 0xFFFFFF, font: "monospace" }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Health Stars above player var stars = ""; for (var h = 0; h < health; h++) stars += "★"; healthText = new Text2(stars, { size: 100, fill: 0xFFDD44, // gold/yellow for stars font: "monospace" }); healthText.anchor.set(0.5, 1); healthText.x = 0; healthText.y = -180; player.addChild(healthText); // Cosmetic tag player.tagText.setText(""); // On-screen left/right controls leftBtn = new AsciiButton(); leftBtn.setLabel("<"); leftBtn.x = 200; leftBtn.y = 2600; leftBtn.txt.fill = 0x00FF99; leftBtn.down = function () { if (gameState !== STATE_PLAY) return; player.x = Math.max(90, player.x - 180); }; game.addChild(leftBtn); rightBtn = new AsciiButton(); rightBtn.setLabel(">"); rightBtn.x = 2048 - 200; rightBtn.y = 2600; rightBtn.txt.fill = 0x00FF99; rightBtn.down = function () { if (gameState !== STATE_PLAY) return; player.x = Math.min(2048 - 90, player.x + 180); }; game.addChild(rightBtn); // Move handler: player follows finger/mouse horizontally game.move = function (x, y, obj) { if (gameState !== STATE_PLAY) { return; } // Clamp player within screen var px = Math.max(90, Math.min(2048 - 90, x)); player.x = px; }; // Down handler: also move instantly game.down = function (x, y, obj) { if (gameState !== STATE_PLAY) { return; } var px = Math.max(90, Math.min(2048 - 90, x)); player.x = px; }; // Up handler: not used, but required for drag logic game.up = function (x, y, obj) {}; // Start with a clear obstacle list for (var i = 0; i < obstacles.length; i++) { obstacles[i].destroy(); } obstacles = []; for (var i = 0; i < powerups.length; i++) { powerups[i].destroy(); } powerups = []; } // --- GAME CLEAR HELPERS --- function clearMenu() { if (menuTitle) { menuTitle.destroy(); menuTitle = null; } if (startBtn) { startBtn.destroy(); startBtn = null; } if (profileBtn) { profileBtn.destroy(); profileBtn = null; } if (bestText) { bestText.destroy(); bestText = null; } } if (game._inputCleanup) { game._inputCleanup(); } function clearProfile() { if (profilePanel) { profilePanel.destroy(); profilePanel = null; } } function clearGame() { if (player) { player.destroy(); player = null; } for (var i = 0; i < obstacles.length; i++) { obstacles[i].destroy(); } obstacles = []; if (scoreText) { scoreText.destroy(); scoreText = null; } if (healthText) { healthText.destroy(); healthText = null; } if (leftBtn) { leftBtn.destroy(); leftBtn = null; } if (rightBtn) { rightBtn.destroy(); rightBtn = null; } if (powerups) { for (var i = 0; i < powerups.length; i++) { powerups[i].destroy(); } powerups = []; } game.move = null; game.down = null; game.up = null; } // --- GAME LOOP --- game.update = function () { if (gameState !== STATE_PLAY) { return; } // Dynamic difficulty: speed and spawn rate increase every 100 points var baseSpeed = 12; var baseSpawn = 40; var speedup = Math.floor(score / 100); var currentSpeed = baseSpeed + speedup * 2; var currentSpawn = Math.max(12, baseSpawn - speedup * 5); // Cosmetic tag reward every 100 points var cosmeticIdx = Math.min(Math.floor(score / 100), cosmeticTags.length - 1); if (cosmeticIdx !== lastCosmetic) { player.tagText.setText(cosmeticTags[cosmeticIdx]); lastCosmetic = cosmeticIdx; } // Cosmetic border every 500 score if (player && player.updateBorder) { var borderStyle = Math.floor(score / 500) % 4; if (typeof player._lastBorderStyle === "undefined" || player._lastBorderStyle !== borderStyle) { player.updateBorder(score); player._lastBorderStyle = borderStyle; } } // Unlock new features at milestones (minimal: e.g. new obstacle shapes, color, etc.) var extraShapes = []; if (score >= 200) { extraShapes.push("/////"); } if (score >= 300) { extraShapes.push("\\\\\\\\\\"); } if (score >= 400) { extraShapes.push("#####", "====="); } if (score >= 500) { extraShapes.push("~~~~~"); } if (score >= 1000) { extraShapes.push("*****"); } // --- ASCII ENEMY/DECORATION LOGIC --- // Enemy words that can hurt the player var ENEMY_WORDS = ["LOL", "UwU", "=====", "!!!"]; // Harmless decorations (fun/chaotic) var DECOR_WORDS = ["<3", "⚔", "~*", "★彡", "✿", "☠", "owo", "zzz", "☆", "彡", "♡", "∞", "☀", "☁", "☂", "☃", "☄", "☾", "☽", "☼", "☻", "☺", "♪", "♫", "♬", "♩", "♭", "♯", "♮", "✧", "✪", "✩", "✰", "✶", "✹", "✺", "✻", "✼", "✽", "✾", "✿", "❀", "❁", "❂", "❃", "❄", "❅", "❆", "❇", "❈", "❉", "❊", "❋", "☘", "☾", "☽", "☄", "☀", "☁", "☂", "☃", "☼", "☽", "彡★", "彡☆", "彡✿", "彡♡"]; // All possible shapes for obstacles (enemies + decos) var ALL_ASCII_SHAPES = ["#####", "=====", "-----", "|||||", "oOoOo", "UwU", "0v0v0", "><(((º>", "LOL", ":-)", "ZZZZZ", "MOO", "BEEP", "!!!", "T_T", "12345", "abcde"].concat(extraShapes).concat(ENEMY_WORDS).concat(DECOR_WORDS); // Decide if this spawn is an enemy or a decoration if (LK.ticks % currentSpawn === 0) { var isEnemy = Math.random() < 0.5; // 50% chance for enemy, 50% for deco var ascii; if (isEnemy) { ascii = ENEMY_WORDS[Math.floor(Math.random() * ENEMY_WORDS.length)]; } else { ascii = DECOR_WORDS[Math.floor(Math.random() * DECOR_WORDS.length)]; } var obs = new AsciiObstacle(); // Set the ASCII text if (obs.children[0] && obs.children[0].setText) { obs.children[0].setText(ascii); } obs.x = 200 + Math.floor(Math.random() * (2048 - 400)); obs.y = -60; obs.speed = currentSpeed; // Mark if this is an enemy for collision logic obs.isEnemy = isEnemy; obstacles.push(obs); game.addChild(obs); } // --- SHIELD DROP LOGIC --- // Drop shield exactly at every 100 points (not random, not more than once per 100) if (score > 0 && score % 100 === 0 && game._lastShieldScore !== score) { // Only drop once per 100 points var shield = new ShieldPowerup(); shield.x = 200 + Math.floor(Math.random() * (2048 - 400)); shield.y = -60; shield.speed = Math.max(8, currentSpeed - 2); powerups.push(shield); game.addChild(shield); game._lastShieldScore = score; } // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { var obs = obstacles[i]; obs.update(); // Only process collision if this is an enemy if (obs.isEnemy && intersects(player, obs)) { // Flash screen LK.effects.flashScreen(0xff2222, 800); health -= 1; combo = 0; if (healthText) { var stars = ""; for (var h = 0; h < health; h++) stars += "★"; healthText.setText(stars); } // Remove obstacle obs.destroy(); obstacles.splice(i, 1); // Game over if health depleted if (health <= 0) { // Update best score if (score > bestScore) { bestScore = score; storage.bestScore = bestScore; } // Update milestones for (var m = 0; m < milestoneThresholds.length; m++) { var th = milestoneThresholds[m]; if (score >= th && milestones.indexOf(th) === -1) { milestones.push(th); } } storage.milestones = milestones; // Show game over (handled by LK) LK.showGameOver(); return; } continue; } // Remove if off screen if (obs.y > 2732 + 100) { obs.destroy(); obstacles.splice(i, 1); } } // Update powerups for (var i = powerups.length - 1; i >= 0; i--) { var p = powerups[i]; p.update(); if (intersects(player, p)) { // Collect shield: +1 health (max 5) if (health < maxHealth) { health += 1; var stars = ""; for (var h = 0; h < health; h++) stars += "★"; healthText.setText(stars); } // Flash blue LK.effects.flashScreen(0x00ffff, 400); p.destroy(); powerups.splice(i, 1); continue; } if (p.y > 2732 + 100) { p.destroy(); powerups.splice(i, 1); } } // Score increases with time if (LK.ticks % 6 === 0) { score++; scoreText.setText("Score: " + score); combo++; } }; // --- GAME OVER HANDLER (reset to menu) --- LK.on('gameover', function () { showMenu(); }); // --- INITIALIZE --- showMenu();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
milestones: []
});
/****
* Classes
****/
// On-screen left/right controls for mobile
var AsciiButton = Container.expand(function () {
var self = Container.call(this);
self.txt = self.addChild(new Text2("", {
size: 120,
fill: 0xFFFFFF,
font: "monospace"
}));
self.txt.anchor.set(0.5, 0.5);
self.setLabel = function (label) {
self.txt.setText(label);
};
return self;
});
// ASCII Obstacle
var AsciiObstacle = Container.expand(function () {
var self = Container.call(this);
// Randomly choose an ASCII obstacle shape, now with more funny blocks!
var shapes = ["#####", "=====", "-----", "|||||", "oOoOo",
// funny bouncy
"UwU",
// cute face
"0v0v0",
// zigzag
"><(((º>",
// fish
"LOL",
// meme
":-)",
// smiley
"ZZZZZ",
// sleepy
"MOO",
// cow
"BEEP",
// robot
"!!!",
// exclamation
"T_T",
// sad face
"12345",
// numbers
"abcde" // letters
];
var ascii = shapes[Math.floor(Math.random() * shapes.length)];
var obsText = self.addChild(new Text2(ascii, {
size: 90,
fill: 0xFF5555,
font: "monospace"
}));
obsText.anchor.set(0.5, 0.5);
// For collision, define a bounding box
self.getBounds = function () {
return {
x: self.x - 225,
y: self.y - 45,
width: 450,
height: 90
};
};
// Move down at a variable speed (default 12, can be overridden)
self.speed = 12;
self.update = function () {
if (typeof self.lastY === "undefined") {
self.lastY = self.y;
}
self.y += self.speed;
self.lastY = self.y;
};
return self;
});
// ASCII Player Character
var AsciiPlayer = Container.expand(function () {
var self = Container.call(this);
// ASCII art for the player (simple stick figure)
var asciiArt = [" O ", " /|\\ ", " / \\ "].join("\n");
var playerText = self.addChild(new Text2(asciiArt, {
size: 90,
fill: 0xFFFFFF,
font: "monospace"
}));
playerText.anchor.set(0.5, 0.5);
// Cosmetic tag above head (for rewards)
self.tagText = self.addChild(new Text2("", {
size: 60,
fill: 0x00FF99,
font: "monospace"
}));
self.tagText.anchor.set(0.5, 1);
self.tagText.x = 0;
self.tagText.y = -160;
// For collision, define a bounding box
self.getBounds = function () {
return {
x: self.x - 90,
y: self.y - 135,
width: 180,
height: 270
};
};
return self;
});
// Power-up: Shield
var ShieldPowerup = Container.expand(function () {
var self = Container.call(this);
var shieldText = self.addChild(new Text2("[SHIELD]", {
size: 80,
fill: 0x00FFFF,
font: "monospace"
}));
shieldText.anchor.set(0.5, 0.5);
self.speed = 10;
self.getBounds = function () {
return {
x: self.x - 120,
y: self.y - 40,
width: 240,
height: 80
};
};
self.update = function () {
if (typeof self.lastY === "undefined") self.lastY = self.y;
self.y += self.speed;
self.lastY = self.y;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Storage for persistent profile/milestones
// Tween for possible future use (not used in MVP, but included for extensibility)
// Game states
var STATE_MENU = 0;
var STATE_PLAY = 1;
var STATE_PROFILE = 2;
var gameState = STATE_MENU;
// Main elements
var player;
var obstacles = [];
var powerups = []; // Make powerups globally defined so it is accessible everywhere
var score = 0;
var bestScore = storage.bestScore || 0;
var milestones = storage.milestones || [];
var milestoneThresholds = [10, 25, 50, 100, 200, 500, 1000];
// GUI elements
var scoreText, bestText, menuTitle, startBtn, profileBtn, profilePanel, profileTitle, profileMilestones, backBtn;
var healthText; // Make healthText globally defined so it is accessible everywhere
var leftBtn; // Make leftBtn globally defined so it is accessible everywhere
var rightBtn; // Make rightBtn globally defined so it is accessible everywhere
// Utility: collision detection (AABB)
function intersects(a, b) {
var ab = a.getBounds();
var bb = b.getBounds();
return ab.x < bb.x + bb.width && ab.x + ab.width > bb.x && ab.y < bb.y + bb.height && ab.y + ab.height > bb.y;
}
// --- MENU UI ---
function showMenu() {
gameState = STATE_MENU;
clearGame();
clearProfile();
// Title
menuTitle = new Text2("ASCII RUNNER", {
size: 140,
fill: 0xFFFFFF,
font: "monospace"
});
menuTitle.anchor.set(0.5, 0);
menuTitle.x = 2048 / 2;
menuTitle.y = 300;
game.addChild(menuTitle);
// Start Button (always enabled, no username required)
startBtn = new Text2("[ START ]", {
size: 110,
fill: 0x00FF99,
font: "monospace"
});
startBtn.anchor.set(0.5, 0.5);
startBtn.x = 2048 / 2;
startBtn.y = 900;
startBtn.alpha = 1;
startBtn.down = function () {
clearMenu();
startGame();
};
game.addChild(startBtn);
// Profile Button
profileBtn = new Text2("[ PROFILE ]", {
size: 90,
fill: 0xCCCCCC,
font: "monospace"
});
profileBtn.anchor.set(0.5, 0.5);
profileBtn.x = 2048 / 2;
profileBtn.y = 1600;
game.addChild(profileBtn);
// Best Score
bestText = new Text2("Best: " + bestScore, {
size: 80,
fill: 0xAAAAAA,
font: "monospace"
});
bestText.anchor.set(0.5, 0.5);
bestText.x = 2048 / 2;
bestText.y = 1800;
game.addChild(bestText);
// Button handlers
profileBtn.down = function () {
showProfile();
};
}
// --- PROFILE UI ---
function showProfile() {
gameState = STATE_PROFILE;
clearMenu();
clearGame();
profilePanel = new Container();
// Username at top
var uname = typeof username !== "undefined" && username ? username : storage.username || "";
var unameText = new Text2(uname, {
size: 90,
fill: 0x00FF99,
font: "monospace"
});
unameText.anchor.set(0.5, 0);
unameText.x = 2048 / 2;
unameText.y = 180;
profilePanel.addChild(unameText);
// Title
profileTitle = new Text2("PROFILE", {
size: 120,
fill: 0xFFFFFF,
font: "monospace"
});
profileTitle.anchor.set(0.5, 0);
profileTitle.x = 2048 / 2;
profileTitle.y = 300;
profilePanel.addChild(profileTitle);
// Milestones
var milestoneLines = [];
for (var i = 0; i < milestoneThresholds.length; i++) {
var th = milestoneThresholds[i];
var unlocked = milestones.indexOf(th) !== -1;
milestoneLines.push((unlocked ? "[✓] " : "[ ] ") + "Score " + th);
}
profileMilestones = new Text2(milestoneLines.join("\n"), {
size: 90,
fill: 0xFFFF99,
font: "monospace"
});
profileMilestones.anchor.set(0.5, 0);
profileMilestones.x = 2048 / 2;
profileMilestones.y = 500;
profilePanel.addChild(profileMilestones);
// Back Button
backBtn = new Text2("[ BACK ]", {
size: 90,
fill: 0x00FF99,
font: "monospace"
});
backBtn.anchor.set(0.5, 0.5);
backBtn.x = 2048 / 2;
backBtn.y = 1800;
profilePanel.addChild(backBtn);
backBtn.down = function () {
showMenu();
};
game.addChild(profilePanel);
}
// --- GAMEPLAY UI ---
function startGame() {
gameState = STATE_PLAY;
clearMenu();
clearProfile();
clearGame();
score = 0;
obstacles = [];
powerups = [];
health = 3;
maxHealth = 5;
combo = 0;
lastCosmetic = -1;
cosmeticTags = ["", "★", "ASCII PRO", "RUNNER", "ELITE", "ASCII KING", "GODMODE"];
game._lastShieldScore = -1; // Reset shield drop tracker
// Player
player = new AsciiPlayer();
player.x = 2048 / 2;
player.y = 2200;
game.addChild(player);
// Cosmetic border container
player.borderBox = new Container();
player.addChild(player.borderBox);
// Function to update border style
player.updateBorder = function (score) {
// Remove previous border
if (player.borderBox.children.length > 0) {
for (var i = 0; i < player.borderBox.children.length; i++) {
player.borderBox.children[i].destroy();
}
player.borderBox.removeChildren();
}
// Choose border style by score
var borderStyle = Math.floor(score / 500) % 4;
var borderArt = "";
var borderColor = 0xFFFFFF;
if (borderStyle === 0) {
borderArt = "+-----+\n| |\n| |\n+-----+";
borderColor = 0xAAAAAA;
} else if (borderStyle === 1) {
borderArt = "☆-----☆\n| |\n| |\n☆-----☆";
borderColor = 0xFFD700;
} else if (borderStyle === 2) {
borderArt = "🔥-----🔥\n| |\n| |\n🔥-----🔥";
borderColor = 0xFF5500;
} else if (borderStyle === 3) {
borderArt = "▓▓▓▓▓▓▓\n| |\n| |\n▓▓▓▓▓▓▓";
borderColor = 0x00FFFF;
}
var borderTxt = new Text2(borderArt, {
size: 100,
fill: borderColor,
font: "monospace"
});
borderTxt.anchor.set(0.5, 0.5);
borderTxt.x = 0;
borderTxt.y = 0;
player.borderBox.addChild(borderTxt);
};
// Initial border
player.updateBorder(0);
// Score Text
scoreText = new Text2("Score: 0", {
size: 100,
fill: 0xFFFFFF,
font: "monospace"
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Health Stars above player
var stars = "";
for (var h = 0; h < health; h++) stars += "★";
healthText = new Text2(stars, {
size: 100,
fill: 0xFFDD44,
// gold/yellow for stars
font: "monospace"
});
healthText.anchor.set(0.5, 1);
healthText.x = 0;
healthText.y = -180;
player.addChild(healthText);
// Cosmetic tag
player.tagText.setText("");
// On-screen left/right controls
leftBtn = new AsciiButton();
leftBtn.setLabel("<");
leftBtn.x = 200;
leftBtn.y = 2600;
leftBtn.txt.fill = 0x00FF99;
leftBtn.down = function () {
if (gameState !== STATE_PLAY) return;
player.x = Math.max(90, player.x - 180);
};
game.addChild(leftBtn);
rightBtn = new AsciiButton();
rightBtn.setLabel(">");
rightBtn.x = 2048 - 200;
rightBtn.y = 2600;
rightBtn.txt.fill = 0x00FF99;
rightBtn.down = function () {
if (gameState !== STATE_PLAY) return;
player.x = Math.min(2048 - 90, player.x + 180);
};
game.addChild(rightBtn);
// Move handler: player follows finger/mouse horizontally
game.move = function (x, y, obj) {
if (gameState !== STATE_PLAY) {
return;
}
// Clamp player within screen
var px = Math.max(90, Math.min(2048 - 90, x));
player.x = px;
};
// Down handler: also move instantly
game.down = function (x, y, obj) {
if (gameState !== STATE_PLAY) {
return;
}
var px = Math.max(90, Math.min(2048 - 90, x));
player.x = px;
};
// Up handler: not used, but required for drag logic
game.up = function (x, y, obj) {};
// Start with a clear obstacle list
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
for (var i = 0; i < powerups.length; i++) {
powerups[i].destroy();
}
powerups = [];
}
// --- GAME CLEAR HELPERS ---
function clearMenu() {
if (menuTitle) {
menuTitle.destroy();
menuTitle = null;
}
if (startBtn) {
startBtn.destroy();
startBtn = null;
}
if (profileBtn) {
profileBtn.destroy();
profileBtn = null;
}
if (bestText) {
bestText.destroy();
bestText = null;
}
}
if (game._inputCleanup) {
game._inputCleanup();
}
function clearProfile() {
if (profilePanel) {
profilePanel.destroy();
profilePanel = null;
}
}
function clearGame() {
if (player) {
player.destroy();
player = null;
}
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
if (scoreText) {
scoreText.destroy();
scoreText = null;
}
if (healthText) {
healthText.destroy();
healthText = null;
}
if (leftBtn) {
leftBtn.destroy();
leftBtn = null;
}
if (rightBtn) {
rightBtn.destroy();
rightBtn = null;
}
if (powerups) {
for (var i = 0; i < powerups.length; i++) {
powerups[i].destroy();
}
powerups = [];
}
game.move = null;
game.down = null;
game.up = null;
}
// --- GAME LOOP ---
game.update = function () {
if (gameState !== STATE_PLAY) {
return;
}
// Dynamic difficulty: speed and spawn rate increase every 100 points
var baseSpeed = 12;
var baseSpawn = 40;
var speedup = Math.floor(score / 100);
var currentSpeed = baseSpeed + speedup * 2;
var currentSpawn = Math.max(12, baseSpawn - speedup * 5);
// Cosmetic tag reward every 100 points
var cosmeticIdx = Math.min(Math.floor(score / 100), cosmeticTags.length - 1);
if (cosmeticIdx !== lastCosmetic) {
player.tagText.setText(cosmeticTags[cosmeticIdx]);
lastCosmetic = cosmeticIdx;
}
// Cosmetic border every 500 score
if (player && player.updateBorder) {
var borderStyle = Math.floor(score / 500) % 4;
if (typeof player._lastBorderStyle === "undefined" || player._lastBorderStyle !== borderStyle) {
player.updateBorder(score);
player._lastBorderStyle = borderStyle;
}
}
// Unlock new features at milestones (minimal: e.g. new obstacle shapes, color, etc.)
var extraShapes = [];
if (score >= 200) {
extraShapes.push("/////");
}
if (score >= 300) {
extraShapes.push("\\\\\\\\\\");
}
if (score >= 400) {
extraShapes.push("#####", "=====");
}
if (score >= 500) {
extraShapes.push("~~~~~");
}
if (score >= 1000) {
extraShapes.push("*****");
}
// --- ASCII ENEMY/DECORATION LOGIC ---
// Enemy words that can hurt the player
var ENEMY_WORDS = ["LOL", "UwU", "=====", "!!!"];
// Harmless decorations (fun/chaotic)
var DECOR_WORDS = ["<3", "⚔", "~*", "★彡", "✿", "☠", "owo", "zzz", "☆", "彡", "♡", "∞", "☀", "☁", "☂", "☃", "☄", "☾", "☽", "☼", "☻", "☺", "♪", "♫", "♬", "♩", "♭", "♯", "♮", "✧", "✪", "✩", "✰", "✶", "✹", "✺", "✻", "✼", "✽", "✾", "✿", "❀", "❁", "❂", "❃", "❄", "❅", "❆", "❇", "❈", "❉", "❊", "❋", "☘", "☾", "☽", "☄", "☀", "☁", "☂", "☃", "☼", "☽", "彡★", "彡☆", "彡✿", "彡♡"];
// All possible shapes for obstacles (enemies + decos)
var ALL_ASCII_SHAPES = ["#####", "=====", "-----", "|||||", "oOoOo", "UwU", "0v0v0", "><(((º>", "LOL", ":-)", "ZZZZZ", "MOO", "BEEP", "!!!", "T_T", "12345", "abcde"].concat(extraShapes).concat(ENEMY_WORDS).concat(DECOR_WORDS);
// Decide if this spawn is an enemy or a decoration
if (LK.ticks % currentSpawn === 0) {
var isEnemy = Math.random() < 0.5; // 50% chance for enemy, 50% for deco
var ascii;
if (isEnemy) {
ascii = ENEMY_WORDS[Math.floor(Math.random() * ENEMY_WORDS.length)];
} else {
ascii = DECOR_WORDS[Math.floor(Math.random() * DECOR_WORDS.length)];
}
var obs = new AsciiObstacle();
// Set the ASCII text
if (obs.children[0] && obs.children[0].setText) {
obs.children[0].setText(ascii);
}
obs.x = 200 + Math.floor(Math.random() * (2048 - 400));
obs.y = -60;
obs.speed = currentSpeed;
// Mark if this is an enemy for collision logic
obs.isEnemy = isEnemy;
obstacles.push(obs);
game.addChild(obs);
}
// --- SHIELD DROP LOGIC ---
// Drop shield exactly at every 100 points (not random, not more than once per 100)
if (score > 0 && score % 100 === 0 && game._lastShieldScore !== score) {
// Only drop once per 100 points
var shield = new ShieldPowerup();
shield.x = 200 + Math.floor(Math.random() * (2048 - 400));
shield.y = -60;
shield.speed = Math.max(8, currentSpeed - 2);
powerups.push(shield);
game.addChild(shield);
game._lastShieldScore = score;
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obs = obstacles[i];
obs.update();
// Only process collision if this is an enemy
if (obs.isEnemy && intersects(player, obs)) {
// Flash screen
LK.effects.flashScreen(0xff2222, 800);
health -= 1;
combo = 0;
if (healthText) {
var stars = "";
for (var h = 0; h < health; h++) stars += "★";
healthText.setText(stars);
}
// Remove obstacle
obs.destroy();
obstacles.splice(i, 1);
// Game over if health depleted
if (health <= 0) {
// Update best score
if (score > bestScore) {
bestScore = score;
storage.bestScore = bestScore;
}
// Update milestones
for (var m = 0; m < milestoneThresholds.length; m++) {
var th = milestoneThresholds[m];
if (score >= th && milestones.indexOf(th) === -1) {
milestones.push(th);
}
}
storage.milestones = milestones;
// Show game over (handled by LK)
LK.showGameOver();
return;
}
continue;
}
// Remove if off screen
if (obs.y > 2732 + 100) {
obs.destroy();
obstacles.splice(i, 1);
}
}
// Update powerups
for (var i = powerups.length - 1; i >= 0; i--) {
var p = powerups[i];
p.update();
if (intersects(player, p)) {
// Collect shield: +1 health (max 5)
if (health < maxHealth) {
health += 1;
var stars = "";
for (var h = 0; h < health; h++) stars += "★";
healthText.setText(stars);
}
// Flash blue
LK.effects.flashScreen(0x00ffff, 400);
p.destroy();
powerups.splice(i, 1);
continue;
}
if (p.y > 2732 + 100) {
p.destroy();
powerups.splice(i, 1);
}
}
// Score increases with time
if (LK.ticks % 6 === 0) {
score++;
scoreText.setText("Score: " + score);
combo++;
}
};
// --- GAME OVER HANDLER (reset to menu) ---
LK.on('gameover', function () {
showMenu();
});
// --- INITIALIZE ---
showMenu();