User prompt
duck fast move
User prompt
make hunter stuck and stand on bottom middle
User prompt
change crosshair to hunter
User prompt
bullet very very fast
User prompt
manual shoot
User prompt
fix the background
User prompt
add background
User prompt
make 1 second shoot interval
User prompt
auto shoot
User prompt
duck fly from left to right
Code edit (1 edits merged)
Please save this source code
User prompt
Duck Hunt Blaster
Initial prompt
vertical shooting game. duch hunt
/**** * 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 = -15; self.update = function () { self.y += self.speed; }; return self; }); var Crosshair = Container.expand(function () { var self = Container.call(this); var outerRing = self.attachAsset('crosshair', { anchorX: 0.5, anchorY: 0.5 }); var centerDot = self.attachAsset('crosshairCenter', { 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 = 3; 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) { crosshair.x = x; crosshair.y = Math.max(y, 2400); // Keep crosshair in bottom portion }; 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 duck.speed = 2 + Math.random() * 3 + difficulty * 0.5; 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(); } };
===================================================================
--- original.js
+++ change.js
@@ -103,9 +103,8 @@
var bullets = [];
var duckSpawnTimer = 0;
var gameScore = 0;
var difficulty = 1;
-var autoShootTimer = 0;
// Initialize crosshair
crosshair = game.addChild(new Crosshair());
crosshair.x = 1024;
crosshair.y = 2600;
@@ -121,10 +120,15 @@
crosshair.x = x;
crosshair.y = Math.max(y, 2400); // Keep crosshair in bottom portion
};
game.down = function (x, y, obj) {
- // Auto-shooting is now handled in game.update
- // This function can be used for other interactions if needed
+ // 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
@@ -139,25 +143,14 @@
LK.getSound('quack').play();
}
game.update = function () {
duckSpawnTimer++;
- autoShootTimer++;
// Spawn ducks based on difficulty
var spawnRate = Math.max(60 - difficulty * 5, 30);
if (duckSpawnTimer >= spawnRate) {
spawnDuck();
duckSpawnTimer = 0;
}
- // Auto-shoot every 60 ticks (1 second interval)
- if (autoShootTimer >= 60) {
- var bullet = new Bullet();
- bullet.x = crosshair.x;
- bullet.y = crosshair.y - 50;
- bullets.push(bullet);
- game.addChild(bullet);
- LK.getSound('shoot').play();
- autoShootTimer = 0;
- }
// Update and check bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove bullets that go off screen