User prompt
Eğer 10 dan fazla target yaşıyor olursa oyuncu kaybetsin
User prompt
Her roket attigimizda score -1 azalsın her targıt vurdugumuzdada score +6 artsın
User prompt
1sn de 1 roket atabilelim ve targetlar 1.5 saniyede 1 çıksın ve haraket hizlarini arttir
User prompt
Bu targetlar 1sn de 1 spawn olsun ve hizli haraket etsinler
User prompt
Bu targetlar yeni assets olsun
User prompt
Add randomly moving targets so that they explode when hit and give us 5 points, and these targets can collide with each other and the edges
User prompt
Let the missile go faster 30
User prompt
Let the missile go faster
User prompt
let the missile go faster
Code edit (1 edits merged)
Please save this source code
User prompt
Missile Strike
Initial prompt
It will be a rocket launcher in the middle bottom part of the screen and wherever we click on the screen it will send a missile in the direction we clicked
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 30;
self.setTarget = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.velocityX = dx / distance * self.speed;
self.velocityY = dy / distance * self.speed;
}
// Rotate missile to face direction of travel
self.rotation = Math.atan2(dy, dx) + Math.PI / 2;
};
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
};
return self;
});
var RocketLauncher = Container.expand(function () {
var self = Container.call(this);
var launcherBase = self.attachAsset('launcher', {
anchorX: 0.5,
anchorY: 1.0
});
var barrel = self.attachAsset('launcherBarrel', {
anchorX: 0.5,
anchorY: 1.0,
y: -20
});
self.targetAngle = 0;
self.currentAngle = 0;
self.rotationSpeed = 0.15;
self.aimAt = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
self.targetAngle = Math.atan2(dx, dy);
};
self.fire = function (targetX, targetY) {
var missile = new Missile();
missile.x = self.x;
missile.y = self.y - 40;
missile.setTarget(targetX, targetY);
missiles.push(missile);
game.addChild(missile);
LK.getSound('launch').play();
// Add some recoil effect
tween(self, {
scaleX: 1.2,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150,
easing: tween.easeOut
});
}
});
};
self.update = function () {
// Smoothly rotate launcher to target angle
var angleDiff = self.targetAngle - self.currentAngle;
// Handle angle wrapping
if (angleDiff > Math.PI) {
angleDiff -= 2 * Math.PI;
} else if (angleDiff < -Math.PI) {
angleDiff += 2 * Math.PI;
}
self.currentAngle += angleDiff * self.rotationSpeed;
self.rotation = self.currentAngle;
};
return self;
});
var Target = Container.expand(function () {
var self = Container.call(this);
// Create target visual
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
// Random movement properties
self.velocityX = (Math.random() - 0.5) * 16;
self.velocityY = (Math.random() - 0.5) * 16;
self.size = 44; // Half of scaled width for collision detection
// Track last position for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastIntersecting = [];
self.update = function () {
// Store last position
self.lastX = self.x;
self.lastY = self.y;
// Move target
self.x += self.velocityX;
self.y += self.velocityY;
// Bounce off edges
if (self.x <= self.size || self.x >= 2048 - self.size) {
self.velocityX *= -1;
self.x = Math.max(self.size, Math.min(2048 - self.size, self.x));
}
if (self.y <= self.size || self.y >= 2732 - 200 - self.size) {
self.velocityY *= -1;
self.y = Math.max(self.size, Math.min(2732 - 200 - self.size, self.y));
}
};
self.explode = function () {
// Visual explosion effect
LK.effects.flashObject(self, 0xFFFF00, 300);
tween(self, {
scaleX: 2.0,
scaleY: 2.0,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
var missiles = [];
var targets = [];
var launcher = null;
var targetSpawnTimer = 0;
// Initialize rocket launcher
launcher = game.addChild(new RocketLauncher());
launcher.x = 2048 / 2;
launcher.y = 2732 - 100;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Instructions
var instructionsTxt = new Text2('Tap anywhere to fire missiles!', {
size: 48,
fill: 0xCCCCCC
});
instructionsTxt.anchor.set(0.5, 0);
instructionsTxt.y = 100;
LK.gui.top.addChild(instructionsTxt);
// Game tap handler
game.down = function (x, y, obj) {
// Don't fire if tapping on launcher area
if (y > 2732 - 200) {
return;
}
// Aim and fire
launcher.aimAt(x, y);
// Check if enough time has passed since last shot (1 second)
if (!game.lastShotTime) game.lastShotTime = 0;
var currentTime = LK.ticks;
if (currentTime - game.lastShotTime >= 60) {
// 60 ticks = 1 second at 60fps
// Small delay before firing for visual feedback
LK.setTimeout(function () {
launcher.fire(x, y);
// Update score - decrease by 1 for firing
LK.setScore(LK.getScore() - 1);
scoreTxt.setText('Score: ' + LK.getScore());
}, 200);
game.lastShotTime = currentTime;
}
};
game.update = function () {
// Spawn targets periodically
targetSpawnTimer++;
if (targetSpawnTimer >= 90 && targets.length < 8) {
// Spawn every 1.5 seconds, max 8 targets
var target = new Target();
target.x = Math.random() * (2048 - 200) + 100;
target.y = Math.random() * (2732 - 400) + 100;
target.lastX = target.x;
target.lastY = target.y;
target.lastIntersecting = [];
targets.push(target);
game.addChild(target);
targetSpawnTimer = 0;
}
// Update missiles
for (var i = missiles.length - 1; i >= 0; i--) {
var missile = missiles[i];
// Track last position for boundary checking
if (missile.lastX === undefined) missile.lastX = missile.x;
if (missile.lastY === undefined) missile.lastY = missile.y;
if (missile.lastIntersecting === undefined) missile.lastIntersecting = [];
// Check missile-target collisions
var hitTarget = false;
for (var j = targets.length - 1; j >= 0; j--) {
var target = targets[j];
var wasIntersecting = missile.lastIntersecting.indexOf(j) !== -1;
var isIntersecting = missile.intersects(target);
if (!wasIntersecting && isIntersecting) {
// Missile hit target
target.explode();
targets.splice(j, 1);
// Update score
LK.setScore(LK.getScore() + 6);
scoreTxt.setText('Score: ' + LK.getScore());
// Remove missile
missile.destroy();
missiles.splice(i, 1);
hitTarget = true;
break;
}
if (isIntersecting) {
if (missile.lastIntersecting.indexOf(j) === -1) {
missile.lastIntersecting.push(j);
}
}
}
if (hitTarget) continue;
// Check if missile went off screen
var offScreen = missile.x < -50 || missile.x > 2048 + 50 || missile.y < -50 || missile.y > 2732 + 50;
if (offScreen) {
missile.destroy();
missiles.splice(i, 1);
continue;
}
// Update last position
missile.lastX = missile.x;
missile.lastY = missile.y;
}
// Check game over condition - if more than 10 targets are alive
if (targets.length > 10) {
LK.showGameOver();
return;
}
// Update targets and handle target-target collisions
for (var i = targets.length - 1; i >= 0; i--) {
var target1 = targets[i];
if (target1.lastIntersecting === undefined) target1.lastIntersecting = [];
// Check collisions with other targets
for (var j = i + 1; j < targets.length; j++) {
var target2 = targets[j];
var wasIntersecting = target1.lastIntersecting.indexOf(j) !== -1;
var isIntersecting = target1.intersects(target2);
if (!wasIntersecting && isIntersecting) {
// Collision detected - bounce off each other
var dx = target2.x - target1.x;
var dy = target2.y - target1.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
// Normalize collision vector
dx /= distance;
dy /= distance;
// Separate targets
var overlap = target1.size + target2.size - distance;
target1.x -= dx * overlap * 0.5;
target1.y -= dy * overlap * 0.5;
target2.x += dx * overlap * 0.5;
target2.y += dy * overlap * 0.5;
// Exchange velocities (simplified collision response)
var tempVelX = target1.velocityX;
var tempVelY = target1.velocityY;
target1.velocityX = target2.velocityX;
target1.velocityY = target2.velocityY;
target2.velocityX = tempVelX;
target2.velocityY = tempVelY;
}
}
// Update intersection tracking
if (isIntersecting) {
if (target1.lastIntersecting.indexOf(j) === -1) {
target1.lastIntersecting.push(j);
}
} else {
var index = target1.lastIntersecting.indexOf(j);
if (index !== -1) {
target1.lastIntersecting.splice(index, 1);
}
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -255,8 +255,13 @@
// Update last position
missile.lastX = missile.x;
missile.lastY = missile.y;
}
+ // Check game over condition - if more than 10 targets are alive
+ if (targets.length > 10) {
+ LK.showGameOver();
+ return;
+ }
// Update targets and handle target-target collisions
for (var i = targets.length - 1; i >= 0; i--) {
var target1 = targets[i];
if (target1.lastIntersecting === undefined) target1.lastIntersecting = [];
a bird's eye view of a tank . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
missile . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
War plane. In-Game asset. 2d. High contrast. No shadows
Cactus. In-Game asset. 2d. High contrast. No shadows
Bomb. In-Game asset. 2d. High contrast. No shadows