User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'LK.audio.play')' in or related to this line: 'LK.audio.play('shootSound'); // Play shoot sound effect' Line Number: 67
User prompt
Make a shoot sound effect after the hero shoots a bullet
User prompt
The boss enemy doesn’t move can you fix it?
User prompt
The boss enemy is spawning on wave one can you fix it..
User prompt
Make a boss enemy spawn every 5 waves
User prompt
Sometimes the color selector makes you click it multiple times before changing the color of the hero can you fix it
User prompt
Make text that says what color your hero is
User prompt
The color selector Dosnt work
User prompt
Fix Bug: 'Script error.' in or related to this line: 'var colorSelector = game.addChild(new ColorSelector());' Line Number: 233
User prompt
Make arrows for the player to chose the color of the hero
User prompt
Make a color selector for the player to choose the color of the hero
User prompt
Make stars in the background
User prompt
Spawn a Boss 2.0 at wave 20 and 30 and 25
User prompt
Make a boss 2.0
User prompt
Fix Bug: 'ReferenceError: Can't find variable: stars' in or related to this line: 'for (var i = 0; i < stars.length; i++) {' Line Number: 202
User prompt
Fix Bug: 'ReferenceError: Can't find variable: stars' in or related to this line: 'for (var i = 0; i < stars.length; i++) {' Line Number: 202
User prompt
Spawn a random number of weak enemys from 1-6
User prompt
Start the wave counter at 1
User prompt
Spawn a random amount of enemys and weak enemys from 1-3
User prompt
Start the wave counter at wave 0
User prompt
Start the wave counter at 0
User prompt
Spawn 4 weak enemys and 1 enemy
User prompt
On wave 1 spawn 4 weak enemy and one enemy
User prompt
Make a weak enemy asset
User prompt
Why do some of the enemys have 1 health?
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,30 @@
/****
* Classes
****/
+var Star = Container.expand(function () {
+ var self = Container.call(this);
+ var starGraphics = self.attachAsset('whiteStar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Set a random scale for the star to vary its size
+ var scale = Math.random() * 0.5 + 0.5;
+ self.scaleX = scale;
+ self.scaleY = scale;
+ // Set a random alpha for the star to vary its brightness
+ self.alpha = Math.random() * 0.5 + 0.5;
+ // Set a random speed for the star to move downwards
+ self.speed = Math.random() * 1 + 0.5;
+ self.move = function () {
+ self.y += self.speed;
+ // Reset star position if it moves off screen
+ if (self.y > 2732) {
+ self.y = -10;
+ self.x = Math.random() * 2048;
+ }
+ };
+});
// Define the Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
@@ -74,71 +97,57 @@
self.move = function () {
self.y += self.speed;
};
});
-// Define the BossEnemy 2.0 class with enhanced features
-var BossEnemy2 = Container.expand(function () {
+// Define the BossEnemy class
+var BossEnemy = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('bossEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
- // Initialize boss 2.0-specific properties
- self.health = 10; // Boss 2.0 has more health
- self.speed = 3; // Boss 2.0 moves slightly faster
- self.shootInterval = 20; // Boss 2.0 shoots more frequently
- self.lastShotTick = 0;
- self.directionX = Math.random() < 0.5 ? -1 : 1;
- self.directionY = Math.random() < 0.5 ? -1 : 1;
- self.specialAttackInterval = 180; // Boss 2.0 has a special attack every 3 seconds
- self.lastSpecialAttackTick = 0;
+ // Initialize boss-specific properties
+ self.health = 50; // Boss has more health
+ self.speed = 2; // Boss moves slower
+ self.shootInterval = 21; // Boss shoots every 0.35 seconds at 60FPS
+ self.lastShotTick = 0; // Track the last shot tick
self.update = function () {
+ // Boss update logic with structured movement
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
+ // Reverse direction when hitting the screen boundaries
if (self.x <= 100 || self.x >= 1948) {
self.directionX *= -1;
}
if (self.y <= 100 || self.y >= 2732 / 2 - 100) {
self.directionY *= -1;
}
+ // Boss specific logic for shooting
self.shoot();
- self.specialAttack();
};
self.shoot = function () {
if (LK.ticks - self.lastShotTick >= self.shootInterval) {
var bullet = new EnemyBullet();
bullet.x = self.x;
- bullet.y = self.y + 50;
+ bullet.y = self.y + 50; // Adjust bullet start position
enemyBullets.push(bullet);
game.addChild(bullet);
self.lastShotTick = LK.ticks;
}
};
- self.specialAttack = function () {
- if (LK.ticks - self.lastSpecialAttackTick >= self.specialAttackInterval) {
- // Special attack logic (e.g., shooting multiple bullets)
- self.lastSpecialAttackTick = LK.ticks;
- }
- };
});
var WaveManager = Container.expand(function () {
var self = Container.call(this);
self.waveCount = -1;
self.enemiesPerWave = self.waveCount === 0 ? 6 : 5;
self.enemies = [];
self.createWave = function () {
- if (self.waveCount === 19 || self.waveCount === 24 || self.waveCount === 29) {
- // Wave 20, 25, 30: Spawn 1 BossEnemy2 and 2 regular Enemies
- var bossEnemy2 = game.addChild(new BossEnemy2());
- bossEnemy2.x = 2048 / 2; // Start in the middle of the screen
- bossEnemy2.y = 2732 / 4; // Start in the upper part of the screen
- self.enemies.push(bossEnemy2);
- for (var i = 0; i < 2; i++) {
- var enemy = game.addChild(new Enemy());
- enemy.x = Math.random() * (2048 - 100) + 50;
- enemy.y = Math.random() * (2732 / 2 - 200) + 100;
- self.enemies.push(enemy);
- }
+ if (self.waveCount === 4) {
+ // Wave 5: Spawn a BossEnemy instead of regular enemies
+ var bossEnemy = game.addChild(new BossEnemy());
+ bossEnemy.x = 2048 / 2; // Start in the middle of the screen
+ bossEnemy.y = 2732 / 4; // Start in the upper part of the screen
+ self.enemies.push(bossEnemy);
} else {
// Other waves: Spawn regular enemies
for (var i = 0; i < self.enemiesPerWave; i++) {
var enemy = game.addChild(new Enemy());
@@ -158,24 +167,8 @@
anchorX: 0.5,
anchorY: 0.5
});
});
-var Star = Container.expand(function () {
- var self = Container.call(this);
- var starGraphics = self.attachAsset('whiteStar', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = Math.random() * 2 + 1; // Random speed between 1 and 3
- self.move = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- // Reset star position if it moves off the bottom of the screen
- self.y = -5;
- self.x = Math.random() * 2048;
- }
- };
-});
/****
* Initialize Game
****/
@@ -185,8 +178,23 @@
/****
* Game Code
****/
+var stars = [];
+for (var i = 0; i < 100; i++) {
+ var star = new Star();
+ star.x = Math.random() * 2048;
+ star.y = Math.random() * 2732;
+ stars.push(star);
+ game.addChild(star);
+}
+// Update the stars in the game tick event
+LK.on('tick', function () {
+ for (var i = 0; i < stars.length; i++) {
+ stars[i].move();
+ }
+ // Existing game tick code...
+});
var waveManager = game.addChild(new WaveManager());
var waveCounterTxt = new Text2('Wave: 0', {
size: 100,
fill: "#ffffff"
@@ -201,25 +209,10 @@
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
var blocks = [];
-// Initialize the stars array to store Star instances
-var stars = [];
// Game tick event
LK.on('tick', function () {
- // Update stars
- for (var i = 0; i < stars.length; i++) {
- stars[i].move();
- }
- // Create new stars
- if (stars.length < 50) {
- // Limit the number of stars to 50
- var newStar = new Star();
- newStar.x = Math.random() * 2048;
- newStar.y = Math.random() * 2732;
- stars.push(newStar);
- game.addChild(newStar);
- }
// Update hero
hero.update();
// Update enemies
for (var i = 0; i < waveManager.enemies.length; i++) {
@@ -304,6 +297,6 @@
hero.x = pos.x;
});
// Ensure the hero stays within the game boundaries
Hero.prototype.update = function () {
- this.x = Math.max(0, Math.min(this.x, 2048 - this.width));
+ this.x = Math.max(50, Math.min(this.x, 2048 - 50));
};
\ No newline at end of file