User prompt
Enemy bullet collide explosion must destroy
User prompt
Fix Bug: 'Timeout.tick error: self.checkCollisionWithEnemyBullets is not a function' in this line: 'self.checkCollisionWithEnemyBullets();' Line Number: 220
User prompt
Diamond or coin get hit by explosion must not be destroy
User prompt
Move explosion a bit more up
User prompt
Normal enemy must shoot bullet too
User prompt
Remove boss
User prompt
Add boss which has hp too and need few shot to kill
User prompt
Fix explosion not appearing in screen
User prompt
Explosion must destroy enemy and enemy bullet in instant
User prompt
If direction line collide with enemy or bullet the enemy or bullet will pass through it
User prompt
Direction line is uncollideable
User prompt
When bullet or enemy collide with direction line it must do nothing
User prompt
Enemy bullet destroy when collide with explodion
User prompt
Enemy died of explosion can drop coin or diamond
User prompt
If enemy collide explosion it die
User prompt
Explosion now lasts 3 sec
User prompt
Fix Bug: 'ReferenceError: explosion is not defined' in this line: 'if (explosion) {' Line Number: 556
User prompt
Fix Bug: 'ReferenceError: explosion is not defined' in this line: 'if (explosion) {' Line Number: 556
User prompt
Change bomb asset to explosion instead, so it will be explosion that lasts 5 second after bomb button pressed, if explosion collide with enemy the enemy die
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'width')' in this line: 'shieldUpgradeButton.x = multiBulletUpgradeButton.width / 2 + 100;' Line Number: 366
User prompt
Put shield upgrade under multi bullet
User prompt
Add shield upgrqde button which increases hp for 20 coins and 10 diamonds
User prompt
Put hero spawn downer
User prompt
Add more direction line below first
User prompt
Longer the direction line length
/**** * Classes ****/ var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet', 0.5, 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.createAsset('healthBar', 'Health Bar', 0, 0.5); var backgroundBar = self.createAsset('healthBarBackground', 'Health Bar Background', 0, 0.5); backgroundBar.x = healthBar.x; var healthBar = self.createAsset('healthBar', 'Health Bar', 0, 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.createAsset('shootButton', 'Shoot Button', 0.5, 0.5); self.on('down', function () { for (var i = 0; i < Math.min(hero.bulletCount, 5); 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; var directionLineEndY = hero.y - hero.children[1].height; newBullet.x = hero.x; newBullet.y = directionLineEndY; if (bullets.length < 50) { bullets.push(newBullet); game.addChild(newBullet); } else { newBullet.destroy(); } } }); }); // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5); self.maxHealth = 100; // Initialize hero's max health to 100 self.health = self.maxHealth; // Initialize hero's current health to max health // Direction indicator line var directionLine = self.createAsset('directionLine', 'Direction Indicator', 0.5, 1); directionLine.y = -heroGraphics.height / 2 - 480; // Further increased length of direction line // 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 self.healthBar.setHealth(self.health / self.maxHealth); }; // 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 }); // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('bullet', 'Hero Bullet', 0.5, 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.createAsset('coin', 'Coin', 0.5, 0.5); self.value = 1; self.speed = 5; self.move = function () { self.y += self.speed; }; self.collect = function () { self.collect = function () { // Increment total diamonds collected totalDiamonds += 1; // Update the total diamonds display diamondsDisplay.updateDiamonds(totalDiamonds); self.destroy(); }; }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemy', 'Enemy character', 0.5, 0.5); self.speed = 1; // Normal enemy speed self.move = function () { self.y += self.speed; }; }); // FastEnemy class var FastEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('fastEnemy', 'Fast Enemy character', 0.5, 0.5); self.speed = 2; // Increased speed for FastEnemy self.shootTimer = 0; self.shootInterval = 300; // 5 seconds at 60FPS self.move = function () { self.y += 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; } }; }); // 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()); }; }); //{5.1} // DiamondsDisplay class var DiamondsDisplay = Container.expand(function () { var self = Container.call(this); var diamondsText = new Text2('Diamonds: 0', { size: 100, fill: "#b9f2ff" }); diamondsText.anchor.set(0.5, 0); self.addChild(diamondsText); self.updateDiamonds = function (totalDiamonds) { diamondsText.setText('Diamonds: ' + totalDiamonds.toString()); }; }); var FrenzyButton = Container.expand(function () { var self = Container.call(this); var frenzyButtonGraphics = self.createAsset('frenzyButton', 'Frenzy Mode Button', 0.5, 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; }, 30000); // 30-second cooldown }, 10000); // Frenzy mode lasts only 10 seconds } }; self.on('down', function () { self.toggleFrenzyMode(); }); }); // Diamond class var Diamond = Container.expand(function () { var self = Container.call(this); var diamondGraphics = self.createAsset('diamond', 'Diamond', 0.5, 0.5); self.value = 5; self.speed = 5; self.move = function () { self.y += self.speed; }; self.collect = function () { // Collection logic will be implemented in the game logic section }; }); // Bomb class var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.createAsset('bomb', 'Bomb', 0.5, 0.5); self.explode = function () { enemies.forEach(function (enemy) { // Determine whether to drop a coin or a diamond var dropChance = Math.random(); if (dropChance < 0.2) { // 20% chance to drop a diamond var newDiamond = new Diamond(); newDiamond.x = enemy.x; newDiamond.y = enemy.y; diamonds.push(newDiamond); game.addChild(newDiamond); } else { // 80% chance to drop a coin var newCoin = new Coin(); newCoin.x = enemy.x; newCoin.y = enemy.y; coins.push(newCoin); game.addChild(newCoin); } // Increase score for each enemy destroyed by the bomb score++; scoreTxt.setText(score.toString()); enemy.destroy(); }); enemies = []; // Clear the enemies array self.destroy(); // Destroy the bomb immediately after explosion }; // Set a timeout to remove the bullet from the game after 0.5 seconds LK.setTimeout(function () { if (self.parent) { self.parent.removeChild(self); } }, 500); }); // BombButton class var BombButton = Container.expand(function () { var self = Container.call(this); var bombButtonGraphics = self.createAsset('bombButton', 'Bomb Button', 0.5, 0.5); self.cooldown = false; self.on('down', function () { if (!self.cooldown) { self.cooldown = true; var bomb = new Bomb(); bomb.x = 2048 / 2; bomb.y = 2732 / 2; game.addChild(bomb); bomb.explode(); LK.setTimeout(function () { self.cooldown = false; }, 5000); } }); }); // MagnetButton class var MagnetButton = Container.expand(function () { var self = Container.call(this); var magnetButtonGraphics = self.createAsset('magnetButton', 'Magnet Button', 0.5, 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 += 1; // Update the total diamonds display diamondsDisplay.updateDiamonds(totalDiamonds); diamond.destroy(); }); diamonds = []; // Clear the diamonds array LK.setTimeout(function () { self.cooldown = false; }, 3000); // 3-second cooldown } }); }); var Thumbstick = Container.expand(function () { var self = Container.call(this); var outerCircle = self.createAsset('thumbstickOuter', 'Thumbstick Outer Circle', 0.5, 0.5); var innerCircle = self.createAsset('thumbstickInner', 'Thumbstick Inner Circle', 0.5, 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 MultiBulletUpgradeButton = Container.expand(function () { var self = Container.call(this); var upgradeButtonGraphics = self.createAsset('multiBulletUpgradeButton', 'Multi Bullet Upgrade Button', 0.5, 0.5); self.on('down', function () { if (totalCoins >= 10 && totalDiamonds >= 5) { hero.bulletCount = Math.min(hero.bulletCount + 1, 5); totalCoins -= 10; totalDiamonds -= 5; coinsDisplay.updateCoins(totalCoins); diamondsDisplay.updateDiamonds(totalDiamonds); } }); }); /**** * Initialize Game ****/ // Create shield upgrade button instance // Create frenzy button instance var game = new LK.Game({ backgroundColor: 0xFFFFFF //Init game with white background }); /**** * Game Code ****/ // Create shield upgrade button instance // Create fire rate upgrade button instance 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, and enemy bullets var enemyBullets = []; var bullets = []; var enemies = []; var coins = []; // Array to store coin instances var diamonds = []; // Array to store diamond instances 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 var diamondsDisplay = new DiamondsDisplay(); diamondsDisplay.scale.set(0.5, 0.5); LK.gui.top.addChild(diamondsDisplay); diamondsDisplay.y = coinsDisplay.y + coinsDisplay.height; // 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 () { // 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)) { hero.health -= 10; // Reduce hero health by 10 on collision hero.healthBar.setHealth(hero.health / 100); // Update health bar if (hero.health <= 0) { hero.health = 0; hero.healthBar.setHealth(0); LK.showGameOver(); // Show game over if health is 0 or less } 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--) { enemies[j].move(); 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 if (hero.health <= 0) { LK.showGameOver(); } enemies[j].destroy(); enemies.splice(j, 1); } } // Check for bullet-enemy collisions for (var b = bullets.length - 1; b >= 0; b--) { for (var e = enemies.length - 1; e >= 0; e--) { if (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(); // Destroy the bullet and remove it from the array bullets[b].destroy(); bullets.splice(b, 1); // Spawn a coin or diamond when an enemy is destroyed if (Math.random() < 0.2) { // 20% chance to drop a diamond if (diamonds.length < 5) { // Limit the number of diamonds on screen var newDiamond = new Diamond(); newDiamond.x = enemies[e].x; newDiamond.y = enemies[e].y; diamonds.push(newDiamond); game.addChild(newDiamond); } } else if (coins.length < 10) { // 80% chance to drop a coin var newCoin = new Coin(); newCoin.x = enemies[e].x; newCoin.y = enemies[e].y; newCoin.value = 1; // Set coin value to 1 coins.push(newCoin); game.addChild(newCoin); } enemies[e].destroy(); enemies.splice(e, 1); break; } } } // Move and collect diamonds for (var d = diamonds.length - 1; d >= 0; d--) { diamonds[d].move(); if (hero.intersects(diamonds[d])) { // Increment total diamonds collected totalDiamonds += 1; // Update the total diamonds display diamondsDisplay.updateDiamonds(totalDiamonds); diamonds[d].destroy(); diamonds.splice(d, 1); } else if (diamonds[d].y > 2732) { // Remove diamonds that have moved off screen diamonds[d].destroy(); diamonds.splice(d, 1); } } // Move and collect coins for (var c = coins.length - 1; c >= 0; c--) { coins[c].move(); if (hero.intersects(coins[c])) { // 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; // Increase the spawn rate by four times during frenzy mode if (LK.ticks % enemySpawnRate == 0) { var regularEnemy = new Enemy(); regularEnemy.x = Math.random() * 1024; regularEnemy.y = -50; enemies.push(regularEnemy); game.addChild(regularEnemy); } if (LK.ticks % (enemySpawnRate * 4) == 0) { var fastEnemy = new FastEnemy(); fastEnemy.x = Math.random() * 1024 + 1024; fastEnemy.y = -50; enemies.push(fastEnemy); game.addChild(fastEnemy); } // 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(); });
/****
* Classes
****/
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet', 0.5, 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.createAsset('healthBar', 'Health Bar', 0, 0.5);
var backgroundBar = self.createAsset('healthBarBackground', 'Health Bar Background', 0, 0.5);
backgroundBar.x = healthBar.x;
var healthBar = self.createAsset('healthBar', 'Health Bar', 0, 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.createAsset('shootButton', 'Shoot Button', 0.5, 0.5);
self.on('down', function () {
for (var i = 0; i < Math.min(hero.bulletCount, 5); 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;
var directionLineEndY = hero.y - hero.children[1].height;
newBullet.x = hero.x;
newBullet.y = directionLineEndY;
if (bullets.length < 50) {
bullets.push(newBullet);
game.addChild(newBullet);
} else {
newBullet.destroy();
}
}
});
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5);
self.maxHealth = 100; // Initialize hero's max health to 100
self.health = self.maxHealth; // Initialize hero's current health to max health
// Direction indicator line
var directionLine = self.createAsset('directionLine', 'Direction Indicator', 0.5, 1);
directionLine.y = -heroGraphics.height / 2 - 480; // Further increased length of direction line
// 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
self.healthBar.setHealth(self.health / self.maxHealth);
};
// 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
});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Hero Bullet', 0.5, 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.createAsset('coin', 'Coin', 0.5, 0.5);
self.value = 1;
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
self.collect = function () {
self.collect = function () {
// Increment total diamonds collected
totalDiamonds += 1;
// Update the total diamonds display
diamondsDisplay.updateDiamonds(totalDiamonds);
self.destroy();
};
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy character', 0.5, 0.5);
self.speed = 1; // Normal enemy speed
self.move = function () {
self.y += self.speed;
};
});
// FastEnemy class
var FastEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('fastEnemy', 'Fast Enemy character', 0.5, 0.5);
self.speed = 2; // Increased speed for FastEnemy
self.shootTimer = 0;
self.shootInterval = 300; // 5 seconds at 60FPS
self.move = function () {
self.y += 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;
}
};
});
// 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());
};
});
//{5.1}
// DiamondsDisplay class
var DiamondsDisplay = Container.expand(function () {
var self = Container.call(this);
var diamondsText = new Text2('Diamonds: 0', {
size: 100,
fill: "#b9f2ff"
});
diamondsText.anchor.set(0.5, 0);
self.addChild(diamondsText);
self.updateDiamonds = function (totalDiamonds) {
diamondsText.setText('Diamonds: ' + totalDiamonds.toString());
};
});
var FrenzyButton = Container.expand(function () {
var self = Container.call(this);
var frenzyButtonGraphics = self.createAsset('frenzyButton', 'Frenzy Mode Button', 0.5, 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;
}, 30000); // 30-second cooldown
}, 10000); // Frenzy mode lasts only 10 seconds
}
};
self.on('down', function () {
self.toggleFrenzyMode();
});
});
// Diamond class
var Diamond = Container.expand(function () {
var self = Container.call(this);
var diamondGraphics = self.createAsset('diamond', 'Diamond', 0.5, 0.5);
self.value = 5;
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
self.collect = function () {
// Collection logic will be implemented in the game logic section
};
});
// Bomb class
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.createAsset('bomb', 'Bomb', 0.5, 0.5);
self.explode = function () {
enemies.forEach(function (enemy) {
// Determine whether to drop a coin or a diamond
var dropChance = Math.random();
if (dropChance < 0.2) {
// 20% chance to drop a diamond
var newDiamond = new Diamond();
newDiamond.x = enemy.x;
newDiamond.y = enemy.y;
diamonds.push(newDiamond);
game.addChild(newDiamond);
} else {
// 80% chance to drop a coin
var newCoin = new Coin();
newCoin.x = enemy.x;
newCoin.y = enemy.y;
coins.push(newCoin);
game.addChild(newCoin);
}
// Increase score for each enemy destroyed by the bomb
score++;
scoreTxt.setText(score.toString());
enemy.destroy();
});
enemies = []; // Clear the enemies array
self.destroy(); // Destroy the bomb immediately after explosion
};
// Set a timeout to remove the bullet from the game after 0.5 seconds
LK.setTimeout(function () {
if (self.parent) {
self.parent.removeChild(self);
}
}, 500);
});
// BombButton class
var BombButton = Container.expand(function () {
var self = Container.call(this);
var bombButtonGraphics = self.createAsset('bombButton', 'Bomb Button', 0.5, 0.5);
self.cooldown = false;
self.on('down', function () {
if (!self.cooldown) {
self.cooldown = true;
var bomb = new Bomb();
bomb.x = 2048 / 2;
bomb.y = 2732 / 2;
game.addChild(bomb);
bomb.explode();
LK.setTimeout(function () {
self.cooldown = false;
}, 5000);
}
});
});
// MagnetButton class
var MagnetButton = Container.expand(function () {
var self = Container.call(this);
var magnetButtonGraphics = self.createAsset('magnetButton', 'Magnet Button', 0.5, 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 += 1;
// Update the total diamonds display
diamondsDisplay.updateDiamonds(totalDiamonds);
diamond.destroy();
});
diamonds = []; // Clear the diamonds array
LK.setTimeout(function () {
self.cooldown = false;
}, 3000); // 3-second cooldown
}
});
});
var Thumbstick = Container.expand(function () {
var self = Container.call(this);
var outerCircle = self.createAsset('thumbstickOuter', 'Thumbstick Outer Circle', 0.5, 0.5);
var innerCircle = self.createAsset('thumbstickInner', 'Thumbstick Inner Circle', 0.5, 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 MultiBulletUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var upgradeButtonGraphics = self.createAsset('multiBulletUpgradeButton', 'Multi Bullet Upgrade Button', 0.5, 0.5);
self.on('down', function () {
if (totalCoins >= 10 && totalDiamonds >= 5) {
hero.bulletCount = Math.min(hero.bulletCount + 1, 5);
totalCoins -= 10;
totalDiamonds -= 5;
coinsDisplay.updateCoins(totalCoins);
diamondsDisplay.updateDiamonds(totalDiamonds);
}
});
});
/****
* Initialize Game
****/
// Create shield upgrade button instance
// Create frenzy button instance
var game = new LK.Game({
backgroundColor: 0xFFFFFF //Init game with white background
});
/****
* Game Code
****/
// Create shield upgrade button instance
// Create fire rate upgrade button instance
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, and enemy bullets
var enemyBullets = [];
var bullets = [];
var enemies = [];
var coins = []; // Array to store coin instances
var diamonds = []; // Array to store diamond instances
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
var diamondsDisplay = new DiamondsDisplay();
diamondsDisplay.scale.set(0.5, 0.5);
LK.gui.top.addChild(diamondsDisplay);
diamondsDisplay.y = coinsDisplay.y + coinsDisplay.height;
// 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 () {
// 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)) {
hero.health -= 10; // Reduce hero health by 10 on collision
hero.healthBar.setHealth(hero.health / 100); // Update health bar
if (hero.health <= 0) {
hero.health = 0;
hero.healthBar.setHealth(0);
LK.showGameOver(); // Show game over if health is 0 or less
}
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--) {
enemies[j].move();
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
if (hero.health <= 0) {
LK.showGameOver();
}
enemies[j].destroy();
enemies.splice(j, 1);
}
}
// Check for bullet-enemy collisions
for (var b = bullets.length - 1; b >= 0; b--) {
for (var e = enemies.length - 1; e >= 0; e--) {
if (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();
// Destroy the bullet and remove it from the array
bullets[b].destroy();
bullets.splice(b, 1);
// Spawn a coin or diamond when an enemy is destroyed
if (Math.random() < 0.2) {
// 20% chance to drop a diamond
if (diamonds.length < 5) {
// Limit the number of diamonds on screen
var newDiamond = new Diamond();
newDiamond.x = enemies[e].x;
newDiamond.y = enemies[e].y;
diamonds.push(newDiamond);
game.addChild(newDiamond);
}
} else if (coins.length < 10) {
// 80% chance to drop a coin
var newCoin = new Coin();
newCoin.x = enemies[e].x;
newCoin.y = enemies[e].y;
newCoin.value = 1; // Set coin value to 1
coins.push(newCoin);
game.addChild(newCoin);
}
enemies[e].destroy();
enemies.splice(e, 1);
break;
}
}
}
// Move and collect diamonds
for (var d = diamonds.length - 1; d >= 0; d--) {
diamonds[d].move();
if (hero.intersects(diamonds[d])) {
// Increment total diamonds collected
totalDiamonds += 1;
// Update the total diamonds display
diamondsDisplay.updateDiamonds(totalDiamonds);
diamonds[d].destroy();
diamonds.splice(d, 1);
} else if (diamonds[d].y > 2732) {
// Remove diamonds that have moved off screen
diamonds[d].destroy();
diamonds.splice(d, 1);
}
}
// Move and collect coins
for (var c = coins.length - 1; c >= 0; c--) {
coins[c].move();
if (hero.intersects(coins[c])) {
// 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; // Increase the spawn rate by four times during frenzy mode
if (LK.ticks % enemySpawnRate == 0) {
var regularEnemy = new Enemy();
regularEnemy.x = Math.random() * 1024;
regularEnemy.y = -50;
enemies.push(regularEnemy);
game.addChild(regularEnemy);
}
if (LK.ticks % (enemySpawnRate * 4) == 0) {
var fastEnemy = new FastEnemy();
fastEnemy.x = Math.random() * 1024 + 1024;
fastEnemy.y = -50;
enemies.push(fastEnemy);
game.addChild(fastEnemy);
}
// 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();
});
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.