/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { coins: 0, unlockedSkins: ["default"] }); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.baseSpeedX = (Math.random() - 0.5) * 6; self.baseSpeedY = Math.random() * 4 + 2; self.update = function () { // Apply difficulty multiplier to speed - double every level var speedMultiplier = Math.pow(2, difficultyLevel - 1); self.x += self.baseSpeedX * speedMultiplier; self.y += self.baseSpeedY * speedMultiplier; }; return self; }); var Coin = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.bobSpeed = Math.random() * 0.15 + 0.08; self.bobOffset = Math.random() * Math.PI * 2; self.update = function () { // Gentle bobbing animation and rotation graphics.y = Math.sin(LK.ticks * self.bobSpeed + self.bobOffset) * 8; graphics.rotation += 0.05; graphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.1; graphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.1; }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.baseSpeedX = (Math.random() - 0.5) * 4; self.baseSpeedY = Math.random() * 3 + 1; self.update = function () { // Apply difficulty multiplier to speed - double every level var speedMultiplier = Math.pow(2, difficultyLevel - 1); self.x += self.baseSpeedX * speedMultiplier; self.y += self.baseSpeedY * speedMultiplier; // Bounce off screen edges if (self.x <= 30 || self.x >= 2018) { self.baseSpeedX *= -1; } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Keep player at normal appearance graphics.alpha = 1.0; graphics.scaleX = 1.0; graphics.scaleY = 1.0; }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.bobSpeed = Math.random() * 0.1 + 0.05; self.bobOffset = Math.random() * Math.PI * 2; self.update = function () { // Gentle bobbing animation graphics.y = Math.sin(LK.ticks * self.bobSpeed + self.bobOffset) * 5; graphics.rotation += 0.02; }; return self; }); var Shop = Container.expand(function () { var self = Container.call(this); // Dark overlay background var overlay = LK.getAsset('shopOverlay', { width: 2048, height: 2732, color: 0x000000, shape: 'box' }); overlay.anchorX = 0.5; overlay.anchorY = 0.5; overlay.alpha = 0.7; self.addChild(overlay); // Shop background - centered modal var background = LK.getAsset('shop', { width: 1200, height: 1500, color: 0x2C3E50, shape: 'box' }); background.anchorX = 0.5; background.anchorY = 0.5; background.alpha = 1.0; self.addChild(background); // Shop title var title = new Text2('SHOP', { size: 100, fill: 0xFFD700 }); title.anchor.set(0.5, 0.5); title.x = 0; title.y = -650; self.addChild(title); // Coins display self.coinsText = new Text2('Coins: ' + storage.coins, { size: 60, fill: 0xFFD700 }); self.coinsText.anchor.set(0.5, 0.5); self.coinsText.x = 0; self.coinsText.y = -550; self.addChild(self.coinsText); // Close button var closeBtn = LK.getAsset('closeBtn', { width: 120, height: 120, color: 0xE74C3C, shape: 'box' }); closeBtn.anchorX = 0.5; closeBtn.anchorY = 0.5; closeBtn.x = 540; closeBtn.y = -650; self.addChild(closeBtn); var closeText = new Text2('X', { size: 80, fill: 0xFFFFFF }); closeText.anchor.set(0.5, 0.5); closeText.x = 540; closeText.y = -650; self.addChild(closeText); // Skin items self.skins = [{ name: 'default', color: 0x4caf50, price: 0, unlocked: true }, { name: 'red', color: 0xF44336, price: 50, unlocked: storage.unlockedSkins.indexOf('red') !== -1 }, { name: 'orange', color: 0xFF9800, price: 100, unlocked: storage.unlockedSkins.indexOf('orange') !== -1 }, { name: 'blue', color: 0x2196F3, price: 150, unlocked: storage.unlockedSkins.indexOf('blue') !== -1 }, { name: 'yellow', color: 0xFFEB3B, price: 200, unlocked: storage.unlockedSkins.indexOf('yellow') !== -1 }, { name: 'purple', color: 0x9C27B0, price: 250, unlocked: storage.unlockedSkins.indexOf('purple') !== -1 }]; self.skinButtons = []; for (var i = 0; i < self.skins.length; i++) { var skin = self.skins[i]; var yPos = -350 + i * 150; // Skin preview var skinPreview = LK.getAsset('skinPreview' + i, { width: 60, height: 60, color: skin.color, shape: 'ellipse' }); skinPreview.anchorX = 0.5; skinPreview.anchorY = 0.5; skinPreview.x = -350; skinPreview.y = yPos; self.addChild(skinPreview); // Skin name var nameText = new Text2(skin.name.toUpperCase(), { size: 40, fill: 0xFFFFFF }); nameText.anchor.set(0, 0.5); nameText.x = -250; nameText.y = yPos - 25; self.addChild(nameText); // Price or status var statusText; if (skin.unlocked) { statusText = new Text2('OWNED', { size: 30, fill: 0x4CAF50 }); } else { statusText = new Text2(skin.price + ' coins', { size: 30, fill: 0xFFD700 }); } statusText.anchor.set(0, 0.5); statusText.x = -250; statusText.y = yPos + 25; self.addChild(statusText); // Buy/Use button var button = LK.getAsset('shopBtn' + i, { width: 160, height: 60, color: skin.unlocked ? 0x4CAF50 : 0x2196F3, shape: 'box' }); button.anchorX = 0.5; button.anchorY = 0.5; button.x = 300; button.y = yPos; button.skinIndex = i; self.addChild(button); self.skinButtons.push(button); var buttonText = new Text2(skin.unlocked ? 'USE' : 'BUY', { size: 30, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); buttonText.x = 300; buttonText.y = yPos; self.addChild(buttonText); } self.down = function (x, y, obj) { var localPos = self.toLocal(obj.parent.toGlobal(obj.position)); // Close button if (localPos.x > 480 && localPos.x < 600 && localPos.y > -710 && localPos.y < -590) { showShop = false; self.visible = false; return; } // Check skin buttons for (var i = 0; i < self.skinButtons.length; i++) { var button = self.skinButtons[i]; var skin = self.skins[i]; if (localPos.x > 220 && localPos.x < 380 && localPos.y > -350 + i * 150 - 30 && localPos.y < -350 + i * 150 + 30) { if (skin.unlocked) { // Use skin currentSkin = skin.name; storage.currentSkin = currentSkin; updatePlayerSkin(); } else { // Buy skin if (storage.coins >= skin.price) { storage.coins -= skin.price; storage.unlockedSkins.push(skin.name); skin.unlocked = true; currentSkin = skin.name; storage.currentSkin = currentSkin; updatePlayerSkin(); self.updateShop(); } } break; } } }; self.updateShop = function () { self.coinsText.setText('Coins: ' + storage.coins); for (var i = 0; i < self.skins.length; i++) { self.skins[i].unlocked = storage.unlockedSkins.indexOf(self.skins[i].name) !== -1; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1A1A2E }); /**** * Game Code ****/ var player; var enemies = []; var bullets = []; var powerups = []; var coins = []; var survivalTime = 0; var spawnTimer = 0; var difficultyLevel = 1; var levelTimer = 0; var baseEnemySpeed = 3; var baseBulletSpeed = 4; var showShop = false; var shop; var currentSkin = storage.currentSkin || 'default'; // Initialize score display var scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize level display var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFD700 }); levelTxt.anchor.set(0.5, 0); levelTxt.x = 2048 / 2; levelTxt.y = 60; LK.gui.addChild(levelTxt); // Initialize coins display var coinsTxt = new Text2('Coins: ' + storage.coins, { size: 50, fill: 0xFFD700 }); coinsTxt.anchor.set(1, 0); coinsTxt.x = 2048 - 20; coinsTxt.y = 20; LK.gui.addChild(coinsTxt); // Initialize shop button var shopBtn = LK.getAsset('shopButton', { width: 150, height: 80, color: 0x9C27B0, shape: 'box' }); shopBtn.anchorX = 0; shopBtn.anchorY = 1; shopBtn.x = 38; // 1cm from left edge (approximately 38px) shopBtn.y = LK.gui.height - 38; // 1cm from bottom edge LK.gui.addChild(shopBtn); var shopBtnText = new Text2('SHOP', { size: 40, fill: 0xFFFFFF }); shopBtnText.anchor.set(0.5, 0.5); shopBtnText.x = 113; // Center of button (38 + 150/2) shopBtnText.y = LK.gui.height - 78; // Center of button vertically LK.gui.addChild(shopBtnText); // Create player player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; // Create shop shop = new Shop(); shop.x = 2048 / 2; shop.y = 2732 / 2; shop.visible = false; game.addChild(shop); // Function to update player skin function updatePlayerSkin() { var skinColors = { 'default': 0x4caf50, 'red': 0xF44336, 'orange': 0xFF9800, 'blue': 0x2196F3, 'yellow': 0xFFEB3B, 'purple': 0x9C27B0 }; if (player && player.children[0]) { player.children[0].tint = skinColors[currentSkin] || skinColors['default']; } } // Apply current skin updatePlayerSkin(); // Movement handling - touch and hold function handleMove(x, y, obj) { if (!showShop) { player.x = Math.max(40, Math.min(2008, x)); player.y = Math.max(40, Math.min(2692, y)); } } game.move = handleMove; game.down = function (x, y, obj) { // Check shop button click (bottom left corner) if (x > 38 && x < 188 && y > LK.gui.height - 118 && y < LK.gui.height - 38) { showShop = !showShop; shop.visible = showShop; if (showShop) { shop.updateShop(); } return; } // Move player to touch position if (!showShop) { handleMove(x, y, obj); } }; game.up = function (x, y, obj) { // No action needed for touch release }; // Spawn enemies function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 1900 + 100; enemy.y = -50; enemies.push(enemy); game.addChild(enemy); } // Spawn bullets function spawnBullet() { var bullet = new Bullet(); bullet.x = Math.random() * 2048; bullet.y = -30; bullets.push(bullet); game.addChild(bullet); } // Spawn power-ups function spawnPowerUp() { var powerup = new PowerUp(); powerup.x = Math.random() * 1800 + 124; powerup.y = Math.random() * 2000 + 100; powerups.push(powerup); game.addChild(powerup); } // Spawn coins function spawnCoin() { var coin = new Coin(); coin.x = Math.random() * 1800 + 124; coin.y = Math.random() * 2000 + 100; coins.push(coin); game.addChild(coin); } // Update game state game.update = function () { // Pause game when shop is open if (showShop) { return; } // Update game progression survivalTime++; levelTimer++; spawnTimer++; // Update score LK.setScore(Math.floor(survivalTime / 60) * 10); scoreTxt.setText('Score: ' + LK.getScore()); // Increase difficulty every 10 seconds (600 ticks at 60fps) if (levelTimer >= 600) { difficultyLevel++; levelTimer = 0; levelTxt.setText('Level: ' + difficultyLevel); // Flash screen to indicate level up LK.effects.flashScreen(0x00FF00, 300); } // Spawn enemies if (spawnTimer % Math.max(120 - difficultyLevel * 10, 30) === 0) { spawnEnemy(); } // Spawn bullets if (spawnTimer % Math.max(90 - difficultyLevel * 5, 20) === 0) { spawnBullet(); } // Spawn power-ups if (spawnTimer % 600 === 0) { spawnPowerUp(); } // Spawn coins if (spawnTimer % 180 === 0) { spawnCoin(); } // Handle enemy collisions and cleanup for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; // Remove off-screen enemies if (enemy.y > 2800) { enemy.destroy(); enemies.splice(i, 1); continue; } // Check collision with player if (enemy.intersects(player)) { LK.getSound('enemyHit').play(); LK.effects.flashScreen(0xFF0000, 500); LK.showGameOver(); return; } } // Handle bullet collisions and cleanup for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; // Remove off-screen bullets if (bullet.y > 2800 || bullet.x < -50 || bullet.x > 2098) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check collision with player if (bullet.intersects(player)) { LK.getSound('enemyHit').play(); LK.effects.flashScreen(0xFF0000, 500); LK.showGameOver(); return; } } // Handle power-up collisions for (var i = powerups.length - 1; i >= 0; i--) { var powerup = powerups[i]; if (powerup.intersects(player)) { LK.getSound('collect').play(); LK.setScore(LK.getScore() + 50); scoreTxt.setText('Score: ' + LK.getScore()); LK.effects.flashObject(player, 0x2196F3, 300); powerup.destroy(); powerups.splice(i, 1); } } // Handle coin collisions for (var i = coins.length - 1; i >= 0; i--) { var coin = coins[i]; if (coin.intersects(player)) { LK.getSound('collect').play(); storage.coins += 10; coinsTxt.setText('Coins: ' + storage.coins); LK.effects.flashObject(player, 0xFFD700, 300); coin.destroy(); coins.splice(i, 1); } } // Win condition if (LK.getScore() >= 1000) { LK.showYouWin(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
coins: 0,
unlockedSkins: ["default"]
});
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.baseSpeedX = (Math.random() - 0.5) * 6;
self.baseSpeedY = Math.random() * 4 + 2;
self.update = function () {
// Apply difficulty multiplier to speed - double every level
var speedMultiplier = Math.pow(2, difficultyLevel - 1);
self.x += self.baseSpeedX * speedMultiplier;
self.y += self.baseSpeedY * speedMultiplier;
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.bobSpeed = Math.random() * 0.15 + 0.08;
self.bobOffset = Math.random() * Math.PI * 2;
self.update = function () {
// Gentle bobbing animation and rotation
graphics.y = Math.sin(LK.ticks * self.bobSpeed + self.bobOffset) * 8;
graphics.rotation += 0.05;
graphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
graphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.baseSpeedX = (Math.random() - 0.5) * 4;
self.baseSpeedY = Math.random() * 3 + 1;
self.update = function () {
// Apply difficulty multiplier to speed - double every level
var speedMultiplier = Math.pow(2, difficultyLevel - 1);
self.x += self.baseSpeedX * speedMultiplier;
self.y += self.baseSpeedY * speedMultiplier;
// Bounce off screen edges
if (self.x <= 30 || self.x >= 2018) {
self.baseSpeedX *= -1;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Keep player at normal appearance
graphics.alpha = 1.0;
graphics.scaleX = 1.0;
graphics.scaleY = 1.0;
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.bobSpeed = Math.random() * 0.1 + 0.05;
self.bobOffset = Math.random() * Math.PI * 2;
self.update = function () {
// Gentle bobbing animation
graphics.y = Math.sin(LK.ticks * self.bobSpeed + self.bobOffset) * 5;
graphics.rotation += 0.02;
};
return self;
});
var Shop = Container.expand(function () {
var self = Container.call(this);
// Dark overlay background
var overlay = LK.getAsset('shopOverlay', {
width: 2048,
height: 2732,
color: 0x000000,
shape: 'box'
});
overlay.anchorX = 0.5;
overlay.anchorY = 0.5;
overlay.alpha = 0.7;
self.addChild(overlay);
// Shop background - centered modal
var background = LK.getAsset('shop', {
width: 1200,
height: 1500,
color: 0x2C3E50,
shape: 'box'
});
background.anchorX = 0.5;
background.anchorY = 0.5;
background.alpha = 1.0;
self.addChild(background);
// Shop title
var title = new Text2('SHOP', {
size: 100,
fill: 0xFFD700
});
title.anchor.set(0.5, 0.5);
title.x = 0;
title.y = -650;
self.addChild(title);
// Coins display
self.coinsText = new Text2('Coins: ' + storage.coins, {
size: 60,
fill: 0xFFD700
});
self.coinsText.anchor.set(0.5, 0.5);
self.coinsText.x = 0;
self.coinsText.y = -550;
self.addChild(self.coinsText);
// Close button
var closeBtn = LK.getAsset('closeBtn', {
width: 120,
height: 120,
color: 0xE74C3C,
shape: 'box'
});
closeBtn.anchorX = 0.5;
closeBtn.anchorY = 0.5;
closeBtn.x = 540;
closeBtn.y = -650;
self.addChild(closeBtn);
var closeText = new Text2('X', {
size: 80,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeText.x = 540;
closeText.y = -650;
self.addChild(closeText);
// Skin items
self.skins = [{
name: 'default',
color: 0x4caf50,
price: 0,
unlocked: true
}, {
name: 'red',
color: 0xF44336,
price: 50,
unlocked: storage.unlockedSkins.indexOf('red') !== -1
}, {
name: 'orange',
color: 0xFF9800,
price: 100,
unlocked: storage.unlockedSkins.indexOf('orange') !== -1
}, {
name: 'blue',
color: 0x2196F3,
price: 150,
unlocked: storage.unlockedSkins.indexOf('blue') !== -1
}, {
name: 'yellow',
color: 0xFFEB3B,
price: 200,
unlocked: storage.unlockedSkins.indexOf('yellow') !== -1
}, {
name: 'purple',
color: 0x9C27B0,
price: 250,
unlocked: storage.unlockedSkins.indexOf('purple') !== -1
}];
self.skinButtons = [];
for (var i = 0; i < self.skins.length; i++) {
var skin = self.skins[i];
var yPos = -350 + i * 150;
// Skin preview
var skinPreview = LK.getAsset('skinPreview' + i, {
width: 60,
height: 60,
color: skin.color,
shape: 'ellipse'
});
skinPreview.anchorX = 0.5;
skinPreview.anchorY = 0.5;
skinPreview.x = -350;
skinPreview.y = yPos;
self.addChild(skinPreview);
// Skin name
var nameText = new Text2(skin.name.toUpperCase(), {
size: 40,
fill: 0xFFFFFF
});
nameText.anchor.set(0, 0.5);
nameText.x = -250;
nameText.y = yPos - 25;
self.addChild(nameText);
// Price or status
var statusText;
if (skin.unlocked) {
statusText = new Text2('OWNED', {
size: 30,
fill: 0x4CAF50
});
} else {
statusText = new Text2(skin.price + ' coins', {
size: 30,
fill: 0xFFD700
});
}
statusText.anchor.set(0, 0.5);
statusText.x = -250;
statusText.y = yPos + 25;
self.addChild(statusText);
// Buy/Use button
var button = LK.getAsset('shopBtn' + i, {
width: 160,
height: 60,
color: skin.unlocked ? 0x4CAF50 : 0x2196F3,
shape: 'box'
});
button.anchorX = 0.5;
button.anchorY = 0.5;
button.x = 300;
button.y = yPos;
button.skinIndex = i;
self.addChild(button);
self.skinButtons.push(button);
var buttonText = new Text2(skin.unlocked ? 'USE' : 'BUY', {
size: 30,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
buttonText.x = 300;
buttonText.y = yPos;
self.addChild(buttonText);
}
self.down = function (x, y, obj) {
var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
// Close button
if (localPos.x > 480 && localPos.x < 600 && localPos.y > -710 && localPos.y < -590) {
showShop = false;
self.visible = false;
return;
}
// Check skin buttons
for (var i = 0; i < self.skinButtons.length; i++) {
var button = self.skinButtons[i];
var skin = self.skins[i];
if (localPos.x > 220 && localPos.x < 380 && localPos.y > -350 + i * 150 - 30 && localPos.y < -350 + i * 150 + 30) {
if (skin.unlocked) {
// Use skin
currentSkin = skin.name;
storage.currentSkin = currentSkin;
updatePlayerSkin();
} else {
// Buy skin
if (storage.coins >= skin.price) {
storage.coins -= skin.price;
storage.unlockedSkins.push(skin.name);
skin.unlocked = true;
currentSkin = skin.name;
storage.currentSkin = currentSkin;
updatePlayerSkin();
self.updateShop();
}
}
break;
}
}
};
self.updateShop = function () {
self.coinsText.setText('Coins: ' + storage.coins);
for (var i = 0; i < self.skins.length; i++) {
self.skins[i].unlocked = storage.unlockedSkins.indexOf(self.skins[i].name) !== -1;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1A1A2E
});
/****
* Game Code
****/
var player;
var enemies = [];
var bullets = [];
var powerups = [];
var coins = [];
var survivalTime = 0;
var spawnTimer = 0;
var difficultyLevel = 1;
var levelTimer = 0;
var baseEnemySpeed = 3;
var baseBulletSpeed = 4;
var showShop = false;
var shop;
var currentSkin = storage.currentSkin || 'default';
// Initialize score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize level display
var levelTxt = new Text2('Level: 1', {
size: 60,
fill: 0xFFD700
});
levelTxt.anchor.set(0.5, 0);
levelTxt.x = 2048 / 2;
levelTxt.y = 60;
LK.gui.addChild(levelTxt);
// Initialize coins display
var coinsTxt = new Text2('Coins: ' + storage.coins, {
size: 50,
fill: 0xFFD700
});
coinsTxt.anchor.set(1, 0);
coinsTxt.x = 2048 - 20;
coinsTxt.y = 20;
LK.gui.addChild(coinsTxt);
// Initialize shop button
var shopBtn = LK.getAsset('shopButton', {
width: 150,
height: 80,
color: 0x9C27B0,
shape: 'box'
});
shopBtn.anchorX = 0;
shopBtn.anchorY = 1;
shopBtn.x = 38; // 1cm from left edge (approximately 38px)
shopBtn.y = LK.gui.height - 38; // 1cm from bottom edge
LK.gui.addChild(shopBtn);
var shopBtnText = new Text2('SHOP', {
size: 40,
fill: 0xFFFFFF
});
shopBtnText.anchor.set(0.5, 0.5);
shopBtnText.x = 113; // Center of button (38 + 150/2)
shopBtnText.y = LK.gui.height - 78; // Center of button vertically
LK.gui.addChild(shopBtnText);
// Create player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
// Create shop
shop = new Shop();
shop.x = 2048 / 2;
shop.y = 2732 / 2;
shop.visible = false;
game.addChild(shop);
// Function to update player skin
function updatePlayerSkin() {
var skinColors = {
'default': 0x4caf50,
'red': 0xF44336,
'orange': 0xFF9800,
'blue': 0x2196F3,
'yellow': 0xFFEB3B,
'purple': 0x9C27B0
};
if (player && player.children[0]) {
player.children[0].tint = skinColors[currentSkin] || skinColors['default'];
}
}
// Apply current skin
updatePlayerSkin();
// Movement handling - touch and hold
function handleMove(x, y, obj) {
if (!showShop) {
player.x = Math.max(40, Math.min(2008, x));
player.y = Math.max(40, Math.min(2692, y));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Check shop button click (bottom left corner)
if (x > 38 && x < 188 && y > LK.gui.height - 118 && y < LK.gui.height - 38) {
showShop = !showShop;
shop.visible = showShop;
if (showShop) {
shop.updateShop();
}
return;
}
// Move player to touch position
if (!showShop) {
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
// No action needed for touch release
};
// Spawn enemies
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 1900 + 100;
enemy.y = -50;
enemies.push(enemy);
game.addChild(enemy);
}
// Spawn bullets
function spawnBullet() {
var bullet = new Bullet();
bullet.x = Math.random() * 2048;
bullet.y = -30;
bullets.push(bullet);
game.addChild(bullet);
}
// Spawn power-ups
function spawnPowerUp() {
var powerup = new PowerUp();
powerup.x = Math.random() * 1800 + 124;
powerup.y = Math.random() * 2000 + 100;
powerups.push(powerup);
game.addChild(powerup);
}
// Spawn coins
function spawnCoin() {
var coin = new Coin();
coin.x = Math.random() * 1800 + 124;
coin.y = Math.random() * 2000 + 100;
coins.push(coin);
game.addChild(coin);
}
// Update game state
game.update = function () {
// Pause game when shop is open
if (showShop) {
return;
}
// Update game progression
survivalTime++;
levelTimer++;
spawnTimer++;
// Update score
LK.setScore(Math.floor(survivalTime / 60) * 10);
scoreTxt.setText('Score: ' + LK.getScore());
// Increase difficulty every 10 seconds (600 ticks at 60fps)
if (levelTimer >= 600) {
difficultyLevel++;
levelTimer = 0;
levelTxt.setText('Level: ' + difficultyLevel);
// Flash screen to indicate level up
LK.effects.flashScreen(0x00FF00, 300);
}
// Spawn enemies
if (spawnTimer % Math.max(120 - difficultyLevel * 10, 30) === 0) {
spawnEnemy();
}
// Spawn bullets
if (spawnTimer % Math.max(90 - difficultyLevel * 5, 20) === 0) {
spawnBullet();
}
// Spawn power-ups
if (spawnTimer % 600 === 0) {
spawnPowerUp();
}
// Spawn coins
if (spawnTimer % 180 === 0) {
spawnCoin();
}
// Handle enemy collisions and cleanup
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
// Remove off-screen enemies
if (enemy.y > 2800) {
enemy.destroy();
enemies.splice(i, 1);
continue;
}
// Check collision with player
if (enemy.intersects(player)) {
LK.getSound('enemyHit').play();
LK.effects.flashScreen(0xFF0000, 500);
LK.showGameOver();
return;
}
}
// Handle bullet collisions and cleanup
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove off-screen bullets
if (bullet.y > 2800 || bullet.x < -50 || bullet.x > 2098) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check collision with player
if (bullet.intersects(player)) {
LK.getSound('enemyHit').play();
LK.effects.flashScreen(0xFF0000, 500);
LK.showGameOver();
return;
}
}
// Handle power-up collisions
for (var i = powerups.length - 1; i >= 0; i--) {
var powerup = powerups[i];
if (powerup.intersects(player)) {
LK.getSound('collect').play();
LK.setScore(LK.getScore() + 50);
scoreTxt.setText('Score: ' + LK.getScore());
LK.effects.flashObject(player, 0x2196F3, 300);
powerup.destroy();
powerups.splice(i, 1);
}
}
// Handle coin collisions
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (coin.intersects(player)) {
LK.getSound('collect').play();
storage.coins += 10;
coinsTxt.setText('Coins: ' + storage.coins);
LK.effects.flashObject(player, 0xFFD700, 300);
coin.destroy();
coins.splice(i, 1);
}
}
// Win condition
if (LK.getScore() >= 1000) {
LK.showYouWin();
}
};