User prompt
The shoot button isn't working
User prompt
The gun is not shooting
User prompt
If press red button shoot the ammo
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'split')' in or related to this line: 'var currentAmmo = parseInt(ammoTxt.text.split(': ')[1]);' Line Number: 295
User prompt
If herosbullet touches the imaginary text the subtract 1 ammo from the ammo text
User prompt
Create an invisible text displaying ____________________________________________________________________________ just above the gun
User prompt
Make it so that even if bullet is not on the target remove one ammo/bullet
User prompt
Move the ammo left side
User prompt
Shift the ammo text on the left side
User prompt
Display ammo left in the gun on upper left corner
User prompt
Reduce the shooting speed of the gun 1 bullet per sec
User prompt
Undo this and add shoot button
User prompt
Remove shoot button and add aim to shoot instead
User prompt
Bullet size smaller
User prompt
Make it so that if the bullet Touches the gun then say game over
User prompt
The enemybullet should remain in top part but should be visible to the player and the bulletonmy should becomes twice it size along with shooting lasers
User prompt
Change enemy spawn time to 40 sec left in the time r
User prompt
Now in 20secs in the timer enemy bullet comes to the frame and stays in the upper most par shooting
User prompt
Now remove the boss mechanism but keep the assest
User prompt
Change the name of the enemy assets as bulletonmy
User prompt
At 40 sec in the timer spawn enemy bullet who is a boss and stays in the top part only and play like the player or hero
Code edit (1 edits merged)
Please save this source code
User prompt
Reduce ammo to 5
Code edit (1 edits merged)
Please save this source code
User prompt
Create a sprite sheet for me in this shooting game the theme is sci-fi space
/**** * Classes ****/ // BossEnemy class var BossEnemy = Container.expand(function () { var self = Container.call(this); var bossGraphics = self.attachAsset('bulletonmy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0; self.update = function () { // Boss stays at the top part of the screen self.y = Math.min(self.y + self.speed, 100); }; self.shoot = function () { var laser = new EnemyBullet(); laser.x = self.x; laser.y = self.y; game.addChild(laser); enemyBullets.push(laser); }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('bulletonmy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Update logic for hero }; self.shoot = function () { if (heroBullets.length < 5 && !self.reloading) { self.reloading = true; var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); heroBullets.push(bullet); ammoTxt.setText('Ammo: ' + (6 - heroBullets.length)); LK.setTimeout(function () { self.reloading = false; }, 1000); } else if (!self.reloading) { self.reloading = true; var reloadText = new Text2('Reloading...', { size: 50, fill: "#ffffff" }); reloadText.anchor.set(0.5, 0.5); reloadText.x = self.x; reloadText.y = self.y - 100; game.addChild(reloadText); LK.setTimeout(function () { self.reloading = false; heroBullets = []; ammoTxt.setText('Ammo: 5'); game.removeChild(reloadText); }, 2000); } }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } }; }); // Shoot button var shootButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shootButton', { anchorX: 0.5, anchorY: 0.5 }); self.x = 2048 - 200; self.y = 2732 - 200; self.down = function (x, y, obj) { hero.shoot(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Function to draw an imaginary grid // Call the drawGrid function to display the grid // New sprite sheet for sci-fi space theme function drawGrid() { var gridSize = 100; // Size of each grid cell var gridColor = 0x00FF00; // Color of the grid lines for (var x = 0; x <= 2048; x += gridSize) { var verticalLine = LK.getAsset('line', { width: 1, height: 2732, color: gridColor }); verticalLine.x = x; game.addChild(verticalLine); } for (var y = 0; y <= 2732; y += gridSize) { var horizontalLine = LK.getAsset('line', { width: 2048, height: 1, color: gridColor }); horizontalLine.y = y; game.addChild(horizontalLine); } } drawGrid(); // Initialize arrays and variables // Update hero bullets var heroBullets = []; if (heroBullets && heroBullets.length) { for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].update(); for (var j = enemies.length - 1; j >= 0; j--) { if (heroBullets[i].intersects(enemies[j])) { enemies[j].destroy(); heroBullets[i].destroy(); enemies.splice(j, 1); heroBullets.splice(i, 1); kills += 1; kills += 1; killsTxt.setText('Kills: ' + kills); if (kills >= 30) { LK.showGameOver(); } break; } } } } var hero; var enemies = []; var heroBullets = []; var enemyBullets = []; var enemiesMoved = false; var bossSpawned = false; var score = 0; var kills = 0; var kills = 0; var gameDuration = 60000; // 1 minute in milliseconds var startTime = Date.now(); var killsTxt = new Text2('Kills: 0', { size: 50, fill: "#ffffff" }); killsTxt.anchor.set(0.5, 0); LK.gui.top.addChild(killsTxt); var ammoTxt = new Text2('Ammo: 5', { size: 50, fill: "#ffffff" }); ammoTxt.anchor.set(0, 0); ammoTxt.x = 0; ammoTxt.y = 20; LK.gui.top.addChild(ammoTxt); var timerTxt = new Text2('Time: 60', { size: 50, fill: "#ffffff" }); timerTxt.anchor.set(1, 0); LK.gui.topRight.addChild(timerTxt); // Initialize hero hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 - 400; hero.reloading = false; game.addChild(hero); // Spawn enemies function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -100; game.addChild(enemy); enemies.push(enemy); } // Function to make half of the enemies come near the hero function makeEnemiesComeNearHero() { var halfEnemies = Math.ceil(enemies.length / 2); for (var i = 0; i < halfEnemies; i++) { var enemy = enemies[i]; enemy.x = hero.x; enemy.y = hero.y - 200; // Position them near the hero } } // Update game state game.update = function () { // Update timer text var elapsedTime = Date.now() - startTime; var remainingTime = Math.max(0, Math.ceil((gameDuration - elapsedTime) / 1000)); timerTxt.setText('Time: ' + remainingTime); if (elapsedTime >= 40000 && !bossSpawned) { var boss = new BossEnemy(); boss.x = 2048 / 2; boss.y = -100; game.addChild(boss); bossSpawned = true; // Make the boss shoot periodically LK.setInterval(function () { boss.shoot(); }, 1000); } if (elapsedTime >= 40000 && !enemiesMoved) { makeEnemiesComeNearHero(); enemiesMoved = true; } if (elapsedTime >= gameDuration) { LK.showGameOver(); alert("You Win! Your score: " + score); alert("Game Over! Your score: " + score); return; } // Update hero hero.update(); // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); if (enemies[i].intersects(hero)) { LK.showGameOver(); } } for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].update(); for (var j = enemies.length - 1; j >= 0; j--) { if (heroBullets[i].intersects(enemies[j])) { var explosion = LK.getAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); explosion.x = enemies[j].x; explosion.y = enemies[j].y; game.addChild(explosion); LK.setTimeout(function () { game.removeChild(explosion); }, 500); enemies[j].destroy(); heroBullets[i].destroy(); enemies.splice(j, 1); heroBullets.splice(i, 1); score += 100; kills += 1; killsTxt.setText('Kills: ' + kills); if (kills >= 30) { LK.showGameOver(); } break; } } } // Update enemy bullets for (var i = enemyBullets.length - 1; i >= 0; i--) { enemyBullets[i].update(); if (enemyBullets[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Game over when bullet touches the gun for (var j = heroBullets.length - 1; j >= 0; j--) { if (enemyBullets[i].intersects(heroBullets[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } // Spawn enemies periodically if (LK.ticks % 60 == 0) { spawnEnemy(); } }; // Handle touch events game.move = function (x, y, obj) { hero.x = x; }; game.up = function (x, y, obj) { // No action needed on touch up }; game.addChild(new shootButton());
===================================================================
--- original.js
+++ change.js
@@ -203,9 +203,9 @@
size: 50,
fill: "#ffffff"
});
ammoTxt.anchor.set(0, 0);
-ammoTxt.x = 20;
+ammoTxt.x = 0;
ammoTxt.y = 20;
LK.gui.top.addChild(ammoTxt);
var timerTxt = new Text2('Time: 60', {
size: 50,