User prompt
Too many ships are coming, reduce it, make the expiry time 200
User prompt
Broken ships Let them reduce our health by 5
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'healthText.style.fill = 0x00FF00; // Green' Line Number: 192
User prompt
Delete energy. Add time,Add health (100 health). İf time is 300 The portal comes and let's retreat into the portal. And let the game be over
Code edit (1 edits merged)
Please save this source code
User prompt
Portal Escape: Broken Ship Survival
Initial prompt
Let the Broken ships come, let us escape from them as a ship. Add counters. Add can. If the counter is 300, let's arrive at a portal. And let's enter the portal, and when we enter the portal, the game ends
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BrokenShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('brokenShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 4; // Random speed between 3-7
self.direction = Math.random() * Math.PI * 2; // Random direction
self.update = function () {
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Wrap around screen edges
if (self.x < -50) self.x = 2048 + 50;
if (self.x > 2048 + 50) self.x = -50;
if (self.y < -50) self.y = 2732 + 50;
if (self.y > 2732 + 50) self.y = -50;
};
return self;
});
var EnergyCan = Container.expand(function () {
var self = Container.call(this);
var canGraphics = self.attachAsset('energyCan', {
anchorX: 0.5,
anchorY: 0.5
});
// Add floating animation
self.floatOffset = Math.random() * Math.PI * 2;
self.baseY = self.y;
self.update = function () {
self.y = self.baseY + Math.sin(LK.ticks * 0.1 + self.floatOffset) * 10;
canGraphics.rotation += 0.02;
};
return self;
});
var PlayerShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
var Portal = Container.expand(function () {
var self = Container.call(this);
var portalGraphics = self.attachAsset('portal', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
portalGraphics.rotation += 0.05;
portalGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.2;
portalGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.2;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000022
});
/****
* Game Code
****/
var player = game.addChild(new PlayerShip());
player.x = 1024;
player.y = 2400;
var brokenShips = [];
var energyCans = [];
var portal = null;
var energyCollected = 0;
var portalSpawned = false;
// UI Elements
var energyText = new Text2('Energy: 0/300', {
size: 60,
fill: 0xFFFFFF
});
energyText.anchor.set(0.5, 0);
LK.gui.top.addChild(energyText);
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
// Keep player within bounds
dragNode.x = Math.max(40, Math.min(2008, dragNode.x));
dragNode.y = Math.max(60, Math.min(2672, dragNode.y));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
function spawnBrokenShip() {
var brokenShip = new BrokenShip();
// Spawn from edges
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// Top
brokenShip.x = Math.random() * 2048;
brokenShip.y = -70;
break;
case 1:
// Right
brokenShip.x = 2118;
brokenShip.y = Math.random() * 2732;
break;
case 2:
// Bottom
brokenShip.x = Math.random() * 2048;
brokenShip.y = 2802;
break;
case 3:
// Left
brokenShip.x = -70;
brokenShip.y = Math.random() * 2732;
break;
}
brokenShips.push(brokenShip);
game.addChild(brokenShip);
}
function spawnEnergyCan() {
var energyCan = new EnergyCan();
energyCan.x = 100 + Math.random() * 1848;
energyCan.y = 100 + Math.random() * 2532;
energyCan.baseY = energyCan.y;
energyCans.push(energyCan);
game.addChild(energyCan);
}
function spawnPortal() {
if (!portalSpawned && energyCollected >= 300) {
portal = new Portal();
portal.x = 1024;
portal.y = 1366;
game.addChild(portal);
portalSpawned = true;
// Flash screen to indicate portal appeared
LK.effects.flashScreen(0x9932CC, 1000);
}
}
// Initial spawns
for (var i = 0; i < 3; i++) {
spawnBrokenShip();
}
for (var i = 0; i < 5; i++) {
spawnEnergyCan();
}
game.update = function () {
// Spawn broken ships periodically
if (LK.ticks % 180 == 0) {
// Every 3 seconds
spawnBrokenShip();
}
// Spawn energy cans periodically
if (LK.ticks % 300 == 0 && energyCans.length < 8) {
// Every 5 seconds, max 8 on screen
spawnEnergyCan();
}
// Check collisions with broken ships
for (var i = brokenShips.length - 1; i >= 0; i--) {
var brokenShip = brokenShips[i];
if (player.intersects(brokenShip)) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
// Remove broken ships that are too far off screen
if (brokenShip.x < -100 || brokenShip.x > 2148 || brokenShip.y < -100 || brokenShip.y > 2832) {
brokenShip.destroy();
brokenShips.splice(i, 1);
}
}
// Check collisions with energy cans
for (var i = energyCans.length - 1; i >= 0; i--) {
var energyCan = energyCans[i];
if (player.intersects(energyCan)) {
energyCollected++;
energyText.setText('Energy: ' + energyCollected + '/300');
LK.getSound('collect').play();
LK.effects.flashObject(energyCan, 0xFFFF00, 300);
energyCan.destroy();
energyCans.splice(i, 1);
// Spawn portal when enough energy collected
if (energyCollected >= 300 && !portalSpawned) {
spawnPortal();
}
}
}
// Check collision with portal
if (portal && player.intersects(portal)) {
LK.effects.flashScreen(0x9932CC, 1500);
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,211 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var BrokenShip = Container.expand(function () {
+ var self = Container.call(this);
+ var shipGraphics = self.attachAsset('brokenShip', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3 + Math.random() * 4; // Random speed between 3-7
+ self.direction = Math.random() * Math.PI * 2; // Random direction
+ self.update = function () {
+ self.x += Math.cos(self.direction) * self.speed;
+ self.y += Math.sin(self.direction) * self.speed;
+ // Wrap around screen edges
+ if (self.x < -50) self.x = 2048 + 50;
+ if (self.x > 2048 + 50) self.x = -50;
+ if (self.y < -50) self.y = 2732 + 50;
+ if (self.y > 2732 + 50) self.y = -50;
+ };
+ return self;
+});
+var EnergyCan = Container.expand(function () {
+ var self = Container.call(this);
+ var canGraphics = self.attachAsset('energyCan', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add floating animation
+ self.floatOffset = Math.random() * Math.PI * 2;
+ self.baseY = self.y;
+ self.update = function () {
+ self.y = self.baseY + Math.sin(LK.ticks * 0.1 + self.floatOffset) * 10;
+ canGraphics.rotation += 0.02;
+ };
+ return self;
+});
+var PlayerShip = Container.expand(function () {
+ var self = Container.call(this);
+ var shipGraphics = self.attachAsset('playerShip', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ return self;
+});
+var Portal = Container.expand(function () {
+ var self = Container.call(this);
+ var portalGraphics = self.attachAsset('portal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ portalGraphics.rotation += 0.05;
+ portalGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.2;
+ portalGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.2;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x000022
+});
+
+/****
+* Game Code
+****/
+var player = game.addChild(new PlayerShip());
+player.x = 1024;
+player.y = 2400;
+var brokenShips = [];
+var energyCans = [];
+var portal = null;
+var energyCollected = 0;
+var portalSpawned = false;
+// UI Elements
+var energyText = new Text2('Energy: 0/300', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+energyText.anchor.set(0.5, 0);
+LK.gui.top.addChild(energyText);
+var dragNode = null;
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ // Keep player within bounds
+ dragNode.x = Math.max(40, Math.min(2008, dragNode.x));
+ dragNode.y = Math.max(60, Math.min(2672, dragNode.y));
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ dragNode = player;
+ handleMove(x, y, obj);
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+function spawnBrokenShip() {
+ var brokenShip = new BrokenShip();
+ // Spawn from edges
+ var side = Math.floor(Math.random() * 4);
+ switch (side) {
+ case 0:
+ // Top
+ brokenShip.x = Math.random() * 2048;
+ brokenShip.y = -70;
+ break;
+ case 1:
+ // Right
+ brokenShip.x = 2118;
+ brokenShip.y = Math.random() * 2732;
+ break;
+ case 2:
+ // Bottom
+ brokenShip.x = Math.random() * 2048;
+ brokenShip.y = 2802;
+ break;
+ case 3:
+ // Left
+ brokenShip.x = -70;
+ brokenShip.y = Math.random() * 2732;
+ break;
+ }
+ brokenShips.push(brokenShip);
+ game.addChild(brokenShip);
+}
+function spawnEnergyCan() {
+ var energyCan = new EnergyCan();
+ energyCan.x = 100 + Math.random() * 1848;
+ energyCan.y = 100 + Math.random() * 2532;
+ energyCan.baseY = energyCan.y;
+ energyCans.push(energyCan);
+ game.addChild(energyCan);
+}
+function spawnPortal() {
+ if (!portalSpawned && energyCollected >= 300) {
+ portal = new Portal();
+ portal.x = 1024;
+ portal.y = 1366;
+ game.addChild(portal);
+ portalSpawned = true;
+ // Flash screen to indicate portal appeared
+ LK.effects.flashScreen(0x9932CC, 1000);
+ }
+}
+// Initial spawns
+for (var i = 0; i < 3; i++) {
+ spawnBrokenShip();
+}
+for (var i = 0; i < 5; i++) {
+ spawnEnergyCan();
+}
+game.update = function () {
+ // Spawn broken ships periodically
+ if (LK.ticks % 180 == 0) {
+ // Every 3 seconds
+ spawnBrokenShip();
+ }
+ // Spawn energy cans periodically
+ if (LK.ticks % 300 == 0 && energyCans.length < 8) {
+ // Every 5 seconds, max 8 on screen
+ spawnEnergyCan();
+ }
+ // Check collisions with broken ships
+ for (var i = brokenShips.length - 1; i >= 0; i--) {
+ var brokenShip = brokenShips[i];
+ if (player.intersects(brokenShip)) {
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ // Remove broken ships that are too far off screen
+ if (brokenShip.x < -100 || brokenShip.x > 2148 || brokenShip.y < -100 || brokenShip.y > 2832) {
+ brokenShip.destroy();
+ brokenShips.splice(i, 1);
+ }
+ }
+ // Check collisions with energy cans
+ for (var i = energyCans.length - 1; i >= 0; i--) {
+ var energyCan = energyCans[i];
+ if (player.intersects(energyCan)) {
+ energyCollected++;
+ energyText.setText('Energy: ' + energyCollected + '/300');
+ LK.getSound('collect').play();
+ LK.effects.flashObject(energyCan, 0xFFFF00, 300);
+ energyCan.destroy();
+ energyCans.splice(i, 1);
+ // Spawn portal when enough energy collected
+ if (energyCollected >= 300 && !portalSpawned) {
+ spawnPortal();
+ }
+ }
+ }
+ // Check collision with portal
+ if (portal && player.intersects(portal)) {
+ LK.effects.flashScreen(0x9932CC, 1500);
+ LK.showYouWin();
+ }
+};
\ No newline at end of file