/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var ActionButton = Container.expand(function (text, action) { var self = Container.call(this); var buttonBg = self.attachAsset('actionButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(text, { size: 24, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.actionType = action; self.down = function (x, y, obj) { performAction(self.actionType); }; return self; }); var Boat = Container.expand(function () { var self = Container.call(this); var boatGraphics = self.attachAsset('boat', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.maxHealth = 100; self.repair = function () { self.health = Math.min(self.health + 20, self.maxHealth); }; self.takeDamage = function (damage) { self.health = Math.max(self.health - damage, 0); LK.effects.flashObject(self, 0xFF0000, 500); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x006994 }); /**** * Game Code ****/ // Game state variables var currentDay = 1; var maxDays = 10; var dayProgress = 0; var dayDuration = 3600; // 60 seconds per day (60 FPS * 60) var isNight = false; // Player stats (0-100) var health = 100; var hunger = 100; var thirst = 100; var energy = 100; // Resources var food = 5; var water = 5; var supplies = 2; // Game objects var ocean = game.addChild(LK.getAsset('ocean', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); var boat = game.addChild(new Boat()); boat.x = 1024; boat.y = 1366; var sun = game.addChild(LK.getAsset('sun', { anchorX: 0.5, anchorY: 0.5, x: 1800, y: 200 })); var moon = game.addChild(LK.getAsset('moon', { anchorX: 0.5, anchorY: 0.5, x: 1800, y: 200, alpha: 0 })); // Clouds for weather var clouds = []; for (var i = 0; i < 3; i++) { var cloud = game.addChild(LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 2048, y: 300 + Math.random() * 200, alpha: 0.7 })); clouds.push(cloud); } // UI Elements var dayText = new Text2('Day 1/10', { size: 48, fill: 0xFFFFFF }); dayText.anchor.set(0.5, 0); LK.gui.top.addChild(dayText); dayText.y = 100; // Resource bars var healthBarBg = LK.gui.topLeft.addChild(LK.getAsset('healthBar', { anchorX: 0, anchorY: 0, x: 120, y: 150, alpha: 0.3 })); var healthBarFg = LK.gui.topLeft.addChild(LK.getAsset('healthBar', { anchorX: 0, anchorY: 0, x: 120, y: 150 })); var hungerBarBg = LK.gui.topLeft.addChild(LK.getAsset('hungerBar', { anchorX: 0, anchorY: 0, x: 120, y: 180, alpha: 0.3 })); var hungerBarFg = LK.gui.topLeft.addChild(LK.getAsset('hungerBar', { anchorX: 0, anchorY: 0, x: 120, y: 180 })); var thirstBarBg = LK.gui.topLeft.addChild(LK.getAsset('thirstBar', { anchorX: 0, anchorY: 0, x: 120, y: 210, alpha: 0.3 })); var thirstBarFg = LK.gui.topLeft.addChild(LK.getAsset('thirstBar', { anchorX: 0, anchorY: 0, x: 120, y: 210 })); var energyBarBg = LK.gui.topLeft.addChild(LK.getAsset('energyBar', { anchorX: 0, anchorY: 0, x: 120, y: 240, alpha: 0.3 })); var energyBarFg = LK.gui.topLeft.addChild(LK.getAsset('energyBar', { anchorX: 0, anchorY: 0, x: 120, y: 240 })); // Resource text var resourceText = new Text2('Food: 5 Water: 5 Signal Flares: 2', { size: 32, fill: 0xFFFFFF }); resourceText.anchor.set(0.5, 0); LK.gui.top.addChild(resourceText); resourceText.y = 160; // Action buttons var actionButtons = []; var buttonActions = [{ text: 'Fish', action: 'fish' }, { text: 'Drink Water', action: 'drink' }, { text: 'Eat Food', action: 'eat' }, { text: 'Purify Water', action: 'purify' }, { text: 'Rest', action: 'rest' }, { text: 'Signal', action: 'signal' }]; for (var i = 0; i < buttonActions.length; i++) { var button = game.addChild(new ActionButton(buttonActions[i].text, buttonActions[i].action)); var row = Math.floor(i / 3); var col = i % 3; button.x = 400 + col * 200; button.y = 2400 + row * 80; actionButtons.push(button); } // Game state var lastEventTick = 0; var eventCooldown = 0; var stormActive = false; var weatherIntensity = 0; function updateResourceBars() { healthBarFg.scaleX = health / 100; hungerBarFg.scaleX = hunger / 100; thirstBarFg.scaleX = thirst / 100; energyBarFg.scaleX = energy / 100; resourceText.setText('Food: ' + food + ' Water: ' + water + ' Signal Flares: ' + supplies); } function performAction(actionType) { if (energy <= 0) return; switch (actionType) { case 'fish': if (energy >= 20 && !stormActive) { energy -= 20; if (Math.random() < 0.6) { food += 1; LK.getSound('wave').play(); } } break; case 'drink': if (water > 0) { water -= 1; thirst = Math.min(thirst + 30, 100); } break; case 'eat': if (food > 0) { food -= 1; hunger = Math.min(hunger + 40, 100); thirst = Math.max(thirst - 15, 0); } break; case 'purify': if (energy >= 15) { energy -= 15; if (Math.random() < 0.2) { water += 1; LK.getSound('wave').play(); } } break; case 'rest': energy = Math.min(energy + 25, 100); hunger = Math.max(hunger - 10, 0); thirst = Math.max(thirst - 10, 0); break; case 'signal': if (supplies > 0 && energy >= 25 && !isNight) { supplies -= 1; energy -= 25; var successRate = 0.02 + currentDay * 0.005; if (Math.random() < successRate) { // Early rescue! LK.showYouWin(); } } break; } updateResourceBars(); } function triggerRandomEvent() { if (eventCooldown > 0) return; var eventRoll = Math.random(); if (eventRoll < 0.2) { // Storm stormActive = true; weatherIntensity = 0.8; LK.getSound('storm').play(); boat.takeDamage(15); eventCooldown = 300; } else if (eventRoll < 0.35) { // Equipment failure supplies = Math.max(supplies - 1, 0); eventCooldown = 240; } else if (eventRoll < 0.45) { // Supply discovery var roll = Math.random(); if (roll < 0.4) food += 1;else if (roll < 0.7) water += 1;else supplies += 1; eventCooldown = 600; } } function updateDayNight() { var dayPhase = dayProgress / dayDuration; if (dayPhase < 0.5 && isNight) { // Sunrise isNight = false; tween(sun, { alpha: 1 }, { duration: 2000 }); tween(moon, { alpha: 0 }, { duration: 2000 }); tween(ocean, { tint: 0x006994 }, { duration: 2000 }); tween(game, { backgroundColor: 0x006994 }, { duration: 2000 }); } else if (dayPhase >= 0.5 && !isNight) { // Sunset isNight = true; tween(sun, { alpha: 0 }, { duration: 2000 }); tween(moon, { alpha: 1 }, { duration: 2000 }); tween(ocean, { tint: 0x003366 }, { duration: 2000 }); tween(game, { backgroundColor: 0x001122 }, { duration: 2000 }); } } function updateWeather() { if (stormActive) { weatherIntensity -= 0.01; if (weatherIntensity <= 0) { stormActive = false; } // Move clouds during storm for (var i = 0; i < clouds.length; i++) { clouds[i].x += (Math.random() - 0.5) * 5; clouds[i].alpha = 0.9; } // Make ocean darker ocean.tint = 0x003333; } else { ocean.tint = isNight ? 0x003366 : 0x006994; for (var i = 0; i < clouds.length; i++) { clouds[i].x += 0.5; if (clouds[i].x > 2148) clouds[i].x = -100; clouds[i].alpha = 0.7; } } } // Start ambient music LK.playMusic('oceanAmbient'); game.update = function () { // Day progression dayProgress++; if (dayProgress >= dayDuration) { dayProgress = 0; currentDay++; if (currentDay > maxDays) { LK.showYouWin(); return; } // Daily supplies (except day 1) if (currentDay > 1) { water += 1; supplies += 1; updateResourceBars(); } dayText.setText('Day ' + currentDay + '/' + maxDays); } // Update day/night cycle updateDayNight(); // Update weather updateWeather(); // Decrease stats over time if (LK.ticks % 60 === 0) { // Every second var dayMultiplier = 1 + (currentDay - 1) * 0.1; hunger = Math.max(hunger - 1.5 * dayMultiplier, 0); thirst = Math.max(thirst - 1.2 * dayMultiplier, 0); if (!isNight) { thirst = Math.max(thirst - 0.3, 0); // Extra thirst during day } if (energy > 0) { energy = Math.max(energy - 0.5 * dayMultiplier, 0); } // Rest bar increases when not doing anything energy = Math.min(energy + 0.3, 100); // General health degradation over time health = Math.max(health - 0.2 * dayMultiplier, 0); // Health effects if (hunger <= 10 || thirst <= 10) { health = Math.max(health - 5, 0); } if (boat.health <= 20) { health = Math.max(health - 3, 0); } updateResourceBars(); // Check game over if (health <= 0) { LK.showGameOver(); return; } } // Random events if (LK.ticks % 30 === 0 && Math.random() < 0.1) { triggerRandomEvent(); } if (eventCooldown > 0) { eventCooldown--; } // Boat bobbing animation boat.y = 1366 + Math.sin(LK.ticks * 0.05) * 10; // Sun/moon movement var timeProgress = dayProgress / dayDuration * Math.PI * 2; sun.x = 1024 + Math.cos(timeProgress) * 800; sun.y = 400 + Math.sin(timeProgress) * 200; moon.x = 1024 + Math.cos(timeProgress + Math.PI) * 800; moon.y = 400 + Math.sin(timeProgress + Math.PI) * 200; };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ActionButton = Container.expand(function (text, action) {
var self = Container.call(this);
var buttonBg = self.attachAsset('actionButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 24,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.actionType = action;
self.down = function (x, y, obj) {
performAction(self.actionType);
};
return self;
});
var Boat = Container.expand(function () {
var self = Container.call(this);
var boatGraphics = self.attachAsset('boat', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.repair = function () {
self.health = Math.min(self.health + 20, self.maxHealth);
};
self.takeDamage = function (damage) {
self.health = Math.max(self.health - damage, 0);
LK.effects.flashObject(self, 0xFF0000, 500);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x006994
});
/****
* Game Code
****/
// Game state variables
var currentDay = 1;
var maxDays = 10;
var dayProgress = 0;
var dayDuration = 3600; // 60 seconds per day (60 FPS * 60)
var isNight = false;
// Player stats (0-100)
var health = 100;
var hunger = 100;
var thirst = 100;
var energy = 100;
// Resources
var food = 5;
var water = 5;
var supplies = 2;
// Game objects
var ocean = game.addChild(LK.getAsset('ocean', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var boat = game.addChild(new Boat());
boat.x = 1024;
boat.y = 1366;
var sun = game.addChild(LK.getAsset('sun', {
anchorX: 0.5,
anchorY: 0.5,
x: 1800,
y: 200
}));
var moon = game.addChild(LK.getAsset('moon', {
anchorX: 0.5,
anchorY: 0.5,
x: 1800,
y: 200,
alpha: 0
}));
// Clouds for weather
var clouds = [];
for (var i = 0; i < 3; i++) {
var cloud = game.addChild(LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: 300 + Math.random() * 200,
alpha: 0.7
}));
clouds.push(cloud);
}
// UI Elements
var dayText = new Text2('Day 1/10', {
size: 48,
fill: 0xFFFFFF
});
dayText.anchor.set(0.5, 0);
LK.gui.top.addChild(dayText);
dayText.y = 100;
// Resource bars
var healthBarBg = LK.gui.topLeft.addChild(LK.getAsset('healthBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 150,
alpha: 0.3
}));
var healthBarFg = LK.gui.topLeft.addChild(LK.getAsset('healthBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 150
}));
var hungerBarBg = LK.gui.topLeft.addChild(LK.getAsset('hungerBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 180,
alpha: 0.3
}));
var hungerBarFg = LK.gui.topLeft.addChild(LK.getAsset('hungerBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 180
}));
var thirstBarBg = LK.gui.topLeft.addChild(LK.getAsset('thirstBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 210,
alpha: 0.3
}));
var thirstBarFg = LK.gui.topLeft.addChild(LK.getAsset('thirstBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 210
}));
var energyBarBg = LK.gui.topLeft.addChild(LK.getAsset('energyBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 240,
alpha: 0.3
}));
var energyBarFg = LK.gui.topLeft.addChild(LK.getAsset('energyBar', {
anchorX: 0,
anchorY: 0,
x: 120,
y: 240
}));
// Resource text
var resourceText = new Text2('Food: 5 Water: 5 Signal Flares: 2', {
size: 32,
fill: 0xFFFFFF
});
resourceText.anchor.set(0.5, 0);
LK.gui.top.addChild(resourceText);
resourceText.y = 160;
// Action buttons
var actionButtons = [];
var buttonActions = [{
text: 'Fish',
action: 'fish'
}, {
text: 'Drink Water',
action: 'drink'
}, {
text: 'Eat Food',
action: 'eat'
}, {
text: 'Purify Water',
action: 'purify'
}, {
text: 'Rest',
action: 'rest'
}, {
text: 'Signal',
action: 'signal'
}];
for (var i = 0; i < buttonActions.length; i++) {
var button = game.addChild(new ActionButton(buttonActions[i].text, buttonActions[i].action));
var row = Math.floor(i / 3);
var col = i % 3;
button.x = 400 + col * 200;
button.y = 2400 + row * 80;
actionButtons.push(button);
}
// Game state
var lastEventTick = 0;
var eventCooldown = 0;
var stormActive = false;
var weatherIntensity = 0;
function updateResourceBars() {
healthBarFg.scaleX = health / 100;
hungerBarFg.scaleX = hunger / 100;
thirstBarFg.scaleX = thirst / 100;
energyBarFg.scaleX = energy / 100;
resourceText.setText('Food: ' + food + ' Water: ' + water + ' Signal Flares: ' + supplies);
}
function performAction(actionType) {
if (energy <= 0) return;
switch (actionType) {
case 'fish':
if (energy >= 20 && !stormActive) {
energy -= 20;
if (Math.random() < 0.6) {
food += 1;
LK.getSound('wave').play();
}
}
break;
case 'drink':
if (water > 0) {
water -= 1;
thirst = Math.min(thirst + 30, 100);
}
break;
case 'eat':
if (food > 0) {
food -= 1;
hunger = Math.min(hunger + 40, 100);
thirst = Math.max(thirst - 15, 0);
}
break;
case 'purify':
if (energy >= 15) {
energy -= 15;
if (Math.random() < 0.2) {
water += 1;
LK.getSound('wave').play();
}
}
break;
case 'rest':
energy = Math.min(energy + 25, 100);
hunger = Math.max(hunger - 10, 0);
thirst = Math.max(thirst - 10, 0);
break;
case 'signal':
if (supplies > 0 && energy >= 25 && !isNight) {
supplies -= 1;
energy -= 25;
var successRate = 0.02 + currentDay * 0.005;
if (Math.random() < successRate) {
// Early rescue!
LK.showYouWin();
}
}
break;
}
updateResourceBars();
}
function triggerRandomEvent() {
if (eventCooldown > 0) return;
var eventRoll = Math.random();
if (eventRoll < 0.2) {
// Storm
stormActive = true;
weatherIntensity = 0.8;
LK.getSound('storm').play();
boat.takeDamage(15);
eventCooldown = 300;
} else if (eventRoll < 0.35) {
// Equipment failure
supplies = Math.max(supplies - 1, 0);
eventCooldown = 240;
} else if (eventRoll < 0.45) {
// Supply discovery
var roll = Math.random();
if (roll < 0.4) food += 1;else if (roll < 0.7) water += 1;else supplies += 1;
eventCooldown = 600;
}
}
function updateDayNight() {
var dayPhase = dayProgress / dayDuration;
if (dayPhase < 0.5 && isNight) {
// Sunrise
isNight = false;
tween(sun, {
alpha: 1
}, {
duration: 2000
});
tween(moon, {
alpha: 0
}, {
duration: 2000
});
tween(ocean, {
tint: 0x006994
}, {
duration: 2000
});
tween(game, {
backgroundColor: 0x006994
}, {
duration: 2000
});
} else if (dayPhase >= 0.5 && !isNight) {
// Sunset
isNight = true;
tween(sun, {
alpha: 0
}, {
duration: 2000
});
tween(moon, {
alpha: 1
}, {
duration: 2000
});
tween(ocean, {
tint: 0x003366
}, {
duration: 2000
});
tween(game, {
backgroundColor: 0x001122
}, {
duration: 2000
});
}
}
function updateWeather() {
if (stormActive) {
weatherIntensity -= 0.01;
if (weatherIntensity <= 0) {
stormActive = false;
}
// Move clouds during storm
for (var i = 0; i < clouds.length; i++) {
clouds[i].x += (Math.random() - 0.5) * 5;
clouds[i].alpha = 0.9;
}
// Make ocean darker
ocean.tint = 0x003333;
} else {
ocean.tint = isNight ? 0x003366 : 0x006994;
for (var i = 0; i < clouds.length; i++) {
clouds[i].x += 0.5;
if (clouds[i].x > 2148) clouds[i].x = -100;
clouds[i].alpha = 0.7;
}
}
}
// Start ambient music
LK.playMusic('oceanAmbient');
game.update = function () {
// Day progression
dayProgress++;
if (dayProgress >= dayDuration) {
dayProgress = 0;
currentDay++;
if (currentDay > maxDays) {
LK.showYouWin();
return;
}
// Daily supplies (except day 1)
if (currentDay > 1) {
water += 1;
supplies += 1;
updateResourceBars();
}
dayText.setText('Day ' + currentDay + '/' + maxDays);
}
// Update day/night cycle
updateDayNight();
// Update weather
updateWeather();
// Decrease stats over time
if (LK.ticks % 60 === 0) {
// Every second
var dayMultiplier = 1 + (currentDay - 1) * 0.1;
hunger = Math.max(hunger - 1.5 * dayMultiplier, 0);
thirst = Math.max(thirst - 1.2 * dayMultiplier, 0);
if (!isNight) {
thirst = Math.max(thirst - 0.3, 0); // Extra thirst during day
}
if (energy > 0) {
energy = Math.max(energy - 0.5 * dayMultiplier, 0);
}
// Rest bar increases when not doing anything
energy = Math.min(energy + 0.3, 100);
// General health degradation over time
health = Math.max(health - 0.2 * dayMultiplier, 0);
// Health effects
if (hunger <= 10 || thirst <= 10) {
health = Math.max(health - 5, 0);
}
if (boat.health <= 20) {
health = Math.max(health - 3, 0);
}
updateResourceBars();
// Check game over
if (health <= 0) {
LK.showGameOver();
return;
}
}
// Random events
if (LK.ticks % 30 === 0 && Math.random() < 0.1) {
triggerRandomEvent();
}
if (eventCooldown > 0) {
eventCooldown--;
}
// Boat bobbing animation
boat.y = 1366 + Math.sin(LK.ticks * 0.05) * 10;
// Sun/moon movement
var timeProgress = dayProgress / dayDuration * Math.PI * 2;
sun.x = 1024 + Math.cos(timeProgress) * 800;
sun.y = 400 + Math.sin(timeProgress) * 200;
moon.x = 1024 + Math.cos(timeProgress + Math.PI) * 800;
moon.y = 400 + Math.sin(timeProgress + Math.PI) * 200;
};