User prompt
make a gun upgrade that allows you to shoot 2 bullets at once
User prompt
make a boss spawn after 50 targets are destroyed
User prompt
make it that when the targets make it to the bottom of the screen you die
User prompt
make the targets take 2 bullets to be destroyed
User prompt
make it spawn targets every second
Code edit (14 edits merged)
Please save this source code
User prompt
make the game spawn more targets
User prompt
make it spawn more targets rapidly
Initial prompt
Please save this source code
/**** * Classes ****/ // Assets will be automatically created and loaded by the LK engine based on usage in the game code. // Player's Bullet var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y -= self.speed; if (self.y < 0) { self.destroy(); } }; }); // Target var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); self.hitPoints = 2; // Add hitPoints property self.update = function () { if (LK.ticks % 60 == 0) { self.y += 80; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Initialize game with a black background }); /**** * Game Code ****/ var bullets = []; var targets = []; var score = 0; // Create a target at a random position function spawnTarget() { var target = new Target(); target.x = Math.random() * 2048; target.y = 0; game.addChild(target); targets.push(target); } // Check for bullet collisions with targets function checkCollisions() { bullets.forEach(function (bullet, bulletIndex) { targets.forEach(function (target, targetIndex) { if (bullet.intersects(target)) { bullet.destroy(); bullets.splice(bulletIndex, 1); target.hitPoints -= 1; // Decrease target's hitPoints if (target.hitPoints <= 0) { target.destroy(); targets.splice(targetIndex, 1); score += 1; } LK.effects.flashObject(target, 0xff0000, 500); // Flash target red on hit } }); }); } // Shoot a bullet from the bottom center of the screen function shoot(x, y) { var bullet = new Bullet(); bullet.x = x; bullet.y = 2732; // Start from the bottom of the screen game.addChild(bullet); bullets.push(bullet); } // Game update function game.update = function () { if (LK.ticks % 30 == 0) { // Spawn a target every second spawnTarget(); } checkCollisions(); targets.forEach(function (target, targetIndex) { if (target.y >= 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); }; // Touch event to shoot game.down = function (x, y, obj) { shoot(x, y); }; // Initialize a few targets for (var i = 10; i < 10; i++) { spawnTarget(); }
===================================================================
--- original.js
+++ change.js
@@ -85,8 +85,14 @@
// Spawn a target every second
spawnTarget();
}
checkCollisions();
+ targets.forEach(function (target, targetIndex) {
+ if (target.y >= 2732) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ });
};
// Touch event to shoot
game.down = function (x, y, obj) {
shoot(x, y);