/**** * 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/200', { 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 >= 200) { 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 + '/200'); // Check if time reached 200 seconds if (gameTime >= 200 && !portalSpawned) { spawnPortal(); } } // Spawn broken ships periodically if (LK.ticks % 360 == 0) { // Every 6 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 -= 5; 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(); } };
/****
* 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/200', {
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 >= 200) {
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 + '/200');
// Check if time reached 200 seconds
if (gameTime >= 200 && !portalSpawned) {
spawnPortal();
}
}
// Spawn broken ships periodically
if (LK.ticks % 360 == 0) {
// Every 6 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 -= 5;
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();
}
};