/**** * 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 && totalCoins >= 10) { self.cooldown = true; totalCoins -= 10; coinsDisplay.updateCoins(totalCoins); var explosion = new Explosion(); explosion.x = 2048 / 2; explosion.y = 2732 / 2 - 500; game.addChild(explosion); explosion.explode(); LK.setTimeout(function () { self.cooldown = false; }, 1000); // 1-second cooldown } }); }); // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); //Create and attach asset. This is the same as calling var xxx = self.addChild(LK.getAsset(...)) var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); //Set bullet speed self.speed = -5; //Set bullet damage self.damage = 10; //This is automatically called every game tick, if the bullet is attached! self.update = function () { self.y += self.speed; }; // Add _move_migrated method to Bullet class self._move_migrated = 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_migrated = 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(); // Drop 20 coins when large enemy dies var coinDropCount = 10 * coinDropMultiplier; // Drop 10 coins, multiplied by coinDropMultiplier for (var coinIndex = 0; coinIndex < coinDropCount; coinIndex++) { var newCoin = new Coin(); newCoin.x = self.x + (Math.random() - 0.5) * self.children[0].width; // Randomize coin x position slightly using the width of the enemy asset newCoin.y = self.y; coins.push(newCoin); game.addChild(newCoin); } self.destroy(); }; }; }); var CoinMultiplierUpgradeButton = Container.expand(function () { var self = Container.call(this); var upgradeButtonGraphics = self.attachAsset('coinMultiplierUpgradeButton', { anchorX: 0.5, anchorY: 0.5 }); self.upgradeCount = 0; // Initialize upgrade count self.on('down', function () { if (self.upgradeCount < 3 && totalCoins >= 25) { coinDropMultiplier *= 2; totalCoins -= 25; coinsDisplay.updateCoins(totalCoins); self.upgradeCount++; } }); }); // 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 = 0.5; // Slower speed for LargeEnemy self.hp = 20; // Set enemy HP to 20 self.maxHp = self.hp; // Initialize maxHp self.bombHits = 0; // Track the number of times the enemy has been hit by a bomb self.shootTimer = 0; // Add health bar to enemy self.healthBar = self.addChild(new HealthBar()); self.healthBar.x = -self.healthBar.children[1].width / 2; self.healthBar.y = enemyGraphics.height / 2 + 40; self.shootInterval = 300; // 5 seconds at 60FPS self._move_migrated = 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.damage = 20; self._move_migrated = 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(); }, 250); }; self.checkCollisionWithEnemy = function () { for (var i = enemies.length - 1; i >= 0; i--) { if (self.intersects(enemies[i])) { // Apply 80% damage to all enemies enemies[i].bombHits += 1; if (enemies[i].bombHits >= 2 || enemies[i].hp <= enemies[i].maxHp * 0.8) { enemies[i].hp = 0; } else { enemies[i].hp *= 0.2; } enemies[i].healthBar.setHealth(enemies[i].hp / 20); // Update health bar // If enemy's HP is reduced to 0 or below, destroy it if (enemies[i].hp <= 0) { // 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) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier 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 when enemy dies var coinDropCount = (Math.floor(Math.random() * 10) + 1) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier 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; 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.hp = 20; // Set fast enemy HP to 20 self.maxHp = self.hp; // Initialize maxHp self.bombHits = 0; // Track the number of times the fast enemy has been hit by a bomb self.shootTimer = 0; // Add health bar to fast enemy self.healthBar = self.addChild(new HealthBar()); self.healthBar.x = -self.healthBar.children[1].width / 2; self.healthBar.y = enemyGraphics.height / 2 + 40; self.shootInterval = 150; // 2.5 seconds at 60FPS self.bumpDamage = 30; // Set bump damage to 30 self._move_migrated = 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.cooldownTime = 10000; // Initialize cooldown time to 10 seconds self.toggleFrenzyMode = function () { if (!self.isFrenzyActive && !self.cooldownActive) { self.isFrenzyActive = true; self.largeEnemySpawned = false; fireRate = Math.max(5, fireRate - 10); enemySpawnRateMultiplier *= 2; // Double enemy spawn rate multiplier LK.setTimeout(function () { self.isFrenzyActive = false; fireRate = 30; // Reset fire rate to default when frenzy mode ends enemySpawnRateMultiplier /= 2; // Reset enemy spawn rate multiplier self.cooldownActive = true; LK.setTimeout(function () { self.cooldownActive = false; }, self.cooldownTime); // Use dynamic cooldown time }, 5000); // Frenzy mode lasts only 5 seconds } }; self.on('down', function () { self.toggleFrenzyMode(); }); }); var HealthBar = Container.expand(function () { var self = Container.call(this); var backgroundBar = self.attachAsset('healthBarBackground', { anchorY: 0.5 }); backgroundBar.width = 200; // Initial full health width if (self.parent instanceof LargeEnemy) { backgroundBar.width *= 2.5; // Extend background bar width for large enemies } var healthBar = self.attachAsset('healthBar', { anchorY: 0.5 }); healthBar.width = 200; // Initial full health width if (self.parent instanceof LargeEnemy) { healthBar.width *= 2.5; // Extend health bar width for large enemies } 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_migrated = 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 = 0; // Initialize hero's max shield to 0 self.shield = 0; // Initialize hero's current shield to 0 self.health = self.maxHealth; // Initialize hero's current health to max health self.bulletCount = Math.min(1, 4); // Initialize with 1 bullet and ensure it does not exceed 4 // The update method for the Hero class self._update_migrated = 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); } }, 2000); } }; // 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 > 0) { self.shieldGraphic = new ShieldGraphic(); self.shieldGraphic.updatePosition(self.x, self.y + self.height / 2 + self.shieldGraphic.height / 2); self.shieldGraphic.updateVisibility(false); var heroIndex = game.getChildIndex(self); if (heroIndex > 0) { game.addChildAt(self.shieldGraphic, heroIndex - 1); // Add shield graphic below hero model } else { game.addChildAt(self.shieldGraphic, 0); // Add shield graphic at the bottom if hero is at index 0 } 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 } // 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 LargeEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('largeEnemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0.5; // Slower speed for LargeEnemy self.hp = 50; // Set large enemy HP to 50 self.maxHp = self.hp; // Initialize maxHp self.bombHits = 0; // Track the number of times the large enemy has been hit by a bomb self.shootTimer = 0; // Add health bar to large enemy self.healthBar = self.addChild(new HealthBar()); self.healthBar.children[0].width *= 2.5; // Extend background bar width self.healthBar.children[1].width *= 2.5; // Extend health bar width self.healthBar.x = -self.healthBar.children[1].width / 2; self.healthBar.y = enemyGraphics.height / 2 + 40; self.shootInterval = 200; // 3.33 seconds at 60FPS self.bumpDamage = 50; // Set bump damage to 50 self._move_migrated = 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; } }; }); 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 (hero.bulletCount < 4 && totalCoins >= 20) { hero.bulletCount++; totalCoins -= 20; coinsDisplay.updateCoins(totalCoins); } }); }); var RushButton = Container.expand(function () { var self = Container.call(this); var rushButtonGraphics = self.attachAsset('rushButton', { anchorX: 0.5, anchorY: 0.5 }); self.upgradeCount = 0; // Initialize upgrade count self.on('down', function () { if (self.upgradeCount < 5 && totalCoins >= 40) { frenzyButton.cooldownTime = Math.max(0, frenzyButton.cooldownTime - 1000); // Reduce cooldown by 1 second totalCoins -= 40; coinsDisplay.updateCoins(totalCoins); self.upgradeCount++; frenzyButtonBio.setText('Cooldown: ' + frenzyButton.cooldownTime / 1000 + 's'); // Update cooldown text } }); }); var ScorePopup = Container.expand(function () { var self = Container.call(this); var scoreText = new Text2('-10', { size: 80, fill: "#000000" }); 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 backgroundBar = self.attachAsset('shieldBarBackground', { anchorY: 0.5 }); backgroundBar.width = 200; // Initial full shield width var shieldBar = self.attachAsset('shieldBar', { anchorY: 0.5 }); 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.maxShield < 100) { hero.maxShield = Math.min(hero.maxShield + 10, 100); // Increase max shield by 10% up to a limit of 100% hero.shield = hero.maxShield; // Reset shield to max after upgrade if (hero.maxShield < 100) { totalCoins -= 30; coinsDisplay.updateCoins(totalCoins); } if (!hero.shieldGraphic) { hero.shieldGraphic = new ShieldGraphic(); hero.shieldGraphic.updatePosition(hero.x, hero.y + hero.height / 2 + hero.shieldGraphic.height / 2); hero.shieldGraphic.updateVisibility(false); game.addChildAt(hero.shieldGraphic, game.getChildIndex(hero) - 1); // Add shield graphic below hero model hero.shieldBar = game.addChild(new ShieldBar()); hero.shieldBar.x = hero.healthBar.x + hero.healthBar.children[1].width + 10; // Position shield bar next to health bar hero.shieldBar.y = hero.healthBar.y; // Align shield bar with health bar } } }); }); // 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 < Math.min(hero.bulletCount, 4); 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 - 1) : 0; newBullet.x = hero.x - hero.width / 2 + bulletSpacing * i; newBullet.y = hero.y - hero.height / 2; 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 (x, y, obj) { self.isDragging = true; var pos = game.toLocal(obj.global); innerCircle.position.set(pos.x, pos.y); }); game.on('move', function (x, y, obj) { if (self.isDragging) { var pos = outerCircle.toLocal(obj.global); 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 (x, y, obj) { self.isDragging = false; innerCircle.position.set(outerCircle.x, outerCircle.y); }); }); /**** * 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 ****/ // Add 'LAG WARNING' text in the middle of the screen var lagWarningText = new Text2('LAG WARNING', { size: 100, fill: "#000000" }); lagWarningText.anchor.set(0.5, 0.5); lagWarningText.x = 2048 / 2; lagWarningText.y = 2732 / 4; game.addChild(lagWarningText); Hero.prototype.autoShoot = function () { for (var i = 0; i < Math.min(this.bulletCount, 4); i++) { var newBullet = new Bullet(); var bulletSpacing = this.bulletCount > 1 ? this.width / (this.bulletCount - 1) : 0; newBullet.x = this.x - this.width / 2 + bulletSpacing * i; newBullet.y = this.y - this.height / 2; if (bullets.length < 20) { bullets.push(newBullet); game.addChild(newBullet); } else { newBullet.destroy(); } } }; LK.setInterval(function () { hero.autoShoot(); }, 1000); // Create shield upgrade button instance var shieldUpgradeButton = game.addChild(new ShieldUpgradeButton()); shieldUpgradeButton.x = shieldUpgradeButton.width / 2 + 100; shieldUpgradeButton.y = 2732 / 2 - shieldUpgradeButton.height / 2; // Create rush button upgrade instance var rushButton = game.addChild(new RushButton()); rushButton.x = shieldUpgradeButton.x; rushButton.y = shieldUpgradeButton.y + shieldUpgradeButton.height + 40; // Add text at right of rush button that says 'Rush Upgrade (40 Coins)' var rushButtonText = new Text2('Rush Upgrade (40 Coins)', { size: 50, fill: "#000000" }); rushButtonText.anchor.set(0, 0.5); rushButtonText.x = rushButton.x + rushButton.width / 2 + 20; rushButtonText.y = rushButton.y; game.addChild(rushButtonText); // Add bio text under rush upgrade text var rushUpgradeBio = new Text2('Reduces the cooldown of frenzy button by 1s per upgrade', { size: 30, fill: "#000000" }); rushUpgradeBio.anchor.set(0, 0.5); rushUpgradeBio.x = rushButtonText.x; rushUpgradeBio.y = rushButtonText.y + 40; game.addChild(rushUpgradeBio); // Create multi bullet upgrade button instance var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton()); multiBulletUpgradeButton.x = rushButton.x; multiBulletUpgradeButton.y = rushButton.y + rushButton.height + 40; // Add text at right of multi bullet upgrade button that says 'Multi Bullet Upgrade' var multiBulletUpgradeText = new Text2('Multi Bullet Upgrade (20 Coins)', { size: 50, fill: "#000000" }); multiBulletUpgradeText.anchor.set(0, 0.5); multiBulletUpgradeText.x = multiBulletUpgradeButton.x + multiBulletUpgradeButton.width / 2 + 20; multiBulletUpgradeText.y = multiBulletUpgradeButton.y; game.addChild(multiBulletUpgradeText); // Add bio text under multi bullet upgrade text var multiBulletUpgradeBio = new Text2('Increases the number of bullets fired by your hero', { size: 30, fill: "#000000" }); multiBulletUpgradeBio.anchor.set(0, 0.5); multiBulletUpgradeBio.x = multiBulletUpgradeText.x; multiBulletUpgradeBio.y = multiBulletUpgradeText.y + 40; game.addChild(multiBulletUpgradeBio); // Create coin multiplier upgrade button instance var coinMultiplierUpgradeButton = game.addChild(new CoinMultiplierUpgradeButton()); coinMultiplierUpgradeButton.x = multiBulletUpgradeButton.x; coinMultiplierUpgradeButton.y = multiBulletUpgradeButton.y + multiBulletUpgradeButton.height + 40; // Add text at right of coin multiplier upgrade button that says 'Coin Multiplier Upgrade' var coinMultiplierUpgradeText = new Text2('Coin Multiplier Upgrade (25 Coins)', { size: 50, fill: "#000000" }); coinMultiplierUpgradeText.anchor.set(0, 0.5); coinMultiplierUpgradeText.x = coinMultiplierUpgradeButton.x + coinMultiplierUpgradeButton.width / 2 + 20; coinMultiplierUpgradeText.y = coinMultiplierUpgradeButton.y; game.addChild(coinMultiplierUpgradeText); // Add bio text under coin multiplier upgrade text var coinMultiplierUpgradeBio = new Text2('Doubles the number of coins dropped by enemies', { size: 30, fill: "#000000" }); coinMultiplierUpgradeBio.anchor.set(0, 0.5); coinMultiplierUpgradeBio.x = coinMultiplierUpgradeText.x; coinMultiplierUpgradeBio.y = coinMultiplierUpgradeText.y + 40; game.addChild(coinMultiplierUpgradeBio); // Add text at right of shield button that says 'Shield Upgrade' var shieldUpgradeText = new Text2('Shield Upgrade (30 Coins)', { size: 50, fill: "#000000" }); shieldUpgradeText.anchor.set(0, 0.5); shieldUpgradeText.x = shieldUpgradeButton.x + shieldUpgradeButton.width / 2 + 20; shieldUpgradeText.y = shieldUpgradeButton.y; game.addChild(shieldUpgradeText); // Add bio text under shield upgrade text var shieldUpgradeBio = new Text2('Increases your shield capacity by 10%', { size: 30, fill: "#000000" }); shieldUpgradeBio.anchor.set(0, 0.5); shieldUpgradeBio.x = shieldUpgradeText.x; shieldUpgradeBio.y = shieldUpgradeText.y + 40; game.addChild(shieldUpgradeBio); // Create shoot button instance var shootButton = game.addChild(new ShootButton()); shootButton.x = 2048 - shootButton.width / 2 - 100; shootButton.y = 2732 - shootButton.height - 100; // Add text under shoot button that says 'Shoot' var shootButtonText = new Text2('Shoot', { size: 50, fill: "#000000" }); shootButtonText.anchor.set(0.5, 0); shootButtonText.x = shootButton.x; shootButtonText.y = shootButton.y + shootButton.height / 2 + 20; game.addChild(shootButtonText); // Add text under 'Shoot' text that says 'Autoshoot every 1s btw' var autoShootText = new Text2('Autoshoot every 1s btw', { size: 30, fill: "#000000" }); autoShootText.anchor.set(0.5, 0); autoShootText.x = shootButton.x; autoShootText.y = shootButtonText.y + 60; game.addChild(autoShootText); var thumbstick = game.addChild(new Thumbstick()); thumbstick.x = thumbstick.width / 2 + 100; thumbstick.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; // Add text left to bomb button that says 'Nuke (5 Coins)' var bombButtonText = new Text2('Nuke (10 Coins)', { size: 50, fill: "#000000" }); bombButtonText.anchor.set(1, 0.5); bombButtonText.x = bombButton.x - bombButton.width / 2 - 20; bombButtonText.y = bombButton.y; game.addChild(bombButtonText); // Add bio text under bomb button text var bombButtonBio = new Text2('Cooldown: 1s', { size: 30, fill: "#000000" }); bombButtonBio.anchor.set(1, 0.5); bombButtonBio.x = bombButtonText.x; bombButtonBio.y = bombButtonText.y + 40; game.addChild(bombButtonBio); // Add text next to frenzy button that says 'Rush' var frenzyButtonText = new Text2('Rush', { size: 50, fill: "#000000" }); frenzyButtonText.anchor.set(1, 0.5); frenzyButtonText.x = frenzyButton.x - frenzyButton.width / 2 - 20; frenzyButtonText.y = frenzyButton.y; game.addChild(frenzyButtonText); // Add bio text under frenzy button text var frenzyButtonBio = new Text2('Cooldown: 10s', { size: 30, fill: "#000000" }); frenzyButtonBio.anchor.set(1, 0.5); frenzyButtonBio.x = frenzyButtonText.x; frenzyButtonBio.y = frenzyButtonText.y + 40; game.addChild(frenzyButtonBio); 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 + 40; // Add text next to magnet button that says 'Pick All Coins' var magnetButtonText = new Text2('Pick All Coins', { size: 50, fill: "#000000" }); magnetButtonText.anchor.set(1, 0.5); magnetButtonText.x = magnetButton.x - magnetButton.width / 2 - 20; magnetButtonText.y = magnetButton.y; game.addChild(magnetButtonText); // Add bio text under magnet button text var magnetButtonBio = new Text2('Cooldown: 3s', { size: 30, fill: "#000000" }); magnetButtonBio.anchor.set(1, 0.5); magnetButtonBio.x = magnetButtonText.x; magnetButtonBio.y = magnetButtonText.y + 40; game.addChild(magnetButtonBio); 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 enemySpawnRateMultiplier = 1; // Initialize enemy spawn rate multiplier to 1 var coinDropMultiplier = 1; // Initialize coin drop multiplier to 1 // 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 = 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.addChildAt(hero, 0); // Add hero at the bottom layer // 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 % (20 * 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_migrated(); if (enemyBullets[i].intersects(hero)) { if (hero.shield > 0) { var remainingDamage = 10 - hero.shield; hero.shield = Math.max(0, hero.shield - 10); hero.shieldBar.setShield(hero.shield / hero.maxShield); if (remainingDamage > 0) { hero.health = Math.max(0, hero.health - remainingDamage); } } else { hero.health = Math.max(0, hero.health - 10); } 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].update(); 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 = 1; enemies[j]._move_migrated(directionX, directionY); if (enemies[j].y > 2732) { enemies[j].destroy(); enemies.splice(j, 1); } else if (hero.intersects(enemies[j])) { var bumpDamage = enemies[j].bumpDamage || 20; // Default to 20 if bumpDamage is not defined if (hero.shield > 0) { var remainingDamage = bumpDamage - hero.shield; hero.shield = Math.max(0, hero.shield - bumpDamage); hero.shieldBar.setShield(hero.shield / hero.maxShield); if (remainingDamage > 0) { hero.health = Math.max(0, hero.health - remainingDamage); if (hero.health <= 0) { livesDisplay.removeLife(); if (livesDisplay.lives > 0) { hero.health = hero.maxHealth; hero.healthBar.setHealth(hero.health / hero.maxHealth); } else { LK.showGameOver(); } } } } else { hero.health = Math.max(0, hero.health - bumpDamage); 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])) { // Apply bullet damage to enemy enemies[e].hp -= bullets[b].damage; enemies[e].healthBar.setHealth(enemies[e].hp / 20); // Update health bar if (enemies[e].hp <= 0) { if (enemies[e] instanceof LargeEnemy) { // Award 5 points when a large enemy is destroyed score += 5; scoreTxt.setText(score.toString()); // Drop 20 coins when large enemy dies var coinDropCount = 20 * coinDropMultiplier; // Drop 20 coins, multiplied by coinDropMultiplier 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); } } // Increase score and update display for non-large enemies if (!(enemies[e] instanceof LargeEnemy)) { 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(); // Destroy the bullet and remove it from the array bullets[b].destroy(); bullets.splice(b, 1); if (enemies[e].hp <= 0) { // Drop coins when fast enemy dies var coinDropCount = (Math.floor(Math.random() * 10) + 1) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier 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); } // Drop coins when enemy dies var coinDropCount = (Math.floor(Math.random() * 10) + 1) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier 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); } 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_migrated(); 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_migrated(); var heroCoinCollectionArea = new Rectangle(hero.x - hero.width * 2, hero.y - hero.height * 2, hero.width * 5, hero.height * 5); 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 enemySpawnRateMultiplier = Math.min(1 + Math.floor(score / 10) * 0.1, 3); // Increase spawn rate multiplier based on score, max 3x var enemySpawnRate = frenzyButton.isFrenzyActive ? Math.floor(30 / enemySpawnRateMultiplier) : Math.floor(240 / enemySpawnRateMultiplier); // Adjust spawn rate based on multiplier if (LK.ticks % enemySpawnRate === 0 && enemies.length < 30) { var enemyType; if (frenzyButton.isFrenzyActive) { if (!frenzyButton.largeEnemySpawned) { enemyType = 'large'; frenzyButton.largeEnemySpawned = true; } else { enemyType = Math.random() < 0.5 ? 'regular' : 'fast'; } } else if (score >= 20 && Math.random() < 0.1) { enemyType = 'large'; } else if (score >= 10 && Math.random() < 0.5) { enemyType = 'fast'; } else { enemyType = 'regular'; } var enemy; if (enemyType === 'regular') { enemy = new Enemy(); } else if (enemyType === 'fast') { enemy = new FastEnemy(); } else { enemy = new LargeEnemy(); } enemy.x = Math.random() * (2048 - enemy.children[0].width) + enemy.children[0].width / 2; enemy.y = -enemy.children[0].height; enemies.push(enemy); game.addChildAt(enemy, 0); // Add enemy at the bottom layer } // 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_migrated(); });
/****
* 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 && totalCoins >= 10) {
self.cooldown = true;
totalCoins -= 10;
coinsDisplay.updateCoins(totalCoins);
var explosion = new Explosion();
explosion.x = 2048 / 2;
explosion.y = 2732 / 2 - 500;
game.addChild(explosion);
explosion.explode();
LK.setTimeout(function () {
self.cooldown = false;
}, 1000); // 1-second cooldown
}
});
});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
//Create and attach asset. This is the same as calling var xxx = self.addChild(LK.getAsset(...))
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
//Set bullet speed
self.speed = -5;
//Set bullet damage
self.damage = 10;
//This is automatically called every game tick, if the bullet is attached!
self.update = function () {
self.y += self.speed;
};
// Add _move_migrated method to Bullet class
self._move_migrated = 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_migrated = 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();
// Drop 20 coins when large enemy dies
var coinDropCount = 10 * coinDropMultiplier; // Drop 10 coins, multiplied by coinDropMultiplier
for (var coinIndex = 0; coinIndex < coinDropCount; coinIndex++) {
var newCoin = new Coin();
newCoin.x = self.x + (Math.random() - 0.5) * self.children[0].width; // Randomize coin x position slightly using the width of the enemy asset
newCoin.y = self.y;
coins.push(newCoin);
game.addChild(newCoin);
}
self.destroy();
};
};
});
var CoinMultiplierUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var upgradeButtonGraphics = self.attachAsset('coinMultiplierUpgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.upgradeCount = 0; // Initialize upgrade count
self.on('down', function () {
if (self.upgradeCount < 3 && totalCoins >= 25) {
coinDropMultiplier *= 2;
totalCoins -= 25;
coinsDisplay.updateCoins(totalCoins);
self.upgradeCount++;
}
});
});
// 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 = 0.5; // Slower speed for LargeEnemy
self.hp = 20; // Set enemy HP to 20
self.maxHp = self.hp; // Initialize maxHp
self.bombHits = 0; // Track the number of times the enemy has been hit by a bomb
self.shootTimer = 0;
// Add health bar to enemy
self.healthBar = self.addChild(new HealthBar());
self.healthBar.x = -self.healthBar.children[1].width / 2;
self.healthBar.y = enemyGraphics.height / 2 + 40;
self.shootInterval = 300; // 5 seconds at 60FPS
self._move_migrated = 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.damage = 20;
self._move_migrated = 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();
}, 250);
};
self.checkCollisionWithEnemy = function () {
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
// Apply 80% damage to all enemies
enemies[i].bombHits += 1;
if (enemies[i].bombHits >= 2 || enemies[i].hp <= enemies[i].maxHp * 0.8) {
enemies[i].hp = 0;
} else {
enemies[i].hp *= 0.2;
}
enemies[i].healthBar.setHealth(enemies[i].hp / 20); // Update health bar
// If enemy's HP is reduced to 0 or below, destroy it
if (enemies[i].hp <= 0) {
// 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) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier
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 when enemy dies
var coinDropCount = (Math.floor(Math.random() * 10) + 1) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier
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;
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.hp = 20; // Set fast enemy HP to 20
self.maxHp = self.hp; // Initialize maxHp
self.bombHits = 0; // Track the number of times the fast enemy has been hit by a bomb
self.shootTimer = 0;
// Add health bar to fast enemy
self.healthBar = self.addChild(new HealthBar());
self.healthBar.x = -self.healthBar.children[1].width / 2;
self.healthBar.y = enemyGraphics.height / 2 + 40;
self.shootInterval = 150; // 2.5 seconds at 60FPS
self.bumpDamage = 30; // Set bump damage to 30
self._move_migrated = 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.cooldownTime = 10000; // Initialize cooldown time to 10 seconds
self.toggleFrenzyMode = function () {
if (!self.isFrenzyActive && !self.cooldownActive) {
self.isFrenzyActive = true;
self.largeEnemySpawned = false;
fireRate = Math.max(5, fireRate - 10);
enemySpawnRateMultiplier *= 2; // Double enemy spawn rate multiplier
LK.setTimeout(function () {
self.isFrenzyActive = false;
fireRate = 30; // Reset fire rate to default when frenzy mode ends
enemySpawnRateMultiplier /= 2; // Reset enemy spawn rate multiplier
self.cooldownActive = true;
LK.setTimeout(function () {
self.cooldownActive = false;
}, self.cooldownTime); // Use dynamic cooldown time
}, 5000); // Frenzy mode lasts only 5 seconds
}
};
self.on('down', function () {
self.toggleFrenzyMode();
});
});
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var backgroundBar = self.attachAsset('healthBarBackground', {
anchorY: 0.5
});
backgroundBar.width = 200; // Initial full health width
if (self.parent instanceof LargeEnemy) {
backgroundBar.width *= 2.5; // Extend background bar width for large enemies
}
var healthBar = self.attachAsset('healthBar', {
anchorY: 0.5
});
healthBar.width = 200; // Initial full health width
if (self.parent instanceof LargeEnemy) {
healthBar.width *= 2.5; // Extend health bar width for large enemies
}
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_migrated = 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 = 0; // Initialize hero's max shield to 0
self.shield = 0; // Initialize hero's current shield to 0
self.health = self.maxHealth; // Initialize hero's current health to max health
self.bulletCount = Math.min(1, 4); // Initialize with 1 bullet and ensure it does not exceed 4
// The update method for the Hero class
self._update_migrated = 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);
}
}, 2000);
}
};
// 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 > 0) {
self.shieldGraphic = new ShieldGraphic();
self.shieldGraphic.updatePosition(self.x, self.y + self.height / 2 + self.shieldGraphic.height / 2);
self.shieldGraphic.updateVisibility(false);
var heroIndex = game.getChildIndex(self);
if (heroIndex > 0) {
game.addChildAt(self.shieldGraphic, heroIndex - 1); // Add shield graphic below hero model
} else {
game.addChildAt(self.shieldGraphic, 0); // Add shield graphic at the bottom if hero is at index 0
}
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
}
// 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 LargeEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('largeEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0.5; // Slower speed for LargeEnemy
self.hp = 50; // Set large enemy HP to 50
self.maxHp = self.hp; // Initialize maxHp
self.bombHits = 0; // Track the number of times the large enemy has been hit by a bomb
self.shootTimer = 0;
// Add health bar to large enemy
self.healthBar = self.addChild(new HealthBar());
self.healthBar.children[0].width *= 2.5; // Extend background bar width
self.healthBar.children[1].width *= 2.5; // Extend health bar width
self.healthBar.x = -self.healthBar.children[1].width / 2;
self.healthBar.y = enemyGraphics.height / 2 + 40;
self.shootInterval = 200; // 3.33 seconds at 60FPS
self.bumpDamage = 50; // Set bump damage to 50
self._move_migrated = 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;
}
};
});
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 (hero.bulletCount < 4 && totalCoins >= 20) {
hero.bulletCount++;
totalCoins -= 20;
coinsDisplay.updateCoins(totalCoins);
}
});
});
var RushButton = Container.expand(function () {
var self = Container.call(this);
var rushButtonGraphics = self.attachAsset('rushButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.upgradeCount = 0; // Initialize upgrade count
self.on('down', function () {
if (self.upgradeCount < 5 && totalCoins >= 40) {
frenzyButton.cooldownTime = Math.max(0, frenzyButton.cooldownTime - 1000); // Reduce cooldown by 1 second
totalCoins -= 40;
coinsDisplay.updateCoins(totalCoins);
self.upgradeCount++;
frenzyButtonBio.setText('Cooldown: ' + frenzyButton.cooldownTime / 1000 + 's'); // Update cooldown text
}
});
});
var ScorePopup = Container.expand(function () {
var self = Container.call(this);
var scoreText = new Text2('-10', {
size: 80,
fill: "#000000"
});
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 backgroundBar = self.attachAsset('shieldBarBackground', {
anchorY: 0.5
});
backgroundBar.width = 200; // Initial full shield width
var shieldBar = self.attachAsset('shieldBar', {
anchorY: 0.5
});
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.maxShield < 100) {
hero.maxShield = Math.min(hero.maxShield + 10, 100); // Increase max shield by 10% up to a limit of 100%
hero.shield = hero.maxShield; // Reset shield to max after upgrade
if (hero.maxShield < 100) {
totalCoins -= 30;
coinsDisplay.updateCoins(totalCoins);
}
if (!hero.shieldGraphic) {
hero.shieldGraphic = new ShieldGraphic();
hero.shieldGraphic.updatePosition(hero.x, hero.y + hero.height / 2 + hero.shieldGraphic.height / 2);
hero.shieldGraphic.updateVisibility(false);
game.addChildAt(hero.shieldGraphic, game.getChildIndex(hero) - 1); // Add shield graphic below hero model
hero.shieldBar = game.addChild(new ShieldBar());
hero.shieldBar.x = hero.healthBar.x + hero.healthBar.children[1].width + 10; // Position shield bar next to health bar
hero.shieldBar.y = hero.healthBar.y; // Align shield bar with health bar
}
}
});
});
// 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 < Math.min(hero.bulletCount, 4); 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 - 1) : 0;
newBullet.x = hero.x - hero.width / 2 + bulletSpacing * i;
newBullet.y = hero.y - hero.height / 2;
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 (x, y, obj) {
self.isDragging = true;
var pos = game.toLocal(obj.global);
innerCircle.position.set(pos.x, pos.y);
});
game.on('move', function (x, y, obj) {
if (self.isDragging) {
var pos = outerCircle.toLocal(obj.global);
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 (x, y, obj) {
self.isDragging = false;
innerCircle.position.set(outerCircle.x, outerCircle.y);
});
});
/****
* 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
****/
// Add 'LAG WARNING' text in the middle of the screen
var lagWarningText = new Text2('LAG WARNING', {
size: 100,
fill: "#000000"
});
lagWarningText.anchor.set(0.5, 0.5);
lagWarningText.x = 2048 / 2;
lagWarningText.y = 2732 / 4;
game.addChild(lagWarningText);
Hero.prototype.autoShoot = function () {
for (var i = 0; i < Math.min(this.bulletCount, 4); i++) {
var newBullet = new Bullet();
var bulletSpacing = this.bulletCount > 1 ? this.width / (this.bulletCount - 1) : 0;
newBullet.x = this.x - this.width / 2 + bulletSpacing * i;
newBullet.y = this.y - this.height / 2;
if (bullets.length < 20) {
bullets.push(newBullet);
game.addChild(newBullet);
} else {
newBullet.destroy();
}
}
};
LK.setInterval(function () {
hero.autoShoot();
}, 1000);
// Create shield upgrade button instance
var shieldUpgradeButton = game.addChild(new ShieldUpgradeButton());
shieldUpgradeButton.x = shieldUpgradeButton.width / 2 + 100;
shieldUpgradeButton.y = 2732 / 2 - shieldUpgradeButton.height / 2;
// Create rush button upgrade instance
var rushButton = game.addChild(new RushButton());
rushButton.x = shieldUpgradeButton.x;
rushButton.y = shieldUpgradeButton.y + shieldUpgradeButton.height + 40;
// Add text at right of rush button that says 'Rush Upgrade (40 Coins)'
var rushButtonText = new Text2('Rush Upgrade (40 Coins)', {
size: 50,
fill: "#000000"
});
rushButtonText.anchor.set(0, 0.5);
rushButtonText.x = rushButton.x + rushButton.width / 2 + 20;
rushButtonText.y = rushButton.y;
game.addChild(rushButtonText);
// Add bio text under rush upgrade text
var rushUpgradeBio = new Text2('Reduces the cooldown of frenzy button by 1s per upgrade', {
size: 30,
fill: "#000000"
});
rushUpgradeBio.anchor.set(0, 0.5);
rushUpgradeBio.x = rushButtonText.x;
rushUpgradeBio.y = rushButtonText.y + 40;
game.addChild(rushUpgradeBio);
// Create multi bullet upgrade button instance
var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton());
multiBulletUpgradeButton.x = rushButton.x;
multiBulletUpgradeButton.y = rushButton.y + rushButton.height + 40;
// Add text at right of multi bullet upgrade button that says 'Multi Bullet Upgrade'
var multiBulletUpgradeText = new Text2('Multi Bullet Upgrade (20 Coins)', {
size: 50,
fill: "#000000"
});
multiBulletUpgradeText.anchor.set(0, 0.5);
multiBulletUpgradeText.x = multiBulletUpgradeButton.x + multiBulletUpgradeButton.width / 2 + 20;
multiBulletUpgradeText.y = multiBulletUpgradeButton.y;
game.addChild(multiBulletUpgradeText);
// Add bio text under multi bullet upgrade text
var multiBulletUpgradeBio = new Text2('Increases the number of bullets fired by your hero', {
size: 30,
fill: "#000000"
});
multiBulletUpgradeBio.anchor.set(0, 0.5);
multiBulletUpgradeBio.x = multiBulletUpgradeText.x;
multiBulletUpgradeBio.y = multiBulletUpgradeText.y + 40;
game.addChild(multiBulletUpgradeBio);
// Create coin multiplier upgrade button instance
var coinMultiplierUpgradeButton = game.addChild(new CoinMultiplierUpgradeButton());
coinMultiplierUpgradeButton.x = multiBulletUpgradeButton.x;
coinMultiplierUpgradeButton.y = multiBulletUpgradeButton.y + multiBulletUpgradeButton.height + 40;
// Add text at right of coin multiplier upgrade button that says 'Coin Multiplier Upgrade'
var coinMultiplierUpgradeText = new Text2('Coin Multiplier Upgrade (25 Coins)', {
size: 50,
fill: "#000000"
});
coinMultiplierUpgradeText.anchor.set(0, 0.5);
coinMultiplierUpgradeText.x = coinMultiplierUpgradeButton.x + coinMultiplierUpgradeButton.width / 2 + 20;
coinMultiplierUpgradeText.y = coinMultiplierUpgradeButton.y;
game.addChild(coinMultiplierUpgradeText);
// Add bio text under coin multiplier upgrade text
var coinMultiplierUpgradeBio = new Text2('Doubles the number of coins dropped by enemies', {
size: 30,
fill: "#000000"
});
coinMultiplierUpgradeBio.anchor.set(0, 0.5);
coinMultiplierUpgradeBio.x = coinMultiplierUpgradeText.x;
coinMultiplierUpgradeBio.y = coinMultiplierUpgradeText.y + 40;
game.addChild(coinMultiplierUpgradeBio);
// Add text at right of shield button that says 'Shield Upgrade'
var shieldUpgradeText = new Text2('Shield Upgrade (30 Coins)', {
size: 50,
fill: "#000000"
});
shieldUpgradeText.anchor.set(0, 0.5);
shieldUpgradeText.x = shieldUpgradeButton.x + shieldUpgradeButton.width / 2 + 20;
shieldUpgradeText.y = shieldUpgradeButton.y;
game.addChild(shieldUpgradeText);
// Add bio text under shield upgrade text
var shieldUpgradeBio = new Text2('Increases your shield capacity by 10%', {
size: 30,
fill: "#000000"
});
shieldUpgradeBio.anchor.set(0, 0.5);
shieldUpgradeBio.x = shieldUpgradeText.x;
shieldUpgradeBio.y = shieldUpgradeText.y + 40;
game.addChild(shieldUpgradeBio);
// Create shoot button instance
var shootButton = game.addChild(new ShootButton());
shootButton.x = 2048 - shootButton.width / 2 - 100;
shootButton.y = 2732 - shootButton.height - 100;
// Add text under shoot button that says 'Shoot'
var shootButtonText = new Text2('Shoot', {
size: 50,
fill: "#000000"
});
shootButtonText.anchor.set(0.5, 0);
shootButtonText.x = shootButton.x;
shootButtonText.y = shootButton.y + shootButton.height / 2 + 20;
game.addChild(shootButtonText);
// Add text under 'Shoot' text that says 'Autoshoot every 1s btw'
var autoShootText = new Text2('Autoshoot every 1s btw', {
size: 30,
fill: "#000000"
});
autoShootText.anchor.set(0.5, 0);
autoShootText.x = shootButton.x;
autoShootText.y = shootButtonText.y + 60;
game.addChild(autoShootText);
var thumbstick = game.addChild(new Thumbstick());
thumbstick.x = thumbstick.width / 2 + 100;
thumbstick.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;
// Add text left to bomb button that says 'Nuke (5 Coins)'
var bombButtonText = new Text2('Nuke (10 Coins)', {
size: 50,
fill: "#000000"
});
bombButtonText.anchor.set(1, 0.5);
bombButtonText.x = bombButton.x - bombButton.width / 2 - 20;
bombButtonText.y = bombButton.y;
game.addChild(bombButtonText);
// Add bio text under bomb button text
var bombButtonBio = new Text2('Cooldown: 1s', {
size: 30,
fill: "#000000"
});
bombButtonBio.anchor.set(1, 0.5);
bombButtonBio.x = bombButtonText.x;
bombButtonBio.y = bombButtonText.y + 40;
game.addChild(bombButtonBio);
// Add text next to frenzy button that says 'Rush'
var frenzyButtonText = new Text2('Rush', {
size: 50,
fill: "#000000"
});
frenzyButtonText.anchor.set(1, 0.5);
frenzyButtonText.x = frenzyButton.x - frenzyButton.width / 2 - 20;
frenzyButtonText.y = frenzyButton.y;
game.addChild(frenzyButtonText);
// Add bio text under frenzy button text
var frenzyButtonBio = new Text2('Cooldown: 10s', {
size: 30,
fill: "#000000"
});
frenzyButtonBio.anchor.set(1, 0.5);
frenzyButtonBio.x = frenzyButtonText.x;
frenzyButtonBio.y = frenzyButtonText.y + 40;
game.addChild(frenzyButtonBio);
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 + 40;
// Add text next to magnet button that says 'Pick All Coins'
var magnetButtonText = new Text2('Pick All Coins', {
size: 50,
fill: "#000000"
});
magnetButtonText.anchor.set(1, 0.5);
magnetButtonText.x = magnetButton.x - magnetButton.width / 2 - 20;
magnetButtonText.y = magnetButton.y;
game.addChild(magnetButtonText);
// Add bio text under magnet button text
var magnetButtonBio = new Text2('Cooldown: 3s', {
size: 30,
fill: "#000000"
});
magnetButtonBio.anchor.set(1, 0.5);
magnetButtonBio.x = magnetButtonText.x;
magnetButtonBio.y = magnetButtonText.y + 40;
game.addChild(magnetButtonBio);
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
enemySpawnRateMultiplier = 1; // Initialize enemy spawn rate multiplier to 1
var coinDropMultiplier = 1; // Initialize coin drop multiplier to 1
// 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 = 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.addChildAt(hero, 0); // Add hero at the bottom layer
// 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 % (20 * 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_migrated();
if (enemyBullets[i].intersects(hero)) {
if (hero.shield > 0) {
var remainingDamage = 10 - hero.shield;
hero.shield = Math.max(0, hero.shield - 10);
hero.shieldBar.setShield(hero.shield / hero.maxShield);
if (remainingDamage > 0) {
hero.health = Math.max(0, hero.health - remainingDamage);
}
} else {
hero.health = Math.max(0, hero.health - 10);
}
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].update();
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 = 1;
enemies[j]._move_migrated(directionX, directionY);
if (enemies[j].y > 2732) {
enemies[j].destroy();
enemies.splice(j, 1);
} else if (hero.intersects(enemies[j])) {
var bumpDamage = enemies[j].bumpDamage || 20; // Default to 20 if bumpDamage is not defined
if (hero.shield > 0) {
var remainingDamage = bumpDamage - hero.shield;
hero.shield = Math.max(0, hero.shield - bumpDamage);
hero.shieldBar.setShield(hero.shield / hero.maxShield);
if (remainingDamage > 0) {
hero.health = Math.max(0, hero.health - remainingDamage);
if (hero.health <= 0) {
livesDisplay.removeLife();
if (livesDisplay.lives > 0) {
hero.health = hero.maxHealth;
hero.healthBar.setHealth(hero.health / hero.maxHealth);
} else {
LK.showGameOver();
}
}
}
} else {
hero.health = Math.max(0, hero.health - bumpDamage);
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])) {
// Apply bullet damage to enemy
enemies[e].hp -= bullets[b].damage;
enemies[e].healthBar.setHealth(enemies[e].hp / 20); // Update health bar
if (enemies[e].hp <= 0) {
if (enemies[e] instanceof LargeEnemy) {
// Award 5 points when a large enemy is destroyed
score += 5;
scoreTxt.setText(score.toString());
// Drop 20 coins when large enemy dies
var coinDropCount = 20 * coinDropMultiplier; // Drop 20 coins, multiplied by coinDropMultiplier
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);
}
}
// Increase score and update display for non-large enemies
if (!(enemies[e] instanceof LargeEnemy)) {
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();
// Destroy the bullet and remove it from the array
bullets[b].destroy();
bullets.splice(b, 1);
if (enemies[e].hp <= 0) {
// Drop coins when fast enemy dies
var coinDropCount = (Math.floor(Math.random() * 10) + 1) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier
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);
}
// Drop coins when enemy dies
var coinDropCount = (Math.floor(Math.random() * 10) + 1) * coinDropMultiplier; // Drop between 1 and 10 coins, multiplied by coinDropMultiplier
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);
}
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_migrated();
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_migrated();
var heroCoinCollectionArea = new Rectangle(hero.x - hero.width * 2, hero.y - hero.height * 2, hero.width * 5, hero.height * 5);
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
enemySpawnRateMultiplier = Math.min(1 + Math.floor(score / 10) * 0.1, 3); // Increase spawn rate multiplier based on score, max 3x
var enemySpawnRate = frenzyButton.isFrenzyActive ? Math.floor(30 / enemySpawnRateMultiplier) : Math.floor(240 / enemySpawnRateMultiplier); // Adjust spawn rate based on multiplier
if (LK.ticks % enemySpawnRate === 0 && enemies.length < 30) {
var enemyType;
if (frenzyButton.isFrenzyActive) {
if (!frenzyButton.largeEnemySpawned) {
enemyType = 'large';
frenzyButton.largeEnemySpawned = true;
} else {
enemyType = Math.random() < 0.5 ? 'regular' : 'fast';
}
} else if (score >= 20 && Math.random() < 0.1) {
enemyType = 'large';
} else if (score >= 10 && Math.random() < 0.5) {
enemyType = 'fast';
} else {
enemyType = 'regular';
}
var enemy;
if (enemyType === 'regular') {
enemy = new Enemy();
} else if (enemyType === 'fast') {
enemy = new FastEnemy();
} else {
enemy = new LargeEnemy();
}
enemy.x = Math.random() * (2048 - enemy.children[0].width) + enemy.children[0].width / 2;
enemy.y = -enemy.children[0].height;
enemies.push(enemy);
game.addChildAt(enemy, 0); // Add enemy at the bottom layer
}
// 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_migrated();
});
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.