User prompt
mermi kutusu gemiye çaptığında geminin mermi atışları ve mermi hatları 2x arttırsın
User prompt
geminin vurduğu bazı asteroitlerden mermi kutusu çıksın bu kutular vurulduğunda geminin mermi atış hızını ve mermi hızını 2x arttırsın
User prompt
gemiyi, mermileri ve asteroitlerin boyutunu büyüt
User prompt
astroidlerin boyutunu 1.5x büyüt
Code edit (1 edits merged)
Please save this source code
User prompt
Cosmic Defender
Initial prompt
herhangi bir oyun yap
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Asteroid = Container.expand(function () {
var self = Container.call(this);
var asteroidGraphics = self.attachAsset('asteroid', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.rotationSpeed = 0.02;
self.update = function () {
self.y += self.speed;
asteroidGraphics.rotation += self.rotationSpeed;
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -12;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 30;
self.age = 0;
self.update = function () {
self.age++;
explosionGraphics.alpha = 1 - self.age / self.lifetime;
explosionGraphics.scaleX = explosionGraphics.scaleY = 1 + self.age / self.lifetime * 0.5;
};
return self;
});
var Ship = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('ship', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000A1A
});
/****
* Game Code
****/
var ship = new Ship();
var bullets = [];
var asteroids = [];
var explosions = [];
var gameTime = 0;
var asteroidSpawnTimer = 0;
var bulletFireTimer = 0;
var difficultyLevel = 1;
// Initialize ship position
ship.x = 2048 / 2;
ship.y = 2732 - 150;
game.addChild(ship);
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Dragging variables
var dragNode = null;
var dragOffset = 0;
function handleMove(x, y, obj) {
if (dragNode) {
var newX = x + dragOffset;
// Keep ship within screen bounds
newX = Math.max(60, Math.min(2048 - 60, newX));
dragNode.x = newX;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Calculate offset from ship center to touch point
dragOffset = ship.x - x;
dragNode = ship;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
dragOffset = 0;
};
function spawnAsteroid() {
var asteroid = new Asteroid();
asteroid.x = Math.random() * (2048 - 160) + 80;
asteroid.y = -40;
asteroid.speed = 3 + Math.random() * 2 + difficultyLevel * 0.5;
asteroid.rotationSpeed = (Math.random() - 0.5) * 0.1;
asteroids.push(asteroid);
game.addChild(asteroid);
}
function spawnBullet() {
var bullet = new Bullet();
bullet.x = ship.x;
bullet.y = ship.y - 40;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
}
function spawnExplosion(x, y) {
var explosion = new Explosion();
explosion.x = x;
explosion.y = y;
explosions.push(explosion);
game.addChild(explosion);
}
function updateScore() {
scoreTxt.setText('Score: ' + LK.getScore());
}
game.update = function () {
gameTime++;
// Increase difficulty over time
difficultyLevel = Math.floor(gameTime / 1800) + 1;
// Spawn bullets
bulletFireTimer++;
if (bulletFireTimer >= 15) {
spawnBullet();
bulletFireTimer = 0;
}
// Spawn asteroids
asteroidSpawnTimer++;
var spawnRate = Math.max(60 - difficultyLevel * 5, 20);
if (asteroidSpawnTimer >= spawnRate) {
spawnAsteroid();
asteroidSpawnTimer = 0;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.lastY === undefined) bullet.lastY = bullet.y;
// Remove bullets that go off screen
if (bullet.lastY >= -10 && bullet.y < -10) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
bullet.lastY = bullet.y;
}
// Update asteroids
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
if (asteroid.lastY === undefined) asteroid.lastY = asteroid.y;
// Remove asteroids that go off screen
if (asteroid.lastY <= 2732 + 40 && asteroid.y > 2732 + 40) {
asteroid.destroy();
asteroids.splice(i, 1);
continue;
}
// Check collision with ship
if (asteroid.intersects(ship)) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
return;
}
asteroid.lastY = asteroid.y;
}
// Update explosions
for (var i = explosions.length - 1; i >= 0; i--) {
var explosion = explosions[i];
if (explosion.age >= explosion.lifetime) {
explosion.destroy();
explosions.splice(i, 1);
}
}
// Check bullet-asteroid collisions
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
var bulletHit = false;
for (var j = asteroids.length - 1; j >= 0; j--) {
var asteroid = asteroids[j];
if (bullet.intersects(asteroid)) {
// Create explosion
spawnExplosion(asteroid.x, asteroid.y);
// Play sound
LK.getSound('explode').play();
// Update score
LK.setScore(LK.getScore() + 10);
updateScore();
// Remove bullet and asteroid
bullet.destroy();
bullets.splice(i, 1);
asteroid.destroy();
asteroids.splice(j, 1);
bulletHit = true;
break;
}
}
if (bulletHit) break;
}
};
// Initialize score display
updateScore(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,220 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Asteroid = Container.expand(function () {
+ var self = Container.call(this);
+ var asteroidGraphics = self.attachAsset('asteroid', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.rotationSpeed = 0.02;
+ self.update = function () {
+ self.y += self.speed;
+ asteroidGraphics.rotation += self.rotationSpeed;
+ };
+ return self;
+});
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -12;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+var Explosion = Container.expand(function () {
+ var self = Container.call(this);
+ var explosionGraphics = self.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lifetime = 30;
+ self.age = 0;
+ self.update = function () {
+ self.age++;
+ explosionGraphics.alpha = 1 - self.age / self.lifetime;
+ explosionGraphics.scaleX = explosionGraphics.scaleY = 1 + self.age / self.lifetime * 0.5;
+ };
+ return self;
+});
+var Ship = Container.expand(function () {
+ var self = Container.call(this);
+ var shipGraphics = self.attachAsset('ship', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x000A1A
+});
+
+/****
+* Game Code
+****/
+var ship = new Ship();
+var bullets = [];
+var asteroids = [];
+var explosions = [];
+var gameTime = 0;
+var asteroidSpawnTimer = 0;
+var bulletFireTimer = 0;
+var difficultyLevel = 1;
+// Initialize ship position
+ship.x = 2048 / 2;
+ship.y = 2732 - 150;
+game.addChild(ship);
+// Score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Dragging variables
+var dragNode = null;
+var dragOffset = 0;
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ var newX = x + dragOffset;
+ // Keep ship within screen bounds
+ newX = Math.max(60, Math.min(2048 - 60, newX));
+ dragNode.x = newX;
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ // Calculate offset from ship center to touch point
+ dragOffset = ship.x - x;
+ dragNode = ship;
+ handleMove(x, y, obj);
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+ dragOffset = 0;
+};
+function spawnAsteroid() {
+ var asteroid = new Asteroid();
+ asteroid.x = Math.random() * (2048 - 160) + 80;
+ asteroid.y = -40;
+ asteroid.speed = 3 + Math.random() * 2 + difficultyLevel * 0.5;
+ asteroid.rotationSpeed = (Math.random() - 0.5) * 0.1;
+ asteroids.push(asteroid);
+ game.addChild(asteroid);
+}
+function spawnBullet() {
+ var bullet = new Bullet();
+ bullet.x = ship.x;
+ bullet.y = ship.y - 40;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ LK.getSound('shoot').play();
+}
+function spawnExplosion(x, y) {
+ var explosion = new Explosion();
+ explosion.x = x;
+ explosion.y = y;
+ explosions.push(explosion);
+ game.addChild(explosion);
+}
+function updateScore() {
+ scoreTxt.setText('Score: ' + LK.getScore());
+}
+game.update = function () {
+ gameTime++;
+ // Increase difficulty over time
+ difficultyLevel = Math.floor(gameTime / 1800) + 1;
+ // Spawn bullets
+ bulletFireTimer++;
+ if (bulletFireTimer >= 15) {
+ spawnBullet();
+ bulletFireTimer = 0;
+ }
+ // Spawn asteroids
+ asteroidSpawnTimer++;
+ var spawnRate = Math.max(60 - difficultyLevel * 5, 20);
+ if (asteroidSpawnTimer >= spawnRate) {
+ spawnAsteroid();
+ asteroidSpawnTimer = 0;
+ }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ if (bullet.lastY === undefined) bullet.lastY = bullet.y;
+ // Remove bullets that go off screen
+ if (bullet.lastY >= -10 && bullet.y < -10) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ continue;
+ }
+ bullet.lastY = bullet.y;
+ }
+ // Update asteroids
+ for (var i = asteroids.length - 1; i >= 0; i--) {
+ var asteroid = asteroids[i];
+ if (asteroid.lastY === undefined) asteroid.lastY = asteroid.y;
+ // Remove asteroids that go off screen
+ if (asteroid.lastY <= 2732 + 40 && asteroid.y > 2732 + 40) {
+ asteroid.destroy();
+ asteroids.splice(i, 1);
+ continue;
+ }
+ // Check collision with ship
+ if (asteroid.intersects(ship)) {
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ asteroid.lastY = asteroid.y;
+ }
+ // Update explosions
+ for (var i = explosions.length - 1; i >= 0; i--) {
+ var explosion = explosions[i];
+ if (explosion.age >= explosion.lifetime) {
+ explosion.destroy();
+ explosions.splice(i, 1);
+ }
+ }
+ // Check bullet-asteroid collisions
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ var bulletHit = false;
+ for (var j = asteroids.length - 1; j >= 0; j--) {
+ var asteroid = asteroids[j];
+ if (bullet.intersects(asteroid)) {
+ // Create explosion
+ spawnExplosion(asteroid.x, asteroid.y);
+ // Play sound
+ LK.getSound('explode').play();
+ // Update score
+ LK.setScore(LK.getScore() + 10);
+ updateScore();
+ // Remove bullet and asteroid
+ bullet.destroy();
+ bullets.splice(i, 1);
+ asteroid.destroy();
+ asteroids.splice(j, 1);
+ bulletHit = true;
+ break;
+ }
+ }
+ if (bulletHit) break;
+ }
+};
+// Initialize score display
+updateScore();
\ No newline at end of file