User prompt
Make the buttons pressable.
User prompt
When you click normal mode, it takes you on to the game from before.
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'toLocal')' in or related to this line: 'var local = mainMenuOverlay.toLocal({' Line Number: 358
User prompt
When you click normal mode it takes you on to the game from before But when you click super hard mode and then I make a new level with completely different
User prompt
Add a kind of main menu screen where it has two options, normal mode and super hard mode.
User prompt
Add Upgraded Gun Into Game
User prompt
Remove the main menu screen.
User prompt
scale it to there, and you know what, just fix the main menu screen because that's what's doing it, I think.
User prompt
The error is still there, it says, read properties of null, reading invincible.
User prompt
It's still there.
User prompt
Please fix the error.
User prompt
There's a bug. Can you fix it? It's error L505.
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'invincible')' in or related to this line: 'if (!minecart.invincible && e.intersects(minecart)) {' Line Number: 505
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'knife')' in or related to this line: 'if (minecart && !(minecart.knife && minecart.knife.visible)) {' Line Number: 584
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'knife')' in or related to this line: 'if (!(minecart.knife && minecart.knife.visible)) {' Line Number: 584
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'invincible')' in or related to this line: 'if (minecart.invincible) {' Line Number: 444
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'attackCooldown')' in or related to this line: 'if (minecart.attackCooldown > 0) {' Line Number: 440
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'setText')' in or related to this line: 'scoreTxt.setText('0');' Line Number: 855
User prompt
Add a main menu screen that has the name Bone Shaft Mayhem.
User prompt
Make a ginger enemy
User prompt
The jumpscare will be just, um, like, the face just jumping at you.
User prompt
Make a jump scare when the bat kills you.
User prompt
Make the back still very hard to find.
User prompt
Make them spawn sometimes at random times, like any random time the bat will spawn.
User prompt
make the bat really hard to find and it does not spawn every run so it like spawns every 10th or 3rd run
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Bullet var Bullet = Container.expand(function () { var self = Container.call(this); var bullet = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.width = bullet.width; self.height = bullet.height; self.speed = -36; // Upwards self.update = function () { self.y += self.speed; }; return self; }); // Enemy base class var Enemy = Container.expand(function () { var self = Container.call(this); self.type = 'enemy'; self.hp = 1; self.speed = 8; self.scoreValue = 1; self.update = function () {}; return self; }); // Skeleton enemy var Skeleton = Enemy.expand(function () { var self = Enemy.call(this); var skeleton = self.attachAsset('enemy_skeleton', { anchorX: 0.5, anchorY: 0.5 }); // Make skeleton bigger skeleton.scaleX = 1.7; skeleton.scaleY = 1.7; self.width = skeleton.width * 1.7; self.height = skeleton.height * 1.7; self.hp = 1; // Make skeleton slower self.speed = 6 + Math.random() * 2.5; self.scoreValue = 2; self.update = function () { self.y += self.speed; }; return self; }); // Goblin enemy var Goblin = Enemy.expand(function () { var self = Enemy.call(this); var goblin = self.attachAsset('enemy_goblin', { anchorX: 0.5, anchorY: 0.5 }); // Make goblin bigger goblin.scaleX = 1.7; goblin.scaleY = 1.7; self.width = goblin.width * 1.7; self.height = goblin.height * 1.7; self.hp = 2; // Make goblin slower self.speed = 5 + Math.random() * 2; self.scoreValue = 3; self.update = function () { self.y += self.speed; }; return self; }); // Bat enemy var Bat = Enemy.expand(function () { var self = Enemy.call(this); var bat = self.attachAsset('enemy_bat', { anchorX: 0.5, anchorY: 0.5 }); // Make bat much bigger so it stands out bat.scaleX = 3.5; bat.scaleY = 3.5; self.width = bat.width * 3.5; self.height = bat.height * 3.5; // Make bat very hard to kill self.hp = 30; // Make bat slower self.speed = 7 + Math.random() * 2.5; // Bat is worth 1000 coins self.scoreValue = 1000; self.update = function () { self.y += self.speed; self.x += Math.sin(LK.ticks / 12 + self._batWobble) * 8; }; self._batWobble = Math.random() * Math.PI * 2; return self; }); // Player Minecart var Minecart = Container.expand(function () { var self = Container.call(this); var cart = self.attachAsset('minecart', { anchorX: 0.5, anchorY: 0.5 }); self.width = cart.width; self.height = cart.height; self.weapon = 'gun'; // 'gun' or 'knife' self.weaponLevel = 1; // Upgrades increase this self.invincible = false; self.invincibleTimer = 0; self.attackCooldown = 0; self.knifeSwinging = false; self.knife = null; // Flash minecart when hit self.flash = function () { self.invincible = true; self.invincibleTimer = 60; // 1 second at 60fps tween(self, { alpha: 0.5 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100 }); } }); }; // Switch weapon self.setWeapon = function (type) { self.weapon = type; }; // Upgrade weapon self.upgradeWeapon = function () { self.weaponLevel += 1; if (self.weaponLevel > 3) self.weaponLevel = 3; }; // Knife attack animation self.swingKnife = function () { if (self.knifeSwinging) return; self.knifeSwinging = true; if (!self.knife) { self.knife = self.attachAsset('knife', { anchorX: 0.1, anchorY: 0.5, x: self.width / 2 + 20, y: 0, rotation: 0 }); } self.knife.visible = true; self.knife.rotation = -0.7; tween(self.knife, { rotation: 0.7 }, { duration: 180, easing: tween.cubicOut, onFinish: function onFinish() { self.knife.visible = false; self.knifeSwinging = false; self.knife.rotation = -0.7; } }); }; return self; }); // Obstacle (rock) var Obstacle = Container.expand(function () { var self = Container.call(this); var rock = self.attachAsset('obstacle_rock', { anchorX: 0.5, anchorY: 0.5 }); self.width = rock.width; self.height = rock.height; self.speed = 14 + Math.random() * 6; self.update = function () { self.y += self.speed; }; return self; }); // Upgrade (gun or knife) var Upgrade = Container.expand(function () { var self = Container.call(this); self.kind = Math.random() < 0.5 ? 'gun' : 'knife'; var assetId = self.kind === 'gun' ? 'upgrade_gun' : 'upgrade_knife'; var upg = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.width = upg.width; self.height = upg.height; self.speed = 10 + Math.random() * 4; self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181818 }); /**** * Game Code ****/ // Maze background image (replace with your maze image asset id) // Upgrade: Knife // Upgrade: Gun // Obstacle: Rock // Enemy: Skeleton // Enemy: Goblin // Enemy: Bat // Player's bullet // Player's knife // Minecart (player) // Game constants var GAME_W = 2048; var GAME_H = 2732; var TRACK_LEFT = 300; var TRACK_RIGHT = GAME_W - 300; var PLAYER_Y = GAME_H - 350; // Game state var minecart = null; var bullets = []; var enemies = []; var obstacles = []; var upgrades = []; var dragNode = null; var lastTouchX = 0; var lastTouchY = 0; var scoreTxt = null; var lastScore = 0; var gameOver = false; var spawnTimer = 0; var obstacleTimer = 0; var upgradeTimer = 0; var difficulty = 1; var knifeHitEnemies = []; var lastKnifeSwingTick = -100; // Add maze background image var mazeBg = LK.getAsset('maze_bg', { anchorX: 0, anchorY: 0, x: 0, y: 0, width: GAME_W, height: GAME_H }); game.addChild(mazeBg); // Score display scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create player minecart = new Minecart(); game.addChild(minecart); minecart.x = GAME_W / 2; minecart.y = PLAYER_Y; // Vertical shooter: drag minecart only in X, fixed Y game.down = function (x, y, obj) { if (gameOver) return; dragNode = minecart; lastTouchX = x; lastTouchY = y; }; game.up = function (x, y, obj) { dragNode = null; }; game.move = function (x, y, obj) { if (gameOver) return; if (dragNode === minecart) { // Only allow movement in X, clamp to track var nx = x; if (nx < TRACK_LEFT) nx = TRACK_LEFT; if (nx > TRACK_RIGHT) nx = TRACK_RIGHT; minecart.x = nx; minecart.y = PLAYER_Y; } }; // Tap to attack (shoot or knife) game.tap = function (x, y, obj) { if (gameOver) return; if (minecart.weapon === 'gun') { if (minecart.attackCooldown <= 0) { fireBullet(); minecart.attackCooldown = 12 - minecart.weaponLevel * 2; // Faster with upgrades if (minecart.attackCooldown < 4) minecart.attackCooldown = 4; } } else if (minecart.weapon === 'knife') { if (LK.ticks - lastKnifeSwingTick > 18) { minecart.swingKnife(); lastKnifeSwingTick = LK.ticks; } } }; // Fire bullet(s) function fireBullet() { var spread = minecart.weaponLevel; for (var i = 0; i < spread; ++i) { var b = new Bullet(); b.x = minecart.x + (i - (spread - 1) / 2) * 40; b.y = minecart.y - minecart.height / 2 - 10; bullets.push(b); game.addChild(b); } } // Main update loop game.update = function () { if (gameOver) return; // Difficulty scaling if (LK.ticks % 300 === 0 && difficulty < 10) { difficulty += 1; } // Attack cooldown if (minecart.attackCooldown > 0) minecart.attackCooldown -= 1; // Invincibility timer if (minecart.invincible) { minecart.invincibleTimer -= 1; if (minecart.invincibleTimer <= 0) { minecart.invincible = false; } } // Bullets update for (var i = bullets.length - 1; i >= 0; --i) { var b = bullets[i]; b.update(); if (b.y < -50) { b.destroy(); bullets.splice(i, 1); continue; } // Bullet hits enemy for (var j = enemies.length - 1; j >= 0; --j) { var e = enemies[j]; if (b.intersects(e)) { e.hp -= 1; // If this is the Bat, update health bar if (game._batEnemy && e === game._batEnemy && game._batHealthBar) { var percent = Math.max(0, e.hp) / game._batMaxHp; // Clamp width to minimum 0 game._batHealthBar.width = 1680 * percent; // Optionally, you can tint the bar as it gets low (not required) } b.destroy(); bullets.splice(i, 1); if (e.hp <= 0) { addScore(e.scoreValue); e.destroy(); enemies.splice(j, 1); // If Bat is dead, remove health bar UI if (game._batEnemy && e === game._batEnemy) { if (game._batHealthBarBg) { LK.gui.top.removeChild(game._batHealthBarBg); game._batHealthBarBg = null; } if (game._batHealthBar) { LK.gui.top.removeChild(game._batHealthBar); game._batHealthBar = null; } game._batEnemy = null; } } break; } } } // Enemies update (vertical shooter: always visible, move down) for (var i = enemies.length - 1; i >= 0; --i) { var e = enemies[i]; e.update(); // Remove if out of bounds if (e.y > GAME_H + 200) { e.destroy(); enemies.splice(i, 1); continue; } // Enemy hits minecart if (!minecart.invincible && e.intersects(minecart)) { minecart.flash(); LK.effects.flashScreen(0xff0000, 600); // End game LK.showGameOver(); gameOver = true; return; } // Enemy hit by knife if (minecart.weapon === 'knife' && minecart.knife && minecart.knife.visible && !knifeHitEnemies.includes(e)) { // Knife is in swing, check collision var knifeGlobal = minecart.toGlobal(minecart.knife.position); var knifeRect = new Rectangle(knifeGlobal.x - 30, knifeGlobal.y - 12, 60, 24); var enemyRect = new Rectangle(e.x - e.width / 2, e.y - e.height / 2, e.width, e.height); if (rectsIntersect(knifeRect, enemyRect)) { e.hp -= 1; // If this is the Bat, update health bar if (game._batEnemy && e === game._batEnemy && game._batHealthBar) { var percent = Math.max(0, e.hp) / game._batMaxHp; game._batHealthBar.width = 1680 * percent; } knifeHitEnemies.push(e); if (e.hp <= 0) { addScore(e.scoreValue); e.destroy(); enemies.splice(i, 1); // If Bat is dead, remove health bar UI if (game._batEnemy && e === game._batEnemy) { if (game._batHealthBarBg) { LK.gui.top.removeChild(game._batHealthBarBg); game._batHealthBarBg = null; } if (game._batHealthBar) { LK.gui.top.removeChild(game._batHealthBar); game._batHealthBar = null; } game._batEnemy = null; } } } } } // Reset knife hit list if knife not swinging if (!(minecart.knife && minecart.knife.visible)) { knifeHitEnemies = []; } // Obstacles update for (var i = obstacles.length - 1; i >= 0; --i) { var o = obstacles[i]; o.update(); if (o.y > GAME_H + 100) { o.destroy(); obstacles.splice(i, 1); continue; } // Obstacle hits minecart if (!minecart.invincible && o.intersects(minecart)) { minecart.flash(); LK.effects.flashScreen(0xff0000, 600); LK.showGameOver(); gameOver = true; return; } } // Upgrades update for (var i = upgrades.length - 1; i >= 0; --i) { var u = upgrades[i]; u.update(); if (u.y > GAME_H + 100) { u.destroy(); upgrades.splice(i, 1); continue; } // Pickup if (u.intersects(minecart)) { if (u.kind === 'gun') { minecart.setWeapon('gun'); minecart.upgradeWeapon(); } else { minecart.setWeapon('knife'); minecart.upgradeWeapon(); } u.destroy(); upgrades.splice(i, 1); } } // Spawning enemies spawnTimer -= 1; if (spawnTimer <= 0) { spawnEnemy(); spawnTimer = Math.max(24, 60 - difficulty * 4 - Math.floor(Math.random() * 10)); } // Spawning obstacles obstacleTimer -= 1; if (obstacleTimer <= 0) { if (Math.random() < 0.5 + difficulty * 0.04) { spawnObstacle(); } obstacleTimer = 90 + Math.floor(Math.random() * 60) - difficulty * 4; if (obstacleTimer < 30) obstacleTimer = 30; } // Spawning upgrades upgradeTimer -= 1; if (upgradeTimer <= 0) { if (Math.random() < 0.18) { spawnUpgrade(); } upgradeTimer = 600 + Math.floor(Math.random() * 300); } // Update score display if (LK.getScore() !== lastScore) { scoreTxt.setText(LK.getScore()); lastScore = LK.getScore(); } }; // Spawn enemy at random X at the top (vertical shooter style) function spawnEnemy() { var enemyType = Math.random(); var e = null; // Only allow Bat to spawn every 3rd or 10th run, otherwise never spawn Bat var allowBat = false; if (game._runCount && (game._runCount % 10 === 0 || game._runCount % 3 === 0)) { allowBat = true; } // Only spawn Bat if allowed this run and random chance, otherwise pick Goblin or Skeleton if (allowBat && enemyType < 0.3) { e = new Bat(); // Show warning text and play creepy music when Bat spawns if (!game._batWarningText) { // Create warning text if not already present var batWarning = new Text2("That is not you.", { size: 120, fill: 0xFF2222, font: "Impact, Arial Black, Tahoma" }); batWarning.anchor.set(0.5, 0.5); batWarning.alpha = 0.0; game._batWarningText = batWarning; // Add to LK.gui.center for true center of screen LK.gui.center.addChild(batWarning); } // Fade in text var warningText = game._batWarningText; warningText.alpha = 0.0; tween(warningText, { alpha: 1 }, { duration: 400, onFinish: function onFinish() { // Fade out after 1.2s tween(warningText, { alpha: 0 }, { duration: 800, delay: 1200 }); } }); // Play creepy music (music asset id: 'creepy_bat') LK.playMusic('creepy_bat', { fade: { start: 0, end: 1, duration: 800 } }); // --- Bat Health Bar UI --- // Remove any previous bat health bar if (game._batHealthBarBg) { LK.gui.top.removeChild(game._batHealthBarBg); game._batHealthBarBg = null; } if (game._batHealthBar) { LK.gui.top.removeChild(game._batHealthBar); game._batHealthBar = null; } // Create background bar (much bigger, at the very top) var barWidth = 1700; var barHeight = 90; var barBg = LK.getAsset('enemy_goblin', { width: barWidth, height: barHeight, color: 0x222222, anchorX: 0.5, anchorY: 0 }); barBg.x = GAME_W / 2; barBg.y = 10; // Very top of the screen // Create health bar (red, much bigger) var bar = LK.getAsset('enemy_goblin', { width: barWidth - 20, height: barHeight - 18, color: 0xff2222, anchorX: 0.5, anchorY: 0 }); bar.x = GAME_W / 2; bar.y = 19; // Just below the background bar // Add to GUI LK.gui.top.addChild(barBg); LK.gui.top.addChild(bar); game._batHealthBarBg = barBg; game._batHealthBar = bar; // Store reference to the Bat instance for health bar updates game._batEnemy = e; game._batMaxHp = e.hp; } else if (enemyType < 0.65 || !allowBat) { e = new Goblin(); } else { e = new Skeleton(); } // Spawn at random X at the top of the screen e.x = TRACK_LEFT + 80 + Math.random() * (TRACK_RIGHT - TRACK_LEFT - 160); e.y = -80; enemies.push(e); game.addChild(e); } // Spawn obstacle function spawnObstacle() { var o = new Obstacle(); o.x = TRACK_LEFT + 80 + Math.random() * (TRACK_RIGHT - TRACK_LEFT - 160); o.y = -60; obstacles.push(o); game.addChild(o); } // Spawn upgrade function spawnUpgrade() { var u = new Upgrade(); u.x = TRACK_LEFT + 80 + Math.random() * (TRACK_RIGHT - TRACK_LEFT - 160); u.y = -60; upgrades.push(u); game.addChild(u); } // Add score function addScore(val) { LK.setScore(LK.getScore() + val); } // Rectangle intersection helper function rectsIntersect(r1, r2) { return !(r2.x > r1.x + r1.width || r2.x + r2.width < r1.x || r2.y > r1.y + r1.height || r2.y + r2.height < r1.y); } // Touch to attack (simulate tap on mobile) game.down = function (origDown) { return function (x, y, obj) { if (origDown) origDown(x, y, obj); game.tap(x, y, obj); }; }(game.down); // Reset game state on game over LK.on('gameover', function () { gameOver = true; }); // Track run count for Bat spawn logic if (typeof game._runCount === "undefined") { game._runCount = 0; } LK.on('newgame', function () { game._runCount = (game._runCount || 0) + 1; gameOver = false; LK.setScore(0); scoreTxt.setText('0'); // Remove all objects for (var i = 0; i < bullets.length; ++i) bullets[i].destroy(); for (var i = 0; i < enemies.length; ++i) enemies[i].destroy(); for (var i = 0; i < obstacles.length; ++i) obstacles[i].destroy(); for (var i = 0; i < upgrades.length; ++i) upgrades[i].destroy(); bullets = []; enemies = []; obstacles = []; upgrades = []; minecart.x = GAME_W / 2; minecart.y = PLAYER_Y; minecart.weapon = 'gun'; minecart.weaponLevel = 1; minecart.invincible = false; minecart.invincibleTimer = 0; minecart.attackCooldown = 0; minecart.knifeSwinging = false; minecart.setWeapon('gun'); difficulty = 1; spawnTimer = 0; obstacleTimer = 0; upgradeTimer = 0; knifeHitEnemies = []; lastKnifeSwingTick = -100; // Remove Bat health bar UI if present if (game._batHealthBarBg) { LK.gui.top.removeChild(game._batHealthBarBg); game._batHealthBarBg = null; } if (game._batHealthBar) { LK.gui.top.removeChild(game._batHealthBar); game._batHealthBar = null; } game._batEnemy = null; game._batMaxHp = null; }); // Initial state spawnTimer = 0; obstacleTimer = 60; upgradeTimer = 600; difficulty = 1; gameOver = false; LK.setScore(0); scoreTxt.setText('0');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Bullet
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bullet = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bullet.width;
self.height = bullet.height;
self.speed = -36; // Upwards
self.update = function () {
self.y += self.speed;
};
return self;
});
// Enemy base class
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.type = 'enemy';
self.hp = 1;
self.speed = 8;
self.scoreValue = 1;
self.update = function () {};
return self;
});
// Skeleton enemy
var Skeleton = Enemy.expand(function () {
var self = Enemy.call(this);
var skeleton = self.attachAsset('enemy_skeleton', {
anchorX: 0.5,
anchorY: 0.5
});
// Make skeleton bigger
skeleton.scaleX = 1.7;
skeleton.scaleY = 1.7;
self.width = skeleton.width * 1.7;
self.height = skeleton.height * 1.7;
self.hp = 1;
// Make skeleton slower
self.speed = 6 + Math.random() * 2.5;
self.scoreValue = 2;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Goblin enemy
var Goblin = Enemy.expand(function () {
var self = Enemy.call(this);
var goblin = self.attachAsset('enemy_goblin', {
anchorX: 0.5,
anchorY: 0.5
});
// Make goblin bigger
goblin.scaleX = 1.7;
goblin.scaleY = 1.7;
self.width = goblin.width * 1.7;
self.height = goblin.height * 1.7;
self.hp = 2;
// Make goblin slower
self.speed = 5 + Math.random() * 2;
self.scoreValue = 3;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Bat enemy
var Bat = Enemy.expand(function () {
var self = Enemy.call(this);
var bat = self.attachAsset('enemy_bat', {
anchorX: 0.5,
anchorY: 0.5
});
// Make bat much bigger so it stands out
bat.scaleX = 3.5;
bat.scaleY = 3.5;
self.width = bat.width * 3.5;
self.height = bat.height * 3.5;
// Make bat very hard to kill
self.hp = 30;
// Make bat slower
self.speed = 7 + Math.random() * 2.5;
// Bat is worth 1000 coins
self.scoreValue = 1000;
self.update = function () {
self.y += self.speed;
self.x += Math.sin(LK.ticks / 12 + self._batWobble) * 8;
};
self._batWobble = Math.random() * Math.PI * 2;
return self;
});
// Player Minecart
var Minecart = Container.expand(function () {
var self = Container.call(this);
var cart = self.attachAsset('minecart', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = cart.width;
self.height = cart.height;
self.weapon = 'gun'; // 'gun' or 'knife'
self.weaponLevel = 1; // Upgrades increase this
self.invincible = false;
self.invincibleTimer = 0;
self.attackCooldown = 0;
self.knifeSwinging = false;
self.knife = null;
// Flash minecart when hit
self.flash = function () {
self.invincible = true;
self.invincibleTimer = 60; // 1 second at 60fps
tween(self, {
alpha: 0.5
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100
});
}
});
};
// Switch weapon
self.setWeapon = function (type) {
self.weapon = type;
};
// Upgrade weapon
self.upgradeWeapon = function () {
self.weaponLevel += 1;
if (self.weaponLevel > 3) self.weaponLevel = 3;
};
// Knife attack animation
self.swingKnife = function () {
if (self.knifeSwinging) return;
self.knifeSwinging = true;
if (!self.knife) {
self.knife = self.attachAsset('knife', {
anchorX: 0.1,
anchorY: 0.5,
x: self.width / 2 + 20,
y: 0,
rotation: 0
});
}
self.knife.visible = true;
self.knife.rotation = -0.7;
tween(self.knife, {
rotation: 0.7
}, {
duration: 180,
easing: tween.cubicOut,
onFinish: function onFinish() {
self.knife.visible = false;
self.knifeSwinging = false;
self.knife.rotation = -0.7;
}
});
};
return self;
});
// Obstacle (rock)
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var rock = self.attachAsset('obstacle_rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = rock.width;
self.height = rock.height;
self.speed = 14 + Math.random() * 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Upgrade (gun or knife)
var Upgrade = Container.expand(function () {
var self = Container.call(this);
self.kind = Math.random() < 0.5 ? 'gun' : 'knife';
var assetId = self.kind === 'gun' ? 'upgrade_gun' : 'upgrade_knife';
var upg = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.width = upg.width;
self.height = upg.height;
self.speed = 10 + Math.random() * 4;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Maze background image (replace with your maze image asset id)
// Upgrade: Knife
// Upgrade: Gun
// Obstacle: Rock
// Enemy: Skeleton
// Enemy: Goblin
// Enemy: Bat
// Player's bullet
// Player's knife
// Minecart (player)
// Game constants
var GAME_W = 2048;
var GAME_H = 2732;
var TRACK_LEFT = 300;
var TRACK_RIGHT = GAME_W - 300;
var PLAYER_Y = GAME_H - 350;
// Game state
var minecart = null;
var bullets = [];
var enemies = [];
var obstacles = [];
var upgrades = [];
var dragNode = null;
var lastTouchX = 0;
var lastTouchY = 0;
var scoreTxt = null;
var lastScore = 0;
var gameOver = false;
var spawnTimer = 0;
var obstacleTimer = 0;
var upgradeTimer = 0;
var difficulty = 1;
var knifeHitEnemies = [];
var lastKnifeSwingTick = -100;
// Add maze background image
var mazeBg = LK.getAsset('maze_bg', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: GAME_W,
height: GAME_H
});
game.addChild(mazeBg);
// Score display
scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create player
minecart = new Minecart();
game.addChild(minecart);
minecart.x = GAME_W / 2;
minecart.y = PLAYER_Y;
// Vertical shooter: drag minecart only in X, fixed Y
game.down = function (x, y, obj) {
if (gameOver) return;
dragNode = minecart;
lastTouchX = x;
lastTouchY = y;
};
game.up = function (x, y, obj) {
dragNode = null;
};
game.move = function (x, y, obj) {
if (gameOver) return;
if (dragNode === minecart) {
// Only allow movement in X, clamp to track
var nx = x;
if (nx < TRACK_LEFT) nx = TRACK_LEFT;
if (nx > TRACK_RIGHT) nx = TRACK_RIGHT;
minecart.x = nx;
minecart.y = PLAYER_Y;
}
};
// Tap to attack (shoot or knife)
game.tap = function (x, y, obj) {
if (gameOver) return;
if (minecart.weapon === 'gun') {
if (minecart.attackCooldown <= 0) {
fireBullet();
minecart.attackCooldown = 12 - minecart.weaponLevel * 2; // Faster with upgrades
if (minecart.attackCooldown < 4) minecart.attackCooldown = 4;
}
} else if (minecart.weapon === 'knife') {
if (LK.ticks - lastKnifeSwingTick > 18) {
minecart.swingKnife();
lastKnifeSwingTick = LK.ticks;
}
}
};
// Fire bullet(s)
function fireBullet() {
var spread = minecart.weaponLevel;
for (var i = 0; i < spread; ++i) {
var b = new Bullet();
b.x = minecart.x + (i - (spread - 1) / 2) * 40;
b.y = minecart.y - minecart.height / 2 - 10;
bullets.push(b);
game.addChild(b);
}
}
// Main update loop
game.update = function () {
if (gameOver) return;
// Difficulty scaling
if (LK.ticks % 300 === 0 && difficulty < 10) {
difficulty += 1;
}
// Attack cooldown
if (minecart.attackCooldown > 0) minecart.attackCooldown -= 1;
// Invincibility timer
if (minecart.invincible) {
minecart.invincibleTimer -= 1;
if (minecart.invincibleTimer <= 0) {
minecart.invincible = false;
}
}
// Bullets update
for (var i = bullets.length - 1; i >= 0; --i) {
var b = bullets[i];
b.update();
if (b.y < -50) {
b.destroy();
bullets.splice(i, 1);
continue;
}
// Bullet hits enemy
for (var j = enemies.length - 1; j >= 0; --j) {
var e = enemies[j];
if (b.intersects(e)) {
e.hp -= 1;
// If this is the Bat, update health bar
if (game._batEnemy && e === game._batEnemy && game._batHealthBar) {
var percent = Math.max(0, e.hp) / game._batMaxHp;
// Clamp width to minimum 0
game._batHealthBar.width = 1680 * percent;
// Optionally, you can tint the bar as it gets low (not required)
}
b.destroy();
bullets.splice(i, 1);
if (e.hp <= 0) {
addScore(e.scoreValue);
e.destroy();
enemies.splice(j, 1);
// If Bat is dead, remove health bar UI
if (game._batEnemy && e === game._batEnemy) {
if (game._batHealthBarBg) {
LK.gui.top.removeChild(game._batHealthBarBg);
game._batHealthBarBg = null;
}
if (game._batHealthBar) {
LK.gui.top.removeChild(game._batHealthBar);
game._batHealthBar = null;
}
game._batEnemy = null;
}
}
break;
}
}
}
// Enemies update (vertical shooter: always visible, move down)
for (var i = enemies.length - 1; i >= 0; --i) {
var e = enemies[i];
e.update();
// Remove if out of bounds
if (e.y > GAME_H + 200) {
e.destroy();
enemies.splice(i, 1);
continue;
}
// Enemy hits minecart
if (!minecart.invincible && e.intersects(minecart)) {
minecart.flash();
LK.effects.flashScreen(0xff0000, 600);
// End game
LK.showGameOver();
gameOver = true;
return;
}
// Enemy hit by knife
if (minecart.weapon === 'knife' && minecart.knife && minecart.knife.visible && !knifeHitEnemies.includes(e)) {
// Knife is in swing, check collision
var knifeGlobal = minecart.toGlobal(minecart.knife.position);
var knifeRect = new Rectangle(knifeGlobal.x - 30, knifeGlobal.y - 12, 60, 24);
var enemyRect = new Rectangle(e.x - e.width / 2, e.y - e.height / 2, e.width, e.height);
if (rectsIntersect(knifeRect, enemyRect)) {
e.hp -= 1;
// If this is the Bat, update health bar
if (game._batEnemy && e === game._batEnemy && game._batHealthBar) {
var percent = Math.max(0, e.hp) / game._batMaxHp;
game._batHealthBar.width = 1680 * percent;
}
knifeHitEnemies.push(e);
if (e.hp <= 0) {
addScore(e.scoreValue);
e.destroy();
enemies.splice(i, 1);
// If Bat is dead, remove health bar UI
if (game._batEnemy && e === game._batEnemy) {
if (game._batHealthBarBg) {
LK.gui.top.removeChild(game._batHealthBarBg);
game._batHealthBarBg = null;
}
if (game._batHealthBar) {
LK.gui.top.removeChild(game._batHealthBar);
game._batHealthBar = null;
}
game._batEnemy = null;
}
}
}
}
}
// Reset knife hit list if knife not swinging
if (!(minecart.knife && minecart.knife.visible)) {
knifeHitEnemies = [];
}
// Obstacles update
for (var i = obstacles.length - 1; i >= 0; --i) {
var o = obstacles[i];
o.update();
if (o.y > GAME_H + 100) {
o.destroy();
obstacles.splice(i, 1);
continue;
}
// Obstacle hits minecart
if (!minecart.invincible && o.intersects(minecart)) {
minecart.flash();
LK.effects.flashScreen(0xff0000, 600);
LK.showGameOver();
gameOver = true;
return;
}
}
// Upgrades update
for (var i = upgrades.length - 1; i >= 0; --i) {
var u = upgrades[i];
u.update();
if (u.y > GAME_H + 100) {
u.destroy();
upgrades.splice(i, 1);
continue;
}
// Pickup
if (u.intersects(minecart)) {
if (u.kind === 'gun') {
minecart.setWeapon('gun');
minecart.upgradeWeapon();
} else {
minecart.setWeapon('knife');
minecart.upgradeWeapon();
}
u.destroy();
upgrades.splice(i, 1);
}
}
// Spawning enemies
spawnTimer -= 1;
if (spawnTimer <= 0) {
spawnEnemy();
spawnTimer = Math.max(24, 60 - difficulty * 4 - Math.floor(Math.random() * 10));
}
// Spawning obstacles
obstacleTimer -= 1;
if (obstacleTimer <= 0) {
if (Math.random() < 0.5 + difficulty * 0.04) {
spawnObstacle();
}
obstacleTimer = 90 + Math.floor(Math.random() * 60) - difficulty * 4;
if (obstacleTimer < 30) obstacleTimer = 30;
}
// Spawning upgrades
upgradeTimer -= 1;
if (upgradeTimer <= 0) {
if (Math.random() < 0.18) {
spawnUpgrade();
}
upgradeTimer = 600 + Math.floor(Math.random() * 300);
}
// Update score display
if (LK.getScore() !== lastScore) {
scoreTxt.setText(LK.getScore());
lastScore = LK.getScore();
}
};
// Spawn enemy at random X at the top (vertical shooter style)
function spawnEnemy() {
var enemyType = Math.random();
var e = null;
// Only allow Bat to spawn every 3rd or 10th run, otherwise never spawn Bat
var allowBat = false;
if (game._runCount && (game._runCount % 10 === 0 || game._runCount % 3 === 0)) {
allowBat = true;
}
// Only spawn Bat if allowed this run and random chance, otherwise pick Goblin or Skeleton
if (allowBat && enemyType < 0.3) {
e = new Bat();
// Show warning text and play creepy music when Bat spawns
if (!game._batWarningText) {
// Create warning text if not already present
var batWarning = new Text2("That is not you.", {
size: 120,
fill: 0xFF2222,
font: "Impact, Arial Black, Tahoma"
});
batWarning.anchor.set(0.5, 0.5);
batWarning.alpha = 0.0;
game._batWarningText = batWarning;
// Add to LK.gui.center for true center of screen
LK.gui.center.addChild(batWarning);
}
// Fade in text
var warningText = game._batWarningText;
warningText.alpha = 0.0;
tween(warningText, {
alpha: 1
}, {
duration: 400,
onFinish: function onFinish() {
// Fade out after 1.2s
tween(warningText, {
alpha: 0
}, {
duration: 800,
delay: 1200
});
}
});
// Play creepy music (music asset id: 'creepy_bat')
LK.playMusic('creepy_bat', {
fade: {
start: 0,
end: 1,
duration: 800
}
});
// --- Bat Health Bar UI ---
// Remove any previous bat health bar
if (game._batHealthBarBg) {
LK.gui.top.removeChild(game._batHealthBarBg);
game._batHealthBarBg = null;
}
if (game._batHealthBar) {
LK.gui.top.removeChild(game._batHealthBar);
game._batHealthBar = null;
}
// Create background bar (much bigger, at the very top)
var barWidth = 1700;
var barHeight = 90;
var barBg = LK.getAsset('enemy_goblin', {
width: barWidth,
height: barHeight,
color: 0x222222,
anchorX: 0.5,
anchorY: 0
});
barBg.x = GAME_W / 2;
barBg.y = 10; // Very top of the screen
// Create health bar (red, much bigger)
var bar = LK.getAsset('enemy_goblin', {
width: barWidth - 20,
height: barHeight - 18,
color: 0xff2222,
anchorX: 0.5,
anchorY: 0
});
bar.x = GAME_W / 2;
bar.y = 19; // Just below the background bar
// Add to GUI
LK.gui.top.addChild(barBg);
LK.gui.top.addChild(bar);
game._batHealthBarBg = barBg;
game._batHealthBar = bar;
// Store reference to the Bat instance for health bar updates
game._batEnemy = e;
game._batMaxHp = e.hp;
} else if (enemyType < 0.65 || !allowBat) {
e = new Goblin();
} else {
e = new Skeleton();
}
// Spawn at random X at the top of the screen
e.x = TRACK_LEFT + 80 + Math.random() * (TRACK_RIGHT - TRACK_LEFT - 160);
e.y = -80;
enemies.push(e);
game.addChild(e);
}
// Spawn obstacle
function spawnObstacle() {
var o = new Obstacle();
o.x = TRACK_LEFT + 80 + Math.random() * (TRACK_RIGHT - TRACK_LEFT - 160);
o.y = -60;
obstacles.push(o);
game.addChild(o);
}
// Spawn upgrade
function spawnUpgrade() {
var u = new Upgrade();
u.x = TRACK_LEFT + 80 + Math.random() * (TRACK_RIGHT - TRACK_LEFT - 160);
u.y = -60;
upgrades.push(u);
game.addChild(u);
}
// Add score
function addScore(val) {
LK.setScore(LK.getScore() + val);
}
// Rectangle intersection helper
function rectsIntersect(r1, r2) {
return !(r2.x > r1.x + r1.width || r2.x + r2.width < r1.x || r2.y > r1.y + r1.height || r2.y + r2.height < r1.y);
}
// Touch to attack (simulate tap on mobile)
game.down = function (origDown) {
return function (x, y, obj) {
if (origDown) origDown(x, y, obj);
game.tap(x, y, obj);
};
}(game.down);
// Reset game state on game over
LK.on('gameover', function () {
gameOver = true;
});
// Track run count for Bat spawn logic
if (typeof game._runCount === "undefined") {
game._runCount = 0;
}
LK.on('newgame', function () {
game._runCount = (game._runCount || 0) + 1;
gameOver = false;
LK.setScore(0);
scoreTxt.setText('0');
// Remove all objects
for (var i = 0; i < bullets.length; ++i) bullets[i].destroy();
for (var i = 0; i < enemies.length; ++i) enemies[i].destroy();
for (var i = 0; i < obstacles.length; ++i) obstacles[i].destroy();
for (var i = 0; i < upgrades.length; ++i) upgrades[i].destroy();
bullets = [];
enemies = [];
obstacles = [];
upgrades = [];
minecart.x = GAME_W / 2;
minecart.y = PLAYER_Y;
minecart.weapon = 'gun';
minecart.weaponLevel = 1;
minecart.invincible = false;
minecart.invincibleTimer = 0;
minecart.attackCooldown = 0;
minecart.knifeSwinging = false;
minecart.setWeapon('gun');
difficulty = 1;
spawnTimer = 0;
obstacleTimer = 0;
upgradeTimer = 0;
knifeHitEnemies = [];
lastKnifeSwingTick = -100;
// Remove Bat health bar UI if present
if (game._batHealthBarBg) {
LK.gui.top.removeChild(game._batHealthBarBg);
game._batHealthBarBg = null;
}
if (game._batHealthBar) {
LK.gui.top.removeChild(game._batHealthBar);
game._batHealthBar = null;
}
game._batEnemy = null;
game._batMaxHp = null;
});
// Initial state
spawnTimer = 0;
obstacleTimer = 60;
upgradeTimer = 600;
difficulty = 1;
gameOver = false;
LK.setScore(0);
scoreTxt.setText('0');
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Minecart Mayhem: Armed Run" and with the description "Survive a wild minecart ride by battling multiple enemy types with guns and knives, dodging obstacles, and collecting upgrades for a high-score chase.". No text on banner!
A skeleton with 3 legs and a creepy face and red eyes. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A silver bullet. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a maze . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Man with bag on head and red eyes. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A man with a bag over his head and red eyes. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Knife. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Rock. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Zombie. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A knife with purple and golden around it. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Man with bag on head with cross on it. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Skeleton player model. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A black monster with a creepy white grin. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Blocky zombie riding blocky chicken. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat