User prompt
turret otomatik ateş etsin biz döndürelim
User prompt
turret bir dikeyi hedef almasın. tıkladığım yöne ateş etsin
User prompt
turret olmasın tıklayarak yok edelim
User prompt
turret döndürülebilsin
User prompt
Compilation error[L14]: Plugins failed to load.
Code edit (1 edits merged)
Please save this source code
User prompt
Meteor Defender: Save the Earth
Initial prompt
Dünyayı Meteorlardan kurtardığımız bir oyun yap. (İngilizce)
/**** * Classes ****/ // Meteor class: Falling enemy var Meteor = Container.expand(function () { var self = Container.call(this); var meteor = self.attachAsset('meteor', { anchorX: 0.5, anchorY: 0.5 }); // Randomize speed and rotation self.speed = 12 + Math.random() * meteorSpeedBoost; self.rotationSpeed = (Math.random() - 0.5) * 0.08; // For intersection tracking self.lastIntersecting = false; self.update = function () { self.y += self.speed; self.rotation += self.rotationSpeed; }; return self; }); /**** * Initialize Game ****/ // No projectile or turret classes needed var game = new LK.Game({ backgroundColor: 0x0a2233 }); /**** * Game Code ****/ // Sound effects // Explosion effect (for future use) // Earth: Ground at the bottom // Meteor: Falling enemy // Projectile: Player's bullet // Turret: Defense cannon at the bottom // Game variables // No turret or projectiles needed var meteors = []; var earth; var scoreTxt; var livesTxt; var dragNode = null; var lastTouchX = 0; var lives = 5; var score = 0; var meteorSpawnInterval = 60; // frames var meteorSpeedBoost = 0; // increases as game progresses var meteorTimer = 0; // Add earth at the bottom earth = LK.getAsset('earth', { anchorX: 0.5, anchorY: 1, x: 2048 / 2, y: 2732 }); game.addChild(earth); // Score text (top center) scoreTxt = new Text2('Score: 0', { size: 100, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Lives text (top right, avoid top left 100x100) livesTxt = new Text2('Lives: 5', { size: 80, fill: 0xFFB300 }); livesTxt.anchor.set(1, 0); LK.gui.topRight.addChild(livesTxt); // Tap to destroy meteors game.tap = function (x, y, obj) { var local = game.toLocal({ x: x, y: y }); // Check for meteors under tap, from topmost to bottom for (var i = meteors.length - 1; i >= 0; i--) { var m = meteors[i]; // Use bounding box for tap detection var dx = local.x - m.x; var dy = local.y - m.y; var r = 60; // meteor radius (half of 120) if (dx * dx + dy * dy <= r * r) { // Hit! LK.getSound('hit').play(); m.destroy(); meteors.splice(i, 1); score += 1; scoreTxt.setText('Score: ' + score); // Optional: explosion effect var explosion = LK.getAsset('explosion', { anchorX: 0.5, anchorY: 0.5, x: m.x, y: m.y }); game.addChild(explosion); (function (exp) { LK.setTimeout(function () { exp.destroy(); }, 350); })(explosion); break; } } }; // Main update loop game.update = function () { // Spawn meteors meteorTimer++; var spawnRate = Math.max(18, meteorSpawnInterval - Math.floor(score / 10) * 4); if (meteorTimer >= spawnRate) { meteorTimer = 0; var m = new Meteor(); // Random X, avoid edges m.x = 120 + Math.random() * (2048 - 240); m.y = -80; meteors.push(m); game.addChild(m); } // Increase difficulty meteorSpeedBoost = Math.min(18, Math.floor(score / 8) * 2); // No projectile logic needed // Update meteors for (var k = meteors.length - 1; k >= 0; k--) { var mtr = meteors[k]; mtr.update(); // If meteor hits earth if (mtr.y + 60 >= earth.y - earth.height / 2) { LK.getSound('lose').play(); mtr.destroy(); meteors.splice(k, 1); lives -= 1; livesTxt.setText('Lives: ' + lives); // Flash screen LK.effects.flashScreen(0xff0000, 400); if (lives <= 0) { LK.showGameOver(); return; } } } };
===================================================================
--- original.js
+++ change.js
@@ -18,78 +18,13 @@
self.rotation += self.rotationSpeed;
};
return self;
});
-// Projectile class: Player's bullet
-var Projectile = Container.expand(function () {
- var self = Container.call(this);
- var proj = self.attachAsset('projectile', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.speed = -38; // Upwards
- self.update = function () {
- // Move in the direction of the turret's angle if set, otherwise straight up
- if (typeof self.angle === "number") {
- self.x += Math.sin(self.angle) * Math.abs(self.speed);
- self.y -= Math.cos(self.angle) * Math.abs(self.speed);
- } else {
- self.y += self.speed;
- }
- };
- return self;
-});
-// Turret class: Player's cannon at the bottom
-var Turret = Container.expand(function () {
- var self = Container.call(this);
- // Barrel
- var barrel = self.attachAsset('turretBarrel', {
- anchorX: 0.5,
- anchorY: 1,
- x: 0,
- y: 0
- });
- // Base
- var base = self.attachAsset('turretBase', {
- anchorX: 0.5,
- anchorY: 0,
- x: 0,
- y: 0
- });
- // For drag offset
- self.dragOffsetX = 0;
- // For firing cooldown
- self.canShoot = true;
- // Turret rotation (in radians)
- self.turretAngle = 0;
- // Set turret rotation (in radians)
- self.setTurretAngle = function (angle) {
- self.turretAngle = angle;
- barrel.rotation = angle;
- };
- // Fire projectile
- self.shoot = function () {
- if (!self.canShoot) return;
- self.canShoot = false;
- // Cooldown (fast)
- LK.setTimeout(function () {
- self.canShoot = true;
- }, 180);
- var proj = new Projectile();
- // Set projectile spawn position and direction based on turret angle
- proj.x = self.x + Math.sin(self.turretAngle) * (barrel.height - 40);
- proj.y = self.y - Math.cos(self.turretAngle) * (barrel.height - 40);
- proj.angle = self.turretAngle;
- projectiles.push(proj);
- game.addChild(proj);
- LK.getSound('shoot').play();
- };
- return self;
-});
/****
* Initialize Game
****/
+// No projectile or turret classes needed
var game = new LK.Game({
backgroundColor: 0x0a2233
});
@@ -102,10 +37,9 @@
// Meteor: Falling enemy
// Projectile: Player's bullet
// Turret: Defense cannon at the bottom
// Game variables
-var turret;
-var projectiles = [];
+// No turret or projectiles needed
var meteors = [];
var earth;
var scoreTxt;
var livesTxt;
@@ -123,13 +57,8 @@
x: 2048 / 2,
y: 2732
});
game.addChild(earth);
-// Add turret
-turret = new Turret();
-turret.x = 2048 / 2;
-turret.y = 2732 - earth.height + 20;
-game.addChild(turret);
// Score text (top center)
scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#fff"
@@ -142,81 +71,45 @@
fill: 0xFFB300
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
-// Handle dragging turret horizontally or rotating barrel
-var isRotatingTurret = false;
-var rotateStartY = 0;
-var rotateStartAngle = 0;
-game.down = function (x, y, obj) {
- // Only allow drag if touch is on or near the turret
+// Tap to destroy meteors
+game.tap = function (x, y, obj) {
var local = game.toLocal({
x: x,
y: y
});
- // If touch is near the barrel, allow rotation
- var barrelTopY = turret.y - 100;
- var barrelBottomY = turret.y + 20;
- var barrelLeftX = turret.x - 60;
- var barrelRightX = turret.x + 60;
- if (local.y > barrelTopY && local.y < barrelBottomY && local.x > barrelLeftX && local.x < barrelRightX) {
- isRotatingTurret = true;
- rotateStartY = local.y;
- rotateStartAngle = turret.turretAngle;
- dragNode = null;
- return;
+ // Check for meteors under tap, from topmost to bottom
+ for (var i = meteors.length - 1; i >= 0; i--) {
+ var m = meteors[i];
+ // Use bounding box for tap detection
+ var dx = local.x - m.x;
+ var dy = local.y - m.y;
+ var r = 60; // meteor radius (half of 120)
+ if (dx * dx + dy * dy <= r * r) {
+ // Hit!
+ LK.getSound('hit').play();
+ m.destroy();
+ meteors.splice(i, 1);
+ score += 1;
+ scoreTxt.setText('Score: ' + score);
+ // Optional: explosion effect
+ var explosion = LK.getAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: m.x,
+ y: m.y
+ });
+ game.addChild(explosion);
+ (function (exp) {
+ LK.setTimeout(function () {
+ exp.destroy();
+ }, 350);
+ })(explosion);
+ break;
+ }
}
- // Otherwise, allow horizontal drag
- if (local.y > turret.y - 120 && local.y < turret.y + 80 && local.x > turret.x - 180 && local.x < turret.x + 180) {
- dragNode = turret;
- dragNode.dragOffsetX = local.x - turret.x;
- lastTouchX = local.x;
- }
};
-game.move = function (x, y, obj) {
- var local = game.toLocal({
- x: x,
- y: y
- });
- if (isRotatingTurret) {
- // Calculate angle based on vertical drag
- var dy = rotateStartY - local.y;
- // Clamp angle between -60deg and +60deg (in radians)
- var maxAngle = Math.PI / 3;
- var minAngle = -Math.PI / 3;
- var newAngle = rotateStartAngle + dy * 0.012;
- if (newAngle > maxAngle) newAngle = maxAngle;
- if (newAngle < minAngle) newAngle = minAngle;
- turret.setTurretAngle(newAngle);
- return;
- }
- if (dragNode) {
- var newX = local.x - dragNode.dragOffsetX;
- // Clamp within screen
- var minX = 110 + 60; // avoid left edge
- var maxX = 2048 - 60;
- dragNode.x = Math.max(minX, Math.min(maxX, newX));
- lastTouchX = local.x;
- }
-};
-game.up = function (x, y, obj) {
- dragNode = null;
- isRotatingTurret = false;
-};
-// Tap to shoot (anywhere on screen)
-game.tap = function (x, y, obj) {
- turret.shoot();
-};
-// For touch devices, treat 'down' as tap if not dragging
-game.down = function (origDown) {
- return function (x, y, obj) {
- origDown(x, y, obj);
- // If not dragging, treat as tap
- if (!dragNode) {
- turret.shoot();
- }
- };
-}(game.down);
// Main update loop
game.update = function () {
// Spawn meteors
meteorTimer++;
@@ -231,34 +124,9 @@
game.addChild(m);
}
// Increase difficulty
meteorSpeedBoost = Math.min(18, Math.floor(score / 8) * 2);
- // Update projectiles
- for (var i = projectiles.length - 1; i >= 0; i--) {
- var p = projectiles[i];
- p.update();
- // Remove if off screen
- if (p.y < -100) {
- p.destroy();
- projectiles.splice(i, 1);
- continue;
- }
- // Check collision with meteors
- for (var j = meteors.length - 1; j >= 0; j--) {
- var m = meteors[j];
- if (p.intersects(m)) {
- // Destroy both
- LK.getSound('hit').play();
- p.destroy();
- m.destroy();
- projectiles.splice(i, 1);
- meteors.splice(j, 1);
- score += 1;
- scoreTxt.setText('Score: ' + score);
- break;
- }
- }
- }
+ // No projectile logic needed
// Update meteors
for (var k = meteors.length - 1; k >= 0; k--) {
var mtr = meteors[k];
mtr.update();
meteor . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
dünya yüzeyi. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
blue meteor. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
green meteorite. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
spaceship. In-Game asset. 2d. High contrast. No shadows
spaceship debris. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
laser projectile. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
space with only stars. In-Game asset. real. High contrast. with shadows. high resolution
dünyanın bir bölümünün yüzeyi. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
alien. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
golden dolar symbol. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
yellow meteor. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
game heart. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
shield. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
red meteor with x2 write. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat