/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boat = Container.expand(function (isSmuggler, speed) {
var self = Container.call(this);
var assetId = isSmuggler ? 'smugglerBoat' : 'civilianBoat';
var boatGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.isSmuggler = isSmuggler;
self.speed = speed || 2;
self.active = true;
self.direction = Math.random() > 0.5 ? 1 : -1;
// Set initial position
if (self.direction > 0) {
self.x = -100;
boatGraphics.scaleX = 1;
} else {
self.x = 2048 + 100;
boatGraphics.scaleX = -1;
}
self.update = function () {
self.x += self.speed * self.direction;
// Remove if off screen on the other side
if (self.direction > 0 && self.x > 2048 + 100 || self.direction < 0 && self.x < -100) {
self.active = false;
// If it's a smuggler and it escaped, lose a point
if (self.isSmuggler && gameActive) {
score--;
if (score < 0) {
score = 0;
}
updateScore();
}
}
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.active = true;
self.update = function () {
self.y += self.speed;
// Remove if off screen
if (self.y > 2732) {
self.active = false;
}
};
return self;
});
var Helicopter = Container.expand(function () {
var self = Container.call(this);
var helicopterBody = self.attachAsset('helicopter', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.fireRate = 30; // frames between shots
self.cooldown = 0;
self.moveLeft = function () {
self.x -= self.speed;
if (self.x < 100) {
self.x = 100;
}
};
self.moveRight = function () {
self.x += self.speed;
if (self.x > 2048 - 100) {
self.x = 2048 - 100;
}
};
self.canFire = function () {
return self.cooldown <= 0;
};
self.resetCooldown = function () {
self.cooldown = self.fireRate;
};
self.update = function () {
if (self.cooldown > 0) {
self.cooldown--;
}
// Automatic left and right movement
if (self.direction === undefined) {
self.direction = 1; // Start moving right
}
self.x += self.speed * self.direction;
// Change direction at screen edges
if (self.x <= 100) {
self.direction = 1; // Move right
} else if (self.x >= 2048 - 100) {
self.direction = -1; // Move left
}
// Ensure helicopter stays within screen bounds
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
if (self.y < 0) {
self.y = 0;
} else if (self.y > 2732) {
self.y = 2732;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0066cc
});
/****
* Game Code
****/
// Game variables
var helicopter;
var bullets = [];
var boats = [];
var score = 0;
var level = 0;
var gameActive = true;
var spawnInterval = 120; // frames between boat spawns
var spawnCounter = 0;
var difficulty = 1;
var levelThreshold = 10; // score needed to level up
var targetPressed = false;
var targetX, targetY;
// UI elements
var smugglerBoatsDestroyedTxt = new Text2('Smuggler Boats Destroyed: ' + score, {
size: 50,
fill: 0xFFFFFF // White color
});
smugglerBoatsDestroyedTxt.anchor.set(0.5, 0);
smugglerBoatsDestroyedTxt.x = 2048 / 2;
smugglerBoatsDestroyedTxt.y = 2732 - 100; // Position above the score
LK.gui.bottom.addChild(smugglerBoatsDestroyedTxt);
var scoreTxt;
var levelTxt;
var instructionsTxt;
// Initialize game
function initGame() {
score = storage.score || 0;
// Removed duplicate definition of smugglerBoatsDestroyedTxt
// Create score text
scoreTxt = new Text2('Score: ' + score, {
size: 50,
fill: 0xFFFFFF // White color
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = 2048 / 2;
scoreTxt.y = 2732 - 50; // Position at the bottom of the screen
LK.gui.bottom.addChild(scoreTxt);
// Create level text
levelTxt = new Text2('Level: ' + level, {
size: 50,
fill: 0xFFFFFF // White color
});
levelTxt.anchor.set(0.5, 0);
levelTxt.x = 2048 / 2;
levelTxt.y = 2732 - 150; // Position above the score
LK.gui.bottom.addChild(levelTxt);
var shootButton = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
shootButton.x = 2048 / 2;
shootButton.y = 2732 - 150;
game.addChild(shootButton);
// Add event listener for shoot button
shootButton.down = function () {
if (gameActive) {
fireBullet();
}
};
// Create ocean background
var ocean = LK.getAsset('ocean', {
anchorX: 0,
anchorY: 0
});
ocean.width = 2048; // Set width to match game width
ocean.height = 2732; // Set height to match game height
game.addChild(ocean);
// Create helicopter
helicopter = new Helicopter();
helicopter.x = 2048 / 2;
helicopter.y = 150;
game.addChild(helicopter);
// Create instructions text
instructionsTxt = new Text2('Tap to move and shoot. Hit smuggler boats (red) and avoid civilian boats (green).', {
size: 30,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionsTxt);
// Remove instructions after 5 seconds
LK.setTimeout(function () {
if (instructionsTxt && instructionsTxt.parent) {
instructionsTxt.parent.removeChild(instructionsTxt);
instructionsTxt = null;
}
}, 5000);
// Start background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
}
// Update score display
function updateScore() {
storage.score = score;
scoreTxt.setText('Score: ' + score);
smugglerBoatsDestroyedTxt.setText('Smuggler Boats Destroyed: ' + score);
// Check for level up
if (score >= level * levelThreshold) {
levelUp();
}
}
// Level up
function levelUp() {
level++;
// Update level display
levelTxt.setText('Level: ' + level);
difficulty += 0.2;
spawnInterval = Math.max(30, Math.floor(120 / difficulty));
}
// Spawn a new boat
function spawnBoat() {
var boatCount = Math.floor(1 + Math.random() * (difficulty + level)); // Increase number of boats based on difficulty and level
for (var i = 0; i < boatCount; i++) {
var isSmuggler = Math.random() < 0.4; // 40% chance for smuggler, increasing civilian boat appearance
var speed = isSmuggler ? (1 + Math.random() * 0.5 + difficulty * 0.2) * (difficulty + level * 0.5) : (1 + Math.random() * 0.5) * (1 + level * 0.1);
var boat = new Boat(isSmuggler, speed);
// Set y position - distribute across the bottom 3/4 of the screen
boat.y = 800 + Math.random() * 1500;
boats.push(boat);
game.addChild(boat);
}
}
// Fire a bullet
function fireBullet() {
if (!helicopter.canFire()) {
return;
}
createBullet(helicopter.x, helicopter.y + 50);
helicopter.resetCooldown();
}
// Create a bullet at a specified position
function createBullet(x, y) {
var bullet = new Bullet();
bullet.x = x;
bullet.y = y;
bullets.push(bullet);
game.addChild(bullet);
// Play sound
LK.getSound('shoot').play();
}
// Check collisions
function checkCollisions() {
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (!bullet.active) {
continue;
}
for (var j = boats.length - 1; j >= 0; j--) {
var boat = boats[j];
if (!boat.active) {
continue;
}
if (bullet.intersects(boat)) {
// Hit a boat
bullet.active = false;
boat.active = false;
// Update score
if (boat.isSmuggler) {
score += 1; // Increase score for hitting a smuggler
updateScore(); // Update score display
// Check if score is a multiple of 10
if (score % 10 === 0) {
// Display an amazing notification
var amazingTxt = new Text2('Amazing!', {
size: 100,
fill: 0xFFD700 // Gold color
});
amazingTxt.anchor.set(0.5, 0.5);
amazingTxt.x = 2048 / 2;
amazingTxt.y = 2732 / 2;
LK.gui.center.addChild(amazingTxt);
// Remove the notification after 2 seconds
LK.setTimeout(function () {
LK.gui.center.removeChild(amazingTxt);
}, 2000);
}
// Create explosion effect
var explosion = LK.getAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
explosion.x = boat.x;
explosion.y = boat.y;
game.addChild(explosion);
// Remove explosion after a short duration
LK.setTimeout(function () {
game.removeChild(explosion);
}, 500);
LK.getSound('explosion').play();
} else {
// Hit civilian - bad!
score -= 2;
if (score < 0) {
score = 0;
}
LK.effects.flashObject(boat, 0xffff00, 500);
LK.getSound('miss').play();
// Game over if helicopter shoots a civilian boat
gameActive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver("Game Over! Final Score: ".concat(score));
score = 0;
storage.score = 0;
}
updateScore();
// Check for win condition
if (score >= 50) {
gameActive = false;
LK.showYouWin();
score = 0;
storage.score = 0;
}
break;
}
}
}
}
// Clean up inactive objects
function cleanupObjects() {
// Clean up bullets
for (var i = bullets.length - 1; i >= 0; i--) {
if (!bullets[i].active) {
game.removeChild(bullets[i]);
bullets.splice(i, 1);
}
}
// Clean up boats
for (var i = boats.length - 1; i >= 0; i--) {
if (!boats[i].active) {
game.removeChild(boats[i]);
boats.splice(i, 1);
}
}
}
// Handle game touches
function handleGameTouch(x, y) {
if (!gameActive) {
return;
}
// Move helicopter directly to touch point
helicopter.x = x;
}
// Handle touch pad for helicopter control
function handleTouchPad(x, y) {
if (!gameActive) {
return;
}
moveHelicopter(x, helicopter.y);
}
// Move helicopter towards a target position
function moveHelicopter(targetX, targetY) {
// Gradually move helicopter towards target position
var moveSpeed = 2; // Adjust speed for slower movement
if (helicopter.x < targetX) {
helicopter.x = Math.min(helicopter.x + moveSpeed, targetX);
} else if (helicopter.x > targetX) {
helicopter.x = Math.max(helicopter.x - moveSpeed, targetX);
}
}
// Game event handlers
game.down = function (x, y, obj) {
handleTouchPad(x, y);
fireBullet();
targetPressed = true;
};
game.move = function (x, y, obj) {
if (targetPressed) {
handleTouchPad(x, y);
fireBullet();
}
};
game.up = function (x, y, obj) {
targetPressed = false;
};
// Main game update
game.update = function () {
if (!gameActive) {
return;
}
// Update helicopter
helicopter.update();
// Update bullets
for (var i = 0; i < bullets.length; i++) {
bullets[i].update();
}
// Update boats
for (var i = 0; i < boats.length; i++) {
boats[i].update();
}
// Spawn boats
spawnCounter++;
if (spawnCounter >= spawnInterval) {
spawnBoat();
spawnCounter = 0;
}
// Check collisions
checkCollisions();
// Clean up inactive objects
cleanupObjects();
};
// Initialize the game
initGame(); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boat = Container.expand(function (isSmuggler, speed) {
var self = Container.call(this);
var assetId = isSmuggler ? 'smugglerBoat' : 'civilianBoat';
var boatGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.isSmuggler = isSmuggler;
self.speed = speed || 2;
self.active = true;
self.direction = Math.random() > 0.5 ? 1 : -1;
// Set initial position
if (self.direction > 0) {
self.x = -100;
boatGraphics.scaleX = 1;
} else {
self.x = 2048 + 100;
boatGraphics.scaleX = -1;
}
self.update = function () {
self.x += self.speed * self.direction;
// Remove if off screen on the other side
if (self.direction > 0 && self.x > 2048 + 100 || self.direction < 0 && self.x < -100) {
self.active = false;
// If it's a smuggler and it escaped, lose a point
if (self.isSmuggler && gameActive) {
score--;
if (score < 0) {
score = 0;
}
updateScore();
}
}
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.active = true;
self.update = function () {
self.y += self.speed;
// Remove if off screen
if (self.y > 2732) {
self.active = false;
}
};
return self;
});
var Helicopter = Container.expand(function () {
var self = Container.call(this);
var helicopterBody = self.attachAsset('helicopter', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.fireRate = 30; // frames between shots
self.cooldown = 0;
self.moveLeft = function () {
self.x -= self.speed;
if (self.x < 100) {
self.x = 100;
}
};
self.moveRight = function () {
self.x += self.speed;
if (self.x > 2048 - 100) {
self.x = 2048 - 100;
}
};
self.canFire = function () {
return self.cooldown <= 0;
};
self.resetCooldown = function () {
self.cooldown = self.fireRate;
};
self.update = function () {
if (self.cooldown > 0) {
self.cooldown--;
}
// Automatic left and right movement
if (self.direction === undefined) {
self.direction = 1; // Start moving right
}
self.x += self.speed * self.direction;
// Change direction at screen edges
if (self.x <= 100) {
self.direction = 1; // Move right
} else if (self.x >= 2048 - 100) {
self.direction = -1; // Move left
}
// Ensure helicopter stays within screen bounds
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
if (self.y < 0) {
self.y = 0;
} else if (self.y > 2732) {
self.y = 2732;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0066cc
});
/****
* Game Code
****/
// Game variables
var helicopter;
var bullets = [];
var boats = [];
var score = 0;
var level = 0;
var gameActive = true;
var spawnInterval = 120; // frames between boat spawns
var spawnCounter = 0;
var difficulty = 1;
var levelThreshold = 10; // score needed to level up
var targetPressed = false;
var targetX, targetY;
// UI elements
var smugglerBoatsDestroyedTxt = new Text2('Smuggler Boats Destroyed: ' + score, {
size: 50,
fill: 0xFFFFFF // White color
});
smugglerBoatsDestroyedTxt.anchor.set(0.5, 0);
smugglerBoatsDestroyedTxt.x = 2048 / 2;
smugglerBoatsDestroyedTxt.y = 2732 - 100; // Position above the score
LK.gui.bottom.addChild(smugglerBoatsDestroyedTxt);
var scoreTxt;
var levelTxt;
var instructionsTxt;
// Initialize game
function initGame() {
score = storage.score || 0;
// Removed duplicate definition of smugglerBoatsDestroyedTxt
// Create score text
scoreTxt = new Text2('Score: ' + score, {
size: 50,
fill: 0xFFFFFF // White color
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = 2048 / 2;
scoreTxt.y = 2732 - 50; // Position at the bottom of the screen
LK.gui.bottom.addChild(scoreTxt);
// Create level text
levelTxt = new Text2('Level: ' + level, {
size: 50,
fill: 0xFFFFFF // White color
});
levelTxt.anchor.set(0.5, 0);
levelTxt.x = 2048 / 2;
levelTxt.y = 2732 - 150; // Position above the score
LK.gui.bottom.addChild(levelTxt);
var shootButton = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
shootButton.x = 2048 / 2;
shootButton.y = 2732 - 150;
game.addChild(shootButton);
// Add event listener for shoot button
shootButton.down = function () {
if (gameActive) {
fireBullet();
}
};
// Create ocean background
var ocean = LK.getAsset('ocean', {
anchorX: 0,
anchorY: 0
});
ocean.width = 2048; // Set width to match game width
ocean.height = 2732; // Set height to match game height
game.addChild(ocean);
// Create helicopter
helicopter = new Helicopter();
helicopter.x = 2048 / 2;
helicopter.y = 150;
game.addChild(helicopter);
// Create instructions text
instructionsTxt = new Text2('Tap to move and shoot. Hit smuggler boats (red) and avoid civilian boats (green).', {
size: 30,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionsTxt);
// Remove instructions after 5 seconds
LK.setTimeout(function () {
if (instructionsTxt && instructionsTxt.parent) {
instructionsTxt.parent.removeChild(instructionsTxt);
instructionsTxt = null;
}
}, 5000);
// Start background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
}
// Update score display
function updateScore() {
storage.score = score;
scoreTxt.setText('Score: ' + score);
smugglerBoatsDestroyedTxt.setText('Smuggler Boats Destroyed: ' + score);
// Check for level up
if (score >= level * levelThreshold) {
levelUp();
}
}
// Level up
function levelUp() {
level++;
// Update level display
levelTxt.setText('Level: ' + level);
difficulty += 0.2;
spawnInterval = Math.max(30, Math.floor(120 / difficulty));
}
// Spawn a new boat
function spawnBoat() {
var boatCount = Math.floor(1 + Math.random() * (difficulty + level)); // Increase number of boats based on difficulty and level
for (var i = 0; i < boatCount; i++) {
var isSmuggler = Math.random() < 0.4; // 40% chance for smuggler, increasing civilian boat appearance
var speed = isSmuggler ? (1 + Math.random() * 0.5 + difficulty * 0.2) * (difficulty + level * 0.5) : (1 + Math.random() * 0.5) * (1 + level * 0.1);
var boat = new Boat(isSmuggler, speed);
// Set y position - distribute across the bottom 3/4 of the screen
boat.y = 800 + Math.random() * 1500;
boats.push(boat);
game.addChild(boat);
}
}
// Fire a bullet
function fireBullet() {
if (!helicopter.canFire()) {
return;
}
createBullet(helicopter.x, helicopter.y + 50);
helicopter.resetCooldown();
}
// Create a bullet at a specified position
function createBullet(x, y) {
var bullet = new Bullet();
bullet.x = x;
bullet.y = y;
bullets.push(bullet);
game.addChild(bullet);
// Play sound
LK.getSound('shoot').play();
}
// Check collisions
function checkCollisions() {
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (!bullet.active) {
continue;
}
for (var j = boats.length - 1; j >= 0; j--) {
var boat = boats[j];
if (!boat.active) {
continue;
}
if (bullet.intersects(boat)) {
// Hit a boat
bullet.active = false;
boat.active = false;
// Update score
if (boat.isSmuggler) {
score += 1; // Increase score for hitting a smuggler
updateScore(); // Update score display
// Check if score is a multiple of 10
if (score % 10 === 0) {
// Display an amazing notification
var amazingTxt = new Text2('Amazing!', {
size: 100,
fill: 0xFFD700 // Gold color
});
amazingTxt.anchor.set(0.5, 0.5);
amazingTxt.x = 2048 / 2;
amazingTxt.y = 2732 / 2;
LK.gui.center.addChild(amazingTxt);
// Remove the notification after 2 seconds
LK.setTimeout(function () {
LK.gui.center.removeChild(amazingTxt);
}, 2000);
}
// Create explosion effect
var explosion = LK.getAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
explosion.x = boat.x;
explosion.y = boat.y;
game.addChild(explosion);
// Remove explosion after a short duration
LK.setTimeout(function () {
game.removeChild(explosion);
}, 500);
LK.getSound('explosion').play();
} else {
// Hit civilian - bad!
score -= 2;
if (score < 0) {
score = 0;
}
LK.effects.flashObject(boat, 0xffff00, 500);
LK.getSound('miss').play();
// Game over if helicopter shoots a civilian boat
gameActive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver("Game Over! Final Score: ".concat(score));
score = 0;
storage.score = 0;
}
updateScore();
// Check for win condition
if (score >= 50) {
gameActive = false;
LK.showYouWin();
score = 0;
storage.score = 0;
}
break;
}
}
}
}
// Clean up inactive objects
function cleanupObjects() {
// Clean up bullets
for (var i = bullets.length - 1; i >= 0; i--) {
if (!bullets[i].active) {
game.removeChild(bullets[i]);
bullets.splice(i, 1);
}
}
// Clean up boats
for (var i = boats.length - 1; i >= 0; i--) {
if (!boats[i].active) {
game.removeChild(boats[i]);
boats.splice(i, 1);
}
}
}
// Handle game touches
function handleGameTouch(x, y) {
if (!gameActive) {
return;
}
// Move helicopter directly to touch point
helicopter.x = x;
}
// Handle touch pad for helicopter control
function handleTouchPad(x, y) {
if (!gameActive) {
return;
}
moveHelicopter(x, helicopter.y);
}
// Move helicopter towards a target position
function moveHelicopter(targetX, targetY) {
// Gradually move helicopter towards target position
var moveSpeed = 2; // Adjust speed for slower movement
if (helicopter.x < targetX) {
helicopter.x = Math.min(helicopter.x + moveSpeed, targetX);
} else if (helicopter.x > targetX) {
helicopter.x = Math.max(helicopter.x - moveSpeed, targetX);
}
}
// Game event handlers
game.down = function (x, y, obj) {
handleTouchPad(x, y);
fireBullet();
targetPressed = true;
};
game.move = function (x, y, obj) {
if (targetPressed) {
handleTouchPad(x, y);
fireBullet();
}
};
game.up = function (x, y, obj) {
targetPressed = false;
};
// Main game update
game.update = function () {
if (!gameActive) {
return;
}
// Update helicopter
helicopter.update();
// Update bullets
for (var i = 0; i < bullets.length; i++) {
bullets[i].update();
}
// Update boats
for (var i = 0; i < boats.length; i++) {
boats[i].update();
}
// Spawn boats
spawnCounter++;
if (spawnCounter >= spawnInterval) {
spawnBoat();
spawnCounter = 0;
}
// Check collisions
checkCollisions();
// Clean up inactive objects
cleanupObjects();
};
// Initialize the game
initGame();
horizontal top down image drugs smugler super boat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
blue white color fishing ship. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
tiger stripe helicopter war. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
drop bom tube. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red fire explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows