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
User prompt
Please fix the bug: 'ReferenceError: score is not defined' in or related to this line: 'score += 100;' Line Number: 263
User prompt
Show kills instead of score
User prompt
Remove current
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.showggwon is not a function' in or related to this line: 'LK.showggwon();' Line Number: 299
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.heyyouwon is not a function' in or related to this line: 'LK.heyyouwon();' Line Number: 299
Code edit (1 edits merged)
Please save this source code
User prompt
The turrent should not kill the player when epwaning it
User prompt
You should earn 100 score for a kill
User prompt
Make a current which will cost 200 score and will shoot those bullets for you
User prompt
It is still small
User prompt
Increase the size of enemy bullet
User prompt
Enemy bullet size increase
User prompt
Enemy bullet size increase
User prompt
Please fix the bug: 'Uncaught TypeError: Graphics is not a constructor' in or related to this line: 'var verticalLine = new Graphics();' Line Number: 130
User prompt
Make an imaginary grid which should be only visible to me
User prompt
After 40sec in the clock make it half of the enemy come near the hear. To make game a little harder
User prompt
Remove boss
User prompt
Show ammo as herobullet left
User prompt
And show how many bullets left as ammo
User prompt
Hero can shoot only six bullets then he have to wait 2 sec
User prompt
Bullet size smaller
/**** * Classes ****/ // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { 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 < 6) { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); heroBullets.push(bullet); ammoTxt.setText('Ammo: ' + (6 - heroBullets.length)); } 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: 6'); 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(); } }; }); var ShootButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shootButton', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { hero.shoot(); }; self.containsPoint = function (point) { var localPoint = self.toLocal(point); return localPoint.x >= -self.width / 2 && localPoint.x <= self.width / 2 && localPoint.y >= -self.height / 2 && localPoint.y <= self.height / 2; }; }); /**** * 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 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); score += 10; kills += 1; scoreTxt.setText('Score: ' + score); if (kills >= 30) { LK.showGameOver(); } break; } } } } var hero; var enemies = []; var heroBullets = []; var enemyBullets = []; var enemiesMoved = false; var score = 0; var kills = 0; var gameDuration = 60000; // 1 minute in milliseconds var startTime = Date.now(); var scoreTxt = new Text2('Score: 0', { size: 50, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var ammoTxt = new Text2('Ammo: 6', { size: 50, fill: "#ffffff" }); ammoTxt.anchor.set(0.5, 0); ammoTxt.x = 2048 / 2; ammoTxt.y = 2732 - 100; 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); // Initialize shoot button var shootButton = new ShootButton(); shootButton.x = 2048 - 200; shootButton.y = 2732 - 200; game.addChild(shootButton); // 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 && !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])) { enemies[j].destroy(); heroBullets[i].destroy(); enemies.splice(j, 1); heroBullets.splice(i, 1); score += 10; kills += 1; scoreTxt.setText('Score: ' + score); 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(); } } // 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 };
===================================================================
--- original.js
+++ change.js
@@ -117,19 +117,23 @@
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 = new Graphics();
- verticalLine.lineStyle(1, gridColor, 1);
- verticalLine.moveTo(x, 0);
- verticalLine.lineTo(x, 2732);
+ 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 = new Graphics();
- horizontalLine.lineStyle(1, gridColor, 1);
- horizontalLine.moveTo(0, y);
- horizontalLine.lineTo(2048, y);
+ var horizontalLine = LK.getAsset('line', {
+ width: 2048,
+ height: 1,
+ color: gridColor
+ });
+ horizontalLine.y = y;
game.addChild(horizontalLine);
}
}
drawGrid();