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 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 portal = null; var gameTime = 0; var playerHealth = 100; var portalSpawned = false; var lastHitTime = 0; // UI Elements var timeText = new Text2('Time: 0/300', { size: 60, fill: 0xFFFFFF }); timeText.anchor.set(0.5, 0); timeText.y = 20; LK.gui.top.addChild(timeText); var healthText = new Text2('Health: 100', { size: 60, fill: 0x00FF00 }); healthText.anchor.set(0.5, 0); healthText.y = 100; LK.gui.top.addChild(healthText); 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 spawnPortal() { if (!portalSpawned && gameTime >= 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(); } game.update = function () { // Update time (60 FPS, so increment every 60 ticks = 1 second) if (LK.ticks % 60 == 0) { gameTime++; timeText.setText('Time: ' + gameTime + '/300'); // Check if time reached 300 seconds if (gameTime >= 300 && !portalSpawned) { spawnPortal(); } } // Spawn broken ships periodically if (LK.ticks % 180 == 0) { // Every 3 seconds spawnBrokenShip(); } // Check collisions with broken ships for (var i = brokenShips.length - 1; i >= 0; i--) { var brokenShip = brokenShips[i]; if (player.intersects(brokenShip) && LK.ticks - lastHitTime > 60) { // Prevent multiple hits in quick succession (1 second cooldown) lastHitTime = LK.ticks; playerHealth -= 10; healthText.setText('Health: ' + playerHealth); // Update health text color based on health level var healthColor; if (playerHealth <= 30) { healthColor = "#FF0000"; // Red } else if (playerHealth <= 60) { healthColor = "#FFFF00"; // Yellow } else { healthColor = "#00FF00"; // Green } // Remove old health text and create new one with updated color LK.gui.top.removeChild(healthText); healthText = new Text2('Health: ' + playerHealth, { size: 60, fill: healthColor }); healthText.anchor.set(0.5, 0); healthText.y = 100; LK.gui.top.addChild(healthText); LK.getSound('hit').play(); LK.effects.flashScreen(0xff0000, 500); // Check if player is dead if (playerHealth <= 0) { 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 collision with portal if (portal && player.intersects(portal)) { LK.effects.flashScreen(0x9932CC, 1500); LK.showYouWin(); } };
===================================================================
--- original.js
+++ change.js
@@ -167,15 +167,25 @@
lastHitTime = LK.ticks;
playerHealth -= 10;
healthText.setText('Health: ' + playerHealth);
// Update health text color based on health level
+ var healthColor;
if (playerHealth <= 30) {
- healthText.style.fill = 0xFF0000; // Red
+ healthColor = "#FF0000"; // Red
} else if (playerHealth <= 60) {
- healthText.style.fill = 0xFFFF00; // Yellow
+ healthColor = "#FFFF00"; // Yellow
} else {
- healthText.style.fill = 0x00FF00; // Green
+ healthColor = "#00FF00"; // Green
}
+ // Remove old health text and create new one with updated color
+ LK.gui.top.removeChild(healthText);
+ healthText = new Text2('Health: ' + playerHealth, {
+ size: 60,
+ fill: healthColor
+ });
+ healthText.anchor.set(0.5, 0);
+ healthText.y = 100;
+ LK.gui.top.addChild(healthText);
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
// Check if player is dead
if (playerHealth <= 0) {