/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
credits: 0,
miningLevel: 1,
laserLevel: 1,
speedLevel: 1,
shieldLevel: 1,
highScore: 0
});
/****
* Classes
****/
var Asteroid = Container.expand(function (size, mineralType) {
var self = Container.call(this);
var assetId = 'asteroid' + (size || Math.floor(Math.random() * 3) + 1);
var asteroidGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.size = size || Math.floor(Math.random() * 3) + 1;
self.health = self.size * 5;
self.maxHealth = self.health;
self.speed = Math.random() * 1 + 1;
self.rotationSpeed = (Math.random() - 0.5) * 0.05;
self.mineralType = mineralType || Math.floor(Math.random() * 3) + 1;
self.mineralValue = self.mineralType * self.size * 5;
self.mineralAmount = self.size * 2;
// Tint asteroid based on mineral type (1=iron, 2=silver, 3=gold)
if (self.mineralType === 1) {
asteroidGraphics.tint = 0x7f8c8d; // Iron (gray)
} else if (self.mineralType === 2) {
asteroidGraphics.tint = 0xbdc3c7; // Silver (light gray)
} else if (self.mineralType === 3) {
asteroidGraphics.tint = 0xf1c40f; // Gold (yellow)
}
self.update = function () {
self.y += self.speed;
asteroidGraphics.rotation += self.rotationSpeed;
if (self.y > 2732 + asteroidGraphics.height) {
self.shouldRemove = true;
}
};
self.takeDamage = function (amount) {
self.health -= amount;
if (self.health <= 0) {
// Spawn minerals
for (var i = 0; i < self.mineralAmount; i++) {
var mineral = new Mineral(self.mineralType);
mineral.x = self.x + (Math.random() - 0.5) * 50;
mineral.y = self.y + (Math.random() - 0.5) * 50;
minerals.push(mineral);
game.addChild(mineral);
}
// Explosion effect
LK.effects.flashObject(self, 0xFFFFFF, 100);
LK.getSound('explosion').play();
self.shouldRemove = true;
}
};
return self;
});
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.power = 1;
self.update = function () {
self.y -= self.speed;
if (self.y < -50) {
self.shouldRemove = true;
}
};
return self;
});
var Mineral = Container.expand(function (type) {
var self = Container.call(this);
var mineralGraphics = self.attachAsset('mineral', {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type || 1;
self.value = self.type * 5;
self.collected = false;
self.speed = Math.random() * 1 + 0.5;
self.driftX = (Math.random() - 0.5) * 2;
// Tint mineral based on type
if (self.type === 1) {
mineralGraphics.tint = 0x7f8c8d; // Iron (gray)
} else if (self.type === 2) {
mineralGraphics.tint = 0xbdc3c7; // Silver (light gray)
} else if (self.type === 3) {
mineralGraphics.tint = 0xf1c40f; // Gold (yellow)
}
self.update = function () {
self.y += self.speed;
self.x += self.driftX;
if (self.y > 2732 + mineralGraphics.height) {
self.shouldRemove = true;
}
};
self.collect = function () {
if (!self.collected) {
self.collected = true;
credits += self.value;
totalMined += self.value;
storage.credits = credits;
if (totalMined > storage.highScore) {
storage.highScore = totalMined;
}
updateStatsDisplay();
LK.setScore(totalMined);
LK.getSound('mineral').play();
LK.effects.flashObject(self, 0xFFFFFF, 200);
self.shouldRemove = true;
}
};
return self;
});
var Pirate = Container.expand(function () {
var self = Container.call(this);
var pirateGraphics = self.attachAsset('pirate', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 10;
self.speed = Math.random() * 2 + 1;
self.movePattern = Math.floor(Math.random() * 3);
self.phase = 0;
self.shotCooldown = 0;
self.update = function () {
self.phase += 0.01;
// Different movement patterns
if (self.movePattern === 0) {
// Straight down
self.y += self.speed;
} else if (self.movePattern === 1) {
// Sine wave
self.y += self.speed;
self.x += Math.sin(self.phase) * 3;
} else if (self.movePattern === 2) {
// Circle-ish
self.y += self.speed * 0.7;
self.x += Math.sin(self.phase * 2) * 4;
}
// Shoot at player
if (self.shotCooldown <= 0) {
var proj = new PirateProjectile();
proj.x = self.x;
proj.y = self.y + 50;
pirateProjectiles.push(proj);
game.addChild(proj);
self.shotCooldown = 120; // Cooldown timer
} else {
self.shotCooldown--;
}
if (self.y > 2732 + pirateGraphics.height) {
self.shouldRemove = true;
}
};
self.takeDamage = function (amount) {
self.health -= amount;
if (self.health <= 0) {
// Chance to drop bonus minerals
if (Math.random() < 0.5) {
var mineral = new Mineral(Math.ceil(Math.random() * 3));
mineral.x = self.x;
mineral.y = self.y;
mineral.value *= 2; // Pirates drop more valuable minerals
minerals.push(mineral);
game.addChild(mineral);
}
LK.effects.flashObject(self, 0xFFFFFF, 100);
LK.getSound('explosion').play();
self.shouldRemove = true;
}
};
return self;
});
var PirateProjectile = Container.expand(function () {
var self = Container.call(this);
var projectileGraphics = self.attachAsset('pirateProjectile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.damage = 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + projectileGraphics.height) {
self.shouldRemove = true;
}
};
return self;
});
var PlayerShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.miningPower = 1;
self.speed = 5;
self.laserPower = 1;
self.shield = 0;
self.update = function () {
// Automatic shield regeneration
if (self.shield < self.shieldLevel * 20 && LK.ticks % 120 === 0) {
self.shield += 1;
updateStatsDisplay();
}
};
self.takeDamage = function (amount) {
// Shield absorbs damage first
if (self.shield > 0) {
if (self.shield >= amount) {
self.shield -= amount;
amount = 0;
} else {
amount -= self.shield;
self.shield = 0;
}
}
// Any remaining damage affects health
if (amount > 0) {
self.health -= amount;
LK.getSound('damage').play();
LK.effects.flashObject(self, 0xFF0000, 500);
if (self.health <= 0) {
gameOver();
}
}
updateStatsDisplay();
};
self.fireLaser = function () {
var laser = new Laser();
laser.x = self.x;
laser.y = self.y - 50;
laser.power = self.laserPower;
lasers.push(laser);
game.addChild(laser);
LK.getSound('laserShot').play();
};
return self;
});
var UIButton = Container.expand(function (width, height, color, text, textSize) {
var self = Container.call(this);
// Create button background
var buttonGraphics = LK.getAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5,
width: width,
height: height
});
buttonGraphics.tint = color;
self.addChild(buttonGraphics);
// Create button text
var buttonText = new Text2(text, {
size: textSize || 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setEnabled = function (enabled) {
if (enabled) {
buttonGraphics.alpha = 1.0;
} else {
buttonGraphics.alpha = 0.5;
}
self.enabled = enabled;
};
self.setText = function (newText) {
buttonText.setText(newText);
};
self.down = function (x, y, obj) {
if (self.enabled !== false) {
LK.effects.flashObject(self, 0xFFFFFF, 200);
if (self.onPress) {
self.onPress();
}
}
};
self.enabled = true;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000022
});
/****
* Game Code
****/
// Game state variables
var player;
var lasers = [];
var asteroids = [];
var minerals = [];
var pirates = [];
var pirateProjectiles = [];
var credits = storage.credits || 0;
var totalMined = 0;
var gameActive = true;
var spawnRate = 150; // Lower is faster
var pirateRate = 600; // Lower is faster
var lastSpawnTick = 0;
var lastPirateTick = 0;
// UI elements
var statsDisplay;
var healthBar;
var shieldBar;
var shopPanel;
var shopVisible = false;
var shopButtons = [];
// Initialize stats and load saved upgrades
var miningLevel = storage.miningLevel || 1;
var laserLevel = storage.laserLevel || 1;
var speedLevel = storage.speedLevel || 1;
var shieldLevel = storage.shieldLevel || 1;
// Initialize player ship
player = new PlayerShip();
player.x = 2048 / 2;
player.y = 2732 - 200;
player.miningPower = miningLevel;
player.laserPower = laserLevel;
player.speed = 3 + speedLevel;
player.shieldLevel = shieldLevel;
player.shield = shieldLevel * 20;
game.addChild(player);
// Create UI elements
function initUI() {
// Stats display
statsDisplay = new Text2("Credits: 0 | Mining: 1 | Laser: 1 | Speed: 1 | Shield: 1", {
size: 40,
fill: 0xFFFFFF
});
statsDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(statsDisplay);
// Health bar
var healthBarBg = LK.getAsset('bullet', {
anchorX: 0,
anchorY: 0,
width: 300,
height: 30
});
healthBarBg.tint = 0x333333;
healthBarBg.x = 150;
healthBarBg.y = 60;
LK.gui.top.addChild(healthBarBg);
healthBar = LK.getAsset('bullet', {
anchorX: 0,
anchorY: 0,
width: 300,
height: 30
});
healthBar.tint = 0x2ecc71;
healthBar.x = 150;
healthBar.y = 60;
LK.gui.top.addChild(healthBar);
// Shield bar
shieldBar = LK.getAsset('bullet', {
anchorX: 0,
anchorY: 0,
width: 0,
height: 30
});
shieldBar.tint = 0x3498db;
shieldBar.x = 150;
shieldBar.y = 60;
LK.gui.top.addChild(shieldBar);
// Shop button
var shopBtn = new UIButton(200, 60, 0xe67e22, "SHOP", 40);
shopBtn.x = 2048 - 120;
shopBtn.y = 100;
shopBtn.onPress = toggleShop;
LK.gui.top.addChild(shopBtn);
// Create shop panel (initially hidden)
createShopPanel();
// Update the display
updateStatsDisplay();
}
function createShopPanel() {
shopPanel = new Container();
shopPanel.visible = false;
// Panel background
var panelBg = LK.getAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5,
width: 1400,
height: 1000
});
panelBg.tint = 0x333333;
panelBg.alpha = 0.95;
shopPanel.addChild(panelBg);
// Shop title
var shopTitle = new Text2("UPGRADE SHOP", {
size: 80,
fill: 0xFFFFFF
});
shopTitle.anchor.set(0.5, 0);
shopTitle.y = -400;
shopPanel.addChild(shopTitle);
// Close button
var closeBtn = new UIButton(80, 80, 0xe74c3c, "X", 50);
closeBtn.x = 650;
closeBtn.y = -400;
closeBtn.onPress = toggleShop;
shopPanel.addChild(closeBtn);
// Create upgrade buttons
var buttonY = -250;
var buttonSpacing = 150;
// Mining upgrade
var miningBtn = new UIButton(1000, 100, 0x2ecc71, "Mining Level " + miningLevel + " → " + (miningLevel + 1) + " (Cost: " + miningLevel * 100 + " credits)", 50);
miningBtn.y = buttonY;
miningBtn.onPress = function () {
upgradeSystem('mining');
};
shopPanel.addChild(miningBtn);
shopButtons.push({
button: miningBtn,
type: 'mining'
});
buttonY += buttonSpacing;
// Laser upgrade
var laserBtn = new UIButton(1000, 100, 0xe74c3c, "Laser Level " + laserLevel + " → " + (laserLevel + 1) + " (Cost: " + laserLevel * 150 + " credits)", 50);
laserBtn.y = buttonY;
laserBtn.onPress = function () {
upgradeSystem('laser');
};
shopPanel.addChild(laserBtn);
shopButtons.push({
button: laserBtn,
type: 'laser'
});
buttonY += buttonSpacing;
// Speed upgrade
var speedBtn = new UIButton(1000, 100, 0x3498db, "Speed Level " + speedLevel + " → " + (speedLevel + 1) + " (Cost: " + speedLevel * 125 + " credits)", 50);
speedBtn.y = buttonY;
speedBtn.onPress = function () {
upgradeSystem('speed');
};
shopPanel.addChild(speedBtn);
shopButtons.push({
button: speedBtn,
type: 'speed'
});
buttonY += buttonSpacing;
// Shield upgrade
var shieldBtn = new UIButton(1000, 100, 0x9b59b6, "Shield Level " + shieldLevel + " → " + (shieldLevel + 1) + " (Cost: " + shieldLevel * 200 + " credits)", 50);
shieldBtn.y = buttonY;
shieldBtn.onPress = function () {
upgradeSystem('shield');
};
shopPanel.addChild(shieldBtn);
shopButtons.push({
button: shieldBtn,
type: 'shield'
});
// Add shop panel to GUI center
shopPanel.x = 2048 / 2;
shopPanel.y = 2732 / 2;
LK.gui.center.addChild(shopPanel);
}
function updateShopButtons() {
shopButtons.forEach(function (buttonData) {
var type = buttonData.type;
var button = buttonData.button;
var level, cost;
if (type === 'mining') {
level = miningLevel;
cost = miningLevel * 100;
button.setText("Mining Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
} else if (type === 'laser') {
level = laserLevel;
cost = laserLevel * 150;
button.setText("Laser Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
} else if (type === 'speed') {
level = speedLevel;
cost = speedLevel * 125;
button.setText("Speed Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
} else if (type === 'shield') {
level = shieldLevel;
cost = shieldLevel * 200;
button.setText("Shield Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
}
// Enable/disable button based on affordability
button.setEnabled(credits >= cost);
});
}
function toggleShop() {
shopVisible = !shopVisible;
shopPanel.visible = shopVisible;
// Pause game while shop is open
gameActive = !shopVisible;
if (shopVisible) {
updateShopButtons();
}
}
function upgradeSystem(type) {
var cost = 0;
if (type === 'mining') {
cost = miningLevel * 100;
if (credits >= cost) {
credits -= cost;
miningLevel++;
player.miningPower = miningLevel;
storage.miningLevel = miningLevel;
}
} else if (type === 'laser') {
cost = laserLevel * 150;
if (credits >= cost) {
credits -= cost;
laserLevel++;
player.laserPower = laserLevel;
storage.laserLevel = laserLevel;
}
} else if (type === 'speed') {
cost = speedLevel * 125;
if (credits >= cost) {
credits -= cost;
speedLevel++;
player.speed = 3 + speedLevel;
storage.speedLevel = speedLevel;
}
} else if (type === 'shield') {
cost = shieldLevel * 200;
if (credits >= cost) {
credits -= cost;
shieldLevel++;
player.shieldLevel = shieldLevel;
player.shield = player.shieldLevel * 20;
storage.shieldLevel = shieldLevel;
}
}
if (cost > 0 && credits >= cost) {
storage.credits = credits;
LK.getSound('upgrade').play();
updateStatsDisplay();
updateShopButtons();
}
}
function updateStatsDisplay() {
// Update stats text
statsDisplay.setText("Credits: " + credits + " | Mining: " + miningLevel + " | Laser: " + laserLevel + " | Speed: " + speedLevel + " | Shield: " + shieldLevel);
// Update health bar
healthBar.width = player.health / player.maxHealth * 300;
// Update shield bar
shieldBar.width = player.shield / (player.shieldLevel * 20) * 300;
}
function spawnAsteroid() {
var asteroid = new Asteroid();
asteroid.x = Math.random() * 2048;
asteroid.y = -200;
asteroids.push(asteroid);
game.addChild(asteroid);
}
function spawnPirate() {
var pirate = new Pirate();
pirate.x = Math.random() * 2048;
pirate.y = -200;
pirates.push(pirate);
game.addChild(pirate);
}
function gameOver() {
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
// Initialize UI
initUI();
// Play background music
LK.playMusic('bgMusic');
// Input handling
var dragOffset = {
x: 0,
y: 0
};
var isDragging = false;
game.down = function (x, y, obj) {
if (gameActive) {
// Start dragging player
isDragging = true;
dragOffset.x = player.x - x;
dragOffset.y = player.y - y;
// Fire laser
player.fireLaser();
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
game.move = function (x, y, obj) {
if (isDragging && gameActive) {
player.x = x + dragOffset.x;
player.y = y + dragOffset.y;
// Keep player on screen
player.x = Math.max(50, Math.min(2048 - 50, player.x));
player.y = Math.max(500, Math.min(2732 - 50, player.y));
}
};
// Main game loop
game.update = function () {
if (!gameActive) {
return;
}
// Update player
player.update();
// Spawn new asteroids
if (LK.ticks - lastSpawnTick > spawnRate) {
spawnAsteroid();
lastSpawnTick = LK.ticks;
// Increase spawn rate over time (to a limit)
spawnRate = Math.max(60, spawnRate - 0.1);
}
// Spawn pirates occasionally
if (LK.ticks - lastPirateTick > pirateRate) {
spawnPirate();
lastPirateTick = LK.ticks;
// Increase pirate spawn rate over time (to a limit)
pirateRate = Math.max(300, pirateRate - 0.2);
}
// Update lasers
for (var i = lasers.length - 1; i >= 0; i--) {
var laser = lasers[i];
laser.update();
if (laser.shouldRemove) {
game.removeChild(laser);
lasers.splice(i, 1);
continue;
}
// Check for laser collisions with asteroids
for (var j = asteroids.length - 1; j >= 0; j--) {
var asteroid = asteroids[j];
if (laser.intersects(asteroid)) {
asteroid.takeDamage(laser.power);
laser.shouldRemove = true;
break;
}
}
// Check for laser collisions with pirates
if (!laser.shouldRemove) {
for (var k = pirates.length - 1; k >= 0; k--) {
var pirate = pirates[k];
if (laser.intersects(pirate)) {
pirate.takeDamage(laser.power);
laser.shouldRemove = true;
break;
}
}
}
}
// Update asteroids
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
asteroid.update();
if (asteroid.shouldRemove) {
game.removeChild(asteroid);
asteroids.splice(i, 1);
continue;
}
// Check for collisions with player
if (asteroid.intersects(player)) {
player.takeDamage(5);
asteroid.takeDamage(asteroid.health); // Destroy asteroid
}
}
// Update minerals
for (var i = minerals.length - 1; i >= 0; i--) {
var mineral = minerals[i];
mineral.update();
if (mineral.shouldRemove) {
game.removeChild(mineral);
minerals.splice(i, 1);
continue;
}
// Auto-collection based on mining level
var dx = player.x - mineral.x;
var dy = player.y - mineral.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var collectRadius = 100 + player.miningPower * 20;
if (distance < collectRadius) {
// Move toward player for collection
var speed = 0.1 * player.miningPower;
mineral.x += dx * speed;
mineral.y += dy * speed;
// Collect if very close
if (distance < 50) {
mineral.collect();
}
}
}
// Update pirates
for (var i = pirates.length - 1; i >= 0; i--) {
var pirate = pirates[i];
pirate.update();
if (pirate.shouldRemove) {
game.removeChild(pirate);
pirates.splice(i, 1);
continue;
}
// Check for collisions with player
if (pirate.intersects(player)) {
player.takeDamage(20);
pirate.takeDamage(pirate.health); // Destroy pirate
}
}
// Update pirate projectiles
for (var i = pirateProjectiles.length - 1; i >= 0; i--) {
var proj = pirateProjectiles[i];
proj.update();
if (proj.shouldRemove) {
game.removeChild(proj);
pirateProjectiles.splice(i, 1);
continue;
}
// Check for collisions with player
if (proj.intersects(player)) {
player.takeDamage(proj.damage);
proj.shouldRemove = true;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,732 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ credits: 0,
+ miningLevel: 1,
+ laserLevel: 1,
+ speedLevel: 1,
+ shieldLevel: 1,
+ highScore: 0
+});
+
+/****
+* Classes
+****/
+var Asteroid = Container.expand(function (size, mineralType) {
+ var self = Container.call(this);
+ var assetId = 'asteroid' + (size || Math.floor(Math.random() * 3) + 1);
+ var asteroidGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.size = size || Math.floor(Math.random() * 3) + 1;
+ self.health = self.size * 5;
+ self.maxHealth = self.health;
+ self.speed = Math.random() * 1 + 1;
+ self.rotationSpeed = (Math.random() - 0.5) * 0.05;
+ self.mineralType = mineralType || Math.floor(Math.random() * 3) + 1;
+ self.mineralValue = self.mineralType * self.size * 5;
+ self.mineralAmount = self.size * 2;
+ // Tint asteroid based on mineral type (1=iron, 2=silver, 3=gold)
+ if (self.mineralType === 1) {
+ asteroidGraphics.tint = 0x7f8c8d; // Iron (gray)
+ } else if (self.mineralType === 2) {
+ asteroidGraphics.tint = 0xbdc3c7; // Silver (light gray)
+ } else if (self.mineralType === 3) {
+ asteroidGraphics.tint = 0xf1c40f; // Gold (yellow)
+ }
+ self.update = function () {
+ self.y += self.speed;
+ asteroidGraphics.rotation += self.rotationSpeed;
+ if (self.y > 2732 + asteroidGraphics.height) {
+ self.shouldRemove = true;
+ }
+ };
+ self.takeDamage = function (amount) {
+ self.health -= amount;
+ if (self.health <= 0) {
+ // Spawn minerals
+ for (var i = 0; i < self.mineralAmount; i++) {
+ var mineral = new Mineral(self.mineralType);
+ mineral.x = self.x + (Math.random() - 0.5) * 50;
+ mineral.y = self.y + (Math.random() - 0.5) * 50;
+ minerals.push(mineral);
+ game.addChild(mineral);
+ }
+ // Explosion effect
+ LK.effects.flashObject(self, 0xFFFFFF, 100);
+ LK.getSound('explosion').play();
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
+var Laser = Container.expand(function () {
+ var self = Container.call(this);
+ var laserGraphics = self.attachAsset('laser', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.power = 1;
+ self.update = function () {
+ self.y -= self.speed;
+ if (self.y < -50) {
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
+var Mineral = Container.expand(function (type) {
+ var self = Container.call(this);
+ var mineralGraphics = self.attachAsset('mineral', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = type || 1;
+ self.value = self.type * 5;
+ self.collected = false;
+ self.speed = Math.random() * 1 + 0.5;
+ self.driftX = (Math.random() - 0.5) * 2;
+ // Tint mineral based on type
+ if (self.type === 1) {
+ mineralGraphics.tint = 0x7f8c8d; // Iron (gray)
+ } else if (self.type === 2) {
+ mineralGraphics.tint = 0xbdc3c7; // Silver (light gray)
+ } else if (self.type === 3) {
+ mineralGraphics.tint = 0xf1c40f; // Gold (yellow)
+ }
+ self.update = function () {
+ self.y += self.speed;
+ self.x += self.driftX;
+ if (self.y > 2732 + mineralGraphics.height) {
+ self.shouldRemove = true;
+ }
+ };
+ self.collect = function () {
+ if (!self.collected) {
+ self.collected = true;
+ credits += self.value;
+ totalMined += self.value;
+ storage.credits = credits;
+ if (totalMined > storage.highScore) {
+ storage.highScore = totalMined;
+ }
+ updateStatsDisplay();
+ LK.setScore(totalMined);
+ LK.getSound('mineral').play();
+ LK.effects.flashObject(self, 0xFFFFFF, 200);
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
+var Pirate = Container.expand(function () {
+ var self = Container.call(this);
+ var pirateGraphics = self.attachAsset('pirate', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 10;
+ self.speed = Math.random() * 2 + 1;
+ self.movePattern = Math.floor(Math.random() * 3);
+ self.phase = 0;
+ self.shotCooldown = 0;
+ self.update = function () {
+ self.phase += 0.01;
+ // Different movement patterns
+ if (self.movePattern === 0) {
+ // Straight down
+ self.y += self.speed;
+ } else if (self.movePattern === 1) {
+ // Sine wave
+ self.y += self.speed;
+ self.x += Math.sin(self.phase) * 3;
+ } else if (self.movePattern === 2) {
+ // Circle-ish
+ self.y += self.speed * 0.7;
+ self.x += Math.sin(self.phase * 2) * 4;
+ }
+ // Shoot at player
+ if (self.shotCooldown <= 0) {
+ var proj = new PirateProjectile();
+ proj.x = self.x;
+ proj.y = self.y + 50;
+ pirateProjectiles.push(proj);
+ game.addChild(proj);
+ self.shotCooldown = 120; // Cooldown timer
+ } else {
+ self.shotCooldown--;
+ }
+ if (self.y > 2732 + pirateGraphics.height) {
+ self.shouldRemove = true;
+ }
+ };
+ self.takeDamage = function (amount) {
+ self.health -= amount;
+ if (self.health <= 0) {
+ // Chance to drop bonus minerals
+ if (Math.random() < 0.5) {
+ var mineral = new Mineral(Math.ceil(Math.random() * 3));
+ mineral.x = self.x;
+ mineral.y = self.y;
+ mineral.value *= 2; // Pirates drop more valuable minerals
+ minerals.push(mineral);
+ game.addChild(mineral);
+ }
+ LK.effects.flashObject(self, 0xFFFFFF, 100);
+ LK.getSound('explosion').play();
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
+var PirateProjectile = Container.expand(function () {
+ var self = Container.call(this);
+ var projectileGraphics = self.attachAsset('pirateProjectile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.damage = 10;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732 + projectileGraphics.height) {
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
+var PlayerShip = Container.expand(function () {
+ var self = Container.call(this);
+ var shipGraphics = self.attachAsset('playerShip', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 100;
+ self.maxHealth = 100;
+ self.miningPower = 1;
+ self.speed = 5;
+ self.laserPower = 1;
+ self.shield = 0;
+ self.update = function () {
+ // Automatic shield regeneration
+ if (self.shield < self.shieldLevel * 20 && LK.ticks % 120 === 0) {
+ self.shield += 1;
+ updateStatsDisplay();
+ }
+ };
+ self.takeDamage = function (amount) {
+ // Shield absorbs damage first
+ if (self.shield > 0) {
+ if (self.shield >= amount) {
+ self.shield -= amount;
+ amount = 0;
+ } else {
+ amount -= self.shield;
+ self.shield = 0;
+ }
+ }
+ // Any remaining damage affects health
+ if (amount > 0) {
+ self.health -= amount;
+ LK.getSound('damage').play();
+ LK.effects.flashObject(self, 0xFF0000, 500);
+ if (self.health <= 0) {
+ gameOver();
+ }
+ }
+ updateStatsDisplay();
+ };
+ self.fireLaser = function () {
+ var laser = new Laser();
+ laser.x = self.x;
+ laser.y = self.y - 50;
+ laser.power = self.laserPower;
+ lasers.push(laser);
+ game.addChild(laser);
+ LK.getSound('laserShot').play();
+ };
+ return self;
+});
+var UIButton = Container.expand(function (width, height, color, text, textSize) {
+ var self = Container.call(this);
+ // Create button background
+ var buttonGraphics = LK.getAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: width,
+ height: height
+ });
+ buttonGraphics.tint = color;
+ self.addChild(buttonGraphics);
+ // Create button text
+ var buttonText = new Text2(text, {
+ size: textSize || 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.setEnabled = function (enabled) {
+ if (enabled) {
+ buttonGraphics.alpha = 1.0;
+ } else {
+ buttonGraphics.alpha = 0.5;
+ }
+ self.enabled = enabled;
+ };
+ self.setText = function (newText) {
+ buttonText.setText(newText);
+ };
+ self.down = function (x, y, obj) {
+ if (self.enabled !== false) {
+ LK.effects.flashObject(self, 0xFFFFFF, 200);
+ if (self.onPress) {
+ self.onPress();
+ }
+ }
+ };
+ self.enabled = true;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x000022
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var player;
+var lasers = [];
+var asteroids = [];
+var minerals = [];
+var pirates = [];
+var pirateProjectiles = [];
+var credits = storage.credits || 0;
+var totalMined = 0;
+var gameActive = true;
+var spawnRate = 150; // Lower is faster
+var pirateRate = 600; // Lower is faster
+var lastSpawnTick = 0;
+var lastPirateTick = 0;
+// UI elements
+var statsDisplay;
+var healthBar;
+var shieldBar;
+var shopPanel;
+var shopVisible = false;
+var shopButtons = [];
+// Initialize stats and load saved upgrades
+var miningLevel = storage.miningLevel || 1;
+var laserLevel = storage.laserLevel || 1;
+var speedLevel = storage.speedLevel || 1;
+var shieldLevel = storage.shieldLevel || 1;
+// Initialize player ship
+player = new PlayerShip();
+player.x = 2048 / 2;
+player.y = 2732 - 200;
+player.miningPower = miningLevel;
+player.laserPower = laserLevel;
+player.speed = 3 + speedLevel;
+player.shieldLevel = shieldLevel;
+player.shield = shieldLevel * 20;
+game.addChild(player);
+// Create UI elements
+function initUI() {
+ // Stats display
+ statsDisplay = new Text2("Credits: 0 | Mining: 1 | Laser: 1 | Speed: 1 | Shield: 1", {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ statsDisplay.anchor.set(0.5, 0);
+ LK.gui.top.addChild(statsDisplay);
+ // Health bar
+ var healthBarBg = LK.getAsset('bullet', {
+ anchorX: 0,
+ anchorY: 0,
+ width: 300,
+ height: 30
+ });
+ healthBarBg.tint = 0x333333;
+ healthBarBg.x = 150;
+ healthBarBg.y = 60;
+ LK.gui.top.addChild(healthBarBg);
+ healthBar = LK.getAsset('bullet', {
+ anchorX: 0,
+ anchorY: 0,
+ width: 300,
+ height: 30
+ });
+ healthBar.tint = 0x2ecc71;
+ healthBar.x = 150;
+ healthBar.y = 60;
+ LK.gui.top.addChild(healthBar);
+ // Shield bar
+ shieldBar = LK.getAsset('bullet', {
+ anchorX: 0,
+ anchorY: 0,
+ width: 0,
+ height: 30
+ });
+ shieldBar.tint = 0x3498db;
+ shieldBar.x = 150;
+ shieldBar.y = 60;
+ LK.gui.top.addChild(shieldBar);
+ // Shop button
+ var shopBtn = new UIButton(200, 60, 0xe67e22, "SHOP", 40);
+ shopBtn.x = 2048 - 120;
+ shopBtn.y = 100;
+ shopBtn.onPress = toggleShop;
+ LK.gui.top.addChild(shopBtn);
+ // Create shop panel (initially hidden)
+ createShopPanel();
+ // Update the display
+ updateStatsDisplay();
+}
+function createShopPanel() {
+ shopPanel = new Container();
+ shopPanel.visible = false;
+ // Panel background
+ var panelBg = LK.getAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: 1400,
+ height: 1000
+ });
+ panelBg.tint = 0x333333;
+ panelBg.alpha = 0.95;
+ shopPanel.addChild(panelBg);
+ // Shop title
+ var shopTitle = new Text2("UPGRADE SHOP", {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ shopTitle.anchor.set(0.5, 0);
+ shopTitle.y = -400;
+ shopPanel.addChild(shopTitle);
+ // Close button
+ var closeBtn = new UIButton(80, 80, 0xe74c3c, "X", 50);
+ closeBtn.x = 650;
+ closeBtn.y = -400;
+ closeBtn.onPress = toggleShop;
+ shopPanel.addChild(closeBtn);
+ // Create upgrade buttons
+ var buttonY = -250;
+ var buttonSpacing = 150;
+ // Mining upgrade
+ var miningBtn = new UIButton(1000, 100, 0x2ecc71, "Mining Level " + miningLevel + " → " + (miningLevel + 1) + " (Cost: " + miningLevel * 100 + " credits)", 50);
+ miningBtn.y = buttonY;
+ miningBtn.onPress = function () {
+ upgradeSystem('mining');
+ };
+ shopPanel.addChild(miningBtn);
+ shopButtons.push({
+ button: miningBtn,
+ type: 'mining'
+ });
+ buttonY += buttonSpacing;
+ // Laser upgrade
+ var laserBtn = new UIButton(1000, 100, 0xe74c3c, "Laser Level " + laserLevel + " → " + (laserLevel + 1) + " (Cost: " + laserLevel * 150 + " credits)", 50);
+ laserBtn.y = buttonY;
+ laserBtn.onPress = function () {
+ upgradeSystem('laser');
+ };
+ shopPanel.addChild(laserBtn);
+ shopButtons.push({
+ button: laserBtn,
+ type: 'laser'
+ });
+ buttonY += buttonSpacing;
+ // Speed upgrade
+ var speedBtn = new UIButton(1000, 100, 0x3498db, "Speed Level " + speedLevel + " → " + (speedLevel + 1) + " (Cost: " + speedLevel * 125 + " credits)", 50);
+ speedBtn.y = buttonY;
+ speedBtn.onPress = function () {
+ upgradeSystem('speed');
+ };
+ shopPanel.addChild(speedBtn);
+ shopButtons.push({
+ button: speedBtn,
+ type: 'speed'
+ });
+ buttonY += buttonSpacing;
+ // Shield upgrade
+ var shieldBtn = new UIButton(1000, 100, 0x9b59b6, "Shield Level " + shieldLevel + " → " + (shieldLevel + 1) + " (Cost: " + shieldLevel * 200 + " credits)", 50);
+ shieldBtn.y = buttonY;
+ shieldBtn.onPress = function () {
+ upgradeSystem('shield');
+ };
+ shopPanel.addChild(shieldBtn);
+ shopButtons.push({
+ button: shieldBtn,
+ type: 'shield'
+ });
+ // Add shop panel to GUI center
+ shopPanel.x = 2048 / 2;
+ shopPanel.y = 2732 / 2;
+ LK.gui.center.addChild(shopPanel);
+}
+function updateShopButtons() {
+ shopButtons.forEach(function (buttonData) {
+ var type = buttonData.type;
+ var button = buttonData.button;
+ var level, cost;
+ if (type === 'mining') {
+ level = miningLevel;
+ cost = miningLevel * 100;
+ button.setText("Mining Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
+ } else if (type === 'laser') {
+ level = laserLevel;
+ cost = laserLevel * 150;
+ button.setText("Laser Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
+ } else if (type === 'speed') {
+ level = speedLevel;
+ cost = speedLevel * 125;
+ button.setText("Speed Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
+ } else if (type === 'shield') {
+ level = shieldLevel;
+ cost = shieldLevel * 200;
+ button.setText("Shield Level " + level + " → " + (level + 1) + " (Cost: " + cost + " credits)");
+ }
+ // Enable/disable button based on affordability
+ button.setEnabled(credits >= cost);
+ });
+}
+function toggleShop() {
+ shopVisible = !shopVisible;
+ shopPanel.visible = shopVisible;
+ // Pause game while shop is open
+ gameActive = !shopVisible;
+ if (shopVisible) {
+ updateShopButtons();
+ }
+}
+function upgradeSystem(type) {
+ var cost = 0;
+ if (type === 'mining') {
+ cost = miningLevel * 100;
+ if (credits >= cost) {
+ credits -= cost;
+ miningLevel++;
+ player.miningPower = miningLevel;
+ storage.miningLevel = miningLevel;
+ }
+ } else if (type === 'laser') {
+ cost = laserLevel * 150;
+ if (credits >= cost) {
+ credits -= cost;
+ laserLevel++;
+ player.laserPower = laserLevel;
+ storage.laserLevel = laserLevel;
+ }
+ } else if (type === 'speed') {
+ cost = speedLevel * 125;
+ if (credits >= cost) {
+ credits -= cost;
+ speedLevel++;
+ player.speed = 3 + speedLevel;
+ storage.speedLevel = speedLevel;
+ }
+ } else if (type === 'shield') {
+ cost = shieldLevel * 200;
+ if (credits >= cost) {
+ credits -= cost;
+ shieldLevel++;
+ player.shieldLevel = shieldLevel;
+ player.shield = player.shieldLevel * 20;
+ storage.shieldLevel = shieldLevel;
+ }
+ }
+ if (cost > 0 && credits >= cost) {
+ storage.credits = credits;
+ LK.getSound('upgrade').play();
+ updateStatsDisplay();
+ updateShopButtons();
+ }
+}
+function updateStatsDisplay() {
+ // Update stats text
+ statsDisplay.setText("Credits: " + credits + " | Mining: " + miningLevel + " | Laser: " + laserLevel + " | Speed: " + speedLevel + " | Shield: " + shieldLevel);
+ // Update health bar
+ healthBar.width = player.health / player.maxHealth * 300;
+ // Update shield bar
+ shieldBar.width = player.shield / (player.shieldLevel * 20) * 300;
+}
+function spawnAsteroid() {
+ var asteroid = new Asteroid();
+ asteroid.x = Math.random() * 2048;
+ asteroid.y = -200;
+ asteroids.push(asteroid);
+ game.addChild(asteroid);
+}
+function spawnPirate() {
+ var pirate = new Pirate();
+ pirate.x = Math.random() * 2048;
+ pirate.y = -200;
+ pirates.push(pirate);
+ game.addChild(pirate);
+}
+function gameOver() {
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+}
+// Initialize UI
+initUI();
+// Play background music
+LK.playMusic('bgMusic');
+// Input handling
+var dragOffset = {
+ x: 0,
+ y: 0
+};
+var isDragging = false;
+game.down = function (x, y, obj) {
+ if (gameActive) {
+ // Start dragging player
+ isDragging = true;
+ dragOffset.x = player.x - x;
+ dragOffset.y = player.y - y;
+ // Fire laser
+ player.fireLaser();
+ }
+};
+game.up = function (x, y, obj) {
+ isDragging = false;
+};
+game.move = function (x, y, obj) {
+ if (isDragging && gameActive) {
+ player.x = x + dragOffset.x;
+ player.y = y + dragOffset.y;
+ // Keep player on screen
+ player.x = Math.max(50, Math.min(2048 - 50, player.x));
+ player.y = Math.max(500, Math.min(2732 - 50, player.y));
+ }
+};
+// Main game loop
+game.update = function () {
+ if (!gameActive) {
+ return;
+ }
+ // Update player
+ player.update();
+ // Spawn new asteroids
+ if (LK.ticks - lastSpawnTick > spawnRate) {
+ spawnAsteroid();
+ lastSpawnTick = LK.ticks;
+ // Increase spawn rate over time (to a limit)
+ spawnRate = Math.max(60, spawnRate - 0.1);
+ }
+ // Spawn pirates occasionally
+ if (LK.ticks - lastPirateTick > pirateRate) {
+ spawnPirate();
+ lastPirateTick = LK.ticks;
+ // Increase pirate spawn rate over time (to a limit)
+ pirateRate = Math.max(300, pirateRate - 0.2);
+ }
+ // Update lasers
+ for (var i = lasers.length - 1; i >= 0; i--) {
+ var laser = lasers[i];
+ laser.update();
+ if (laser.shouldRemove) {
+ game.removeChild(laser);
+ lasers.splice(i, 1);
+ continue;
+ }
+ // Check for laser collisions with asteroids
+ for (var j = asteroids.length - 1; j >= 0; j--) {
+ var asteroid = asteroids[j];
+ if (laser.intersects(asteroid)) {
+ asteroid.takeDamage(laser.power);
+ laser.shouldRemove = true;
+ break;
+ }
+ }
+ // Check for laser collisions with pirates
+ if (!laser.shouldRemove) {
+ for (var k = pirates.length - 1; k >= 0; k--) {
+ var pirate = pirates[k];
+ if (laser.intersects(pirate)) {
+ pirate.takeDamage(laser.power);
+ laser.shouldRemove = true;
+ break;
+ }
+ }
+ }
+ }
+ // Update asteroids
+ for (var i = asteroids.length - 1; i >= 0; i--) {
+ var asteroid = asteroids[i];
+ asteroid.update();
+ if (asteroid.shouldRemove) {
+ game.removeChild(asteroid);
+ asteroids.splice(i, 1);
+ continue;
+ }
+ // Check for collisions with player
+ if (asteroid.intersects(player)) {
+ player.takeDamage(5);
+ asteroid.takeDamage(asteroid.health); // Destroy asteroid
+ }
+ }
+ // Update minerals
+ for (var i = minerals.length - 1; i >= 0; i--) {
+ var mineral = minerals[i];
+ mineral.update();
+ if (mineral.shouldRemove) {
+ game.removeChild(mineral);
+ minerals.splice(i, 1);
+ continue;
+ }
+ // Auto-collection based on mining level
+ var dx = player.x - mineral.x;
+ var dy = player.y - mineral.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var collectRadius = 100 + player.miningPower * 20;
+ if (distance < collectRadius) {
+ // Move toward player for collection
+ var speed = 0.1 * player.miningPower;
+ mineral.x += dx * speed;
+ mineral.y += dy * speed;
+ // Collect if very close
+ if (distance < 50) {
+ mineral.collect();
+ }
+ }
+ }
+ // Update pirates
+ for (var i = pirates.length - 1; i >= 0; i--) {
+ var pirate = pirates[i];
+ pirate.update();
+ if (pirate.shouldRemove) {
+ game.removeChild(pirate);
+ pirates.splice(i, 1);
+ continue;
+ }
+ // Check for collisions with player
+ if (pirate.intersects(player)) {
+ player.takeDamage(20);
+ pirate.takeDamage(pirate.health); // Destroy pirate
+ }
+ }
+ // Update pirate projectiles
+ for (var i = pirateProjectiles.length - 1; i >= 0; i--) {
+ var proj = pirateProjectiles[i];
+ proj.update();
+ if (proj.shouldRemove) {
+ game.removeChild(proj);
+ pirateProjectiles.splice(i, 1);
+ continue;
+ }
+ // Check for collisions with player
+ if (proj.intersects(player)) {
+ player.takeDamage(proj.damage);
+ proj.shouldRemove = true;
+ }
+ }
+};
\ No newline at end of file
create bullet from ak-56. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
create a blue and white spaceship. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
create a brown asteroid with red holes. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
create tesla laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
create a green and blue money. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
create a rainbow sword. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
create a rainbow alien in a UFO. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows