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.angle = 0; // Default straight up, can be set externally
	self.update = function () {
		// Move in direction of angle (angle 0 = straight up)
		self.x += Math.sin(self.angle) * Math.abs(self.speed);
		self.y += Math.cos(self.angle) * 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;
// Spread shot power-up state
var spreadShotActive = false;
var spreadShotTimer = 0;
// 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;
// Helper: spawn hero bullet
function spawnHeroBullet(x, y, angle) {
	var b = new HeroBullet();
	b.x = x;
	b.y = y - hero.height / 2;
	// If angle is provided, set it for spread, otherwise 0 (straight up)
	b.angle = angle || 0;
	heroBullets.push(b);
	game.addChild(b);
}
// Helper: activate spread shot power-up for a duration (in frames)
function activateSpreadShot(duration) {
	spreadShotActive = true;
	spreadShotTimer = duration;
}
// 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));
	// Reset spread shot
	spreadShotActive = false;
	spreadShotTimer = 0;
	// 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) {
		if (spreadShotActive) {
			// 3-way spread: center, left, right
			var spreadAngle = 18 * Math.PI / 180; // 18 degrees in radians
			// Center bullet (straight up)
			spawnHeroBullet(hero.x, hero.y - hero.height / 2, 0);
			// Left bullet (slightly left)
			spawnHeroBullet(hero.x, hero.y - hero.height / 2, -spreadAngle);
			// Right bullet (slightly right)
			spawnHeroBullet(hero.x, hero.y - hero.height / 2, spreadAngle);
		} else {
			// Single straight bullet
			spawnHeroBullet(hero.x, hero.y - hero.height / 2, 0);
		}
		hero.cooldown = 18;
	}
	// Spread shot timer countdown
	if (spreadShotActive) {
		spreadShotTimer--;
		if (spreadShotTimer <= 0) {
			spreadShotActive = false;
		}
	}
	// 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);
	}
	// Reward: Activate spread shot for 6 seconds (360 frames) when score is a multiple of 20 (but not at 0)
	if (LK.getScore() > 0 && LK.getScore() % 20 === 0 && !spreadShotActive) {
		activateSpreadShot(360);
	}
};
// Start game
resetGame(); ===================================================================
--- original.js
+++ change.js
@@ -144,8 +144,11 @@
 var spawnTimer = 0;
 var wave = 1;
 var nextWaveScore = 10;
 var gameOver = false;
+// Spread shot power-up state
+var spreadShotActive = false;
+var spreadShotTimer = 0;
 // Player lives
 var heroLives = 3;
 var livesTxt = new Text2('♥♥♥', {
 	size: 100,
@@ -153,9 +156,8 @@
 });
 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, angle) {
 	var b = new HeroBullet();
 	b.x = x;
@@ -164,8 +166,13 @@
 	b.angle = angle || 0;
 	heroBullets.push(b);
 	game.addChild(b);
 }
+// Helper: activate spread shot power-up for a duration (in frames)
+function activateSpreadShot(duration) {
+	spreadShotActive = true;
+	spreadShotTimer = duration;
+}
 // Helper: spawn enemy bullet
 function spawnEnemyBullet(x, y) {
 	var b = new EnemyBullet();
 	b.x = x;
@@ -212,8 +219,11 @@
 	gameOver = false;
 	// Reset lives
 	heroLives = 3;
 	livesTxt.setText('♥'.repeat(heroLives));
+	// Reset spread shot
+	spreadShotActive = false;
+	spreadShotTimer = 0;
 	// Hero
 	if (hero) hero.destroy();
 	hero = new HeroShip();
 	hero.x = 2048 / 2;
@@ -255,18 +265,30 @@
 	if (gameOver) return;
 	// Hero fire
 	if (hero.cooldown > 0) hero.cooldown--;
 	if (hero.cooldown <= 0) {
-		// 3-way spread: center, left, right
-		var spreadAngle = 18 * Math.PI / 180; // 18 degrees in radians
-		// Center bullet (straight up)
-		spawnHeroBullet(hero.x, hero.y - hero.height / 2, 0);
-		// Left bullet (slightly left)
-		spawnHeroBullet(hero.x, hero.y - hero.height / 2, -spreadAngle);
-		// Right bullet (slightly right)
-		spawnHeroBullet(hero.x, hero.y - hero.height / 2, spreadAngle);
+		if (spreadShotActive) {
+			// 3-way spread: center, left, right
+			var spreadAngle = 18 * Math.PI / 180; // 18 degrees in radians
+			// Center bullet (straight up)
+			spawnHeroBullet(hero.x, hero.y - hero.height / 2, 0);
+			// Left bullet (slightly left)
+			spawnHeroBullet(hero.x, hero.y - hero.height / 2, -spreadAngle);
+			// Right bullet (slightly right)
+			spawnHeroBullet(hero.x, hero.y - hero.height / 2, spreadAngle);
+		} else {
+			// Single straight bullet
+			spawnHeroBullet(hero.x, hero.y - hero.height / 2, 0);
+		}
 		hero.cooldown = 18;
 	}
+	// Spread shot timer countdown
+	if (spreadShotActive) {
+		spreadShotTimer--;
+		if (spreadShotTimer <= 0) {
+			spreadShotActive = false;
+		}
+	}
 	// Update hero bullets
 	for (var i = heroBullets.length - 1; i >= 0; i--) {
 		var b = heroBullets[i];
 		b.update();
@@ -357,7 +379,11 @@
 		wave++;
 		nextWaveScore += 10 + wave * 2;
 		spawnWave(wave);
 	}
+	// Reward: Activate spread shot for 6 seconds (360 frames) when score is a multiple of 20 (but not at 0)
+	if (LK.getScore() > 0 && LK.getScore() % 20 === 0 && !spreadShotActive) {
+		activateSpreadShot(360);
+	}
 };
 // Start game
 resetGame();
\ No newline at end of file