User prompt
Show lives
User prompt
My game is lagging fix lagging
User prompt
Give player three lives
User prompt
Decrease player firing rate
User prompt
Fix the game
User prompt
Make bots fire
User prompt
Make a scorecard
User prompt
Make bullets autofire
User prompt
Make bots move
User prompt
Fix the game
Initial prompt
Shooter
/**** * Classes ****/ // Bot class var Bot = Container.expand(function () { var self = Container.call(this); var botGraphics = self.attachAsset('bot', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; // Bot firing logic if (LK.ticks % 60 == 0) { // Adjust the firing rate by changing the modulus value var botBullet = new BotBullet(); botBullet.x = self.x; botBullet.y = self.y; game.addChild(botBullet); botBullets.push(botBullet); } }; }); // BotBullet class var BotBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; }; }); // Bullet class 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; }; }); // The assets will be automatically created and loaded by the LK engine // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player movement logic goes here }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 100; // Initialize score display var score = 0; var scoreTxt = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize bots and bullets var bots = []; var bullets = []; var botBullets = []; // Game update function game.update = function () { // Update player player.update(); // Update bots for (var i = 0; i < bots.length; i++) { bots[i].update(); } // Update bullets for (var i = 0; i < bullets.length; i++) { bullets[i].update(); } // Update bot bullets for (var i = botBullets.length - 1; i >= 0; i--) { botBullets[i].update(); // Check collision with player if (botBullets[i].intersects(player)) { // Handle player hit by bot bullet LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); botBullets[i].destroy(); botBullets.splice(i, 1); } } // Autofire bullets if (LK.ticks % 15 == 0) { // Adjust the firing rate by changing the modulus value var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); } // Collision detection for (var i = bots.length - 1; i >= 0; i--) { for (var j = bullets.length - 1; j >= 0; j--) { if (bots[i].intersects(bullets[j])) { bots[i].destroy(); bullets[j].destroy(); bots.splice(i, 1); bullets.splice(j, 1); // Update score score += 10; scoreTxt.setText('Score: ' + score); break; } } } // Spawn bots if (LK.ticks % 120 == 0) { var bot = new Bot(); bot.x = Math.random() * 2048; bot.y = 0; bots.push(bot); game.addChild(bot); } }; // Player control game.down = function (x, y, obj) { player.x = x; player.y = y; }; game.move = function (x, y, obj) { player.x = x; player.y = y; }; game.up = function (x, y, obj) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); };
===================================================================
--- original.js
+++ change.js
@@ -10,10 +10,31 @@
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
+ // Bot firing logic
+ if (LK.ticks % 60 == 0) {
+ // Adjust the firing rate by changing the modulus value
+ var botBullet = new BotBullet();
+ botBullet.x = self.x;
+ botBullet.y = self.y;
+ game.addChild(botBullet);
+ botBullets.push(botBullet);
+ }
};
});
+// BotBullet class
+var BotBullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ };
+});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
@@ -63,8 +84,9 @@
LK.gui.top.addChild(scoreTxt);
// Initialize bots and bullets
var bots = [];
var bullets = [];
+var botBullets = [];
// Game update function
game.update = function () {
// Update player
player.update();
@@ -75,8 +97,20 @@
// Update bullets
for (var i = 0; i < bullets.length; i++) {
bullets[i].update();
}
+ // Update bot bullets
+ for (var i = botBullets.length - 1; i >= 0; i--) {
+ botBullets[i].update();
+ // Check collision with player
+ if (botBullets[i].intersects(player)) {
+ // Handle player hit by bot bullet
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ botBullets[i].destroy();
+ botBullets.splice(i, 1);
+ }
+ }
// Autofire bullets
if (LK.ticks % 15 == 0) {
// Adjust the firing rate by changing the modulus value
var bullet = new Bullet();