User prompt
Get rid of the helpers all together
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'helperTxt.setText')' in or related to this line: 'helperTxt.setText('HELPERS: on');' Line Number: 448
Code edit (1 edits merged)
Please save this source code
User prompt
Let’s make helpers automatically turn on every time you spawn in
User prompt
Let’s make the helper ship purple
User prompt
Let’s make a helper upgrade spawn every 20 seconds
User prompt
Make the helper upgrade orb purple
User prompt
Let’s make the helper upgrade, just like the rest of the upgrades and wear off just like the other upgrades
User prompt
Let’s get rid of the three lives function and add an upgrade that makes smaller NPC helper ships spawn that will kill enemy ships ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Let’s get rid of the permanent upgrades function
User prompt
Let’s make an upgrade button that allows you to go to the upgrade shop on the left corner
User prompt
Let’s make the smaller enemies die with one hit
User prompt
Let’s add ship permanent upgrades and make them have to be bought with points ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Let’s add a boss health bar
User prompt
Let’s make the boss die after 50 hits
User prompt
Make the small ships stop spawning during the boss battle
User prompt
Make the boss spawn immediately when you get to 500 points then make it survive until killed by player ship
User prompt
Delete the last thing I said
User prompt
Let’s make the smaller ship stop spawning during the boss battle, and then restart again after it’s gone
User prompt
Change the boss spawning from 1000 to 500
Code edit (1 edits merged)
Please save this source code
User prompt
Let’s make a boss spawn every 1000 points and then stay there until the player kill it. Let’s make it take 100 hits to kill it.
User prompt
Let’s make a boss not spawn until player reaches 1000 points
User prompt
Let’s make a boss spawn every 1000 points
User prompt
Let’s increase the stick sensitivity
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1");
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Boss = Container.expand(function () {
var self = Container.call(this);
// Boss main body (larger than regular enemy)
var bossBody = self.attachAsset('enemyShipBody', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Boss wings (scaled up)
var bossWings = self.attachAsset('enemyShipWings', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -60,
scaleX: 5,
scaleY: 3
});
// Boss core (scaled up)
var bossCore = self.attachAsset('enemyShipCore', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
scaleX: 3,
scaleY: 3
});
// Boss thruster (scaled up)
var bossThruster = self.attachAsset('enemyShipThruster', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 120,
scaleX: 4,
scaleY: 4
});
self.health = 50;
self.maxHealth = 50;
self.speed = 1;
self.shootTimer = 0;
self.shootInterval = 30;
self.moveTimer = 0;
self.moveDirection = 1;
self.lastHealth = self.health;
self.update = function () {
// Boss movement pattern - side to side
self.moveTimer++;
if (self.moveTimer % 120 == 0) {
self.moveDirection *= -1;
}
self.x += self.moveDirection * 2;
// Keep boss on screen
if (self.x <= 200) {
self.x = 200;
self.moveDirection = 1;
}
if (self.x >= 1848) {
self.x = 1848;
self.moveDirection = -1;
}
// Boss shooting - multiple bullets
self.shootTimer++;
if (self.shootTimer >= self.shootInterval) {
self.shootTimer = 0;
// Fire 5 bullets in spread pattern
for (var bulletIndex = 0; bulletIndex < 5; bulletIndex++) {
var bullet = new EnemyBullet();
bullet.x = self.x + (bulletIndex - 2) * 50;
bullet.y = self.y + 80;
bullet.lastY = bullet.y;
bullet.speed = 6;
enemyBullets.push(bullet);
game.addChild(bullet);
}
}
};
return self;
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
};
return self;
});
var EnemyShip = Container.expand(function () {
var self = Container.call(this);
// Main body
var shipBody = self.attachAsset('enemyShipBody', {
anchorX: 0.5,
anchorY: 0.5
});
// Wings
var wings = self.attachAsset('enemyShipWings', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -15
});
// Core/cockpit
var core = self.attachAsset('enemyShipCore', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
// Thruster
var thruster = self.attachAsset('enemyShipThruster', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 30
});
self.speed = 3;
self.health = 1;
self.shootTimer = 0;
self.shootInterval = 60 + Math.random() * 120; // Random shooting interval
self.update = function () {
self.y += self.speed;
// Enemy shooting logic
self.shootTimer++;
if (self.shootTimer >= self.shootInterval) {
self.shootTimer = 0;
self.shootInterval = 60 + Math.random() * 120; // Reset with new random interval
// Create enemy bullet
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + 40;
bullet.lastY = bullet.y;
enemyBullets.push(bullet);
game.addChild(bullet);
}
};
return self;
});
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('playerBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -12;
self.update = function () {
self.y += self.speed;
};
return self;
});
var PlayerShip = Container.expand(function () {
var self = Container.call(this);
// Main body
var shipBody = self.attachAsset('playerShipBody', {
anchorX: 0.5,
anchorY: 0.5
});
// Wings
var leftWing = self.attachAsset('playerShipWings', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 20
});
// Cockpit
var cockpit = self.attachAsset('playerShipCockpit', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -15
});
// Engine thrusters
var leftEngine = self.attachAsset('playerShipEngines', {
anchorX: 0.5,
anchorY: 0.5,
x: -25,
y: 35
});
var rightEngine = self.attachAsset('playerShipEngines', {
anchorX: 0.5,
anchorY: 0.5,
x: 25,
y: 35
});
// Shield visual effect (initially hidden)
var shieldGraphics = self.attachAsset('shieldEffect', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
alpha: 0
});
self.shieldGraphics = shieldGraphics;
self.shootTimer = 0;
self.shootInterval = 15; // Shoot every 15 ticks (4 times per second)
self.update = function () {
// Auto-shooting logic
self.shootTimer++;
var currentShootInterval = playerUpgrades.rapidFire ? Math.floor(self.shootInterval / 2) : self.shootInterval;
if (self.shootTimer >= currentShootInterval) {
self.shootTimer = 0;
if (playerUpgrades.tripleShot) {
// Triple shot
for (var shotIndex = 0; shotIndex < 3; shotIndex++) {
var bullet = new PlayerBullet();
bullet.x = self.x + (shotIndex - 1) * 30; // Spread shots
bullet.y = self.y - 50;
bullet.lastY = bullet.y;
playerBullets.push(bullet);
game.addChild(bullet);
}
} else {
// Single shot
var bullet = new PlayerBullet();
bullet.x = self.x;
bullet.y = self.y - 50;
bullet.lastY = bullet.y;
playerBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('shoot').play();
}
};
return self;
});
var Upgrade = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.speed = 4;
var upgradeGraphics = self.attachAsset('upgrade' + type, {
anchorX: 0.5,
anchorY: 0.5
});
// Pulsing animation
tween(upgradeGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(upgradeGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the pulsing animation
if (self.parent) {
tween(upgradeGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: arguments.callee.caller
});
}
}
});
}
});
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000011
});
/****
* Game Code
****/
// Game variables
var playerBullets = [];
var enemyBullets = [];
var enemies = [];
var bosses = [];
var upgrades = [];
var enemySpawnTimer = 0;
var enemySpawnInterval = 120; // Start with 2 seconds between spawns
var upgradeSpawnTimer = 0;
var upgradeSpawnInterval = 600; // 10 seconds between upgrades
var dragNode = null;
var difficultyTimer = 0;
// Upgrade system
var playerUpgrades = {
rapidFire: false,
rapidFireTimer: 0,
shield: false,
shieldTimer: 0,
tripleShot: false,
tripleShotTimer: 0
};
// Permanent upgrade system
var permanentUpgrades = storage.permanentUpgrades || {
damageLevel: 1,
speedLevel: 1,
healthLevel: 1
};
var upgradeCosts = {
damageLevel: 100,
speedLevel: 150,
healthLevel: 200
};
// Current player stats based on permanent upgrades
var playerStats = {
damage: permanentUpgrades.damageLevel,
speed: 1 + (permanentUpgrades.speedLevel - 1) * 0.3,
health: permanentUpgrades.healthLevel
};
var playerHealth = playerStats.health;
var maxPlayerHealth = playerStats.health;
// Create player ship
var player = game.addChild(new PlayerShip());
player.x = 1024; // Center horizontally
player.y = 2400; // Near bottom of screen
// Create game title
var titleTxt = new Text2('SPACE INVADERS 2.0', {
size: 80,
fill: 0x00ff00
});
titleTxt.anchor.set(0.5, 0);
titleTxt.x = 0;
titleTxt.y = 20;
LK.gui.top.addChild(titleTxt);
// Create score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = 120;
LK.gui.top.addChild(scoreTxt);
scoreTxt.setText(LK.getScore());
// Create boss health bar (initially hidden)
var bossHealthBarBg = LK.getAsset('bossHealthBarBg', {
anchorX: 0.5,
anchorY: 0,
alpha: 0
});
var bossHealthBarFill = LK.getAsset('bossHealthBarFill', {
anchorX: 0,
anchorY: 0,
alpha: 0
});
bossHealthBarBg.x = 0;
bossHealthBarBg.y = 220;
bossHealthBarFill.x = -200;
bossHealthBarFill.y = 0;
LK.gui.top.addChild(bossHealthBarBg);
bossHealthBarBg.addChild(bossHealthBarFill);
// Boss health bar text
var bossHealthTxt = new Text2('BOSS', {
size: 40,
fill: 0xff0000
});
bossHealthTxt.anchor.set(0.5, 0);
bossHealthTxt.x = 0;
bossHealthTxt.y = 250;
bossHealthTxt.alpha = 0;
LK.gui.top.addChild(bossHealthTxt);
// Upgrade Shop UI
var shopButton = new Text2('UPGRADES', {
size: 60,
fill: 0x00ff00
});
shopButton.anchor.set(1, 0);
shopButton.x = -20;
shopButton.y = 20;
LK.gui.topRight.addChild(shopButton);
var shopVisible = false;
var shopContainer = new Container();
shopContainer.alpha = 0;
LK.gui.center.addChild(shopContainer);
// Shop background
var shopBg = LK.getAsset('enemyShipBody', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 12,
scaleY: 8,
alpha: 0.8
});
shopContainer.addChild(shopBg);
// Shop title
var shopTitle = new Text2('PERMANENT UPGRADES', {
size: 70,
fill: 0x00ff00
});
shopTitle.anchor.set(0.5, 0.5);
shopTitle.y = -250;
shopContainer.addChild(shopTitle);
// Damage upgrade
var damageUpgradeText = new Text2('DAMAGE LV.' + permanentUpgrades.damageLevel + ' - COST: ' + upgradeCosts.damageLevel * permanentUpgrades.damageLevel, {
size: 50,
fill: 0xffffff
});
damageUpgradeText.anchor.set(0.5, 0.5);
damageUpgradeText.y = -100;
shopContainer.addChild(damageUpgradeText);
// Speed upgrade
var speedUpgradeText = new Text2('SPEED LV.' + permanentUpgrades.speedLevel + ' - COST: ' + upgradeCosts.speedLevel * permanentUpgrades.speedLevel, {
size: 50,
fill: 0xffffff
});
speedUpgradeText.anchor.set(0.5, 0.5);
speedUpgradeText.y = 0;
shopContainer.addChild(speedUpgradeText);
// Health upgrade
var healthUpgradeText = new Text2('HEALTH LV.' + permanentUpgrades.healthLevel + ' - COST: ' + upgradeCosts.healthLevel * permanentUpgrades.healthLevel, {
size: 50,
fill: 0xffffff
});
healthUpgradeText.anchor.set(0.5, 0.5);
healthUpgradeText.y = 100;
shopContainer.addChild(healthUpgradeText);
// Close button
var closeButton = new Text2('CLOSE', {
size: 60,
fill: 0xff0000
});
closeButton.anchor.set(0.5, 0.5);
closeButton.y = 200;
shopContainer.addChild(closeButton);
// Upgrade button in left corner
var upgradeButton = new Text2('UPGRADE', {
size: 50,
fill: 0x00ff00
});
upgradeButton.anchor.set(0, 0);
upgradeButton.x = 120; // Position to avoid the menu icon area
upgradeButton.y = 20;
LK.gui.topLeft.addChild(upgradeButton);
// Player health display
var healthTxt = new Text2('HEALTH: ' + playerHealth + '/' + maxPlayerHealth, {
size: 60,
fill: 0xff4444
});
healthTxt.anchor.set(0, 0);
healthTxt.x = 20;
healthTxt.y = 300;
LK.gui.topLeft.addChild(healthTxt);
// Stick control variables
var stickActive = false;
var stickStartX = 0;
var stickStartY = 0;
var stickCurrentX = 0;
var stickCurrentY = 0;
var maxStickDistance = 150;
// Touch controls for stick movement
function handleMove(x, y, obj) {
if (stickActive) {
stickCurrentX = x;
stickCurrentY = y;
// Calculate distance from start point
var deltaX = stickCurrentX - stickStartX;
var deltaY = stickCurrentY - stickStartY;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// Limit stick movement to max distance
if (distance > maxStickDistance) {
var angle = Math.atan2(deltaY, deltaX);
deltaX = Math.cos(angle) * maxStickDistance;
deltaY = Math.sin(angle) * maxStickDistance;
stickCurrentX = stickStartX + deltaX;
stickCurrentY = stickStartY + deltaY;
}
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Check shop interactions
if (shopVisible) {
var localPos = shopContainer.toLocal({
x: x,
y: y
});
// Check upgrade purchases
if (Math.abs(localPos.x) < 400 && Math.abs(localPos.y + 100) < 25) {
// Damage upgrade clicked
var cost = upgradeCosts.damageLevel * permanentUpgrades.damageLevel;
if (LK.getScore() >= cost) {
LK.setScore(LK.getScore() - cost);
permanentUpgrades.damageLevel++;
playerStats.damage = permanentUpgrades.damageLevel;
storage.permanentUpgrades = permanentUpgrades;
damageUpgradeText.setText('DAMAGE LV.' + permanentUpgrades.damageLevel + ' - COST: ' + upgradeCosts.damageLevel * permanentUpgrades.damageLevel);
scoreTxt.setText(LK.getScore());
LK.effects.flashScreen(0x00ff00, 300);
}
return;
}
if (Math.abs(localPos.x) < 400 && Math.abs(localPos.y) < 25) {
// Speed upgrade clicked
var cost = upgradeCosts.speedLevel * permanentUpgrades.speedLevel;
if (LK.getScore() >= cost) {
LK.setScore(LK.getScore() - cost);
permanentUpgrades.speedLevel++;
playerStats.speed = 1 + (permanentUpgrades.speedLevel - 1) * 0.3;
storage.permanentUpgrades = permanentUpgrades;
speedUpgradeText.setText('SPEED LV.' + permanentUpgrades.speedLevel + ' - COST: ' + upgradeCosts.speedLevel * permanentUpgrades.speedLevel);
scoreTxt.setText(LK.getScore());
LK.effects.flashScreen(0x00ff00, 300);
}
return;
}
if (Math.abs(localPos.x) < 400 && Math.abs(localPos.y - 100) < 25) {
// Health upgrade clicked
var cost = upgradeCosts.healthLevel * permanentUpgrades.healthLevel;
if (LK.getScore() >= cost) {
LK.setScore(LK.getScore() - cost);
permanentUpgrades.healthLevel++;
playerStats.health = permanentUpgrades.healthLevel;
maxPlayerHealth = playerStats.health;
playerHealth = maxPlayerHealth; // Heal to full
storage.permanentUpgrades = permanentUpgrades;
healthUpgradeText.setText('HEALTH LV.' + permanentUpgrades.healthLevel + ' - COST: ' + upgradeCosts.healthLevel * permanentUpgrades.healthLevel);
healthTxt.setText('HEALTH: ' + playerHealth + '/' + maxPlayerHealth);
scoreTxt.setText(LK.getScore());
LK.effects.flashScreen(0x00ff00, 300);
}
return;
}
if (Math.abs(localPos.x) < 200 && Math.abs(localPos.y - 200) < 30) {
// Close button clicked
shopVisible = false;
tween(shopContainer, {
alpha: 0
}, {
duration: 300,
easing: tween.easeOut
});
return;
}
} else {
// Check if upgrade button clicked (left corner)
var upgradeButtonPos = LK.gui.topLeft.toLocal({
x: x,
y: y
});
if (upgradeButtonPos.x >= 120 && upgradeButtonPos.x <= 280 && upgradeButtonPos.y >= 20 && upgradeButtonPos.y <= 70) {
shopVisible = true;
tween(shopContainer, {
alpha: 1
}, {
duration: 300,
easing: tween.easeIn
});
return;
}
// Check if shop button clicked
var shopButtonPos = LK.gui.topRight.toLocal({
x: x,
y: y
});
if (shopButtonPos.x >= -220 && shopButtonPos.x <= -20 && shopButtonPos.y >= 20 && shopButtonPos.y <= 80) {
shopVisible = true;
tween(shopContainer, {
alpha: 1
}, {
duration: 300,
easing: tween.easeIn
});
return;
}
}
if (!shopVisible) {
stickActive = true;
stickStartX = x;
stickStartY = y;
stickCurrentX = x;
stickCurrentY = y;
}
};
game.up = function (x, y, obj) {
stickActive = false;
};
game.update = function () {
// Move player based on stick input
if (stickActive && !shopVisible) {
var deltaX = stickCurrentX - stickStartX;
var deltaY = stickCurrentY - stickStartY;
// Normalize movement based on stick distance
var moveSpeed = 16 * playerStats.speed;
var normalizedX = deltaX / maxStickDistance;
var normalizedY = deltaY / maxStickDistance;
// Apply movement
player.x += normalizedX * moveSpeed;
player.y += normalizedY * moveSpeed;
// Keep player within screen bounds
player.x = Math.max(40, Math.min(2008, player.x));
player.y = Math.max(100, Math.min(2632, player.y));
}
// Update difficulty over time
difficultyTimer++;
if (difficultyTimer % 600 == 0) {
// Every 10 seconds
enemySpawnInterval = Math.max(30, enemySpawnInterval - 10); // Faster spawning, minimum 0.5 seconds
}
// Update upgrade timers
if (playerUpgrades.rapidFire) {
playerUpgrades.rapidFireTimer--;
if (playerUpgrades.rapidFireTimer <= 0) {
playerUpgrades.rapidFire = false;
// Flash effect when upgrade expires
LK.effects.flashObject(player, 0x00ff00, 300);
}
}
if (playerUpgrades.shield) {
playerUpgrades.shieldTimer--;
if (playerUpgrades.shieldTimer <= 0) {
playerUpgrades.shield = false;
player.alpha = 1.0; // Reset transparency
// Hide shield visual effect
tween.stop(player.shieldGraphics);
tween(player.shieldGraphics, {
alpha: 0
}, {
duration: 300,
easing: tween.easeOut
});
}
}
if (playerUpgrades.tripleShot) {
playerUpgrades.tripleShotTimer--;
if (playerUpgrades.tripleShotTimer <= 0) {
playerUpgrades.tripleShot = false;
// Flash effect when upgrade expires
LK.effects.flashObject(player, 0xff0080, 300);
}
}
// Spawn upgrades
upgradeSpawnTimer++;
if (upgradeSpawnTimer >= upgradeSpawnInterval) {
upgradeSpawnTimer = 0;
var upgradeTypes = ['RapidFire', 'Shield', 'TripleShot'];
var randomType = upgradeTypes[Math.floor(Math.random() * upgradeTypes.length)];
var upgrade = new Upgrade(randomType);
upgrade.x = 100 + Math.random() * 1848;
upgrade.y = -50;
upgrade.lastY = upgrade.y;
upgrades.push(upgrade);
game.addChild(upgrade);
}
// Spawn enemies (but not during boss battles)
enemySpawnTimer++;
if (enemySpawnTimer >= enemySpawnInterval && bosses.length === 0) {
enemySpawnTimer = 0;
var enemy = new EnemyShip();
enemy.x = 100 + Math.random() * 1848; // Random x position within screen
enemy.y = -50; // Start above screen
enemy.lastY = enemy.y;
enemy.speed = 2 + Math.random() * 3 + LK.getScore() / 50; // Increase speed with score
enemies.push(enemy);
game.addChild(enemy);
}
// Update and check player bullets
for (var i = playerBullets.length - 1; i >= 0; i--) {
var bullet = playerBullets[i];
if (bullet.lastY === undefined) {
bullet.lastY = bullet.y;
}
// Remove bullets that go off screen
if (bullet.lastY >= -25 && bullet.y < -25) {
bullet.destroy();
playerBullets.splice(i, 1);
continue;
}
// Check collision with enemies
var hitEnemy = false;
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (bullet.intersects(enemy)) {
// Deal damage based on upgrade level
enemy.health -= playerStats.damage;
bullet.destroy();
playerBullets.splice(i, 1);
hitEnemy = true;
if (enemy.health <= 0) {
// Enemy destroyed
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Visual effect
LK.effects.flashObject(enemy, 0xffffff, 200);
// Clean up
enemy.destroy();
enemies.splice(j, 1);
LK.getSound('enemyDestroy').play();
} else {
// Enemy damaged but not destroyed
LK.effects.flashObject(enemy, 0xff0000, 100);
}
break;
}
}
if (!hitEnemy) {
bullet.lastY = bullet.y;
}
}
// Update and check enemy bullets
for (var i = enemyBullets.length - 1; i >= 0; i--) {
var bullet = enemyBullets[i];
if (bullet.lastY === undefined) {
bullet.lastY = bullet.y;
}
// Remove bullets that go off screen
if (bullet.lastY <= 2757 && bullet.y > 2757) {
bullet.destroy();
enemyBullets.splice(i, 1);
continue;
}
// Check collision with player
if (bullet.intersects(player)) {
if (!playerUpgrades.shield) {
playerHealth--;
healthTxt.setText('HEALTH: ' + playerHealth + '/' + maxPlayerHealth);
LK.effects.flashObject(player, 0xff0000, 300);
LK.getSound('playerHit').play();
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
} else {
// Shield absorbs the hit
LK.effects.flashObject(player, 0x0080ff, 200);
}
bullet.destroy();
enemyBullets.splice(i, 1);
continue;
}
bullet.lastY = bullet.y;
}
// Update and check upgrades
for (var i = upgrades.length - 1; i >= 0; i--) {
var upgrade = upgrades[i];
if (upgrade.lastY === undefined) {
upgrade.lastY = upgrade.y;
}
// Remove upgrades that go off screen
if (upgrade.lastY <= 2757 && upgrade.y > 2757) {
upgrade.destroy();
upgrades.splice(i, 1);
continue;
}
// Check collision with player
if (upgrade.intersects(player)) {
LK.getSound('upgradePickup').play();
if (upgrade.type === 'RapidFire') {
playerUpgrades.rapidFire = true;
playerUpgrades.rapidFireTimer = 600; // 10 seconds
LK.effects.flashObject(player, 0x00ff00, 500);
} else if (upgrade.type === 'Shield') {
playerUpgrades.shield = true;
playerUpgrades.shieldTimer = 600; // 10 seconds
player.alpha = 0.7; // Make player semi-transparent to show shield
// Show shield visual effect
player.shieldGraphics.alpha = 0.6;
// Start pulsing animation for shield
tween(player.shieldGraphics, {
alpha: 0.3
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (playerUpgrades.shield) {
tween(player.shieldGraphics, {
alpha: 0.6
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: arguments.callee.caller
});
}
}
});
LK.effects.flashObject(player, 0x0080ff, 500);
} else if (upgrade.type === 'TripleShot') {
playerUpgrades.tripleShot = true;
playerUpgrades.tripleShotTimer = 600; // 10 seconds
LK.effects.flashObject(player, 0xff0080, 500);
}
upgrade.destroy();
upgrades.splice(i, 1);
continue;
}
upgrade.lastY = upgrade.y;
}
// Boss spawn logic - spawn immediately at 500 points and stay until killed
var currentScore = LK.getScore();
var shouldSpawnBoss = false;
if (currentScore >= 500 && bosses.length === 0) {
shouldSpawnBoss = true;
}
if (shouldSpawnBoss) {
var boss = new Boss();
boss.x = 1024;
boss.y = 200;
boss.lastY = boss.y;
boss.lastHealth = boss.health;
bosses.push(boss);
game.addChild(boss);
LK.effects.flashScreen(0xff0000, 500);
// Show boss health bar
bossHealthBarBg.alpha = 1;
bossHealthBarFill.alpha = 1;
bossHealthTxt.alpha = 1;
}
// Update and check bosses
for (var i = bosses.length - 1; i >= 0; i--) {
var boss = bosses[i];
if (boss.lastY === undefined) {
boss.lastY = boss.y;
}
if (boss.lastHealth === undefined) {
boss.lastHealth = boss.health;
}
// Check collision with player bullets
for (var j = playerBullets.length - 1; j >= 0; j--) {
var bullet = playerBullets[j];
if (bullet.intersects(boss)) {
boss.health -= playerStats.damage;
LK.effects.flashObject(boss, 0xffffff, 100);
bullet.destroy();
playerBullets.splice(j, 1);
// Update boss health bar
var healthPercentage = boss.health / boss.maxHealth;
bossHealthBarFill.scaleX = healthPercentage;
if (boss.health <= 0) {
// Boss defeated
LK.setScore(LK.getScore() + 500);
scoreTxt.setText(LK.getScore());
LK.effects.flashObject(boss, 0xffffff, 1000);
boss.destroy();
bosses.splice(i, 1);
LK.getSound('enemyDestroy').play();
// Hide boss health bar
bossHealthBarBg.alpha = 0;
bossHealthBarFill.alpha = 0;
bossHealthTxt.alpha = 0;
break;
}
}
}
// Check collision with player
if (boss.intersects(player)) {
if (!playerUpgrades.shield) {
playerHealth -= 2; // Boss does more damage
healthTxt.setText('HEALTH: ' + playerHealth + '/' + maxPlayerHealth);
LK.effects.flashObject(player, 0xff0000, 500);
LK.getSound('playerHit').play();
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
} else {
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
LK.effects.flashObject(player, 0x0080ff, 200);
}
}
boss.lastY = boss.y;
boss.lastHealth = boss.health;
}
// Update and check enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (enemy.lastY === undefined) {
enemy.lastY = enemy.y;
}
// Remove enemies that go off screen
if (enemy.lastY <= 2757 && enemy.y > 2757) {
enemy.destroy();
enemies.splice(i, 1);
continue;
}
// Check collision with player
if (enemy.intersects(player)) {
if (!playerUpgrades.shield) {
playerHealth--;
healthTxt.setText('HEALTH: ' + playerHealth + '/' + maxPlayerHealth);
LK.effects.flashObject(player, 0xff0000, 300);
LK.getSound('playerHit').play();
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
} else {
// Shield absorbs the hit and destroys the enemy
LK.setScore(LK.getScore() + 5); // Bonus points for shield collision
scoreTxt.setText(LK.getScore());
LK.effects.flashObject(player, 0x0080ff, 200);
}
enemy.destroy();
enemies.splice(i, 1);
continue;
}
enemy.lastY = enemy.y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -438,8 +438,17 @@
});
closeButton.anchor.set(0.5, 0.5);
closeButton.y = 200;
shopContainer.addChild(closeButton);
+// Upgrade button in left corner
+var upgradeButton = new Text2('UPGRADE', {
+ size: 50,
+ fill: 0x00ff00
+});
+upgradeButton.anchor.set(0, 0);
+upgradeButton.x = 120; // Position to avoid the menu icon area
+upgradeButton.y = 20;
+LK.gui.topLeft.addChild(upgradeButton);
// Player health display
var healthTxt = new Text2('HEALTH: ' + playerHealth + '/' + maxPlayerHealth, {
size: 60,
fill: 0xff4444
@@ -539,8 +548,23 @@
});
return;
}
} else {
+ // Check if upgrade button clicked (left corner)
+ var upgradeButtonPos = LK.gui.topLeft.toLocal({
+ x: x,
+ y: y
+ });
+ if (upgradeButtonPos.x >= 120 && upgradeButtonPos.x <= 280 && upgradeButtonPos.y >= 20 && upgradeButtonPos.y <= 70) {
+ shopVisible = true;
+ tween(shopContainer, {
+ alpha: 1
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ return;
+ }
// Check if shop button clicked
var shopButtonPos = LK.gui.topRight.toLocal({
x: x,
y: y