/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var HealthPack = Container.expand(function () { var self = Container.call(this); var healthGraphics = self.attachAsset('healthPack', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4 + Math.random() * 3; self.healAmount = 20; // Heal exactly 20 health self.rotationSpeed = 0.05; // Add pulsing animation for visibility self.pulseOffset = Math.random() * Math.PI * 2; self.update = function () { self.y += self.speed; healthGraphics.rotation += self.rotationSpeed; // Pulsing scale animation to make it noticeable var pulse = 1 + Math.sin(LK.ticks * 0.1 + self.pulseOffset) * 0.2; healthGraphics.scaleX = pulse; healthGraphics.scaleY = pulse; }; return self; }); var MonsterBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('projectile', { anchorX: 0.5, anchorY: 0.5 }); bulletGraphics.tint = 0xFF0000; // Red color for monster bullets self.speed = 10; self.update = function () { self.y += self.speed; }; return self; }); var Projectile = Container.expand(function () { var self = Container.call(this); var projectileGraphics = self.attachAsset('projectile', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -12; self.update = function () { self.y += self.speed; }; return self; }); var SeaMonster = Container.expand(function () { var self = Container.call(this); var monsterGraphics = self.attachAsset('seaMonster', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8 + Math.random() * 6; self.health = 1; self.lastShotTime = 0; self.shotCooldown = 600 + Math.random() * 400; // Random shooting interval self.update = function () { self.y += self.speed; // Monster shooting logic if (Date.now() - self.lastShotTime > self.shotCooldown) { self.lastShotTime = Date.now(); var bullet = new MonsterBullet(); bullet.x = self.x; bullet.y = self.y + 50; bullet.lastY = bullet.y; monsterBullets.push(bullet); game.addChild(bullet); } }; self.takeDamage = function () { self.health--; if (self.health <= 0) { LK.effects.flashObject(self, 0xFF0000, 200); return true; // Monster destroyed } return false; }; return self; }); var Seagull = Container.expand(function () { var self = Container.call(this); var seagullGraphics = self.attachAsset('seagull', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8 + Math.random() * 6; // Flying seagulls self.rotationSpeed = 0.05 + Math.random() * 0.1; self.update = function () { self.y += self.speed; seagullGraphics.rotation += self.rotationSpeed; }; return self; }); var Ship = Container.expand(function () { var self = Container.call(this); // Add boat graphics first (underneath) var boatGraphics = self.attachAsset('boat', { anchorX: 0.5, anchorY: 0.5 }); // Add ship graphics on top var shipGraphics = self.attachAsset('ship', { anchorX: 0.5, anchorY: 0.3 }); shipGraphics.y = -10; // Position ship slightly above boat self.speed = 8; self.lastShotTime = 0; self.shotCooldown = 300; // milliseconds self.moveLeft = function () { self.x -= self.speed; if (self.x < shipGraphics.width / 2) { self.x = shipGraphics.width / 2; } }; self.moveRight = function () { self.x += self.speed; if (self.x > 2048 - shipGraphics.width / 2) { self.x = 2048 - shipGraphics.width / 2; } }; self.canShoot = function () { return Date.now() - self.lastShotTime > self.shotCooldown; }; self.shoot = function () { if (self.canShoot()) { self.lastShotTime = Date.now(); return true; } return false; }; return self; }); var Wave = Container.expand(function () { var self = Container.call(this); var waveGraphics = self.attachAsset('wave', { anchorX: 0.5, anchorY: 0.5 }); waveGraphics.alpha = 0.4 + Math.random() * 0.3; // Varied transparency self.speed = 2 + Math.random() * 5; // More varied wave speeds self.originalX = self.x; self.waveOffset = Math.random() * Math.PI * 2; self.horizontalAmplitude = 20 + Math.random() * 40; // More varied wave movement // Add tint variation for realistic ocean colors var blueVariation = 0x4080C0 + Math.floor(Math.random() * 0x202020); waveGraphics.tint = blueVariation; self.update = function () { // Move wave downward with varying speed for realism self.y += self.speed + Math.sin(LK.ticks * 0.02 + self.waveOffset) * 0.5; // Animate wave with realistic horizontal sine wave motion self.x = self.originalX + Math.sin(LK.ticks * 0.04 + self.waveOffset) * self.horizontalAmplitude; // Add realistic wave rolling motion var rollMotion = Math.sin(LK.ticks * 0.05 + self.waveOffset); waveGraphics.rotation = rollMotion * 0.1; // Add wave scaling for more dynamic ocean effect var scaleVariation = 1 + Math.sin(LK.ticks * 0.03 + self.waveOffset) * 0.15; waveGraphics.scaleX = scaleVariation; waveGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.025 + self.waveOffset) * 0.1; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x006994 }); /**** * Game Code ****/ var ship; var projectiles = []; var seaMonsters = []; var monsterBullets = []; var seagulls = []; var waves = []; var healthPacks = []; var dragNode = null; var waveSpawnTimer = 0; var waveSpawnInterval = 80; // More frequent waves for realistic ocean var monsterSpawnTimer = 0; var monsterSpawnInterval = 120; // frames var seagullSpawnTimer = 0; var seagullSpawnInterval = 90; // frames - seagulls spawn regularly var healthPackSpawnTimer = 0; var healthPackSpawnInterval = 480; // frames - spawn health packs less frequently var difficultyTimer = 0; // Initialize ship ship = game.addChild(new Ship()); ship.x = 2048 / 2; ship.y = 2732 - 150; // Score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Health display var healthTxt = new Text2('Health: 100', { size: 60, fill: 0xFFFFFF }); healthTxt.anchor.set(0, 0); healthTxt.x = 120; healthTxt.y = 20; LK.gui.topLeft.addChild(healthTxt); // Level display var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFD700 }); levelTxt.anchor.set(1, 0); levelTxt.x = -20; levelTxt.y = 20; LK.gui.topRight.addChild(levelTxt); var playerHealth = 100; var currentLevel = 1; var maxLevel = 100; var pointsPerLevel = 100; function updateScore() { scoreTxt.setText('Score: ' + LK.getScore()); checkLevelUp(); } function updateHealth() { healthTxt.setText('Health: ' + playerHealth); } function updateLevel() { levelTxt.setText('Level: ' + currentLevel); } function checkLevelUp() { var newLevel = Math.floor(LK.getScore() / pointsPerLevel) + 1; if (newLevel > currentLevel && newLevel <= maxLevel) { currentLevel = newLevel; updateLevel(); // Flash screen gold when leveling up LK.effects.flashScreen(0xFFD700, 800); // Increase difficulty with each level monsterSpawnInterval = Math.max(20, 120 - currentLevel * 2); return true; } return false; } function spawnMonster() { var monster = new SeaMonster(); monster.x = Math.random() * (2048 - 100) + 50; monster.y = -50; monster.lastY = monster.y; seaMonsters.push(monster); game.addChild(monster); } function spawnSeagull() { var seagull = new Seagull(); seagull.x = Math.random() * (2048 - 60) + 30; seagull.y = -60; seagull.lastY = seagull.y; seagulls.push(seagull); game.addChild(seagull); } function spawnWave() { var wave = new Wave(); wave.x = Math.random() * 2048; // Random horizontal position wave.y = -100; // Start further from top of screen wave.originalX = wave.x; wave.lastY = wave.y; waves.push(wave); game.addChild(wave); // Add realistic wave animation with tween - more dramatic effect tween(wave, { alpha: 0.9, scaleY: 1.5, scaleX: 1.2 }, { duration: 3000, easing: tween.easeInOut, onFinish: function onFinish() { // Fade out wave at the end tween(wave, { alpha: 0.3, scaleY: 0.8 }, { duration: 1000, easing: tween.easeOut }); } }); } function spawnHealthPack() { var healthPack = new HealthPack(); healthPack.x = Math.random() * (2048 - 80) + 40; healthPack.y = -80; healthPack.lastY = healthPack.y; healthPacks.push(healthPack); game.addChild(healthPack); // Add entrance animation with tween tween(healthPack, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 800, easing: tween.bounceOut }); } function handleMove(x, y, obj) { if (dragNode === ship) { ship.x = x; if (ship.x < 60) ship.x = 60; if (ship.x > 2048 - 60) ship.x = 2048 - 60; } } game.move = handleMove; game.down = function (x, y, obj) { dragNode = ship; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; game.update = function () { // Increase difficulty over time difficultyTimer++; if (difficultyTimer % 1800 === 0) { // Every 30 seconds monsterSpawnInterval = Math.max(30, monsterSpawnInterval - 10); } // Spawn monsters monsterSpawnTimer++; if (monsterSpawnTimer >= monsterSpawnInterval) { spawnMonster(); monsterSpawnTimer = 0; } // Spawn seagulls seagullSpawnTimer++; if (seagullSpawnTimer >= seagullSpawnInterval) { spawnSeagull(); seagullSpawnTimer = 0; } // Spawn waves waveSpawnTimer++; if (waveSpawnTimer >= waveSpawnInterval) { spawnWave(); waveSpawnTimer = 0; } // Spawn health packs healthPackSpawnTimer++; if (healthPackSpawnTimer >= healthPackSpawnInterval) { spawnHealthPack(); healthPackSpawnTimer = 0; } // Auto-shoot from ship if (ship.shoot()) { var projectile = new Projectile(); projectile.x = ship.x; projectile.y = ship.y - 40; projectile.lastY = projectile.y; projectiles.push(projectile); game.addChild(projectile); LK.getSound('shoot').play(); } // Update and check projectiles for (var i = projectiles.length - 1; i >= 0; i--) { var projectile = projectiles[i]; // Check if projectile went off screen if (projectile.lastY >= -20 && projectile.y < -20) { projectile.destroy(); projectiles.splice(i, 1); continue; } // Check projectile-monster collisions var hit = false; for (var j = seaMonsters.length - 1; j >= 0; j--) { var monster = seaMonsters[j]; if (projectile.intersects(monster)) { if (monster.takeDamage()) { LK.setScore(LK.getScore() + 10); updateScore(); LK.getSound('explosion').play(); monster.destroy(); seaMonsters.splice(j, 1); } projectile.destroy(); projectiles.splice(i, 1); hit = true; break; } } if (!hit) { projectile.lastY = projectile.y; } } // Update and check monster bullets for (var b = monsterBullets.length - 1; b >= 0; b--) { var bullet = monsterBullets[b]; // Check if bullet hit ship if (bullet.intersects(ship)) { playerHealth -= 15; updateHealth(); LK.effects.flashScreen(0xFF0000, 300); bullet.destroy(); monsterBullets.splice(b, 1); if (playerHealth <= 0) { LK.showGameOver(); return; } continue; } // Check if bullet went off screen (bottom) if (bullet.lastY <= 2732 + 20 && bullet.y > 2732 + 20) { bullet.destroy(); monsterBullets.splice(b, 1); continue; } bullet.lastY = bullet.y; } // Update and check sea monsters for (var k = seaMonsters.length - 1; k >= 0; k--) { var monster = seaMonsters[k]; // Check if monster reached ship if (monster.intersects(ship)) { playerHealth -= 20; updateHealth(); LK.effects.flashScreen(0xFF0000, 500); monster.destroy(); seaMonsters.splice(k, 1); if (playerHealth <= 0) { LK.showGameOver(); return; } continue; } // Check if monster went off screen (bottom) - player loses health if (monster.lastY <= 2732 + 50 && monster.y > 2732 + 50) { playerHealth -= 10; // Lose health when monster passes updateHealth(); LK.effects.flashScreen(0xFFFF00, 200); // Yellow flash for passed monster monster.destroy(); seaMonsters.splice(k, 1); if (playerHealth <= 0) { LK.showGameOver(); return; } continue; } monster.lastY = monster.y; } // Update and check seagulls for (var m = seagulls.length - 1; m >= 0; m--) { var seagull = seagulls[m]; // Check if seagull hit ship if (seagull.intersects(ship)) { playerHealth -= 15; // Seagulls do moderate damage updateHealth(); LK.effects.flashScreen(0xFFFFFF, 300); // White flash for seagull hit seagull.destroy(); seagulls.splice(m, 1); if (playerHealth <= 0) { LK.showGameOver(); return; } continue; } // Check if seagull went off screen (bottom) if (seagull.lastY <= 2732 + 60 && seagull.y > 2732 + 60) { seagull.destroy(); seagulls.splice(m, 1); continue; } seagull.lastY = seagull.y; } // Update and clean up waves for (var w = waves.length - 1; w >= 0; w--) { var wave = waves[w]; // Check if wave went off screen (bottom) if (wave.lastY <= 2732 + 80 && wave.y > 2732 + 80) { wave.destroy(); waves.splice(w, 1); continue; } wave.lastY = wave.y; } // Update and check health packs for (var h = healthPacks.length - 1; h >= 0; h--) { var healthPack = healthPacks[h]; // Check if health pack hit ship if (healthPack.intersects(ship)) { playerHealth = Math.min(100, playerHealth + healthPack.healAmount); // Cap at 100 updateHealth(); LK.effects.flashScreen(0x00FF00, 300); // Green flash for healing LK.getSound('heal').play(); // Add healing animation to ship tween(ship, { tint: 0x00FF00 }, { duration: 200, onFinish: function onFinish() { tween(ship, { tint: 0xFFFFFF }, { duration: 200 }); } }); healthPack.destroy(); healthPacks.splice(h, 1); continue; } // Check if health pack went off screen (bottom) if (healthPack.lastY <= 2732 + 80 && healthPack.y > 2732 + 80) { healthPack.destroy(); healthPacks.splice(h, 1); continue; } healthPack.lastY = healthPack.y; } // Win condition - reach level 100 if (currentLevel >= maxLevel) { LK.showYouWin(); } }; // Start background music LK.playMusic('ocean'); // Initialize displays updateScore(); updateHealth(); updateLevel();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var HealthPack = Container.expand(function () {
var self = Container.call(this);
var healthGraphics = self.attachAsset('healthPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4 + Math.random() * 3;
self.healAmount = 20; // Heal exactly 20 health
self.rotationSpeed = 0.05;
// Add pulsing animation for visibility
self.pulseOffset = Math.random() * Math.PI * 2;
self.update = function () {
self.y += self.speed;
healthGraphics.rotation += self.rotationSpeed;
// Pulsing scale animation to make it noticeable
var pulse = 1 + Math.sin(LK.ticks * 0.1 + self.pulseOffset) * 0.2;
healthGraphics.scaleX = pulse;
healthGraphics.scaleY = pulse;
};
return self;
});
var MonsterBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('projectile', {
anchorX: 0.5,
anchorY: 0.5
});
bulletGraphics.tint = 0xFF0000; // Red color for monster bullets
self.speed = 10;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Projectile = Container.expand(function () {
var self = Container.call(this);
var projectileGraphics = self.attachAsset('projectile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -12;
self.update = function () {
self.y += self.speed;
};
return self;
});
var SeaMonster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('seaMonster', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8 + Math.random() * 6;
self.health = 1;
self.lastShotTime = 0;
self.shotCooldown = 600 + Math.random() * 400; // Random shooting interval
self.update = function () {
self.y += self.speed;
// Monster shooting logic
if (Date.now() - self.lastShotTime > self.shotCooldown) {
self.lastShotTime = Date.now();
var bullet = new MonsterBullet();
bullet.x = self.x;
bullet.y = self.y + 50;
bullet.lastY = bullet.y;
monsterBullets.push(bullet);
game.addChild(bullet);
}
};
self.takeDamage = function () {
self.health--;
if (self.health <= 0) {
LK.effects.flashObject(self, 0xFF0000, 200);
return true; // Monster destroyed
}
return false;
};
return self;
});
var Seagull = Container.expand(function () {
var self = Container.call(this);
var seagullGraphics = self.attachAsset('seagull', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8 + Math.random() * 6; // Flying seagulls
self.rotationSpeed = 0.05 + Math.random() * 0.1;
self.update = function () {
self.y += self.speed;
seagullGraphics.rotation += self.rotationSpeed;
};
return self;
});
var Ship = Container.expand(function () {
var self = Container.call(this);
// Add boat graphics first (underneath)
var boatGraphics = self.attachAsset('boat', {
anchorX: 0.5,
anchorY: 0.5
});
// Add ship graphics on top
var shipGraphics = self.attachAsset('ship', {
anchorX: 0.5,
anchorY: 0.3
});
shipGraphics.y = -10; // Position ship slightly above boat
self.speed = 8;
self.lastShotTime = 0;
self.shotCooldown = 300; // milliseconds
self.moveLeft = function () {
self.x -= self.speed;
if (self.x < shipGraphics.width / 2) {
self.x = shipGraphics.width / 2;
}
};
self.moveRight = function () {
self.x += self.speed;
if (self.x > 2048 - shipGraphics.width / 2) {
self.x = 2048 - shipGraphics.width / 2;
}
};
self.canShoot = function () {
return Date.now() - self.lastShotTime > self.shotCooldown;
};
self.shoot = function () {
if (self.canShoot()) {
self.lastShotTime = Date.now();
return true;
}
return false;
};
return self;
});
var Wave = Container.expand(function () {
var self = Container.call(this);
var waveGraphics = self.attachAsset('wave', {
anchorX: 0.5,
anchorY: 0.5
});
waveGraphics.alpha = 0.4 + Math.random() * 0.3; // Varied transparency
self.speed = 2 + Math.random() * 5; // More varied wave speeds
self.originalX = self.x;
self.waveOffset = Math.random() * Math.PI * 2;
self.horizontalAmplitude = 20 + Math.random() * 40; // More varied wave movement
// Add tint variation for realistic ocean colors
var blueVariation = 0x4080C0 + Math.floor(Math.random() * 0x202020);
waveGraphics.tint = blueVariation;
self.update = function () {
// Move wave downward with varying speed for realism
self.y += self.speed + Math.sin(LK.ticks * 0.02 + self.waveOffset) * 0.5;
// Animate wave with realistic horizontal sine wave motion
self.x = self.originalX + Math.sin(LK.ticks * 0.04 + self.waveOffset) * self.horizontalAmplitude;
// Add realistic wave rolling motion
var rollMotion = Math.sin(LK.ticks * 0.05 + self.waveOffset);
waveGraphics.rotation = rollMotion * 0.1;
// Add wave scaling for more dynamic ocean effect
var scaleVariation = 1 + Math.sin(LK.ticks * 0.03 + self.waveOffset) * 0.15;
waveGraphics.scaleX = scaleVariation;
waveGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.025 + self.waveOffset) * 0.1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x006994
});
/****
* Game Code
****/
var ship;
var projectiles = [];
var seaMonsters = [];
var monsterBullets = [];
var seagulls = [];
var waves = [];
var healthPacks = [];
var dragNode = null;
var waveSpawnTimer = 0;
var waveSpawnInterval = 80; // More frequent waves for realistic ocean
var monsterSpawnTimer = 0;
var monsterSpawnInterval = 120; // frames
var seagullSpawnTimer = 0;
var seagullSpawnInterval = 90; // frames - seagulls spawn regularly
var healthPackSpawnTimer = 0;
var healthPackSpawnInterval = 480; // frames - spawn health packs less frequently
var difficultyTimer = 0;
// Initialize ship
ship = game.addChild(new Ship());
ship.x = 2048 / 2;
ship.y = 2732 - 150;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Health display
var healthTxt = new Text2('Health: 100', {
size: 60,
fill: 0xFFFFFF
});
healthTxt.anchor.set(0, 0);
healthTxt.x = 120;
healthTxt.y = 20;
LK.gui.topLeft.addChild(healthTxt);
// Level display
var levelTxt = new Text2('Level: 1', {
size: 60,
fill: 0xFFD700
});
levelTxt.anchor.set(1, 0);
levelTxt.x = -20;
levelTxt.y = 20;
LK.gui.topRight.addChild(levelTxt);
var playerHealth = 100;
var currentLevel = 1;
var maxLevel = 100;
var pointsPerLevel = 100;
function updateScore() {
scoreTxt.setText('Score: ' + LK.getScore());
checkLevelUp();
}
function updateHealth() {
healthTxt.setText('Health: ' + playerHealth);
}
function updateLevel() {
levelTxt.setText('Level: ' + currentLevel);
}
function checkLevelUp() {
var newLevel = Math.floor(LK.getScore() / pointsPerLevel) + 1;
if (newLevel > currentLevel && newLevel <= maxLevel) {
currentLevel = newLevel;
updateLevel();
// Flash screen gold when leveling up
LK.effects.flashScreen(0xFFD700, 800);
// Increase difficulty with each level
monsterSpawnInterval = Math.max(20, 120 - currentLevel * 2);
return true;
}
return false;
}
function spawnMonster() {
var monster = new SeaMonster();
monster.x = Math.random() * (2048 - 100) + 50;
monster.y = -50;
monster.lastY = monster.y;
seaMonsters.push(monster);
game.addChild(monster);
}
function spawnSeagull() {
var seagull = new Seagull();
seagull.x = Math.random() * (2048 - 60) + 30;
seagull.y = -60;
seagull.lastY = seagull.y;
seagulls.push(seagull);
game.addChild(seagull);
}
function spawnWave() {
var wave = new Wave();
wave.x = Math.random() * 2048; // Random horizontal position
wave.y = -100; // Start further from top of screen
wave.originalX = wave.x;
wave.lastY = wave.y;
waves.push(wave);
game.addChild(wave);
// Add realistic wave animation with tween - more dramatic effect
tween(wave, {
alpha: 0.9,
scaleY: 1.5,
scaleX: 1.2
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Fade out wave at the end
tween(wave, {
alpha: 0.3,
scaleY: 0.8
}, {
duration: 1000,
easing: tween.easeOut
});
}
});
}
function spawnHealthPack() {
var healthPack = new HealthPack();
healthPack.x = Math.random() * (2048 - 80) + 40;
healthPack.y = -80;
healthPack.lastY = healthPack.y;
healthPacks.push(healthPack);
game.addChild(healthPack);
// Add entrance animation with tween
tween(healthPack, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 800,
easing: tween.bounceOut
});
}
function handleMove(x, y, obj) {
if (dragNode === ship) {
ship.x = x;
if (ship.x < 60) ship.x = 60;
if (ship.x > 2048 - 60) ship.x = 2048 - 60;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = ship;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
game.update = function () {
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer % 1800 === 0) {
// Every 30 seconds
monsterSpawnInterval = Math.max(30, monsterSpawnInterval - 10);
}
// Spawn monsters
monsterSpawnTimer++;
if (monsterSpawnTimer >= monsterSpawnInterval) {
spawnMonster();
monsterSpawnTimer = 0;
}
// Spawn seagulls
seagullSpawnTimer++;
if (seagullSpawnTimer >= seagullSpawnInterval) {
spawnSeagull();
seagullSpawnTimer = 0;
}
// Spawn waves
waveSpawnTimer++;
if (waveSpawnTimer >= waveSpawnInterval) {
spawnWave();
waveSpawnTimer = 0;
}
// Spawn health packs
healthPackSpawnTimer++;
if (healthPackSpawnTimer >= healthPackSpawnInterval) {
spawnHealthPack();
healthPackSpawnTimer = 0;
}
// Auto-shoot from ship
if (ship.shoot()) {
var projectile = new Projectile();
projectile.x = ship.x;
projectile.y = ship.y - 40;
projectile.lastY = projectile.y;
projectiles.push(projectile);
game.addChild(projectile);
LK.getSound('shoot').play();
}
// Update and check projectiles
for (var i = projectiles.length - 1; i >= 0; i--) {
var projectile = projectiles[i];
// Check if projectile went off screen
if (projectile.lastY >= -20 && projectile.y < -20) {
projectile.destroy();
projectiles.splice(i, 1);
continue;
}
// Check projectile-monster collisions
var hit = false;
for (var j = seaMonsters.length - 1; j >= 0; j--) {
var monster = seaMonsters[j];
if (projectile.intersects(monster)) {
if (monster.takeDamage()) {
LK.setScore(LK.getScore() + 10);
updateScore();
LK.getSound('explosion').play();
monster.destroy();
seaMonsters.splice(j, 1);
}
projectile.destroy();
projectiles.splice(i, 1);
hit = true;
break;
}
}
if (!hit) {
projectile.lastY = projectile.y;
}
}
// Update and check monster bullets
for (var b = monsterBullets.length - 1; b >= 0; b--) {
var bullet = monsterBullets[b];
// Check if bullet hit ship
if (bullet.intersects(ship)) {
playerHealth -= 15;
updateHealth();
LK.effects.flashScreen(0xFF0000, 300);
bullet.destroy();
monsterBullets.splice(b, 1);
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
continue;
}
// Check if bullet went off screen (bottom)
if (bullet.lastY <= 2732 + 20 && bullet.y > 2732 + 20) {
bullet.destroy();
monsterBullets.splice(b, 1);
continue;
}
bullet.lastY = bullet.y;
}
// Update and check sea monsters
for (var k = seaMonsters.length - 1; k >= 0; k--) {
var monster = seaMonsters[k];
// Check if monster reached ship
if (monster.intersects(ship)) {
playerHealth -= 20;
updateHealth();
LK.effects.flashScreen(0xFF0000, 500);
monster.destroy();
seaMonsters.splice(k, 1);
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
continue;
}
// Check if monster went off screen (bottom) - player loses health
if (monster.lastY <= 2732 + 50 && monster.y > 2732 + 50) {
playerHealth -= 10; // Lose health when monster passes
updateHealth();
LK.effects.flashScreen(0xFFFF00, 200); // Yellow flash for passed monster
monster.destroy();
seaMonsters.splice(k, 1);
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
continue;
}
monster.lastY = monster.y;
}
// Update and check seagulls
for (var m = seagulls.length - 1; m >= 0; m--) {
var seagull = seagulls[m];
// Check if seagull hit ship
if (seagull.intersects(ship)) {
playerHealth -= 15; // Seagulls do moderate damage
updateHealth();
LK.effects.flashScreen(0xFFFFFF, 300); // White flash for seagull hit
seagull.destroy();
seagulls.splice(m, 1);
if (playerHealth <= 0) {
LK.showGameOver();
return;
}
continue;
}
// Check if seagull went off screen (bottom)
if (seagull.lastY <= 2732 + 60 && seagull.y > 2732 + 60) {
seagull.destroy();
seagulls.splice(m, 1);
continue;
}
seagull.lastY = seagull.y;
}
// Update and clean up waves
for (var w = waves.length - 1; w >= 0; w--) {
var wave = waves[w];
// Check if wave went off screen (bottom)
if (wave.lastY <= 2732 + 80 && wave.y > 2732 + 80) {
wave.destroy();
waves.splice(w, 1);
continue;
}
wave.lastY = wave.y;
}
// Update and check health packs
for (var h = healthPacks.length - 1; h >= 0; h--) {
var healthPack = healthPacks[h];
// Check if health pack hit ship
if (healthPack.intersects(ship)) {
playerHealth = Math.min(100, playerHealth + healthPack.healAmount); // Cap at 100
updateHealth();
LK.effects.flashScreen(0x00FF00, 300); // Green flash for healing
LK.getSound('heal').play();
// Add healing animation to ship
tween(ship, {
tint: 0x00FF00
}, {
duration: 200,
onFinish: function onFinish() {
tween(ship, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
healthPack.destroy();
healthPacks.splice(h, 1);
continue;
}
// Check if health pack went off screen (bottom)
if (healthPack.lastY <= 2732 + 80 && healthPack.y > 2732 + 80) {
healthPack.destroy();
healthPacks.splice(h, 1);
continue;
}
healthPack.lastY = healthPack.y;
}
// Win condition - reach level 100
if (currentLevel >= maxLevel) {
LK.showYouWin();
}
};
// Start background music
LK.playMusic('ocean');
// Initialize displays
updateScore();
updateHealth();
updateLevel();
IĢnsan. In-Game asset. 2d. High contrast. No shadows
BuĢyuĢk tekne. In-Game asset. 2d. High contrast. No shadows
KoĢpek balıgĢı. In-Game asset. 2d. High contrast. No shadows
Deniz dalgası. In-Game asset. 2d. High contrast. No shadows
SagĢlık paketi. In-Game asset. 2d. High contrast. No shadows
Martı. In-Game asset. 2d. High contrast. No shadows