User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'speed')' in or related to this line: 'self.speed = -15; // Increase speed for special bullets' Line Number: 69
User prompt
Can u help making special bullet button in screen
User prompt
Add button to shoot different bullet
User prompt
Remove all turret related codes
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'bombButton.x = frenzyButton.x;' Line Number: 645
User prompt
put red orb button over frenzy button
User prompt
ADD BUTTON TO SHOOT RED ORB
User prompt
Please fix the bug: 'Uncaught ReferenceError: redOrbButton is not defined' in or related to this line: 'redOrbButton.x = 2048 - redOrbButton.width / 2 - 100;' Line Number: 659
User prompt
Please fix the bug: 'Uncaught ReferenceError: RedOrbButton is not defined' in or related to this line: 'var redOrbButton = game.addChild(new RedOrbButton());' Line Number: 657
User prompt
add red orb shooting button and put it over frenzy button
User prompt
Add new button to do move: red, it shoots red orb and kill all enemies it collide with and it will only removed when its outside of screen part
User prompt
if enemy got out of map it doesnt give score
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'addEventListener')' in or related to this line: 'document.addEventListener('keydown', function (event) {' Line Number: 644
User prompt
add pc controls
User prompt
Remove turrets
User prompt
Fix turrets not killing enemies
User prompt
Turret's bullet must kill enemies and enemy must drop coins either
User prompt
Make turret only shoot when shoot button press
User prompt
Add 4 small turrets that shoots bullet behind hero's spawn in bottom screen and both 4 separated from each other
User prompt
Move bullet shooting center to direction line pos
User prompt
Increase shooting cooldown by 1 second for fast enemy
User prompt
Reduce fast enemy shooting cooldoe
User prompt
Reduce the speed of the FastEnemy class even more
User prompt
Reduce speed of fast enemy more
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'addEventListener')' in this line: 'document.addEventListener('keydown', function (event) {' Line Number: 546
/****
* Classes
****/
// BombButton class
var BombButton = Container.expand(function () {
var self = Container.call(this);
var bombButtonGraphics = self.attachAsset('bombButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.cooldown = false;
self.on('down', function () {
if (!self.cooldown) {
self.cooldown = true;
var explosion = new Explosion();
explosion.x = 2048 / 2;
explosion.y = 2732 / 2 - 500;
game.addChild(explosion);
explosion.explode();
LK.setTimeout(function () {
self.cooldown = false;
}, 5000);
}
});
});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.move = function () {
self.y += self.speed;
};
});
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 1;
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
self.collect = function () {
self.collect = function () {
// Increment total coins collected by 1
totalCoins += 1;
// Update the total coins display
coinsDisplay.updateCoins(totalCoins);
// Create and animate the '+1' text for coins
var scorePopup = new ScorePopup();
scorePopup.x = self.x;
scorePopup.y = self.y;
game.addChild(scorePopup);
scorePopups.push(scorePopup);
scorePopup.animate();
self.destroy();
};
};
});
// CoinsDisplay class
var CoinsDisplay = Container.expand(function () {
var self = Container.call(this);
var coinsText = new Text2('Coins: 0', {
size: 100,
fill: "#ffd700"
});
coinsText.anchor.set(0.5, 0);
self.addChild(coinsText);
self.updateCoins = function (totalCoins) {
coinsText.setText('Coins: ' + totalCoins.toString());
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1; // Normal enemy speed
self.shootTimer = 0;
self.shootInterval = 300; // 5 seconds at 60FPS
self.move = function (directionX, directionY) {
self.x += directionX * self.speed;
self.y += directionY * self.speed;
self.x = Math.max(0, Math.min(2048 - self.children[0].width, self.x));
self.y += directionY * self.speed;
};
self.shoot = function () {
if (self.shootTimer >= self.shootInterval) {
var enemyBullet = new EnemyBullet();
enemyBullet.x = self.x;
enemyBullet.y = self.y + enemyGraphics.height / 2;
enemyBullets.push(enemyBullet);
game.addChild(enemyBullet);
self.shootTimer = 0;
}
};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
// Bomb class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
self.explode = function () {
LK.setTimeout(function () {
self.checkCollisionWithEnemy();
self.destroy();
}, 1000);
};
self.checkCollisionWithEnemy = function () {
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
// Increase score for each enemy destroyed by the explosion
score++;
scoreTxt.setText(score.toString());
// Spawn a coin and diamonds when an enemy is destroyed
var coinDropCount = Math.floor(Math.random() * 10) + 1; // Drop between 1 and 10 coins
var diamondDropCount = Math.floor(Math.random() * 5) + 1; // Drop between 1 and 5 diamonds
for (var coinIndex = 0; coinIndex < coinDropCount; coinIndex++) {
var newCoin = new Coin();
newCoin.x = enemies[i].x + (Math.random() - 0.5) * enemies[i].children[0].width; // Randomize coin x position slightly using the width of the enemy asset
newCoin.y = enemies[i].y;
newCoin.value = 1; // Set coin value to 1
coins.push(newCoin);
game.addChild(newCoin);
}
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Check for enemy bullet-explosion collisions
for (var j = enemyBullets.length - 1; j >= 0; j--) {
if (self.intersects(enemyBullets[j])) {
enemyBullets[j].destroy();
enemyBullets.splice(j, 1);
}
}
};
});
// FastEnemy class
var FastEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('fastEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2; // Increased speed for FastEnemy
self.shootTimer = 0;
self.shootInterval = 150; // 2.5 seconds at 60FPS
self.move = function () {
var directionX = Math.random() < 0.5 ? -1 : 1;
var directionY = 1;
self.x += directionX * self.speed;
self.y += directionY * self.speed;
self.x = Math.max(0, Math.min(2048 - self.children[0].width, self.x));
self.y += directionY * self.speed;
};
self.shoot = function () {
if (self.shootTimer >= self.shootInterval) {
var enemyBullet = new EnemyBullet();
enemyBullet.x = self.x;
enemyBullet.y = self.y + enemyGraphics.height / 2;
enemyBullets.push(enemyBullet);
game.addChild(enemyBullet);
self.shootTimer = 0;
}
};
});
//{5.1}
// DiamondsDisplay class
var FrenzyButton = Container.expand(function () {
var self = Container.call(this);
var frenzyButtonGraphics = self.attachAsset('frenzyButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.isFrenzyActive = false;
self.toggleFrenzyMode = function () {
if (!self.isFrenzyActive && !self.cooldownActive) {
self.isFrenzyActive = true;
fireRate = Math.max(5, fireRate - 10);
LK.setTimeout(function () {
self.isFrenzyActive = false;
fireRate = 30; // Reset fire rate to default when frenzy mode ends
self.cooldownActive = true;
LK.setTimeout(function () {
self.cooldownActive = false;
}, 20000); // 20-second cooldown
}, 10000); // Frenzy mode lasts only 10 seconds
}
};
self.on('down', function () {
self.toggleFrenzyMode();
});
});
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var healthBar = self.attachAsset('healthBar', {
anchorY: 0.5
});
var backgroundBar = self.attachAsset('healthBarBackground', {
anchorY: 0.5
});
backgroundBar.x = healthBar.x;
var healthBar = self.attachAsset('healthBar', {
anchorY: 0.5
});
healthBar.width = 200; // Initial full health width
self.setHealth = function (percentage) {
healthBar.width = 200 * percentage;
};
});
var HealthOrb = Container.expand(function () {
var self = Container.call(this);
var orbGraphics = self.attachAsset('healthOrb', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.move = function () {
self.y += self.speed;
};
self.collect = function () {
if (hero.health < hero.maxHealth) {
hero.health = Math.min(hero.health + 20, hero.maxHealth);
hero.healthBar.setHealth(hero.health / hero.maxHealth);
self.destroy();
}
};
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 100; // Initialize hero's max health to 100
self.maxShield = 100; // Initialize hero's max shield to 100
self.health = self.maxHealth; // Initialize hero's current health to max health
// Direction indicator line
var directionLine = self.attachAsset('directionLine', {
anchorX: 0.5,
anchorY: 1
});
directionLine.y = -heroGraphics.height / 2 - 60;
// Direction indicator line
self.bulletCount = 1; // Initialize with 1 bullet
// The update method for the Hero class
self.update = function () {
// Add hero movement or other periodic update logic here
if (self.shield > 0) {
var shieldPercentage = self.shield / self.maxShield;
self.shieldBar.setShield(shieldPercentage);
self.shieldGraphic.updateVisibility(true);
self.shieldGraphic.updatePosition(self.x, self.y);
} else if (self.shieldGraphic) {
self.shieldGraphic.updateVisibility(false);
}
self.healthBar.setHealth(self.health / self.maxHealth);
if (!self.shieldRegenerationTimer) {
self.shieldRegenerationTimer = LK.setInterval(function () {
if (self.shield < self.maxShield) {
self.shield = Math.min(self.shield + self.maxShield * 0.05, self.maxShield);
self.shieldBar.setShield(self.shield / self.maxShield);
}
}, 4000);
}
};
// Health bar for the hero
self.healthBar = game.addChild(new HealthBar());
self.healthBar.x = 50; // Move health bar 50 pixels to the right
self.healthBar.y = 2732 - self.healthBar.children[1].height; // Position at the left bottom corner
// Initialize shield graphic and shield bar only if shield upgrade has been purchased
if (self.shield) {
self.shieldGraphic = game.addChild(new ShieldGraphic());
self.shieldGraphic.updatePosition(self.x, self.y);
self.shieldGraphic.updateVisibility(false);
self.shieldBar = game.addChild(new ShieldBar());
self.shieldBar.x = self.healthBar.x + self.healthBar.children[1].width + 10; // Position shield bar next to health bar
self.shieldBar.y = self.healthBar.y; // Align shield bar with health bar
}
// Regeneration timer for the hero
self.regenerationTimer = LK.setInterval(function () {
if (self.health < self.maxHealth && self.health > 0) {
self.health = Math.min(self.health + 10, self.maxHealth);
self.healthBar.setHealth(self.health / self.maxHealth);
}
}, 4000);
// Initialize shield graphic and shield bar only if shield upgrade has been purchased
if (self.shield) {
self.shieldGraphic = game.addChild(new ShieldGraphic());
self.shieldGraphic.updatePosition(self.x, self.y);
self.shieldGraphic.updateVisibility(false);
self.shieldBar = game.addChild(new ShieldBar());
self.shieldBar.x = self.healthBar.x + self.healthBar.children[1].width + 10; // Position shield bar next to health bar
self.shieldBar.y = self.healthBar.y; // Align shield bar with health bar
}
});
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('lifeIcon', {
anchorX: 0.5,
anchorY: 0.5
});
});
var LivesDisplay = Container.expand(function () {
var self = Container.call(this);
self.lives = 3;
self.icons = [];
for (var i = 0; i < self.lives; i++) {
var life = new Life();
life.x = (life.width + 10) * i;
self.addChild(life);
self.icons.push(life);
}
self.removeLife = function () {
if (self.lives > 0) {
self.lives--;
var lifeToRemove = self.icons[self.lives];
lifeToRemove.destroy();
self.icons.pop();
}
};
});
// MagnetButton class
var MagnetButton = Container.expand(function () {
var self = Container.call(this);
var magnetButtonGraphics = self.attachAsset('magnetButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.cooldown = false;
self.on('down', function () {
if (!self.cooldown) {
self.cooldown = true;
coins.forEach(function (coin) {
// Increment total coins collected
totalCoins += coin.value;
// Update the total coins display
coinsDisplay.updateCoins(totalCoins);
coin.destroy();
});
coins = []; // Clear the coins array
diamonds.forEach(function (diamond) {
// Increment total diamonds collected by 1
totalDiamonds += 2;
diamond.destroy();
});
diamonds = []; // Clear the diamonds array
LK.setTimeout(function () {
self.cooldown = false;
}, 3000); // 3-second cooldown
}
});
});
var MultiBulletUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var upgradeButtonGraphics = self.attachAsset('multiBulletUpgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function () {
if (totalCoins >= 20 && hero.bulletCount < 4) {
hero.bulletCount++;
totalCoins -= 20;
coinsDisplay.updateCoins(totalCoins);
}
});
});
// RedOrb class
var RedOrb = Container.expand(function () {
var self = Container.call(this);
var orbGraphics = self.attachAsset('redOrb', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.move = function () {
self.y -= self.speed;
};
self.checkCollisionWithEnemies = function () {
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
// Increase score for each enemy destroyed
score++;
scoreTxt.setText(score.toString());
// Drop coins
var newCoin = new Coin();
newCoin.x = enemies[i].x;
newCoin.y = enemies[i].y;
coins.push(newCoin);
game.addChild(newCoin);
// Remove the enemy
enemies[i].destroy();
enemies.splice(i, 1);
}
}
};
});
var ScorePopup = Container.expand(function () {
var self = Container.call(this);
var scoreText = new Text2('+1', {
size: 80,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0.5);
self.addChild(scoreText);
self.animate = function () {
self.y -= 2;
if (self.alpha > 0) {
self.alpha -= 0.05;
} else {
self.destroy();
}
};
});
var ShieldBar = Container.expand(function () {
var self = Container.call(this);
var shieldBar = self.attachAsset('shieldBar', {
anchorY: 0.5
});
var backgroundBar = self.attachAsset('shieldBarBackground', {
anchorY: 0.5
});
backgroundBar.x = shieldBar.x;
shieldBar.width = 200; // Initial full shield width
self.setShield = function (percentage) {
shieldBar.width = 200 * percentage;
};
});
var ShieldGraphic = Container.expand(function () {
var self = Container.call(this);
var shieldGraphic = self.attachAsset('shieldGraphic', {
anchorX: 0.5,
anchorY: 0.5
});
self.updatePosition = function (x, y) {
self.x = x;
self.y = y;
};
self.updateVisibility = function (visible) {
self.visible = visible;
};
});
// ShieldUpgradeButton class
var ShieldUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var shieldButtonGraphics = self.attachAsset('shieldButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function () {
if (totalCoins >= 30) {
hero.maxHealth = Math.min(hero.maxHealth * 1.25, 200); // Increase max health by 25% up to a limit of 200
hero.health = hero.maxHealth; // Reset health to max after upgrade
totalCoins -= 30;
coinsDisplay.updateCoins(totalCoins);
hero.healthBar.setHealth(hero.health / hero.maxHealth);
// Extend the health bar's width to reflect the increased max health
hero.healthBar.children[1].width = hero.healthBar.children[1].width / (hero.maxHealth - 20) * hero.maxHealth;
}
});
});
// ShootButton class
var ShootButton = Container.expand(function () {
var self = Container.call(this);
var shootButtonGraphics = self.attachAsset('shootButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.cooldown = false;
self.on('down', function () {
if (!self.cooldown) {
self.cooldown = true;
for (var i = 0; i < hero.bulletCount; i++) {
var newBullet = new Bullet();
// Calculate the distance between bullets based on the current bullet count
var bulletSpacing = hero.bulletCount > 1 ? hero.width / hero.bulletCount : 0;
newBullet.x = hero.x - hero.width / 2 + bulletSpacing * i;
newBullet.y = hero.y - hero.children[1].height;
if (bullets.length < 40) {
bullets.push(newBullet);
game.addChild(newBullet);
} else {
newBullet.destroy();
}
}
LK.setTimeout(function () {
self.cooldown = false;
}, 250);
}
});
});
var Thumbstick = Container.expand(function () {
var self = Container.call(this);
var outerCircle = self.attachAsset('thumbstickOuter', {
anchorX: 0.5,
anchorY: 0.5
});
var innerCircle = self.attachAsset('thumbstickInner', {
anchorX: 0.5,
anchorY: 0.5
});
self.isDragging = false;
self.on('down', function (obj) {
self.isDragging = true;
var pos = obj.event.getLocalPosition(game);
innerCircle.position.set(pos.x, pos.y);
});
game.on('move', function (obj) {
if (self.isDragging) {
var pos = obj.event.getLocalPosition(outerCircle);
var dx = pos.x - outerCircle.width * 0.5;
var dy = pos.y - outerCircle.height * 0.5;
var distance = Math.sqrt(dx * dx + dy * dy);
var maxDistance = outerCircle.width * 0.5;
if (distance > maxDistance) {
var angle = Math.atan2(dy, dx);
innerCircle.x = Math.cos(angle) * maxDistance;
innerCircle.y = Math.sin(angle) * maxDistance;
} else {
innerCircle.position.set(pos.x, pos.y);
}
var heroMoveX = Math.min(10, Math.abs(dx * 0.05)) * Math.sign(dx);
var heroMoveY = Math.min(10, Math.abs(dy * 0.05)) * Math.sign(dy);
hero.x = Math.max(hero.width / 2, Math.min(2048 - hero.width / 2, hero.x + heroMoveX));
hero.y = Math.max(hero.height / 2, Math.min(2732 - hero.height / 2, hero.y + heroMoveY));
}
});
game.on('up', function (obj) {
self.isDragging = false;
innerCircle.position.set(outerCircle.x, outerCircle.y);
});
});
var Turret = Container.expand(function () {
var self = Container.call(this);
var turretGraphics = self.attachAsset('turret', {
anchorX: 0.5,
anchorY: 1
});
self.shootInterval = 180; // 3 seconds at 60FPS
self.shootTimer = 0;
self.bullets = [];
self.shoot = function () {
if (self.shootTimer >= self.shootInterval) {
var turretBullet = new Bullet();
turretBullet.x = self.x;
turretBullet.y = self.y - turretGraphics.height / 2;
turretBullet.isTurretBullet = true; // Flag to identify bullets from the turret
self.bullets.push(turretBullet);
game.addChild(turretBullet);
self.shootTimer = 0;
}
};
self.update = function () {
self.shootTimer++;
for (var i = self.bullets.length - 1; i >= 0; i--) {
self.bullets[i].move();
if (self.bullets[i].y > 2732) {
self.bullets[i].destroy();
self.bullets.splice(i, 1);
}
}
};
});
/****
* Initialize Game
****/
// DiamondsDisplay class
// Create diamonds display instance
// Create diamonds display instance
// Create frenzy button instance
var game = new LK.Game({
icon: 'newGameIcon',
// Set the new game icon asset
backgroundColor: 0xE0FFD6 //Init game with very light green background
});
/****
* Game Code
****/
// Create multi bullet upgrade button instance
var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton());
multiBulletUpgradeButton.x = multiBulletUpgradeButton.width / 2 + 100;
multiBulletUpgradeButton.y = 2732 / 2 - multiBulletUpgradeButton.height / 2;
// Create shield upgrade button instance
var shieldUpgradeButton = game.addChild(new ShieldUpgradeButton());
shieldUpgradeButton.x = multiBulletUpgradeButton.width / 2 + 100;
shieldUpgradeButton.y = multiBulletUpgradeButton.y + multiBulletUpgradeButton.height + 20;
var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton());
multiBulletUpgradeButton.x = multiBulletUpgradeButton.width / 2 + 100;
multiBulletUpgradeButton.y = 2732 / 2 - multiBulletUpgradeButton.height / 2;
var shootButton = game.addChild(new ShootButton());
shootButton.x = 2048 - shootButton.width / 2 - 100;
shootButton.y = 2732 - shootButton.height - 100;
var thumbstick = game.addChild(new Thumbstick());
thumbstick.x = thumbstick.width / 2 + 100;
thumbstick.y = 2732 - shootButton.height - 100;
// Create shoot button instance
// Create multi bullet upgrade button instance
var shootButton = game.addChild(new ShootButton());
shootButton.x = 2048 - shootButton.width / 2 - 100;
shootButton.y = 2732 - shootButton.height - 100;
var frenzyButton = game.addChild(new FrenzyButton());
frenzyButton.x = 2048 - frenzyButton.width / 2 - 100;
frenzyButton.y = 2732 / 2;
var bombButton = game.addChild(new BombButton());
bombButton.x = frenzyButton.x;
bombButton.y = frenzyButton.y + frenzyButton.height + 20;
var frenzyButton = game.addChild(new FrenzyButton());
var magnetButton = game.addChild(new MagnetButton());
magnetButton.x = 2048 - magnetButton.width / 2 - 100;
magnetButton.y = bombButton.y + bombButton.height + 20;
frenzyButton.x = 2048 - frenzyButton.width / 2 - 100;
frenzyButton.y = 2732 / 2;
// Initialize important asset arrays, score, coins, diamonds, fire rate, enemy bullets, and explosion
var enemyBullets = [];
var bullets = [];
var enemies = [];
var coins = []; // Array to store coin instances
var diamonds = []; // Array to store diamond instances
var currentExplosion = null; // Variable to store the current explosion instance
var fireRate = 30; // Initialize fire rate to 30
var scorePopups = []; // Array to store instances of ScorePopup
var totalCoins = 0; // Initialize total coins collected to 0
var totalDiamonds = 0; // Initialize total diamonds collected to 0
var score = 0; // Initialize score to 0
// Create score display
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#000000"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create coins display instance
var coinsDisplay = new CoinsDisplay();
coinsDisplay.scale.set(0.5, 0.5);
LK.gui.top.addChild(coinsDisplay);
coinsDisplay.y = scoreTxt.height;
// Create diamonds display instance
// Create LivesDisplay instance
var livesDisplay = game.addChild(new LivesDisplay());
livesDisplay.x = 2048 - (livesDisplay.width + 10 * livesDisplay.lives);
livesDisplay.y = 100;
// Create hero instance
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - hero.height / 2 - 100; // Position hero a bit more up from the bottom of the screen
// Game tick event
LK.on('tick', function () {
// Spawn HealthOrb every 10 seconds if hero's health is not full
if (hero.health < hero.maxHealth && LK.ticks % (10 * 60) == 0) {
// Check if there is already a HealthOrb on screen
var existingHealthOrbs = game.children.filter(function (child) {
return child instanceof HealthOrb;
});
if (existingHealthOrbs.length === 0) {
var healthOrb = new HealthOrb();
healthOrb.x = Math.random() * (2048 - healthOrb.width) + healthOrb.width / 2;
healthOrb.y = -healthOrb.height;
game.addChild(healthOrb);
}
}
// Move enemy bullets and check for collisions with hero
for (var i = enemyBullets.length - 1; i >= 0; i--) {
enemyBullets[i].move();
if (enemyBullets[i].intersects(hero)) {
if (hero.shield > 0) {
hero.shield = Math.max(0, hero.shield - 10);
} else {
hero.health = Math.max(0, hero.health - 10);
// Reset the health regeneration timer each time the hero is damaged
LK.clearInterval(hero.regenerationTimer);
hero.regenerationTimer = LK.setInterval(function () {
if (hero.health < hero.maxHealth && hero.health > 0) {
hero.health = Math.min(hero.health + 10, hero.maxHealth);
hero.healthBar.setHealth(hero.health / hero.maxHealth);
}
}, 4000);
}
hero.healthBar.setHealth(hero.health / 100); // Update health bar
if (hero.health <= 0) {
livesDisplay.removeLife();
if (livesDisplay.lives > 0) {
hero.health = hero.maxHealth;
hero.healthBar.setHealth(hero.health / hero.maxHealth);
} else {
LK.showGameOver();
}
}
enemyBullets[i].destroy();
enemyBullets.splice(i, 1);
} else if (enemyBullets[i].y > 2732) {
enemyBullets[i].destroy();
enemyBullets.splice(i, 1);
}
}
// Handle enemy shooting
for (var j = 0; j < enemies.length; j++) {
enemies[j].shootTimer++;
if (typeof enemies[j].shoot === 'function') {
enemies[j].shoot();
}
}
// Move bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].move();
if (bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Move enemies and check for collision with hero
for (var j = enemies.length - 1; j >= 0; j--) {
var directionX = Math.random() < 0.5 ? -1 : 1;
var directionY = Math.random() < 0.5 ? 0 : 1;
enemies[j].move(directionX, directionY);
if (enemies[j].y > 2732) {
enemies[j].destroy();
enemies.splice(j, 1);
} else if (hero.intersects(enemies[j])) {
hero.health -= 10; // Reduce hero health by 10 on collision
// Reset the health regeneration timer each time the hero is damaged
LK.clearInterval(hero.regenerationTimer);
hero.regenerationTimer = LK.setInterval(function () {
if (hero.health < hero.maxHealth && hero.health > 0) {
hero.health = Math.min(hero.health + 10, hero.maxHealth);
hero.healthBar.setHealth(hero.health / hero.maxHealth);
}
}, 4000);
if (hero.health <= 0) {
livesDisplay.removeLife();
if (livesDisplay.lives > 0) {
hero.health = hero.maxHealth;
hero.healthBar.setHealth(hero.health / hero.maxHealth);
} else {
LK.showGameOver();
}
}
enemies[j].destroy();
enemies.splice(j, 1);
}
}
// Check for bullet-enemy collisions and bullet-enemyBullet collisions
for (var b = bullets.length - 1; b >= 0; b--) {
for (var eb = enemyBullets.length - 1; eb >= 0; eb--) {
if (bullets[b].intersects(enemyBullets[eb])) {
bullets[b].destroy();
bullets.splice(b, 1);
enemyBullets[eb].destroy();
enemyBullets.splice(eb, 1);
break; // Exit the loop after handling collision
}
}
for (var e = enemies.length - 1; e >= 0; e--) {
if (bullets[b] && bullets[b].intersects(enemies[e])) {
// Increase score and update display
score++;
scoreTxt.setText(score.toString());
// Create and animate the '+1' text
var scorePopup = new ScorePopup();
scorePopup.x = enemies[e].x;
scorePopup.y = enemies[e].y;
game.addChild(scorePopup);
// Animate the '+1' text
scorePopups.push(scorePopup);
scorePopup.animate();
// Drop coins regardless of the bullet source
var coinDropCount = Math.floor(Math.random() * 10) + 1; // Drop between 1 and 10 coins
for (var coinIndex = 0; coinIndex < coinDropCount; coinIndex++) {
var newCoin = new Coin();
newCoin.x = enemies[e].x + (Math.random() - 0.5) * enemies[e].children[0].width; // Randomize coin x position slightly using the width of the enemy asset
newCoin.y = enemies[e].y;
coins.push(newCoin);
game.addChild(newCoin);
}
// Destroy the bullet and remove it from the array
bullets[b].destroy();
bullets.splice(b, 1);
enemies[e].destroy();
enemies.splice(e, 1);
break;
}
}
}
// Move and collect HealthOrb
var healthOrbs = game.children.filter(function (child) {
return child instanceof HealthOrb;
});
for (var h = healthOrbs.length - 1; h >= 0; h--) {
healthOrbs[h].move();
if (healthOrbs[h].intersects(hero)) {
healthOrbs[h].collect();
} else if (healthOrbs[h].y > 2732) {
healthOrbs[h].destroy();
}
}
// Move and collect coins
for (var c = coins.length - 1; c >= 0; c--) {
coins[c].move();
var heroCoinCollectionArea = new Rectangle(hero.x - hero.width, hero.y - hero.height, hero.width * 3, hero.height * 3);
if (heroCoinCollectionArea.contains(coins[c].x, coins[c].y)) {
// Increment total coins collected
totalCoins += coins[c].value;
// Update the total coins display
coinsDisplay.updateCoins(totalCoins);
coins[c].destroy();
coins.splice(c, 1);
} else if (coins[c].y > 2732) {
// Remove coins that have moved off screen
coins[c].destroy();
coins.splice(c, 1);
}
}
// Spawn enemies
var enemySpawnRate = frenzyButton.isFrenzyActive ? 120 : 480; // Spawn rate is the same for both regular and fast enemies
if (LK.ticks % enemySpawnRate == 0) {
var regularEnemy = new Enemy();
regularEnemy.x = Math.random() * 1024;
regularEnemy.y = -50;
enemies.push(regularEnemy);
game.addChild(regularEnemy);
var fastEnemy = new FastEnemy();
fastEnemy.x = Math.random() * 1024 + 1024;
fastEnemy.y = -50;
enemies.push(fastEnemy);
game.addChild(fastEnemy);
}
// Check for explosion-enemy collisions
// Animate and remove the '+1' text popups
for (var p = scorePopups.length - 1; p >= 0; p--) {
scorePopups[p].animate();
if (scorePopups[p].alpha <= 0) {
scorePopups.splice(p, 1);
}
}
// Update hero
hero.update();
}); ===================================================================
--- original.js
+++ change.js
@@ -1,151 +1,29 @@
/****
* Classes
****/
-var EnemyBullet = Container.expand(function () {
+// BombButton class
+var BombButton = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.attachAsset('enemyBullet', {
+ var bombButtonGraphics = self.attachAsset('bombButton', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 5;
- self.move = function () {
- self.y += self.speed;
- };
-});
-var HealthBar = Container.expand(function () {
- var self = Container.call(this);
- var healthBar = self.attachAsset('healthBar', {
- anchorY: 0.5
- });
- var backgroundBar = self.attachAsset('healthBarBackground', {
- anchorY: 0.5
- });
- backgroundBar.x = healthBar.x;
- var healthBar = self.attachAsset('healthBar', {
- anchorY: 0.5
- });
- healthBar.width = 200; // Initial full health width
- self.setHealth = function (percentage) {
- healthBar.width = 200 * percentage;
- };
-});
-var ScorePopup = Container.expand(function () {
- var self = Container.call(this);
- var scoreText = new Text2('+1', {
- size: 80,
- fill: "#ffffff"
- });
- scoreText.anchor.set(0.5, 0.5);
- self.addChild(scoreText);
- self.animate = function () {
- self.y -= 2;
- if (self.alpha > 0) {
- self.alpha -= 0.05;
- } else {
- self.destroy();
- }
- };
-});
-// ShootButton class
-var ShootButton = Container.expand(function () {
- var self = Container.call(this);
- var shootButtonGraphics = self.attachAsset('shootButton', {
- anchorX: 0.5,
- anchorY: 0.5
- });
self.cooldown = false;
self.on('down', function () {
if (!self.cooldown) {
self.cooldown = true;
- for (var i = 0; i < hero.bulletCount; i++) {
- var newBullet = new Bullet();
- // Calculate the distance between bullets based on the current bullet count
- var bulletSpacing = hero.bulletCount > 1 ? hero.width / hero.bulletCount : 0;
- newBullet.x = hero.x - hero.width / 2 + bulletSpacing * i;
- newBullet.y = hero.y - hero.children[1].height;
- if (bullets.length < 40) {
- bullets.push(newBullet);
- game.addChild(newBullet);
- } else {
- newBullet.destroy();
- }
- }
+ var explosion = new Explosion();
+ explosion.x = 2048 / 2;
+ explosion.y = 2732 / 2 - 500;
+ game.addChild(explosion);
+ explosion.explode();
LK.setTimeout(function () {
self.cooldown = false;
- }, 250);
+ }, 5000);
}
});
});
-// Hero class
-var Hero = Container.expand(function () {
- var self = Container.call(this);
- var heroGraphics = self.attachAsset('hero', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.maxHealth = 100; // Initialize hero's max health to 100
- self.maxShield = 100; // Initialize hero's max shield to 100
- self.health = self.maxHealth; // Initialize hero's current health to max health
- // Direction indicator line
- var directionLine = self.attachAsset('directionLine', {
- anchorX: 0.5,
- anchorY: 1
- });
- directionLine.y = -heroGraphics.height / 2 - 60;
- // Direction indicator line
- self.bulletCount = 1; // Initialize with 1 bullet
- // The update method for the Hero class
- self.update = function () {
- // Add hero movement or other periodic update logic here
- if (self.shield > 0) {
- var shieldPercentage = self.shield / self.maxShield;
- self.shieldBar.setShield(shieldPercentage);
- self.shieldGraphic.updateVisibility(true);
- self.shieldGraphic.updatePosition(self.x, self.y);
- } else if (self.shieldGraphic) {
- self.shieldGraphic.updateVisibility(false);
- }
- self.healthBar.setHealth(self.health / self.maxHealth);
- if (!self.shieldRegenerationTimer) {
- self.shieldRegenerationTimer = LK.setInterval(function () {
- if (self.shield < self.maxShield) {
- self.shield = Math.min(self.shield + self.maxShield * 0.05, self.maxShield);
- self.shieldBar.setShield(self.shield / self.maxShield);
- }
- }, 4000);
- }
- };
- // Health bar for the hero
- self.healthBar = game.addChild(new HealthBar());
- self.healthBar.x = 50; // Move health bar 50 pixels to the right
- self.healthBar.y = 2732 - self.healthBar.children[1].height; // Position at the left bottom corner
- // Initialize shield graphic and shield bar only if shield upgrade has been purchased
- if (self.shield) {
- self.shieldGraphic = game.addChild(new ShieldGraphic());
- self.shieldGraphic.updatePosition(self.x, self.y);
- self.shieldGraphic.updateVisibility(false);
- self.shieldBar = game.addChild(new ShieldBar());
- self.shieldBar.x = self.healthBar.x + self.healthBar.children[1].width + 10; // Position shield bar next to health bar
- self.shieldBar.y = self.healthBar.y; // Align shield bar with health bar
- }
- // Regeneration timer for the hero
- self.regenerationTimer = LK.setInterval(function () {
- if (self.health < self.maxHealth && self.health > 0) {
- self.health = Math.min(self.health + 10, self.maxHealth);
- self.healthBar.setHealth(self.health / self.maxHealth);
- }
- }, 4000);
- // Initialize shield graphic and shield bar only if shield upgrade has been purchased
- if (self.shield) {
- self.shieldGraphic = game.addChild(new ShieldGraphic());
- self.shieldGraphic.updatePosition(self.x, self.y);
- self.shieldGraphic.updateVisibility(false);
- self.shieldBar = game.addChild(new ShieldBar());
- self.shieldBar.x = self.healthBar.x + self.healthBar.children[1].width + 10; // Position shield bar next to health bar
- self.shieldBar.y = self.healthBar.y; // Align shield bar with health bar
- }
-});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
@@ -185,8 +63,21 @@
self.destroy();
};
};
});
+// CoinsDisplay class
+var CoinsDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ var coinsText = new Text2('Coins: 0', {
+ size: 100,
+ fill: "#ffd700"
+ });
+ coinsText.anchor.set(0.5, 0);
+ self.addChild(coinsText);
+ self.updateCoins = function (totalCoins) {
+ coinsText.setText('Coins: ' + totalCoins.toString());
+ };
+});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
@@ -211,8 +102,62 @@
self.shootTimer = 0;
}
};
});
+var EnemyBullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('enemyBullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.move = function () {
+ self.y += self.speed;
+ };
+});
+// Bomb class
+var Explosion = Container.expand(function () {
+ var self = Container.call(this);
+ var explosionGraphics = self.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.explode = function () {
+ LK.setTimeout(function () {
+ self.checkCollisionWithEnemy();
+ self.destroy();
+ }, 1000);
+ };
+ self.checkCollisionWithEnemy = function () {
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ if (self.intersects(enemies[i])) {
+ // Increase score for each enemy destroyed by the explosion
+ score++;
+ scoreTxt.setText(score.toString());
+ // Spawn a coin and diamonds when an enemy is destroyed
+ var coinDropCount = Math.floor(Math.random() * 10) + 1; // Drop between 1 and 10 coins
+ var diamondDropCount = Math.floor(Math.random() * 5) + 1; // Drop between 1 and 5 diamonds
+ for (var coinIndex = 0; coinIndex < coinDropCount; coinIndex++) {
+ var newCoin = new Coin();
+ newCoin.x = enemies[i].x + (Math.random() - 0.5) * enemies[i].children[0].width; // Randomize coin x position slightly using the width of the enemy asset
+ newCoin.y = enemies[i].y;
+ newCoin.value = 1; // Set coin value to 1
+ coins.push(newCoin);
+ game.addChild(newCoin);
+ }
+ enemies[i].destroy();
+ enemies.splice(i, 1);
+ }
+ }
+ // Check for enemy bullet-explosion collisions
+ for (var j = enemyBullets.length - 1; j >= 0; j--) {
+ if (self.intersects(enemyBullets[j])) {
+ enemyBullets[j].destroy();
+ enemyBullets.splice(j, 1);
+ }
+ }
+ };
+});
// FastEnemy class
var FastEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('fastEnemy', {
@@ -240,48 +185,51 @@
self.shootTimer = 0;
}
};
});
-// CoinsDisplay class
-var CoinsDisplay = Container.expand(function () {
+//{5.1}
+// DiamondsDisplay class
+var FrenzyButton = Container.expand(function () {
var self = Container.call(this);
- var coinsText = new Text2('Coins: 0', {
- size: 100,
- fill: "#ffd700"
+ var frenzyButtonGraphics = self.attachAsset('frenzyButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- coinsText.anchor.set(0.5, 0);
- self.addChild(coinsText);
- self.updateCoins = function (totalCoins) {
- coinsText.setText('Coins: ' + totalCoins.toString());
+ self.isFrenzyActive = false;
+ self.toggleFrenzyMode = function () {
+ if (!self.isFrenzyActive && !self.cooldownActive) {
+ self.isFrenzyActive = true;
+ fireRate = Math.max(5, fireRate - 10);
+ LK.setTimeout(function () {
+ self.isFrenzyActive = false;
+ fireRate = 30; // Reset fire rate to default when frenzy mode ends
+ self.cooldownActive = true;
+ LK.setTimeout(function () {
+ self.cooldownActive = false;
+ }, 20000); // 20-second cooldown
+ }, 10000); // Frenzy mode lasts only 10 seconds
+ }
};
+ self.on('down', function () {
+ self.toggleFrenzyMode();
+ });
});
-var ShieldBar = Container.expand(function () {
+var HealthBar = Container.expand(function () {
var self = Container.call(this);
- var shieldBar = self.attachAsset('shieldBar', {
+ var healthBar = self.attachAsset('healthBar', {
anchorY: 0.5
});
- var backgroundBar = self.attachAsset('shieldBarBackground', {
+ var backgroundBar = self.attachAsset('healthBarBackground', {
anchorY: 0.5
});
- backgroundBar.x = shieldBar.x;
- shieldBar.width = 200; // Initial full shield width
- self.setShield = function (percentage) {
- shieldBar.width = 200 * percentage;
- };
-});
-var ShieldGraphic = Container.expand(function () {
- var self = Container.call(this);
- var shieldGraphic = self.attachAsset('shieldGraphic', {
- anchorX: 0.5,
+ backgroundBar.x = healthBar.x;
+ var healthBar = self.attachAsset('healthBar', {
anchorY: 0.5
});
- self.updatePosition = function (x, y) {
- self.x = x;
- self.y = y;
+ healthBar.width = 200; // Initial full health width
+ self.setHealth = function (percentage) {
+ healthBar.width = 200 * percentage;
};
- self.updateVisibility = function (visible) {
- self.visible = visible;
- };
});
var HealthOrb = Container.expand(function () {
var self = Container.call(this);
var orbGraphics = self.attachAsset('healthOrb', {
@@ -299,8 +247,77 @@
self.destroy();
}
};
});
+// Hero class
+var Hero = Container.expand(function () {
+ var self = Container.call(this);
+ var heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 100; // Initialize hero's max health to 100
+ self.maxShield = 100; // Initialize hero's max shield to 100
+ self.health = self.maxHealth; // Initialize hero's current health to max health
+ // Direction indicator line
+ var directionLine = self.attachAsset('directionLine', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ directionLine.y = -heroGraphics.height / 2 - 60;
+ // Direction indicator line
+ self.bulletCount = 1; // Initialize with 1 bullet
+ // The update method for the Hero class
+ self.update = function () {
+ // Add hero movement or other periodic update logic here
+ if (self.shield > 0) {
+ var shieldPercentage = self.shield / self.maxShield;
+ self.shieldBar.setShield(shieldPercentage);
+ self.shieldGraphic.updateVisibility(true);
+ self.shieldGraphic.updatePosition(self.x, self.y);
+ } else if (self.shieldGraphic) {
+ self.shieldGraphic.updateVisibility(false);
+ }
+ self.healthBar.setHealth(self.health / self.maxHealth);
+ if (!self.shieldRegenerationTimer) {
+ self.shieldRegenerationTimer = LK.setInterval(function () {
+ if (self.shield < self.maxShield) {
+ self.shield = Math.min(self.shield + self.maxShield * 0.05, self.maxShield);
+ self.shieldBar.setShield(self.shield / self.maxShield);
+ }
+ }, 4000);
+ }
+ };
+ // Health bar for the hero
+ self.healthBar = game.addChild(new HealthBar());
+ self.healthBar.x = 50; // Move health bar 50 pixels to the right
+ self.healthBar.y = 2732 - self.healthBar.children[1].height; // Position at the left bottom corner
+ // Initialize shield graphic and shield bar only if shield upgrade has been purchased
+ if (self.shield) {
+ self.shieldGraphic = game.addChild(new ShieldGraphic());
+ self.shieldGraphic.updatePosition(self.x, self.y);
+ self.shieldGraphic.updateVisibility(false);
+ self.shieldBar = game.addChild(new ShieldBar());
+ self.shieldBar.x = self.healthBar.x + self.healthBar.children[1].width + 10; // Position shield bar next to health bar
+ self.shieldBar.y = self.healthBar.y; // Align shield bar with health bar
+ }
+ // Regeneration timer for the hero
+ self.regenerationTimer = LK.setInterval(function () {
+ if (self.health < self.maxHealth && self.health > 0) {
+ self.health = Math.min(self.health + 10, self.maxHealth);
+ self.healthBar.setHealth(self.health / self.maxHealth);
+ }
+ }, 4000);
+ // Initialize shield graphic and shield bar only if shield upgrade has been purchased
+ if (self.shield) {
+ self.shieldGraphic = game.addChild(new ShieldGraphic());
+ self.shieldGraphic.updatePosition(self.x, self.y);
+ self.shieldGraphic.updateVisibility(false);
+ self.shieldBar = game.addChild(new ShieldBar());
+ self.shieldBar.x = self.healthBar.x + self.healthBar.children[1].width + 10; // Position shield bar next to health bar
+ self.shieldBar.y = self.healthBar.y; // Align shield bar with health bar
+ }
+});
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('lifeIcon', {
anchorX: 0.5,
@@ -325,159 +342,174 @@
self.icons.pop();
}
};
});
-var Turret = Container.expand(function () {
+// MagnetButton class
+var MagnetButton = Container.expand(function () {
var self = Container.call(this);
- var turretGraphics = self.attachAsset('turret', {
+ var magnetButtonGraphics = self.attachAsset('magnetButton', {
anchorX: 0.5,
- anchorY: 1
+ anchorY: 0.5
});
- self.shootInterval = 180; // 3 seconds at 60FPS
- self.shootTimer = 0;
- self.bullets = [];
- self.shoot = function () {
- if (self.shootTimer >= self.shootInterval) {
- var turretBullet = new Bullet();
- turretBullet.x = self.x;
- turretBullet.y = self.y - turretGraphics.height / 2;
- turretBullet.isTurretBullet = true; // Flag to identify bullets from the turret
- self.bullets.push(turretBullet);
- game.addChild(turretBullet);
- self.shootTimer = 0;
+ self.cooldown = false;
+ self.on('down', function () {
+ if (!self.cooldown) {
+ self.cooldown = true;
+ coins.forEach(function (coin) {
+ // Increment total coins collected
+ totalCoins += coin.value;
+ // Update the total coins display
+ coinsDisplay.updateCoins(totalCoins);
+ coin.destroy();
+ });
+ coins = []; // Clear the coins array
+ diamonds.forEach(function (diamond) {
+ // Increment total diamonds collected by 1
+ totalDiamonds += 2;
+ diamond.destroy();
+ });
+ diamonds = []; // Clear the diamonds array
+ LK.setTimeout(function () {
+ self.cooldown = false;
+ }, 3000); // 3-second cooldown
}
- };
- self.update = function () {
- self.shootTimer++;
- for (var i = self.bullets.length - 1; i >= 0; i--) {
- self.bullets[i].move();
- if (self.bullets[i].y > 2732) {
- self.bullets[i].destroy();
- self.bullets.splice(i, 1);
- }
- }
- };
+ });
});
-//{5.1}
-// DiamondsDisplay class
-var FrenzyButton = Container.expand(function () {
+var MultiBulletUpgradeButton = Container.expand(function () {
var self = Container.call(this);
- var frenzyButtonGraphics = self.attachAsset('frenzyButton', {
+ var upgradeButtonGraphics = self.attachAsset('multiBulletUpgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
- self.isFrenzyActive = false;
- self.toggleFrenzyMode = function () {
- if (!self.isFrenzyActive && !self.cooldownActive) {
- self.isFrenzyActive = true;
- fireRate = Math.max(5, fireRate - 10);
- LK.setTimeout(function () {
- self.isFrenzyActive = false;
- fireRate = 30; // Reset fire rate to default when frenzy mode ends
- self.cooldownActive = true;
- LK.setTimeout(function () {
- self.cooldownActive = false;
- }, 20000); // 20-second cooldown
- }, 10000); // Frenzy mode lasts only 10 seconds
- }
- };
self.on('down', function () {
- self.toggleFrenzyMode();
+ if (totalCoins >= 20 && hero.bulletCount < 4) {
+ hero.bulletCount++;
+ totalCoins -= 20;
+ coinsDisplay.updateCoins(totalCoins);
+ }
});
});
-// Bomb class
-var Explosion = Container.expand(function () {
+// RedOrb class
+var RedOrb = Container.expand(function () {
var self = Container.call(this);
- var explosionGraphics = self.attachAsset('explosion', {
+ var orbGraphics = self.attachAsset('redOrb', {
anchorX: 0.5,
anchorY: 0.5
});
- self.explode = function () {
- LK.setTimeout(function () {
- self.checkCollisionWithEnemy();
- self.destroy();
- }, 1000);
+ self.speed = 10;
+ self.move = function () {
+ self.y -= self.speed;
};
- self.checkCollisionWithEnemy = function () {
+ self.checkCollisionWithEnemies = function () {
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
- // Increase score for each enemy destroyed by the explosion
+ // Increase score for each enemy destroyed
score++;
scoreTxt.setText(score.toString());
- // Spawn a coin and diamonds when an enemy is destroyed
- var coinDropCount = Math.floor(Math.random() * 10) + 1; // Drop between 1 and 10 coins
- var diamondDropCount = Math.floor(Math.random() * 5) + 1; // Drop between 1 and 5 diamonds
- for (var coinIndex = 0; coinIndex < coinDropCount; coinIndex++) {
- var newCoin = new Coin();
- newCoin.x = enemies[i].x + (Math.random() - 0.5) * enemies[i].children[0].width; // Randomize coin x position slightly using the width of the enemy asset
- newCoin.y = enemies[i].y;
- newCoin.value = 1; // Set coin value to 1
- coins.push(newCoin);
- game.addChild(newCoin);
- }
+ // Drop coins
+ var newCoin = new Coin();
+ newCoin.x = enemies[i].x;
+ newCoin.y = enemies[i].y;
+ coins.push(newCoin);
+ game.addChild(newCoin);
+ // Remove the enemy
enemies[i].destroy();
enemies.splice(i, 1);
}
}
- // Check for enemy bullet-explosion collisions
- for (var j = enemyBullets.length - 1; j >= 0; j--) {
- if (self.intersects(enemyBullets[j])) {
- enemyBullets[j].destroy();
- enemyBullets.splice(j, 1);
- }
+ };
+});
+var ScorePopup = Container.expand(function () {
+ var self = Container.call(this);
+ var scoreText = new Text2('+1', {
+ size: 80,
+ fill: "#ffffff"
+ });
+ scoreText.anchor.set(0.5, 0.5);
+ self.addChild(scoreText);
+ self.animate = function () {
+ self.y -= 2;
+ if (self.alpha > 0) {
+ self.alpha -= 0.05;
+ } else {
+ self.destroy();
}
};
});
-// BombButton class
-var BombButton = Container.expand(function () {
+var ShieldBar = Container.expand(function () {
var self = Container.call(this);
- var bombButtonGraphics = self.attachAsset('bombButton', {
+ var shieldBar = self.attachAsset('shieldBar', {
+ anchorY: 0.5
+ });
+ var backgroundBar = self.attachAsset('shieldBarBackground', {
+ anchorY: 0.5
+ });
+ backgroundBar.x = shieldBar.x;
+ shieldBar.width = 200; // Initial full shield width
+ self.setShield = function (percentage) {
+ shieldBar.width = 200 * percentage;
+ };
+});
+var ShieldGraphic = Container.expand(function () {
+ var self = Container.call(this);
+ var shieldGraphic = self.attachAsset('shieldGraphic', {
anchorX: 0.5,
anchorY: 0.5
});
- self.cooldown = false;
+ self.updatePosition = function (x, y) {
+ self.x = x;
+ self.y = y;
+ };
+ self.updateVisibility = function (visible) {
+ self.visible = visible;
+ };
+});
+// ShieldUpgradeButton class
+var ShieldUpgradeButton = Container.expand(function () {
+ var self = Container.call(this);
+ var shieldButtonGraphics = self.attachAsset('shieldButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.on('down', function () {
- if (!self.cooldown) {
- self.cooldown = true;
- var explosion = new Explosion();
- explosion.x = 2048 / 2;
- explosion.y = 2732 / 2 - 500;
- game.addChild(explosion);
- explosion.explode();
- LK.setTimeout(function () {
- self.cooldown = false;
- }, 5000);
+ if (totalCoins >= 30) {
+ hero.maxHealth = Math.min(hero.maxHealth * 1.25, 200); // Increase max health by 25% up to a limit of 200
+ hero.health = hero.maxHealth; // Reset health to max after upgrade
+ totalCoins -= 30;
+ coinsDisplay.updateCoins(totalCoins);
+ hero.healthBar.setHealth(hero.health / hero.maxHealth);
+ // Extend the health bar's width to reflect the increased max health
+ hero.healthBar.children[1].width = hero.healthBar.children[1].width / (hero.maxHealth - 20) * hero.maxHealth;
}
});
});
-// MagnetButton class
-var MagnetButton = Container.expand(function () {
+// ShootButton class
+var ShootButton = Container.expand(function () {
var self = Container.call(this);
- var magnetButtonGraphics = self.attachAsset('magnetButton', {
+ var shootButtonGraphics = self.attachAsset('shootButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.cooldown = false;
self.on('down', function () {
if (!self.cooldown) {
self.cooldown = true;
- coins.forEach(function (coin) {
- // Increment total coins collected
- totalCoins += coin.value;
- // Update the total coins display
- coinsDisplay.updateCoins(totalCoins);
- coin.destroy();
- });
- coins = []; // Clear the coins array
- diamonds.forEach(function (diamond) {
- // Increment total diamonds collected by 1
- totalDiamonds += 2;
- diamond.destroy();
- });
- diamonds = []; // Clear the diamonds array
+ for (var i = 0; i < hero.bulletCount; i++) {
+ var newBullet = new Bullet();
+ // Calculate the distance between bullets based on the current bullet count
+ var bulletSpacing = hero.bulletCount > 1 ? hero.width / hero.bulletCount : 0;
+ newBullet.x = hero.x - hero.width / 2 + bulletSpacing * i;
+ newBullet.y = hero.y - hero.children[1].height;
+ if (bullets.length < 40) {
+ bullets.push(newBullet);
+ game.addChild(newBullet);
+ } else {
+ newBullet.destroy();
+ }
+ }
LK.setTimeout(function () {
self.cooldown = false;
- }, 3000); // 3-second cooldown
+ }, 250);
}
});
});
var Thumbstick = Container.expand(function () {
@@ -520,40 +552,38 @@
self.isDragging = false;
innerCircle.position.set(outerCircle.x, outerCircle.y);
});
});
-var MultiBulletUpgradeButton = Container.expand(function () {
+var Turret = Container.expand(function () {
var self = Container.call(this);
- var upgradeButtonGraphics = self.attachAsset('multiBulletUpgradeButton', {
+ var turretGraphics = self.attachAsset('turret', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 1
});
- self.on('down', function () {
- if (totalCoins >= 20 && hero.bulletCount < 4) {
- hero.bulletCount++;
- totalCoins -= 20;
- coinsDisplay.updateCoins(totalCoins);
+ self.shootInterval = 180; // 3 seconds at 60FPS
+ self.shootTimer = 0;
+ self.bullets = [];
+ self.shoot = function () {
+ if (self.shootTimer >= self.shootInterval) {
+ var turretBullet = new Bullet();
+ turretBullet.x = self.x;
+ turretBullet.y = self.y - turretGraphics.height / 2;
+ turretBullet.isTurretBullet = true; // Flag to identify bullets from the turret
+ self.bullets.push(turretBullet);
+ game.addChild(turretBullet);
+ self.shootTimer = 0;
}
- });
-});
-// ShieldUpgradeButton class
-var ShieldUpgradeButton = Container.expand(function () {
- var self = Container.call(this);
- var shieldButtonGraphics = self.attachAsset('shieldButton', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.on('down', function () {
- if (totalCoins >= 30) {
- hero.maxHealth = Math.min(hero.maxHealth * 1.25, 200); // Increase max health by 25% up to a limit of 200
- hero.health = hero.maxHealth; // Reset health to max after upgrade
- totalCoins -= 30;
- coinsDisplay.updateCoins(totalCoins);
- hero.healthBar.setHealth(hero.health / hero.maxHealth);
- // Extend the health bar's width to reflect the increased max health
- hero.healthBar.children[1].width = hero.healthBar.children[1].width / (hero.maxHealth - 20) * hero.maxHealth;
+ };
+ self.update = function () {
+ self.shootTimer++;
+ for (var i = self.bullets.length - 1; i >= 0; i--) {
+ self.bullets[i].move();
+ if (self.bullets[i].y > 2732) {
+ self.bullets[i].destroy();
+ self.bullets.splice(i, 1);
+ }
}
- });
+ };
});
/****
* Initialize Game
Coin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Fighter jet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Has rocket behind to boost movement to down faster
Explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Medkit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.