Code edit (3 edits merged)
Please save this source code
User prompt
add code so that EnemyBossShip moves side to side
User prompt
Fix Bug: 'Timeout.tick error: bigEnemyPoints is not defined' in this line: 'if (currentScore >= (smallEnemyPoints * 10 + bigEnemyPoints) * currentLevel && !game.bossSpawned) {' Line Number: 193
Code edit (8 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'enemyBossShipBullets')' in this line: 'var enemyBullet = enemyBossShips[i].enemyBossShipBullets[k];' Line Number: 243
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'enemyBossShipBullets')' in this line: 'var enemyBullet = enemy.enemyBossShipBullets[k];' Line Number: 214
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'enemyBossShipBullets')' in this line: 'var enemyBullet = enemy.enemyBossShipBullets[k];' Line Number: 214
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: initialY is not defined' in this line: 'if (self.y <= initialY) {' Line Number: 108
Code edit (1 edits merged)
Please save this source code
User prompt
update EnemyBossBullet so it continues to move off the screen
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: initialY is not defined' in this line: 'var angle = Math.atan2(initialY - self.y, initialX - self.x);' Line Number: 106
User prompt
Fix Bug: 'ReferenceError: heroShipY is not defined' in this line: 'enemy.shoot(heroShip.x, heroShipY);' Line Number: 228
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'for (j = enemy.enemyBossBullets.length - 1; j >= 0; j--) {' Line Number: 228
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'for (j = enemyBossShips.enemyBossBullets.length - 1; j >= 0; j--) {' Line Number: 228
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: player is not defined' in this line: 'enemy.shoot(player.X, player.Y);' Line Number: 223
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'y')' in this line: 'if (bullet.y > game.height + bullet.height || bullet.x < -bullet.width || bullet.x > game.width + bullet.width) {' Line Number: 240
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'move')' in this line: 'bullet.move(heroShip.x, heroShip.y);' Line Number: 237
===================================================================
--- original.js
+++ change.js
@@ -1,130 +1,132 @@
/****
* Classes
****/
var Starfield = Container.expand(function () {
- var self = Container.call(this);
- self.stars = [];
- var numberOfStars = 300;
- for (var i = 0; i < numberOfStars; i++) {
- var star = LK.getAsset('star', 'Star');
- star.anchor.set(0.5, 0.5);
- star.x = Math.random() * game.width;
- star.y = Math.random() * game.height;
- star.speed = Math.random() * 1 + 0.1;
- star.alpha = Math.random() * 0.2 + 0.1;
- star.tint = Math.random() * 0xFFFFFF;
- self.addChild(star);
- self.stars.push(star);
- }
- self.moveStars = function () {
- for (var i = 0; i < self.stars.length; i++) {
- var star = self.stars[i];
- star.y += star.speed;
- if (star.y > game.height) {
- star.y = -30;
- }
- }
- };
+ var self = Container.call(this);
+ self.stars = [];
+ var numberOfStars = 300;
+ for (var i = 0; i < numberOfStars; i++) {
+ var star = LK.getAsset('star', 'Star');
+ star.anchor.set(0.5, 0.5);
+ star.x = Math.random() * game.width;
+ star.y = Math.random() * game.height;
+ star.speed = Math.random() * 1 + 0.1;
+ star.alpha = Math.random() * 0.2 + 0.1;
+ star.tint = Math.random() * 0xFFFFFF;
+ self.addChild(star);
+ self.stars.push(star);
+ }
+ self.moveStars = function () {
+ for (var i = 0; i < self.stars.length; i++) {
+ var star = self.stars[i];
+ star.y += star.speed;
+ if (star.y > game.height) {
+ star.y = -30;
+ }
+ }
+ };
});
// Hero ship class
var HeroShip = Container.expand(function () {
- var self = Container.call(this);
- var shipGraphics = self.createAsset('heroShip', 'Cute smiley ship', 0.5, 0.5);
- self.speed = 5;
- self.isShooting = false;
- self.shootingInterval = 30;
- self._shootingCounter = 0;
- self.shoot = function () {
- var bullet = new HeroBullet();
- bullet.x = self.x;
- bullet.y = self.y - self.height / 2;
- game.addChild(bullet);
- return bullet;
- };
+ var self = Container.call(this);
+ var shipGraphics = self.createAsset('heroShip', 'Cute smiley ship', 0.5, 0.5);
+ self.speed = 5;
+ self.isShooting = false;
+ self.shootingInterval = 30;
+ self._shootingCounter = 0;
+ self.shoot = function () {
+ var bullet = new HeroBullet();
+ bullet.x = self.x;
+ bullet.y = self.y - self.height / 2;
+ game.addChild(bullet);
+ return bullet;
+ };
});
// Hero bullet class
var HeroBullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.createAsset('heroBullet', 'Heart bullet', 0.5, 1);
- self.speed = -10;
- self.move = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.createAsset('heroBullet', 'Heart bullet', 0.5, 1);
+ self.speed = -10;
+ self.move = function () {
+ self.y += self.speed;
+ };
});
// Enemy ship class
var EnemyShip = Container.expand(function () {
- var self = Container.call(this);
- var shipGraphics = self.createAsset('enemyShip', 'Evil smiley', 0.5, 0.5);
- self.speed = 2;
- self.move = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var shipGraphics = self.createAsset('enemyShip', 'Evil smiley', 0.5, 0.5);
+ self.speed = 2;
+ self.move = function () {
+ self.y += self.speed;
+ };
});
// Enemy ship class
var EnemyBossShip = Container.expand(function () {
- var self = Container.call(this);
- var shipGraphics = self.createAsset('enemyBossShip', 'Evil Boss smiley', 0.5, 0.5);
- self.speed = 6;
- self.hitCount = 0;
- self.maxHits = 10;
- self.targetY = game.height * (1 / 4);
- self.shootingInterval = 30;
- self._shootingCounter = 0;
- self.canShoot = false;
- self.enemyBossShipBullets = [];
- self.shoot = function () {
- if (self.canShoot) {
- var bullet = new EnemyBossBullet();
- bullet.x = self.x + 100;
- bullet.y = self.y;
- self.enemyBossShipBullets.push(bullet);
- game.addChild(bullet);
- }
- };
- self.move = function () {
- if (self.y < self.targetY) {
- self.y += self.speed;
- } else if (self.speed !== 0) {
- self.speed = 0;
- self.canShoot = true;
- }
- };
- self.isDestroyed = function () {
- return self.hitCount >= self.maxHits;
- };
+ var self = Container.call(this);
+ var shipGraphics = self.createAsset('enemyBossShip', 'Evil Boss smiley', 0.5, 0.5);
+ self.speed = 6;
+ self.hitCount = 0;
+ self.maxHits = 10;
+ self.targetY = game.height * (1 / 4);
+ self.shootingInterval = 30;
+ self._shootingCounter = 0;
+ self.canShoot = false;
+ self.enemyBossShipBullets = [];
+ self.shoot = function () {
+ if (self.canShoot) {
+ var bullet = new EnemyBossBullet();
+ bullet.x = self.x + 100;
+ bullet.y = self.y;
+ self.enemyBossShipBullets.push(bullet);
+ game.addChild(bullet);
+ }
+ };
+ self.move = function () {
+ if (self.y < self.targetY) {
+ self.y += self.speed;
+ } else if (self.speed !== 0) {
+ self.speed = 0;
+ self.canShoot = true;
+ }
+ };
+ self.isDestroyed = function () {
+ return self.hitCount >= self.maxHits;
+ };
});
// Enemy boss bullet class
var EnemyBossBullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.createAsset('enemyBossBullet', 'Evil Boss Bullet', 0.5, 1);
- self.speed = -5;
- self.move = function (playerX, playerY) {
- var angle = Math.atan2(playerY - self.y, playerX - self.x);
- self.x += Math.cos(angle) * self.speed;
- self.y += Math.sin(angle) * self.speed;
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.createAsset('enemyBossBullet', 'Evil Boss Bullet', 0.5, 1);
+ self.speed = -5;
+ self.move = function (playerX, playerY) {
+ var angle = Math.atan2(playerY - self.y, playerX - self.x);
+ self.x += Math.cos(angle) * self.speed;
+ self.y += Math.sin(angle) * self.speed;
+ };
});
var ScoreDisplay = Container.expand(function () {
- var self = Container.call(this);
- var scoreText = new Text2('0', {
- size: 150,
- fill: "#FF6900"
- });
- scoreText.anchor.set(0.5, 0);
- self.addChild(scoreText);
- self.updateScore = function (newScore) {
- scoreText.setText(newScore.toString());
- };
+ var self = Container.call(this);
+ var scoreText = new Text2('0', {
+ size: 150,
+ fill: "#FF6900"
+ });
+ scoreText.anchor.set(0.5, 0);
+ self.addChild(scoreText);
+ self.updateScore = function (newScore) {
+ scoreText.setText(newScore.toString());
+ };
});
+
/****
* Initialize Game
****/
// Initialize starfield
var game = new LK.Game({
- backgroundColor: 0xFEF3BD,
- bossSpawned: false // Flag to track if boss has been spawned
+ backgroundColor: 0xFEF3BD,
+ bossSpawned: false // Flag to track if boss has been spawned
});
+
/****
* Game Code
****/
// Initialize starfield
@@ -148,121 +150,124 @@
heroShip.y = game.height - 450;
// Create enemies
function spawnEnemyShip(speed) {
- var enemyShip = new EnemyShip();
- enemyShip.speed = speed || Math.random() * 3 + 1; // Default speed if not provided
- enemyShip.x = Math.random() * (game.width - enemyShip.width) + enemyShip.width / 2;
- enemyShip.y = -enemyShip.height / 2;
- game.addChild(enemyShip);
- enemyShips.push(enemyShip);
+ var enemyShip = new EnemyShip();
+ enemyShip.speed = speed || Math.random() * 3 + 1; // Default speed if not provided
+ enemyShip.x = Math.random() * (game.width - enemyShip.width) + enemyShip.width / 2;
+ enemyShip.y = -enemyShip.height / 2;
+ game.addChild(enemyShip);
+ enemyShips.push(enemyShip);
}
// Game tick event
LK.on('tick', function () {
- // Move the starfield
- starfield.moveStars();
+ // Move the starfield
+ starfield.moveStars();
- // Move hero bullets
- for (var i = heroBullets.length - 1; i >= 0; i--) {
- var bullet = heroBullets[i];
- bullet.move();
- if (bullet.y < -bullet.height) {
- bullet.destroy();
- heroBullets.splice(i, 1);
- } else {
- // Check collision with enemies
- for (var j = enemyShips.length - 1; j >= 0; j--) {
- if (bullet.intersects(enemyShips[j])) {
- bullet.destroy();
- heroBullets.splice(i, 1);
- {
- enemyShips[j].destroy();
- enemyShips.splice(j, 1);
- currentScore += 100;
- scoreDisplay.updateScore(currentScore);
- }
- break;
- }
- }
+ // Move hero bullets
+ for (var i = heroBullets.length - 1; i >= 0; i--) {
+ var bullet = heroBullets[i];
+ bullet.move();
+ if (bullet.y < -bullet.height) {
+ bullet.destroy();
+ heroBullets.splice(i, 1);
+ } else {
+ // Check collision with enemies
+ for (var j = enemyShips.length - 1; j >= 0; j--) {
+ if (bullet.intersects(enemyShips[j])) {
+ bullet.destroy();
+ heroBullets.splice(i, 1);
+ {
+ enemyShips[j].destroy();
+ enemyShips.splice(j, 1);
+ currentScore += 100;
+ scoreDisplay.updateScore(currentScore);
+ }
+ break;
+ }
+ }
- //Enemy Boss collision
- for (var j = enemyBossShips.length - 1; j >= 0; j--) {
- if (bullet.intersects(enemyBossShips[j])) {
- bullet.destroy();
- heroBullets.splice(i, 1);
- enemyBossShips[j].hitCount++;
- if (enemyBossShips[j].isDestroyed()) {
- enemyBossShips[j].destroy();
- enemyBossShips.splice(j, 1);
- currentScore += 1000;
- scoreDisplay.updateScore(currentScore);
- }
- }
- }
- }
- }
+ //Enemy Boss collision
+ for (var j = enemyBossShips.length - 1; j >= 0; j--) {
+ if (bullet.intersects(enemyBossShips[j])) {
+ bullet.destroy();
+ heroBullets.splice(i, 1);
+ enemyBossShips[j].hitCount++;
+ if (enemyBossShips[j].isDestroyed()) {
+ enemyBossShips[j].destroy();
+ enemyBossShips.splice(j, 1);
+ currentScore += 1000;
+ scoreDisplay.updateScore(currentScore);
+ }
+ }
+ }
+ }
+ }
- // Move enemy ships
- for (var i = enemyShips.length - 1; i >= 0; i--) {
- var enemy = enemyShips[i];
- enemy.move();
- if (enemy.y > game.height + enemy.height / 2) {
- enemy.destroy();
- enemyShips.splice(i, 1);
- }
- }
+ // Move enemy ships
+ for (var i = enemyShips.length - 1; i >= 0; i--) {
+ var enemy = enemyShips[i];
+ enemy.move();
+ if (enemy.y > game.height + enemy.height / 2) {
+ enemy.destroy();
+ enemyShips.splice(i, 1);
+ }
+ }
- // Move enemy Boss ships
- for (var i = enemyBossShips.length - 1; i >= 0; i--) {
- var enemy = enemyBossShips[i];
- enemy.move();
- enemy.shoot();
- if (enemy.y > game.height + enemy.height / 2) {
- enemy.destroy();
- enemyBossShips.splice(i, 1);
- }
- for (j = enemyBossShips.enemyBossBullets.length - 1; j >= 0; j--) {}
- }
+ // Move enemy Boss ships
+ for (var i = enemyBossShips.length - 1; i >= 0; i--) {
+ var enemy = enemyBossShips[i];
+ enemy.move();
+ //enemy.shoot();
+ if (enemy.y > game.height + enemy.height / 2) {
+ enemy.destroy();
+ enemyBossShips.splice(i, 1);
+ }
+ for (j = enemy.enemyBossBullets.length - 1; j >= 0; j--) {
+ //var enemyBullet = enemyBossShips.enemyBossBullets[j];
+ //enemyBullet.move(heroShip.x, heroShip.y);
+ }
+ }
- // Shoot bullets
- if (heroShip._shootingCounter % heroShip.shootingInterval == 0) {
- if (heroShip.isShooting) {
- heroBullets.push(heroShip.shoot());
- heroShip._shootingCounter = 0;
- }
- }
- heroShip._shootingCounter += 1;
+ // Shoot bullets
+ if (heroShip._shootingCounter % heroShip.shootingInterval == 0) {
+ if (heroShip.isShooting) {
+ heroBullets.push(heroShip.shoot());
+ heroShip._shootingCounter = 0;
+ }
+ }
+ heroShip._shootingCounter += 1;
});
// Function to randomly spawn enemy ships or the enemy boss
function randomSpawnEnemyShip() {
- var minSpawnDelay = 1000; // 1 second
- var maxSpawnDelay = 3000; // 3 seconds
- var spawnDelay = Math.random() * (maxSpawnDelay - minSpawnDelay) + minSpawnDelay;
- LK.setTimeout(function () {
- if (currentScore >= 000 && !game.bossSpawned) {
- game.bossSpawned = true;
- var enemyBossShip = new EnemyBossShip();
- enemyBossShip.x = game.width / 2;
- enemyBossShip.y = -enemyBossShip.height / 2;
- game.addChild(enemyBossShip);
- enemyBossShips.push(enemyBossShip);
- } else if (!game.bossSpawned) {
- spawnEnemyShip();
- }
- randomSpawnEnemyShip(); // Schedule next spawn
- }, spawnDelay);
+ var minSpawnDelay = 1000; // 1 second
+ var maxSpawnDelay = 3000; // 3 seconds
+ var spawnDelay = Math.random() * (maxSpawnDelay - minSpawnDelay) + minSpawnDelay;
+ LK.setTimeout(function () {
+ if (currentScore >= 200 && !game.bossSpawned) {
+ game.bossSpawned = true;
+ var enemyBossShip = new EnemyBossShip();
+ enemyBossShip.x = game.width / 2;
+ enemyBossShip.y = -enemyBossShip.height / 2;
+ game.addChild(enemyBossShip);
+ enemyBossShips.push(enemyBossShip);
+ } else if (!game.bossSpawned) {
+ spawnEnemyShip();
+ }
+ randomSpawnEnemyShip(); // Schedule next spawn
+ }, spawnDelay);
}
randomSpawnEnemyShip(); // Start the spawning process
// Touch controls to make heroShip follow the pointer
game.on('move', function (obj) {
- var touchPos = obj.event.getLocalPosition(game);
- heroShip.x = touchPos.x;
+ var touchPos = obj.event.getLocalPosition(game);
+ heroShip.x = touchPos.x;
});
game.on('down', function (obj) {
- heroShip._shootingCounter = 0;
- heroShip.isShooting = true;
+ heroShip._shootingCounter = 0;
+ heroShip.isShooting = true;
});
game.on('up', function (obj) {
- heroShip.isShooting = false;
+ heroShip.isShooting = false;
});
\ No newline at end of file
a cute cool looking emoji face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute looking heart. bright red.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
an evil looking emoji. purple and blue colors.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a shiny blue cute star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A start button. White on Red.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a grey touchpad. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a bright yellow shiny cute star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.