Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: LK.restartGame is not a function' in or related to this line: 'LK.restartGame();' Line Number: 916
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'play')' in or related to this line: 'LK.sound.play('explosion', {' Line Number: 129
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'play')' in or related to this line: 'LK.sound.play('shoot', {' Line Number: 304
User prompt
Please fix the bug: 'TypeError: Graphics is not a constructor' in or related to this line: 'var bulletGraphics = new Graphics();' Line Number: 27
User prompt
Please fix the bug: 'Timeout.tick error: LK.showPauseMenu is not a function' in or related to this line: 'LK.showPauseMenu();' Line Number: 1055
User prompt
Please fix the bug: 'Timeout.tick error: LK.showPauseMenu is not a function' in or related to this line: 'LK.showPauseMenu();' Line Number: 1055
User prompt
Please fix the bug: 'Timeout.tick error: LK.pauseGame is not a function' in or related to this line: 'LK.pauseGame();' Line Number: 1055
User prompt
Please fix the bug: 'Timeout.tick error: LK.pauseGame is not a function' in or related to this line: 'LK.pauseGame();' Line Number: 1055
User prompt
Please fix the bug: 'Timeout.tick error: LK.pauseGame is not a function' in or related to this line: 'LK.pauseGame();' Line Number: 1055
User prompt
Please fix the bug: 'Timeout.tick error: Graphics is not a constructor' in or related to this line: 'var star = new Graphics();' Line Number: 1029
User prompt
Please fix the bug: 'Timeout.tick error: Graphics is not a constructor' in or related to this line: 'var bg = new Graphics();' Line Number: 922
User prompt
Please fix the bug: 'Timeout.tick error: Graphics is not a constructor' in or related to this line: 'var overlay = new Graphics();' Line Number: 998
User prompt
Please fix the bug: 'Timeout.tick error: Graphics is not a constructor' in or related to this line: 'var overlay = new Graphics();' Line Number: 994
User prompt
Please fix the bug: 'Graphics is not a constructor' in or related to this line: 'var particle = new Graphics();' Line Number: 212
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'statusMessage.style.fill = color || 0xFFFFFF;' Line Number: 678
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var bg1 = game.addChild(new Sprite('background'));' Line Number: 579
User prompt
Please fix the bug: 'Graphics is not a constructor' in or related to this line: 'var shieldGraphics = new Graphics();' Line Number: 271
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Error: Invalid end type for property scale: object' in or related to this line: 'tween(enemyGraphics, {' Line Number: 64
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 145
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'enemyShips[l].destroy();' Line Number: 171
User prompt
Please fix the bug: 'Uncaught TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 91
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Class for enemy ships with wave-based spawning and better animation var EnemyShip = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShip', { anchorX: 0.5, anchorY: 0.5 }); // Spawn animation: Fade in & Scale up enemyGraphics.scale.set(0); enemyGraphics.alpha = 0; tween(enemyGraphics.scale, { x: 1, y: 1 }, { duration: 500 }); tween(enemyGraphics, { alpha: 1 }, { duration: 500 }); self.speed = 3 + Math.random() * 2; // Slight variation in speed self.driftAmount = 3; // Side drift range self.driftSpeed = 50 + Math.random() * 20; // Slight variation in drift speed self.health = 1; // Basic enemies have 1 health self.hit = function () { self.health -= 1; if (self.health <= 0) { self.explode(); return true; // Enemy destroyed } // Flash effect when hit but not destroyed tween(enemyGraphics, { alpha: 0.2 }, { duration: 100, onFinish: function onFinish() { tween(enemyGraphics, { alpha: 1 }, { duration: 100 }); } }); return false; // Enemy still alive }; self.explode = function () { tween(enemyGraphics, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); enemyShips.splice(enemyShips.indexOf(self), 1); // Add score increaseScore(self.scoreValue || 1); } }); tween(enemyGraphics.scale, { x: 1.5, y: 1.5 }, { duration: 300 }); }; self.update = function () { self.y += self.speed; self.x += Math.sin(LK.ticks / self.driftSpeed) * self.driftAmount; // Destroy if off-screen with fade-out effect if (self.y > 2732 + enemyGraphics.height / 2) { tween(enemyGraphics, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { self.destroy(); var index = enemyShips.indexOf(self); if (index !== -1) { enemyShips.splice(index, 1); } } }); } }; return self; }); // Class for tougher enemy ships var BossEnemy = EnemyShip.expand(function () { var self = EnemyShip.call(this); // Make boss larger self.getChildAt(0).scale.set(1.5); // Make boss tougher self.health = 5; self.speed = 1.5; self.scoreValue = 5; return self; }); // Class for player bullets with proper destruction var PlayerBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('playerBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height) { self.destroy(); var index = playerBullets.indexOf(self); if (index !== -1) { playerBullets.splice(index, 1); } } }; return self; }); // Class for the player's ship with shooting cooldown var PlayerShip = Container.expand(function () { var self = Container.call(this); var shipGraphics = self.attachAsset('playerShip', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.canShoot = true; // Prevents spam shooting self.shootCooldown = 300; // 300ms cooldown self.lives = 3; // Player starts with 3 lives self.invulnerable = false; // Invulnerability after being hit self.shoot = function () { if (self.canShoot) { var bullet = new PlayerBullet(); bullet.x = self.x; bullet.y = self.y - shipGraphics.height / 2; game.addChild(bullet); playerBullets.push(bullet); self.canShoot = false; LK.setTimeout(function () { self.canShoot = true; }, self.shootCooldown); } }; self.hit = function () { if (self.invulnerable) { return; } self.lives--; updateLivesDisplay(); if (self.lives <= 0) { LK.showGameOver(); return; } // Make player invulnerable temporarily self.invulnerable = true; // Flash effect var flashCount = 0; var flashInterval = LK.setInterval(function () { shipGraphics.alpha = shipGraphics.alpha === 1 ? 0.3 : 1; flashCount++; if (flashCount >= 10) { LK.clearInterval(flashInterval); shipGraphics.alpha = 1; self.invulnerable = false; } }, 150); }; self.update = function () { if (self.invulnerable) { return; } for (var i = 0; i < enemyShips.length; i++) { if (self.intersects(enemyShips[i])) { self.hit(); enemyShips[i].explode(); break; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Using bullet as placeholder - replace with proper explosion /**** * Game Variables ****/ var playerBullets = []; var enemyShips = []; var player = game.addChild(new PlayerShip()); player.x = 2048 / 2; player.y = 2732 - 200; // Score Display var scoreText = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); scoreText.x = 2048 / 2; scoreText.y = 50; LK.gui.top.addChild(scoreText); // Lives Display var livesText = new Text2('Lives: 3', { size: 100, fill: 0xFFFFFF }); livesText.anchor.set(0, 0); livesText.x = 50; livesText.y = 50; LK.gui.top.addChild(livesText); // Wave Display var waveText = new Text2('Wave: 1', { size: 100, fill: 0xFFFFFF }); waveText.anchor.set(1, 0); waveText.x = 2048 - 50; waveText.y = 50; LK.gui.top.addChild(waveText); // Wave Variables var waveNumber = 1; var enemiesPerWave = 5; var enemiesSpawned = 0; var waveInProgress = true; var waveCooldown = false; // Helper Functions function updateLivesDisplay() { livesText.setText('Lives: ' + player.lives); } function increaseScore(amount) { LK.setScore(LK.getScore() + amount); scoreText.setText(LK.getScore()); } function updateWaveDisplay() { waveText.setText('Wave: ' + waveNumber); } // Function to spawn enemies in waves function spawnEnemy() { if (!waveInProgress || waveCooldown) { return; } if (enemiesSpawned < enemiesPerWave) { var enemy; // Every 3 waves, add a boss if (waveNumber > 0 && waveNumber % 3 === 0 && enemiesSpawned === enemiesPerWave - 1) { enemy = new BossEnemy(); } else { enemy = new EnemyShip(); } enemy.x = Math.random() * 2048; enemy.y = -100; game.addChild(enemy); enemyShips.push(enemy); enemiesSpawned++; if (enemiesSpawned >= enemiesPerWave) { waveInProgress = false; } } } function startNextWave() { waveNumber++; updateWaveDisplay(); enemiesPerWave += 2; // Increase difficulty each wave enemiesSpawned = 0; waveInProgress = true; // Display wave number var newWaveText = new Text2('WAVE ' + waveNumber, { size: 250, fill: 0xFFFFFF }); newWaveText.anchor.set(0.5, 0.5); newWaveText.x = 2048 / 2; newWaveText.y = 2732 / 2; game.addChild(newWaveText); // Animate and remove wave text tween(newWaveText.scale, { x: 1.5, y: 1.5 }, { duration: 800, onFinish: function onFinish() { tween(newWaveText, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { newWaveText.destroy(); } }); } }); } // Game update loop game.update = function () { // Update player player.update(); // Update player bullets for (var i = playerBullets.length - 1; i >= 0; i--) { if (playerBullets[i]) { playerBullets[i].update(); } } // Update enemy ships for (var j = enemyShips.length - 1; j >= 0; j--) { if (enemyShips[j]) { enemyShips[j].update(); } } // Check for collisions between player bullets and enemy ships for (var k = playerBullets.length - 1; k >= 0; k--) { if (!playerBullets[k]) { continue; } for (var l = enemyShips.length - 1; l >= 0; l--) { if (!enemyShips[l]) { continue; } if (playerBullets[k] && enemyShips[l] && playerBullets[k].intersects(enemyShips[l])) { // Enemy hit by bullet var destroyed = enemyShips[l].hit(); // Remove bullet playerBullets[k].destroy(); playerBullets.splice(k, 1); break; } } } // Spawn enemies periodically if (LK.ticks % 60 === 0) { spawnEnemy(); } // Check if wave is complete and start next wave if (!waveInProgress && enemyShips.length === 0 && !waveCooldown) { waveCooldown = true; LK.setTimeout(function () { startNextWave(); waveCooldown = false; }, 2000); } }; // Handle player movement game.move = function (x, y, obj) { // Constrain player to screen boundaries var halfWidth = player.getChildAt(0).width / 2; player.x = Math.min(Math.max(x, halfWidth), 2048 - halfWidth); }; // Handle shooting game.down = function (x, y, obj) { player.shoot(); };
===================================================================
--- original.js
+++ change.js
@@ -5,88 +5,33 @@
/****
* Classes
****/
-// Class for enemy bullets
-var EnemyBullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.attachAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0xFF0000,
- scaleX: 0.2,
- scaleY: 0.2
- });
- self.speed = 8;
- self.update = function () {
- self.y += self.speed;
- // Destroy if off-screen
- if (self.y > SCREEN_HEIGHT + 20) {
- self.destroy();
- var index = enemyBullets.indexOf(self);
- if (index !== -1) {
- enemyBullets.splice(index, 1);
- }
- }
- };
- return self;
-});
// Class for enemy ships with wave-based spawning and better animation
-var EnemyShip = Container.expand(function (type) {
+var EnemyShip = Container.expand(function () {
var self = Container.call(this);
- self.type = type || ENEMY_TYPES.BASIC;
var enemyGraphics = self.attachAsset('enemyShip', {
anchorX: 0.5,
anchorY: 0.5
});
- // Set properties based on enemy type
- switch (self.type) {
- case ENEMY_TYPES.FAST:
- enemyGraphics.tint = 0x00FF00;
- self.speed = 5 + Math.random() * 2;
- self.health = 1;
- self.scoreValue = 2;
- self.driftAmount = 6;
- break;
- case ENEMY_TYPES.TANK:
- enemyGraphics.tint = 0xFF0000;
- self.speed = 2 + Math.random() * 1;
- self.health = 3;
- self.scoreValue = 3;
- self.driftAmount = 2;
- break;
- case ENEMY_TYPES.BOSS:
- enemyGraphics.tint = 0xFF00FF;
- enemyGraphics.scale.set(1.5);
- self.speed = 1.5;
- self.health = 15;
- self.scoreValue = 10;
- self.driftAmount = 3;
- break;
- default:
- // BASIC
- self.speed = 3 + Math.random() * 2;
- self.health = 1;
- self.scoreValue = 1;
- self.driftAmount = 3;
- }
// Spawn animation: Fade in & Scale up
enemyGraphics.scale.set(0);
enemyGraphics.alpha = 0;
tween(enemyGraphics.scale, {
- x: self.type === ENEMY_TYPES.BOSS ? 1.5 : 1,
- y: self.type === ENEMY_TYPES.BOSS ? 1.5 : 1
+ x: 1,
+ y: 1
}, {
duration: 500
});
tween(enemyGraphics, {
alpha: 1
}, {
duration: 500
});
+ self.speed = 3 + Math.random() * 2; // Slight variation in speed
+ self.driftAmount = 3; // Side drift range
self.driftSpeed = 50 + Math.random() * 20; // Slight variation in drift speed
- self.shootCooldown = self.type === ENEMY_TYPES.BOSS ? 1500 : 3000; // Boss shoots more frequently
- self.canShoot = true;
+ self.health = 1; // Basic enemies have 1 health
self.hit = function () {
self.health -= 1;
if (self.health <= 0) {
self.explode();
@@ -104,24 +49,11 @@
duration: 100
});
}
});
- // Emit particles when hit
- particleSystem.emit(self.x, self.y, 5);
return false; // Enemy still alive
};
self.explode = function () {
- // Play explosion sound
- LK.getSound('explosion').play({
- volume: 0.5
- });
- // Emit particles for explosion
- particleSystem.emit(self.x, self.y, 20);
- // Chance to drop powerup (higher chance for bosses)
- var dropChance = self.type === ENEMY_TYPES.BOSS ? 0.8 : 0.1;
- if (Math.random() < dropChance) {
- spawnPowerup(self.x, self.y);
- }
tween(enemyGraphics, {
alpha: 0
}, {
duration: 300,
@@ -138,31 +70,13 @@
}, {
duration: 300
});
};
- self.shoot = function () {
- if (!self.canShoot) {
- return;
- }
- var bullet = new EnemyBullet();
- bullet.x = self.x;
- bullet.y = self.y + enemyGraphics.height / 2;
- game.addChild(bullet);
- enemyBullets.push(bullet);
- self.canShoot = false;
- LK.setTimeout(function () {
- self.canShoot = true;
- }, self.shootCooldown);
- };
self.update = function () {
self.y += self.speed;
self.x += Math.sin(LK.ticks / self.driftSpeed) * self.driftAmount;
- // Bosses and some enemies shoot at the player
- if ((self.type === ENEMY_TYPES.BOSS || Math.random() < 0.005) && self.y > 0) {
- self.shoot();
- }
// Destroy if off-screen with fade-out effect
- if (self.y > SCREEN_HEIGHT + enemyGraphics.height / 2) {
+ if (self.y > 2732 + enemyGraphics.height / 2) {
tween(enemyGraphics, {
alpha: 0
}, {
duration: 500,
@@ -177,57 +91,17 @@
}
};
return self;
});
-/****
-* Particle System
-****/
-var ParticleSystem = Container.expand(function (config) {
- var self = Container.call(this);
- self.particles = [];
- self.maxParticles = config.maxParticles || 20;
- self.minLifetime = config.minLifetime || 300;
- self.maxLifetime = config.maxLifetime || 600;
- self.minSpeed = config.minSpeed || 1;
- self.maxSpeed = config.maxSpeed || 3;
- self.colors = config.colors || [0xFFFFFF];
- self.size = config.size || 5;
- self.emit = function (x, y, count) {
- count = count || 10;
- for (var i = 0; i < count && self.particles.length < self.maxParticles; i++) {
- var angle = Math.random() * Math.PI * 2;
- var speed = self.minSpeed + Math.random() * (self.maxSpeed - self.minSpeed);
- var lifetime = self.minLifetime + Math.random() * (self.maxLifetime - self.minLifetime);
- var particle = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: self.colors[Math.floor(Math.random() * self.colors.length)],
- scaleX: self.size / 10,
- scaleY: self.size / 10
- });
- particle.x = x;
- particle.y = y;
- particle.vx = Math.cos(angle) * speed;
- particle.vy = Math.sin(angle) * speed;
- particle.alpha = 1;
- particle.lifetime = lifetime;
- self.addChild(particle);
- self.particles.push(particle);
- }
- };
- self.update = function () {
- for (var i = self.particles.length - 1; i >= 0; i--) {
- var p = self.particles[i];
- p.x += p.vx;
- p.y += p.vy;
- p.lifetime -= LK.deltaTime;
- p.alpha = p.lifetime / self.maxLifetime;
- if (p.lifetime <= 0) {
- p.destroy();
- self.particles.splice(i, 1);
- }
- }
- };
+// Class for tougher enemy ships
+var BossEnemy = EnemyShip.expand(function () {
+ var self = EnemyShip.call(this);
+ // Make boss larger
+ self.getChildAt(0).scale.set(1.5);
+ // Make boss tougher
+ self.health = 5;
+ self.speed = 1.5;
+ self.scoreValue = 5;
return self;
});
// Class for player bullets with proper destruction
var PlayerBullet = Container.expand(function () {
@@ -238,12 +112,8 @@
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
- // Add trail effect
- if (LK.ticks % 3 === 0) {
- particleSystem.emit(self.x, self.y + bulletGraphics.height / 2, 1);
- }
if (self.y < -bulletGraphics.height) {
self.destroy();
var index = playerBullets.indexOf(self);
if (index !== -1) {
@@ -259,54 +129,20 @@
var shipGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
- // Shield graphics
- var shieldGraphics = self.attachAsset('shield', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- shieldGraphics.visible = false;
- self.defaultSpeed = 10;
- self.speed = self.defaultSpeed;
+ self.speed = 10;
self.canShoot = true; // Prevents spam shooting
self.shootCooldown = 300; // 300ms cooldown
self.lives = 3; // Player starts with 3 lives
self.invulnerable = false; // Invulnerability after being hit
- self.hasTripleShot = false;
- self.hasShield = false;
- self.tripleShotTimer = null;
- self.shieldTimer = null;
- self.speedBoostTimer = null;
- // Thruster particles
- self.thrusterParticles = function () {
- if (LK.ticks % 3 === 0) {
- particleSystem.emit(self.x, self.y + shipGraphics.height / 2, 2);
- }
- };
self.shoot = function () {
if (self.canShoot) {
- // Play shoot sound
- LK.getSound('shoot').play({
- volume: 0.3
- });
- if (self.hasTripleShot) {
- // Triple shot pattern
- for (var i = -1; i <= 1; i++) {
- var bullet = new PlayerBullet();
- bullet.x = self.x + i * 30;
- bullet.y = self.y - shipGraphics.height / 2;
- game.addChild(bullet);
- playerBullets.push(bullet);
- }
- } else {
- // Single shot
- var bullet = new PlayerBullet();
- bullet.x = self.x;
- bullet.y = self.y - shipGraphics.height / 2;
- game.addChild(bullet);
- playerBullets.push(bullet);
- }
+ var bullet = new PlayerBullet();
+ bullet.x = self.x;
+ bullet.y = self.y - shipGraphics.height / 2;
+ game.addChild(bullet);
+ playerBullets.push(bullet);
self.canShoot = false;
LK.setTimeout(function () {
self.canShoot = true;
}, self.shootCooldown);
@@ -315,25 +151,11 @@
self.hit = function () {
if (self.invulnerable) {
return;
}
- // If player has shield, remove it instead of taking damage
- if (self.hasShield) {
- self.setShield(false);
- // Special shield break effect
- particleSystem.emit(self.x, self.y, 30);
- // Brief invulnerability after shield breaks
- self.invulnerable = true;
- LK.setTimeout(function () {
- self.invulnerable = false;
- }, 1000);
- return;
- }
self.lives--;
updateLivesDisplay();
if (self.lives <= 0) {
- // Final explosion effect
- particleSystem.emit(self.x, self.y, 50);
LK.showGameOver();
return;
}
// Make player invulnerable temporarily
@@ -349,189 +171,22 @@
self.invulnerable = false;
}
}, 150);
};
- // Powerup methods
- self.setTripleShot = function (active) {
- self.hasTripleShot = active;
- // Show triple shot status
- showStatusMessage(active ? "TRIPLE SHOT!" : "Triple shot expired", 0x00FFFF);
- // Clear existing timer if any
- if (self.tripleShotTimer) {
- LK.clearTimeout(self.tripleShotTimer);
- }
- // Set timer to remove triple shot
- if (active) {
- self.tripleShotTimer = LK.setTimeout(function () {
- self.setTripleShot(false);
- }, 10000); // 10 seconds
- }
- };
- self.setShield = function (active) {
- self.hasShield = active;
- shieldGraphics.visible = active;
- if (active) {
- // Show shield animation
- shieldGraphics.scale.set(0);
- tween(shieldGraphics.scale, {
- x: 1,
- y: 1
- }, {
- duration: 300
- });
- showStatusMessage("SHIELD ACTIVATED!", 0x0088FF);
- }
- // Clear existing timer if any
- if (self.shieldTimer) {
- LK.clearTimeout(self.shieldTimer);
- }
- // Set timer to remove shield
- if (active) {
- self.shieldTimer = LK.setTimeout(function () {
- if (self.hasShield) {
- self.setShield(false);
- showStatusMessage("Shield expired", 0x0088FF);
- }
- }, 15000); // 15 seconds
- }
- };
- self.setSpeedBoost = function (active) {
- self.speed = active ? self.defaultSpeed * 1.5 : self.defaultSpeed;
- showStatusMessage(active ? "SPEED BOOST!" : "Speed boost expired", 0xFFFF00);
- // Clear existing timer if any
- if (self.speedBoostTimer) {
- LK.clearTimeout(self.speedBoostTimer);
- }
- // Set timer to remove speed boost
- if (active) {
- self.speedBoostTimer = LK.setTimeout(function () {
- self.setSpeedBoost(false);
- }, 8000); // 8 seconds
- }
- };
- self.addLife = function () {
- self.lives++;
- updateLivesDisplay();
- showStatusMessage("EXTRA LIFE!", 0xFF0000);
- };
self.update = function () {
- // Thruster effect
- self.thrusterParticles();
- // Shield rotation effect
- if (self.hasShield) {
- shieldGraphics.rotation += 0.01;
- }
if (self.invulnerable) {
return;
}
- // Check collision with enemy ships
for (var i = 0; i < enemyShips.length; i++) {
if (self.intersects(enemyShips[i])) {
self.hit();
enemyShips[i].explode();
break;
}
}
- // Check collision with enemy bullets
- for (var j = 0; j < enemyBullets.length; j++) {
- if (self.intersects(enemyBullets[j])) {
- self.hit();
- enemyBullets[j].destroy();
- enemyBullets.splice(j, 1);
- break;
- }
- }
- // Check collision with powerups
- for (var k = 0; k < powerups.length; k++) {
- if (self.intersects(powerups[k])) {
- powerups[k].collect();
- break;
- }
- }
};
return self;
});
-// Class for powerups
-var Powerup = Container.expand(function (type) {
- var self = Container.call(this);
- self.type = type || POWERUP_TYPES.TRIPLE_SHOT;
- var powerupGraphics = self.attachAsset('powerup', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Set color based on powerup type
- switch (self.type) {
- case POWERUP_TYPES.TRIPLE_SHOT:
- powerupGraphics.tint = 0x00FFFF;
- break;
- case POWERUP_TYPES.SHIELD:
- powerupGraphics.tint = 0x0000FF;
- break;
- case POWERUP_TYPES.SPEED:
- powerupGraphics.tint = 0xFFFF00;
- break;
- case POWERUP_TYPES.LIFE:
- powerupGraphics.tint = 0xFF0000;
- break;
- }
- // Floating animation
- self.floatOffset = Math.random() * Math.PI * 2;
- self.speed = 2 + Math.random();
- self.update = function () {
- self.y += self.speed;
- self.x += Math.sin((LK.ticks + self.floatOffset) / 20) * 1.5;
- // Add sparkle effect
- if (LK.ticks % 10 === 0) {
- particleSystem.emit(self.x, self.y, 1);
- }
- // Destroy if off-screen
- if (self.y > SCREEN_HEIGHT + powerupGraphics.height) {
- self.destroy();
- var index = powerups.indexOf(self);
- if (index !== -1) {
- powerups.splice(index, 1);
- }
- }
- };
- self.collect = function () {
- // Play powerup sound
- LK.sound.play('powerup', {
- volume: 0.7
- });
- // Apply powerup effect
- switch (self.type) {
- case POWERUP_TYPES.TRIPLE_SHOT:
- player.setTripleShot(true);
- break;
- case POWERUP_TYPES.SHIELD:
- player.setShield(true);
- break;
- case POWERUP_TYPES.SPEED:
- player.setSpeedBoost(true);
- break;
- case POWERUP_TYPES.LIFE:
- player.addLife();
- break;
- }
- // Remove powerup with effect
- tween(powerupGraphics.scale, {
- x: 2,
- y: 2
- }, {
- duration: 200
- });
- tween(powerupGraphics, {
- alpha: 0
- }, {
- duration: 200,
- onFinish: function onFinish() {
- self.destroy();
- powerups.splice(powerups.indexOf(self), 1);
- }
- });
- };
- return self;
-});
/****
* Initialize Game
****/
@@ -541,81 +196,24 @@
/****
* Game Code
****/
+// Using bullet as placeholder - replace with proper explosion
/****
-* Game Constants
-****/
-// Replace with actual sound ID
-// Replace with actual sound ID
-// Replace with actual sound ID
-// Replace with actual powerup image ID
-// Replace with actual background image ID
-// Additional assets
-// Add scrolling background
-var SCREEN_WIDTH = 2048;
-var SCREEN_HEIGHT = 2732;
-var ENEMY_TYPES = {
- BASIC: 'basic',
- FAST: 'fast',
- TANK: 'tank',
- BOSS: 'boss'
-};
-var POWERUP_TYPES = {
- TRIPLE_SHOT: 'tripleShot',
- SHIELD: 'shield',
- SPEED: 'speed',
- LIFE: 'life'
-};
-function createScrollingBackground() {
- var bg1 = game.addChild(LK.getAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
- }));
- var bg2 = game.addChild(LK.getAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
- }));
- bg1.y = 0;
- bg2.y = -SCREEN_HEIGHT;
- game.updateBackground = function () {
- bg1.y += 1;
- bg2.y += 1;
- if (bg1.y >= SCREEN_HEIGHT) {
- bg1.y = bg2.y - SCREEN_HEIGHT;
- }
- if (bg2.y >= SCREEN_HEIGHT) {
- bg2.y = bg1.y - SCREEN_HEIGHT;
- }
- };
-}
-/****
* Game Variables
****/
var playerBullets = [];
-var enemyBullets = [];
var enemyShips = [];
-var powerups = [];
var player = game.addChild(new PlayerShip());
-player.x = SCREEN_WIDTH / 2;
-player.y = SCREEN_HEIGHT - 200;
-// Create particle system
-var particleSystem = game.addChild(new ParticleSystem({
- maxParticles: 200,
- minLifetime: 300,
- maxLifetime: 800,
- minSpeed: 1,
- maxSpeed: 4,
- colors: [0x00FFFF, 0x0088FF, 0xFFFFFF],
- size: 4
-}));
+player.x = 2048 / 2;
+player.y = 2732 - 200;
// Score Display
var scoreText = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
-scoreText.x = SCREEN_WIDTH / 2;
+scoreText.x = 2048 / 2;
scoreText.y = 50;
LK.gui.top.addChild(scoreText);
// Lives Display
var livesText = new Text2('Lives: 3', {
@@ -631,30 +229,18 @@
size: 100,
fill: 0xFFFFFF
});
waveText.anchor.set(1, 0);
-waveText.x = SCREEN_WIDTH - 50;
+waveText.x = 2048 - 50;
waveText.y = 50;
LK.gui.top.addChild(waveText);
-// Status message display
-var statusMessage = new Text2('', {
- size: 100,
- fill: 0xFFFFFF
-});
-statusMessage.anchor.set(0.5, 0);
-statusMessage.x = SCREEN_WIDTH / 2;
-statusMessage.y = 200;
-statusMessage.alpha = 0;
-LK.gui.top.addChild(statusMessage);
// Wave Variables
var waveNumber = 1;
var enemiesPerWave = 5;
var enemiesSpawned = 0;
var waveInProgress = true;
var waveCooldown = false;
-/****
-* Helper Functions
-****/
+// Helper Functions
function updateLivesDisplay() {
livesText.setText('Lives: ' + player.lives);
}
function increaseScore(amount) {
@@ -663,63 +249,22 @@
}
function updateWaveDisplay() {
waveText.setText('Wave: ' + waveNumber);
}
-function showStatusMessage(message, color) {
- statusMessage.setText(message);
- statusMessage.setStyle({
- fill: color || 0xFFFFFF
- });
- statusMessage.alpha = 1;
- // Animation
- statusMessage.scale.set(0.8);
- tween(statusMessage.scale, {
- x: 1,
- y: 1
- }, {
- duration: 300
- });
- // Fade out
- tween(statusMessage, {
- alpha: 0
- }, {
- duration: 1500,
- delay: 1000
- });
-}
-function spawnPowerup(x, y) {
- var types = Object.values(POWERUP_TYPES);
- var type = types[Math.floor(Math.random() * types.length)];
- var powerup = new Powerup(type);
- powerup.x = x;
- powerup.y = y;
- game.addChild(powerup);
- powerups.push(powerup);
-}
// Function to spawn enemies in waves
function spawnEnemy() {
if (!waveInProgress || waveCooldown) {
return;
}
if (enemiesSpawned < enemiesPerWave) {
var enemy;
- var enemyType;
- // Every 3 waves, add a boss as the last enemy
+ // Every 3 waves, add a boss
if (waveNumber > 0 && waveNumber % 3 === 0 && enemiesSpawned === enemiesPerWave - 1) {
- enemyType = ENEMY_TYPES.BOSS;
+ enemy = new BossEnemy();
} else {
- // Determine enemy type based on wave number and random chance
- var random = Math.random();
- if (waveNumber >= 5 && random < 0.2) {
- enemyType = ENEMY_TYPES.TANK;
- } else if (waveNumber >= 3 && random < 0.4) {
- enemyType = ENEMY_TYPES.FAST;
- } else {
- enemyType = ENEMY_TYPES.BASIC;
- }
+ enemy = new EnemyShip();
}
- enemy = new EnemyShip(enemyType);
- enemy.x = Math.random() * SCREEN_WIDTH;
+ enemy.x = Math.random() * 2048;
enemy.y = -100;
game.addChild(enemy);
enemyShips.push(enemy);
enemiesSpawned++;
@@ -739,10 +284,10 @@
size: 250,
fill: 0xFFFFFF
});
newWaveText.anchor.set(0.5, 0.5);
- newWaveText.x = SCREEN_WIDTH / 2;
- newWaveText.y = SCREEN_HEIGHT / 2;
+ newWaveText.x = 2048 / 2;
+ newWaveText.y = 2732 / 2;
game.addChild(newWaveText);
// Animate and remove wave text
tween(newWaveText.scale, {
x: 1.5,
@@ -760,60 +305,39 @@
});
}
});
}
-// Initialize game elements
-function initGame() {
- createScrollingBackground();
- showStatusMessage("GET READY!", 0xFFFFFF);
-}
-// Call initialization
-initGame();
-/****
-* Game update loop
-****/
+// Game update loop
game.update = function () {
- // Update scrolling background
- if (game.updateBackground) {
- game.updateBackground();
- }
- // Update particle system
- particleSystem.update();
// Update player
player.update();
// Update player bullets
for (var i = playerBullets.length - 1; i >= 0; i--) {
if (playerBullets[i]) {
playerBullets[i].update();
}
}
- // Update enemy bullets
- for (var j = enemyBullets.length - 1; j >= 0; j--) {
- if (enemyBullets[j]) {
- enemyBullets[j].update();
+ // Update enemy ships
+ for (var j = enemyShips.length - 1; j >= 0; j--) {
+ if (enemyShips[j]) {
+ enemyShips[j].update();
}
}
- // Update powerups
- for (var l = powerups.length - 1; l >= 0; l--) {
- if (powerups[l]) {
- powerups[l].update();
- }
- }
// Check for collisions between player bullets and enemy ships
- for (var m = playerBullets.length - 1; m >= 0; m--) {
- if (!playerBullets[m]) {
+ for (var k = playerBullets.length - 1; k >= 0; k--) {
+ if (!playerBullets[k]) {
continue;
}
- for (var n = enemyShips.length - 1; n >= 0; n--) {
- if (!enemyShips[n]) {
+ for (var l = enemyShips.length - 1; l >= 0; l--) {
+ if (!enemyShips[l]) {
continue;
}
- if (playerBullets[m] && enemyShips[n] && playerBullets[m].intersects(enemyShips[n])) {
+ if (playerBullets[k] && enemyShips[l] && playerBullets[k].intersects(enemyShips[l])) {
// Enemy hit by bullet
- var destroyed = enemyShips[n].hit();
+ var destroyed = enemyShips[l].hit();
// Remove bullet
- playerBullets[m].destroy();
- playerBullets.splice(m, 1);
+ playerBullets[k].destroy();
+ playerBullets.splice(k, 1);
break;
}
}
}
@@ -831,263 +355,12 @@
}
};
// Handle player movement
game.move = function (x, y, obj) {
- // Calculate movement based on speed
- var targetX = x;
- var currentX = player.x;
- var dx = targetX - currentX;
- // Apply player speed
- if (Math.abs(dx) > player.speed) {
- dx = Math.sign(dx) * player.speed;
- }
// Constrain player to screen boundaries
var halfWidth = player.getChildAt(0).width / 2;
- player.x = Math.min(Math.max(currentX + dx, halfWidth), SCREEN_WIDTH - halfWidth);
+ player.x = Math.min(Math.max(x, halfWidth), 2048 - halfWidth);
};
// Handle shooting
game.down = function (x, y, obj) {
player.shoot();
-};
-// Add pause/resume functionality
-LK.gui.pauseButton = function () {
- var pauseBtn = new Container();
- var pauseBg = new Graphics();
- pauseBg.beginFill(0x000000, 0.5);
- pauseBg.drawCircle(0, 0, 40);
- pauseBg.endFill();
- pauseBtn.addChild(pauseBg);
- var pauseIcon = new Graphics();
- pauseIcon.beginFill(0xFFFFFF);
- pauseIcon.drawRect(-15, -15, 10, 30);
- pauseIcon.drawRect(5, -15, 10, 30);
- pauseIcon.endFill();
- pauseBtn.addChild(pauseIcon);
- pauseBtn.x = SCREEN_WIDTH - 60;
- pauseBtn.y = 60;
- pauseBtn.interactive = true;
- pauseBtn.down = function () {
- showPauseMenu();
- showPauseMenu();
- };
- return pauseBtn;
-};
-// Custom pause menu
-function showPauseMenu() {
- var pauseMenu = new Container();
- var overlay = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0x000000,
- alpha: 0.7,
- scaleX: SCREEN_WIDTH / 100,
- scaleY: SCREEN_HEIGHT / 100
- });
- pauseMenu.addChild(overlay);
- var title = new Text2("PAUSED", {
- size: 200,
- fill: 0xFFFFFF
- });
- title.anchor.set(0.5, 0.5);
- title.x = SCREEN_WIDTH / 2;
- title.y = SCREEN_HEIGHT / 3;
- pauseMenu.addChild(title);
- var resumeBtn = createButton("RESUME", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, function () {
- pauseMenu.destroy();
- LK.resumeGame();
- });
- pauseMenu.addChild(resumeBtn);
- var restartBtn = createButton("RESTART", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 150, function () {
- pauseMenu.destroy();
- LK.showGameOver();
- });
- pauseMenu.addChild(restartBtn);
- LK.gui.addChild(pauseMenu);
-}
-// Helper function to create buttons
-function createButton(text, x, y, callback) {
- var button = new Container();
- var bg = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0x333333,
- scaleX: 3,
- scaleY: 0.8
- });
- button.addChild(bg);
- var label = new Text2(text, {
- size: 60,
- fill: 0xFFFFFF
- });
- label.anchor.set(0.5, 0.5);
- button.addChild(label);
- button.x = x;
- button.y = y;
- button.interactive = true;
- button.down = function () {
- // Button press effect
- button.scale.set(0.95);
- LK.setTimeout(function () {
- button.scale.set(1);
- if (callback) {
- callback();
- }
- }, 100);
- };
- return button;
-}
-// Custom game over screen
-LK.showGameOver = function () {
- var gameOver = new Container();
- var overlay = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0x000000,
- alpha: 0.8,
- scaleX: SCREEN_WIDTH / 100,
- scaleY: SCREEN_HEIGHT / 100
- });
- gameOver.addChild(overlay);
- var title = new Text2("GAME OVER", {
- size: 200,
- fill: 0xFF0000
- });
- title.anchor.set(0.5, 0.5);
- title.x = SCREEN_WIDTH / 2;
- title.y = SCREEN_HEIGHT / 3;
- gameOver.addChild(title);
- var scoreDisplay = new Text2("SCORE: " + LK.getScore(), {
- size: 120,
- fill: 0xFFFFFF
- });
- scoreDisplay.anchor.set(0.5, 0.5);
- scoreDisplay.x = SCREEN_WIDTH / 2;
- scoreDisplay.y = SCREEN_HEIGHT / 2;
- gameOver.addChild(scoreDisplay);
- var waveDisplay = new Text2("WAVES COMPLETED: " + (waveNumber - 1), {
- size: 80,
- fill: 0xFFFFFF
- });
- waveDisplay.anchor.set(0.5, 0.5);
- waveDisplay.x = SCREEN_WIDTH / 2;
- waveDisplay.y = SCREEN_HEIGHT / 2 + 100;
- gameOver.addChild(waveDisplay);
- var restartBtn = createButton("PLAY AGAIN", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 250, function () {
- gameOver.destroy();
- LK.showGameOver();
- });
- gameOver.addChild(restartBtn);
- // Add final explosion particles
- for (var i = 0; i < 10; i++) {
- LK.setTimeout(function () {
- particleSystem.emit(SCREEN_WIDTH / 2 + (Math.random() * 500 - 250), SCREEN_HEIGHT / 2 + (Math.random() * 500 - 250), 30);
- }, i * 200);
- }
- LK.gui.addChild(gameOver);
- showPauseMenu();
-};
-// Add a start menu
-function showStartMenu() {
- var startMenu = new Container();
- var overlay = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0x000033,
- alpha: 0.9,
- scaleX: SCREEN_WIDTH / 100,
- scaleY: SCREEN_HEIGHT / 100
- });
- startMenu.addChild(overlay);
- var title = new Text2("SPACE SHOOTER", {
- size: 200,
- fill: 0x00FFFF
- });
- title.anchor.set(0.5, 0.5);
- title.x = SCREEN_WIDTH / 2;
- title.y = SCREEN_HEIGHT / 3;
- startMenu.addChild(title);
- var startBtn = createButton("START GAME", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 100, function () {
- startMenu.destroy();
- // Show tutorial message
- showStatusMessage("TAP TO SHOOT, DRAG TO MOVE", 0xFFFFFF);
- });
- startMenu.addChild(startBtn);
- // Add stars effect
- for (var i = 0; i < 50; i++) {
- var star = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0xFFFFFF,
- scaleX: (1 + Math.random() * 3) / 10,
- scaleY: (1 + Math.random() * 3) / 10,
- alpha: 0.3 + Math.random() * 0.7
- });
- star.x = Math.random() * SCREEN_WIDTH;
- star.y = Math.random() * SCREEN_HEIGHT;
- // Twinkle animation
- (function (s) {
- var duration = 1000 + Math.random() * 2000;
- var _animate = function animate() {
- tween(s, {
- alpha: 0.2 + Math.random() * 0.8
- }, {
- duration: duration,
- onFinish: _animate
- });
- };
- _animate();
- })(star);
- startMenu.addChild(star);
- }
- LK.gui.addChild(startMenu);
- showPauseMenu();
-}
-// Show start menu on game load
-LK.setTimeout(function () {
- showStartMenu();
-}, 100);
-// Add cheats for debugging
-var cheats = {
- invincible: false,
- toggleInvincible: function toggleInvincible() {
- this.invincible = !this.invincible;
- player.invulnerable = this.invincible;
- showStatusMessage("Invincibility: " + (this.invincible ? "ON" : "OFF"), 0xFFFF00);
- },
- addLife: function addLife() {
- player.addLife();
- },
- skipWave: function skipWave() {
- enemyShips.forEach(function (ship) {
- ship.explode();
- });
- enemyShips = [];
- waveInProgress = false;
- },
- activateAllPowerups: function activateAllPowerups() {
- player.setTripleShot(true);
- player.setShield(true);
- player.setSpeedBoost(true);
- }
-};
-// Uncomment to enable console cheats
-/*
-LK.console = function(command) {
-switch (command) {
-case "god":
-cheats.toggleInvincible();
-break;
-case "life":
-cheats.addLife();
-break;
-case "skip":
-cheats.skipWave();
-break;
-case "power":
-cheats.activateAllPowerups();
-break;
-default:
-return "Unknown command";
-}
-return "Command executed: " + command;
-};
-*/
\ No newline at end of file
+};
\ No newline at end of file
A 2D top-down view of a futuristic player spaceship with a streamlined silver and blue body, glowing thrusters, and dual laser cannons. The design is sleek and modern for a space shooter game. Single Game Texture. 2d. Blank background. High contrast. No shadows
A 2D top-down view of an alien spaceship with a dark metallic body, glowing red energy cores, and sharp angular wings. The design is sleek and futuristic, suitable for a space shooter game.. Single Game Texture. 2d. Blank background. High contrast. No shadows
A 2D top-down view of a futuristic energy bullet for a space shooter game. The bullet is a glowing blue plasma projectile with a sleek, elongated shape and a slight energy trail behind it. The design is simple, bright, and high-speed-looking, suitable for fast-paced shooting gameplay. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
A 2D top-down view of a futuristic energy bullet for a space shooter game. The bullet is a glowing red plasma projectile elongated shape and a slight energy trail behind it. The design is simple, bright, and high-speed-looking, suitable for fast-paced shooting gameplay. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
A vibrant and dynamic 2D space background for a top-down space shooter game. The scene features a deep, dark space filled with glowing nebulae in shades of blue and purple, scattered distant stars, and swirling cosmic dust. A subtle parallax effect is suggested with faintly glowing planets and asteroids in the background. The atmosphere is slightly mysterious and futuristic, with soft light gradients to create depth. The overall tone is immersive but does not distract from gameplay, ensuring clear visibility of player and enemy ships.. Single Game Texture. Blank background. High contrast. No shadows
A vibrant and dynamic 2D space background for a top-down space shooter game. The scene features a deep, dark space filled with glowing nebulae in shades of blue and purple, scattered distant stars, and swirling cosmic dust. A subtle parallax effect is suggested with faintly glowing planets and asteroids in the background. The atmosphere is slightly mysterious and futuristic, with soft light gradients to create depth. The overall tone is immersive but does not distract from gameplay, ensuring clear visibility of player and enemy ships.. Single Game Texture. Blank background. High contrast. No shadows
powerup boll. Single Game Texture. Blank background. High contrast. No shadows