User prompt
Bu 3 lü atışı bir ödül sonucu ver normal atış tekli ve dikey yönlü olsun
User prompt
Oyuncunun atışını 3 lü ve etrafa yayılan şekilde yap
User prompt
Oyuncuya 3 can hakkı ver
User prompt
Düşmanların hızını azalt
Code edit (1 edits merged)
Please save this source code
User prompt
Space Impact: Uzay Savaşı
Initial prompt
Space impact tarzı oyun yapmak istiyorum
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Enemy Class var Enemy = Container.expand(function () { var self = Container.call(this); var enemy = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.width = enemy.width; self.height = enemy.height; self.speed = 3 + Math.random() * 2; // Downwards, slower and less random self.type = 0; // 0: normal, 1: zigzag, 2: shooter self.dir = Math.random() < 0.5 ? -1 : 1; // for zigzag self.shootCooldown = 0; self.update = function () { if (self.type === 1) { // Zigzag self.x += self.dir * 12 * Math.sin(LK.ticks / 20 + self._zigzagSeed); } self.y += self.speed; // Shooter if (self.type === 2) { self.shootCooldown--; if (self.shootCooldown <= 0) { self.shootCooldown = 90 + Math.floor(Math.random() * 60); spawnEnemyBullet(self.x, self.y + self.height / 2); } } }; // For zigzag self._zigzagSeed = Math.random() * 1000; // Flash on hit self.flash = function () { tween(enemy, { tint: 0xffffff }, { duration: 80, onFinish: function onFinish() { tween(enemy, { tint: 0xff3333 }, { duration: 120 }); } }); }; enemy.tint = 0xff3333; return self; }); // Enemy Bullet Class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bullet = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 18; // Downwards self.update = function () { self.y += self.speed; }; return self; }); // Hero Bullet Class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bullet = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -32; // Upwards self.update = function () { self.y += self.speed; }; return self; }); // Hero Ship Class var HeroShip = Container.expand(function () { var self = Container.call(this); // Attach ship asset (box, blue) var ship = self.attachAsset('heroShip', { anchorX: 0.5, anchorY: 0.5 }); // Ship properties self.width = ship.width; self.height = ship.height; self.cooldown = 0; // fire cooldown // Ship hit flash self.flash = function () { tween(ship, { tint: 0xff0000 }, { duration: 100, onFinish: function onFinish() { tween(ship, { tint: 0x3399ff }, { duration: 200 }); } }); }; // Ship reset color ship.tint = 0x3399ff; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000010 }); /**** * Game Code ****/ // Score text // Asset definitions (shapes) var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game variables var hero = null; var heroBullets = []; var enemies = []; var enemyBullets = []; var dragNode = null; var lastHeroX = 0; var lastHeroY = 0; var spawnTimer = 0; var wave = 1; var nextWaveScore = 10; var gameOver = false; // Player lives var heroLives = 3; var livesTxt = new Text2('♥♥♥', { size: 100, fill: 0xFF4444 }); livesTxt.anchor.set(0.5, 0); LK.gui.top.addChild(livesTxt); livesTxt.x = 2048 / 2 - 400; livesTxt.y = 0; // Helper: spawn hero bullet function spawnHeroBullet(x, y) { var b = new HeroBullet(); b.x = x; b.y = y - hero.height / 2; heroBullets.push(b); game.addChild(b); } // Helper: spawn enemy bullet function spawnEnemyBullet(x, y) { var b = new EnemyBullet(); b.x = x; b.y = y; enemyBullets.push(b); game.addChild(b); } // Helper: spawn enemy function spawnEnemy(type, x, y) { var e = new Enemy(); e.x = x; e.y = y; e.type = type; if (type === 2) { e.shootCooldown = 60 + Math.floor(Math.random() * 60); } enemies.push(e); game.addChild(e); } // Helper: spawn wave function spawnWave(waveNum) { var count = 3 + waveNum; var spacing = 2048 / (count + 1); for (var i = 0; i < count; i++) { var type = 0; if (waveNum >= 2 && i % 3 === 0) type = 1; // zigzag if (waveNum >= 3 && i % 4 === 0) type = 2; // shooter spawnEnemy(type, spacing * (i + 1), -150 - Math.random() * 200); } } // Reset game state function resetGame() { // Remove all for (var i = 0; i < heroBullets.length; i++) heroBullets[i].destroy(); for (var i = 0; i < enemies.length; i++) enemies[i].destroy(); for (var i = 0; i < enemyBullets.length; i++) enemyBullets[i].destroy(); heroBullets = []; enemies = []; enemyBullets = []; wave = 1; nextWaveScore = 10; LK.setScore(0); scoreTxt.setText('0'); gameOver = false; // Reset lives heroLives = 3; livesTxt.setText('♥'.repeat(heroLives)); // Hero if (hero) hero.destroy(); hero = new HeroShip(); hero.x = 2048 / 2; hero.y = 2732 - 220; game.addChild(hero); // First wave spawnWave(wave); } // Drag/move handler function handleMove(x, y, obj) { if (dragNode && !gameOver) { // Clamp inside screen var minX = hero.width / 2; var maxX = 2048 - hero.width / 2; dragNode.x = Math.max(minX, Math.min(maxX, x)); // Y is fixed (bottom) dragNode.y = hero.y; } } // Touch/drag events game.down = function (x, y, obj) { if (gameOver) return; // Only allow drag if touch is on hero var local = hero.toLocal(game.toGlobal({ x: x, y: y })); if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) { dragNode = hero; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragNode = null; }; game.move = handleMove; // Main update loop game.update = function () { if (gameOver) return; // Hero fire if (hero.cooldown > 0) hero.cooldown--; if (hero.cooldown <= 0) { spawnHeroBullet(hero.x, hero.y - hero.height / 2); hero.cooldown = 18; } // Update hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { var b = heroBullets[i]; b.update(); // Off screen if (b.y < -80) { b.destroy(); heroBullets.splice(i, 1); continue; } // Hit enemy var hit = false; for (var j = enemies.length - 1; j >= 0; j--) { var e = enemies[j]; if (b.intersects(e)) { e.flash(); b.destroy(); heroBullets.splice(i, 1); enemies.splice(j, 1); e.destroy(); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); hit = true; break; } } if (hit) continue; } // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { var e = enemies[i]; e.update(); // Off screen if (e.y > 2732 + 100) { e.destroy(); enemies.splice(i, 1); continue; } // Collide with hero if (e.intersects(hero)) { hero.flash(); LK.effects.flashScreen(0xff0000, 1000); heroLives--; livesTxt.setText('♥'.repeat(heroLives)); if (heroLives <= 0) { gameOver = true; LK.showGameOver(); return; } else { // Remove enemy and continue e.destroy(); enemies.splice(i, 1); continue; } } } // Update enemy bullets for (var i = enemyBullets.length - 1; i >= 0; i--) { var b = enemyBullets[i]; b.update(); // Off screen if (b.y > 2732 + 80) { b.destroy(); enemyBullets.splice(i, 1); continue; } // Hit hero if (b.intersects(hero)) { hero.flash(); b.destroy(); enemyBullets.splice(i, 1); LK.effects.flashScreen(0xff0000, 1000); heroLives--; livesTxt.setText('♥'.repeat(heroLives)); if (heroLives <= 0) { gameOver = true; LK.showGameOver(); return; } } } // Spawn new wave if all enemies gone if (enemies.length === 0) { wave++; spawnWave(wave); } // Next wave at score milestones if (LK.getScore() >= nextWaveScore) { wave++; nextWaveScore += 10 + wave * 2; spawnWave(wave); } }; // Start game resetGame();
===================================================================
--- original.js
+++ change.js
@@ -141,8 +141,18 @@
var spawnTimer = 0;
var wave = 1;
var nextWaveScore = 10;
var gameOver = false;
+// Player lives
+var heroLives = 3;
+var livesTxt = new Text2('♥♥♥', {
+ size: 100,
+ fill: 0xFF4444
+});
+livesTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(livesTxt);
+livesTxt.x = 2048 / 2 - 400;
+livesTxt.y = 0;
// Helper: spawn hero bullet
function spawnHeroBullet(x, y) {
var b = new HeroBullet();
b.x = x;
@@ -194,8 +204,11 @@
nextWaveScore = 10;
LK.setScore(0);
scoreTxt.setText('0');
gameOver = false;
+ // Reset lives
+ heroLives = 3;
+ livesTxt.setText('♥'.repeat(heroLives));
// Hero
if (hero) hero.destroy();
hero = new HeroShip();
hero.x = 2048 / 2;
@@ -282,11 +295,20 @@
// Collide with hero
if (e.intersects(hero)) {
hero.flash();
LK.effects.flashScreen(0xff0000, 1000);
- gameOver = true;
- LK.showGameOver();
- return;
+ heroLives--;
+ livesTxt.setText('♥'.repeat(heroLives));
+ if (heroLives <= 0) {
+ gameOver = true;
+ LK.showGameOver();
+ return;
+ } else {
+ // Remove enemy and continue
+ e.destroy();
+ enemies.splice(i, 1);
+ continue;
+ }
}
}
// Update enemy bullets
for (var i = enemyBullets.length - 1; i >= 0; i--) {
@@ -303,11 +325,15 @@
hero.flash();
b.destroy();
enemyBullets.splice(i, 1);
LK.effects.flashScreen(0xff0000, 1000);
- gameOver = true;
- LK.showGameOver();
- return;
+ heroLives--;
+ livesTxt.setText('♥'.repeat(heroLives));
+ if (heroLives <= 0) {
+ gameOver = true;
+ LK.showGameOver();
+ return;
+ }
}
}
// Spawn new wave if all enemies gone
if (enemies.length === 0) {