/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -50; self.update = function () { self.y += self.speed; }; return self; }); var Crosshair = Container.expand(function () { var self = Container.call(this); var hunter = self.attachAsset('hunter', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Duck = Container.expand(function () { var self = Container.call(this); var duckBody = self.attachAsset('duck', { anchorX: 0.5, anchorY: 0.5 }); var leftWing = self.attachAsset('duckWing', { anchorX: 0.5, anchorY: 0.5, x: -30, y: -10 }); var rightWing = self.attachAsset('duckWing', { anchorX: 0.5, anchorY: 0.5, x: 30, y: -10 }); self.speed = 12; self.direction = 1; self.wingAnimation = 0; self.isHit = false; self.update = function () { if (self.isHit) return; self.x += self.speed * self.direction; // Wing flapping animation self.wingAnimation += 0.3; leftWing.rotation = Math.sin(self.wingAnimation) * 0.5; rightWing.rotation = -Math.sin(self.wingAnimation) * 0.5; }; self.hit = function () { if (self.isHit) return false; self.isHit = true; LK.getSound('hit').play(); // Duck falls down when hit tween(self, { y: self.y + 200, rotation: Math.PI }, { duration: 800, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); } }); return true; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Add sky background var skyBg = game.addChild(LK.getAsset('skyBackground', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Game variables var crosshair; var ducks = []; var bullets = []; var duckSpawnTimer = 0; var gameScore = 0; var difficulty = 1; // Initialize crosshair crosshair = game.addChild(new Crosshair()); crosshair.x = 1024; crosshair.y = 2600; // Initialize score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game controls game.move = function (x, y, obj) { // Hunter is stuck in position - no movement allowed }; game.down = function (x, y, obj) { // Manual shooting on touch/tap var bullet = new Bullet(); bullet.x = crosshair.x; bullet.y = crosshair.y - 50; bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); }; function spawnDuck() { var duck = new Duck(); // Always spawn from left side duck.x = -100; duck.direction = 1; // Random height in upper half of screen duck.y = Math.random() * 800 + 400; // Random speed based on difficulty - very fast movement duck.speed = 8 + Math.random() * 6 + difficulty * 2; ducks.push(duck); game.addChild(duck); LK.getSound('quack').play(); } game.update = function () { duckSpawnTimer++; // Spawn ducks based on difficulty var spawnRate = Math.max(60 - difficulty * 5, 30); if (duckSpawnTimer >= spawnRate) { spawnDuck(); duckSpawnTimer = 0; } // Update and check bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; // Remove bullets that go off screen if (bullet.y < -50) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check bullet-duck collisions for (var j = ducks.length - 1; j >= 0; j--) { var duck = ducks[j]; if (!duck.isHit && bullet.intersects(duck)) { if (duck.hit()) { gameScore += 10 * difficulty; LK.setScore(gameScore); scoreTxt.setText('Score: ' + gameScore); // Remove duck from array ducks.splice(j, 1); // Remove bullet bullet.destroy(); bullets.splice(i, 1); break; } } } } // Check for ducks that escaped (only check right side since ducks fly left to right) for (var k = ducks.length - 1; k >= 0; k--) { var duck = ducks[k]; if (!duck.isHit && duck.x > 2200) { duck.destroy(); ducks.splice(k, 1); } } // Increase difficulty every 100 points var newDifficulty = Math.floor(gameScore / 100) + 1; if (newDifficulty > difficulty) { difficulty = newDifficulty; } // Win condition - score 500 points if (gameScore >= 500) { LK.showYouWin(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -50;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Crosshair = Container.expand(function () {
var self = Container.call(this);
var hunter = self.attachAsset('hunter', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Duck = Container.expand(function () {
var self = Container.call(this);
var duckBody = self.attachAsset('duck', {
anchorX: 0.5,
anchorY: 0.5
});
var leftWing = self.attachAsset('duckWing', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
y: -10
});
var rightWing = self.attachAsset('duckWing', {
anchorX: 0.5,
anchorY: 0.5,
x: 30,
y: -10
});
self.speed = 12;
self.direction = 1;
self.wingAnimation = 0;
self.isHit = false;
self.update = function () {
if (self.isHit) return;
self.x += self.speed * self.direction;
// Wing flapping animation
self.wingAnimation += 0.3;
leftWing.rotation = Math.sin(self.wingAnimation) * 0.5;
rightWing.rotation = -Math.sin(self.wingAnimation) * 0.5;
};
self.hit = function () {
if (self.isHit) return false;
self.isHit = true;
LK.getSound('hit').play();
// Duck falls down when hit
tween(self, {
y: self.y + 200,
rotation: Math.PI
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
}
});
return true;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Add sky background
var skyBg = game.addChild(LK.getAsset('skyBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Game variables
var crosshair;
var ducks = [];
var bullets = [];
var duckSpawnTimer = 0;
var gameScore = 0;
var difficulty = 1;
// Initialize crosshair
crosshair = game.addChild(new Crosshair());
crosshair.x = 1024;
crosshair.y = 2600;
// Initialize score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Game controls
game.move = function (x, y, obj) {
// Hunter is stuck in position - no movement allowed
};
game.down = function (x, y, obj) {
// Manual shooting on touch/tap
var bullet = new Bullet();
bullet.x = crosshair.x;
bullet.y = crosshair.y - 50;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
};
function spawnDuck() {
var duck = new Duck();
// Always spawn from left side
duck.x = -100;
duck.direction = 1;
// Random height in upper half of screen
duck.y = Math.random() * 800 + 400;
// Random speed based on difficulty - very fast movement
duck.speed = 8 + Math.random() * 6 + difficulty * 2;
ducks.push(duck);
game.addChild(duck);
LK.getSound('quack').play();
}
game.update = function () {
duckSpawnTimer++;
// Spawn ducks based on difficulty
var spawnRate = Math.max(60 - difficulty * 5, 30);
if (duckSpawnTimer >= spawnRate) {
spawnDuck();
duckSpawnTimer = 0;
}
// Update and check bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove bullets that go off screen
if (bullet.y < -50) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-duck collisions
for (var j = ducks.length - 1; j >= 0; j--) {
var duck = ducks[j];
if (!duck.isHit && bullet.intersects(duck)) {
if (duck.hit()) {
gameScore += 10 * difficulty;
LK.setScore(gameScore);
scoreTxt.setText('Score: ' + gameScore);
// Remove duck from array
ducks.splice(j, 1);
// Remove bullet
bullet.destroy();
bullets.splice(i, 1);
break;
}
}
}
}
// Check for ducks that escaped (only check right side since ducks fly left to right)
for (var k = ducks.length - 1; k >= 0; k--) {
var duck = ducks[k];
if (!duck.isHit && duck.x > 2200) {
duck.destroy();
ducks.splice(k, 1);
}
}
// Increase difficulty every 100 points
var newDifficulty = Math.floor(gameScore / 100) + 1;
if (newDifficulty > difficulty) {
difficulty = newDifficulty;
}
// Win condition - score 500 points
if (gameScore >= 500) {
LK.showYouWin();
}
};