User prompt
add boss boss and improve game
User prompt
improve game
User prompt
add
Code edit (1 edits merged)
Please save this source code
User prompt
the enemyies are vibrating some time pls solve
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (enemyGraphics.height && self.y > 2732 + enemyGraphics.height / 2) {' Line Number: 157 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (self.y > 2732 + enemyGraphics.height / 2) {' Line Number: 157 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'tween(enemyGraphics.scale, {' Line Number: 44 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (self.y > 2732 + enemyGraphics.height / 2) {' Line Number: 157
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446
User prompt
Please fix the bug: 'Unable to load plugin: @upit/tween.v1 - Cannot read properties of undefined (reading '@upit/tween.v1')' in or related to this line: 'var tween = LK.import("@upit/tween.v1").tween;' Line Number: 466 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'self.targetY = y;' Line Number: 424
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'self.targetY = y;' Line Number: 424
User prompt
Please fix the bug: 'Uncaught TypeError: flashGraphics.beginFill is not a function' in or related to this line: 'flashGraphics.beginFill(0x00FFFF, 0.8);' Line Number: 320
User prompt
Please fix the bug: 'Uncaught TypeError: Graphics is not a constructor' in or related to this line: 'var flash = new Graphics();' Line Number: 310
User prompt
Please fix the bug: 'tween.to is not a function' in or related to this line: 'tween.to(shipGraphics, {' Line Number: 295 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 441
Code edit (1 edits merged)
Please save this source code
User prompt
remove explosion
User prompt
Please fix the bug: 'Uncaught Error: getChildAt: Supplied index 0 does not exist in the child list, or the supplied DisplayObject must be a child of the caller' in or related to this line: 'var halfWidth = player.getChildAt(0).width / 2;' Line Number: 368
Code edit (1 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
===================================================================
--- original.js
+++ change.js
@@ -5,69 +5,154 @@
/****
* Classes
****/
-// Class for enemy ships with wave-based spawning and better animation
+// Class for enemy ships with enhanced animation and movement patterns
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
+ // Enhanced spawn animation: Spiral entry with rotation
enemyGraphics.scale.set(0);
enemyGraphics.alpha = 0;
- tween(enemyGraphics.scale, {
- x: 1,
- y: 1
+ enemyGraphics.rotation = Math.PI * 2; // Start with a full rotation
+ // Sequence of animations for more interesting entry
+ tween(enemyGraphics, {
+ alpha: 1,
+ rotation: 0
}, {
- duration: 500
+ duration: 800,
+ easing: "easeOutQuad"
});
- tween(enemyGraphics, {
- alpha: 1
+ tween(enemyGraphics.scale, {
+ x: 1.2,
+ y: 1.2
}, {
- duration: 500
+ duration: 600,
+ easing: "easeOutBack",
+ onFinish: function onFinish() {
+ tween(enemyGraphics.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 300,
+ easing: "easeInOutQuad"
+ });
+ }
});
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.driftAmount = 3 + Math.random() * 2; // Enhanced side drift range with randomness
+ self.driftSpeed = 50 + Math.random() * 30; // More variation in drift speed
self.health = 1; // Basic enemies have 1 health
+ self.movementPattern = Math.floor(Math.random() * 3); // Random movement pattern (0, 1, or 2)
+ self.startX = 0; // Will be set when enemy is added to stage
+ self.startTime = LK.ticks; // Remember when enemy was created for time-based patterns
self.hit = function () {
self.health -= 1;
if (self.health <= 0) {
self.explode();
return true; // Enemy destroyed
}
- // Flash effect when hit but not destroyed
+ // Enhanced hit effect: Shake and flash
+ var originalX = self.x;
+ var shakeTimes = 0;
+ var shakeInterval = LK.setInterval(function () {
+ self.x = originalX + (Math.random() * 20 - 10);
+ shakeTimes++;
+ if (shakeTimes >= 5) {
+ LK.clearInterval(shakeInterval);
+ self.x = originalX;
+ }
+ }, 50);
+ // Flash red then back to normal
+ enemyGraphics.tint = 0xFF0000;
tween(enemyGraphics, {
- alpha: 0.2
+ alpha: 0.5
}, {
duration: 100,
onFinish: function onFinish() {
tween(enemyGraphics, {
alpha: 1
}, {
- duration: 100
+ duration: 100,
+ onFinish: function onFinish() {
+ enemyGraphics.tint = 0xFFFFFF; // Reset tint
+ }
});
}
});
return false; // Enemy still alive
};
self.explode = function () {
+ // Create explosion effect before destroying
+ var explosion = new Container();
+ var explosionGraphics = explosion.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ explosion.x = self.x;
+ explosion.y = self.y;
+ explosionGraphics.scale.set(0.1);
+ explosionGraphics.alpha = 0.8;
+ game.addChild(explosion);
+ // Animate explosion
+ tween(explosionGraphics.scale, {
+ x: 1.5,
+ y: 1.5
+ }, {
+ duration: 500,
+ easing: "easeOutQuad"
+ });
+ tween(explosionGraphics, {
+ alpha: 0
+ }, {
+ duration: 800,
+ onFinish: function onFinish() {
+ explosion.destroy();
+ }
+ });
+ // Remove enemy
self.destroy();
enemyShips.splice(enemyShips.indexOf(self), 1);
// Add score
increaseScore(self.scoreValue || 1);
};
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
+ var timeSinceSpawn = LK.ticks - self.startTime;
+ // Apply different movement patterns based on enemy type
+ switch (self.movementPattern) {
+ case 0:
+ // Standard vertical movement with sine wave drift
+ self.y += self.speed;
+ self.x = self.startX + Math.sin(LK.ticks / self.driftSpeed) * self.driftAmount * 5;
+ break;
+ case 1:
+ // Zigzag pattern
+ self.y += self.speed;
+ self.x = self.startX + Math.sin(LK.ticks / (self.driftSpeed * 0.5)) * self.driftAmount * 10;
+ // Rotate ship to match movement direction
+ var angleOffset = Math.cos(LK.ticks / (self.driftSpeed * 0.5)) * 0.2;
+ enemyGraphics.rotation = angleOffset;
+ break;
+ case 2:
+ // Circular pattern
+ self.y += self.speed * 0.7; // Slower vertical movement
+ var circleRadius = 50 + Math.random() * 30;
+ self.x = self.startX + Math.sin(timeSinceSpawn / (self.driftSpeed * 0.8)) * circleRadius;
+ // Add slight rotation for visual effect
+ enemyGraphics.rotation = Math.sin(timeSinceSpawn / 500) * 0.1;
+ break;
+ }
+ // Destroy if off-screen with enhanced fade-out effect
if (self.y > 2732 + enemyGraphics.height / 2) {
tween(enemyGraphics, {
- alpha: 0
+ alpha: 0,
+ rotation: Math.PI // Rotate while fading out
}, {
duration: 500,
+ easing: "easeInQuad",
onFinish: function onFinish() {
self.destroy();
var index = enemyShips.indexOf(self);
if (index !== -1) {
@@ -78,17 +163,72 @@
}
};
return self;
});
-// Class for tougher enemy ships
+// Class for tougher enemy ships with enhanced boss behaviors
var BossEnemy = EnemyShip.expand(function () {
var self = EnemyShip.call(this);
// Make boss larger
- self.getChildAt(0).scale.set(1.5);
+ self.getChildAt(0).scale.set(0);
+ // More impressive boss entrance
+ tween(self.getChildAt(0).scale, {
+ x: 1.8,
+ y: 1.8
+ }, {
+ duration: 1200,
+ easing: "easeOutElastic"
+ });
// Make boss tougher
self.health = 5;
self.speed = 1.5;
self.scoreValue = 5;
+ // Override boss movement pattern
+ self.movementPattern = 3; // Special boss pattern
+ self.attackCooldown = 0;
+ // Override update method for boss-specific behavior
+ var parentUpdate = self.update;
+ self.update = function () {
+ // Special boss movement: hover at the top area and move side to side
+ if (self.y < 400) {
+ self.y += self.speed;
+ } else {
+ // Wide side-to-side movement
+ self.x = 2048 / 2 + Math.sin(LK.ticks / 100) * 800;
+ // Periodically perform special attack (rotate)
+ self.attackCooldown--;
+ if (self.attackCooldown <= 0) {
+ // Start a spin attack
+ tween(self.getChildAt(0), {
+ rotation: self.getChildAt(0).rotation + Math.PI * 2
+ }, {
+ duration: 1000,
+ easing: "easeInOutQuad"
+ });
+ // Reset cooldown
+ self.attackCooldown = 300;
+ }
+ }
+ };
+ // Override hit method for boss-specific effect
+ var parentHit = self.hit;
+ self.hit = function () {
+ // Flash the boss with a different color on each hit
+ var hitColors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF];
+ var colorIndex = 5 - self.health;
+ self.getChildAt(0).tint = hitColors[colorIndex];
+ // Flash the screen slightly
+ var flashOverlay = new Graphics();
+ flashOverlay.beginFill(0xFFFFFF, 0.2);
+ flashOverlay.drawRect(0, 0, 2048, 2732);
+ flashOverlay.endFill();
+ game.addChild(flashOverlay);
+ // Remove the flash overlay
+ LK.setTimeout(function () {
+ game.removeChild(flashOverlay);
+ flashOverlay.destroy();
+ }, 100);
+ return parentHit.call(self);
+ };
return self;
});
// Class for player bullets with proper destruction
var PlayerBullet = Container.expand(function () {
@@ -96,22 +236,39 @@
var bulletGraphics = self.attachAsset('playerBullet', {
anchorX: 0.5,
anchorY: 0.5
});
+ // Enhanced bullet appearance
+ bulletGraphics.alpha = 0;
+ tween(bulletGraphics, {
+ alpha: 1
+ }, {
+ duration: 100
+ });
self.speed = -15;
self.update = function () {
self.y += self.speed;
+ // Add slight wobble to bullets
+ self.x += Math.sin(LK.ticks / 10) * 0.5;
if (self.y < -bulletGraphics.height) {
- self.destroy();
- var index = playerBullets.indexOf(self);
- if (index !== -1) {
- playerBullets.splice(index, 1);
- }
+ // Fade out bullets that miss
+ tween(bulletGraphics, {
+ alpha: 0
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ 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
+// Class for the player's ship with enhanced movement and effects
var PlayerShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
@@ -121,15 +278,58 @@
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.targetX = null; // Target X position for smooth movement
+ self.targetY = null; // Target Y position for smooth movement
+ // Player ship entrance animation
+ shipGraphics.alpha = 0;
+ shipGraphics.y = 100;
+ tween(shipGraphics, {
+ alpha: 1,
+ y: 0
+ }, {
+ duration: 1000,
+ easing: "easeOutQuad"
+ });
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);
+ // Add muzzle flash effect
+ var flash = new Graphics();
+ flash.beginFill(0x00FFFF, 0.8);
+ flash.drawCircle(0, 0, 20);
+ flash.endFill();
+ flash.x = self.x;
+ flash.y = self.y - shipGraphics.height / 2;
+ game.addChild(flash);
+ // Animate and remove flash
+ tween(flash.scale, {
+ x: 0,
+ y: 0
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ flash.destroy();
+ }
+ });
+ // Add slight recoil effect
+ tween(shipGraphics, {
+ y: 5
+ }, {
+ duration: 50,
+ onFinish: function onFinish() {
+ tween(shipGraphics, {
+ y: 0
+ }, {
+ duration: 100
+ });
+ }
+ });
self.canShoot = false;
LK.setTimeout(function () {
self.canShoot = true;
}, self.shootCooldown);
@@ -141,13 +341,59 @@
}
self.lives--;
updateLivesDisplay();
if (self.lives <= 0) {
- LK.showGameOver();
+ // Add dramatic death animation
+ var explosions = 5;
+ var explodeInterval = LK.setInterval(function () {
+ var explosion = new Container();
+ var explosionGraphics = explosion.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ explosion.x = self.x + (Math.random() * 100 - 50);
+ explosion.y = self.y + (Math.random() * 100 - 50);
+ explosionGraphics.scale.set(0.1);
+ explosionGraphics.alpha = 0.8;
+ game.addChild(explosion);
+ tween(explosionGraphics.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 500
+ });
+ tween(explosionGraphics, {
+ alpha: 0
+ }, {
+ duration: 800,
+ onFinish: function onFinish() {
+ explosion.destroy();
+ }
+ });
+ explosions--;
+ if (explosions <= 0) {
+ LK.clearInterval(explodeInterval);
+ self.visible = false;
+ LK.showGameOver();
+ }
+ }, 150);
return;
}
// Make player invulnerable temporarily
self.invulnerable = true;
+ // Enhanced hit effect with shake
+ var originalX = self.x;
+ var shakeAmount = 15;
+ var shakeTimes = 0;
+ var shakeInterval = LK.setInterval(function () {
+ self.x = originalX + (Math.random() * shakeAmount - shakeAmount / 2);
+ shakeAmount *= 0.9;
+ shakeTimes++;
+ if (shakeTimes >= 10) {
+ LK.clearInterval(shakeInterval);
+ self.x = originalX;
+ }
+ }, 50);
// Flash effect
var flashCount = 0;
var flashInterval = LK.setInterval(function () {
shipGraphics.alpha = shipGraphics.alpha === 1 ? 0.3 : 1;
@@ -158,17 +404,39 @@
self.invulnerable = false;
}
}, 150);
};
+ // Move player ship to target position with smooth animation
+ self.moveToPosition = function (x, y) {
+ self.targetX = x;
+ self.targetY = y;
+ };
self.update = function () {
- if (self.invulnerable) {
- return;
+ // Smooth movement toward target position
+ if (self.targetX !== null && self.targetY !== null) {
+ var dx = self.targetX - self.x;
+ var dy = self.targetY - self.y;
+ // Only move if the distance is significant
+ if (Math.abs(dx) > 1 || Math.abs(dy) > 1) {
+ self.x += dx * 0.1;
+ self.y += dy * 0.1;
+ // Slight tilt effect based on horizontal movement
+ var tiltAmount = -dx * 0.0005;
+ tiltAmount = Math.max(-0.2, Math.min(0.2, tiltAmount));
+ shipGraphics.rotation = tiltAmount;
+ } else {
+ // Reached target, reset rotation
+ shipGraphics.rotation = 0;
+ }
}
- for (var i = 0; i < enemyShips.length; i++) {
- if (self.intersects(enemyShips[i])) {
- self.hit();
- enemyShips[i].explode();
- break;
+ // Check for collisions with enemies if not invulnerable
+ if (!self.invulnerable) {
+ for (var i = 0; i < enemyShips.length; i++) {
+ if (self.intersects(enemyShips[i])) {
+ self.hit();
+ enemyShips[i].explode();
+ break;
+ }
}
}
};
return self;
@@ -183,9 +451,8 @@
/****
* Game Code
****/
-// Using bullet as placeholder - replace with proper explosion
/****
* Game Variables
****/
var playerBullets = [];
@@ -236,9 +503,9 @@
}
function updateWaveDisplay() {
waveText.setText('Wave: ' + waveNumber);
}
-// Function to spawn enemies in waves
+// Function to spawn enemies in waves with enhanced patterns
function spawnEnemy() {
if (!waveInProgress || waveCooldown) {
return;
}
@@ -246,12 +513,14 @@
var enemy;
// Every 3 waves, add a boss
if (waveNumber > 0 && waveNumber % 3 === 0 && enemiesSpawned === enemiesPerWave - 1) {
enemy = new BossEnemy();
+ enemy.x = 2048 / 2; // Boss appears in center
} else {
enemy = new EnemyShip();
+ enemy.x = 200 + Math.random() * (2048 - 400); // Random position, avoiding edges
}
- enemy.x = Math.random() * 2048;
+ enemy.startX = enemy.x; // Store starting X for movement patterns
enemy.y = -100;
game.addChild(enemy);
enemyShips.push(enemy);
enemiesSpawned++;
@@ -265,28 +534,32 @@
updateWaveDisplay();
enemiesPerWave += 2; // Increase difficulty each wave
enemiesSpawned = 0;
waveInProgress = true;
- // Display wave number
+ // Enhanced wave announcement with scaling and color
var newWaveText = new Text2('WAVE ' + waveNumber, {
size: 250,
- fill: 0xFFFFFF
+ fill: 0x00FFFF
});
newWaveText.anchor.set(0.5, 0.5);
newWaveText.x = 2048 / 2;
newWaveText.y = 2732 / 2;
+ newWaveText.scale.set(0.5);
game.addChild(newWaveText);
// Animate and remove wave text
tween(newWaveText.scale, {
- x: 1.5,
- y: 1.5
+ x: 1.8,
+ y: 1.8
}, {
duration: 800,
+ easing: "easeOutElastic",
onFinish: function onFinish() {
tween(newWaveText, {
- alpha: 0
+ alpha: 0,
+ y: newWaveText.y - 100
}, {
duration: 500,
+ easing: "easeInQuad",
onFinish: function onFinish() {
newWaveText.destroy();
}
});
@@ -340,17 +613,12 @@
waveCooldown = false;
}, 2000);
}
};
-// Handle player movement
+// Handle player movement - Update to allow free movement
game.move = function (x, y, obj) {
- // Constrain player to screen boundaries
- if (player.children.length > 0) {
- var halfWidth = player.getChildAt(0).width / 2;
- } else {
- var halfWidth = 0; // Default to 0 if no children
- }
- player.x = Math.min(Math.max(x, halfWidth), 2048 - halfWidth);
+ // Set target position for smooth movement anywhere on screen
+ player.moveToPosition(x, y);
};
// Handle shooting
game.down = function (x, y, obj) {
player.shoot();
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