User prompt
Maximum hero speed set to 5
User prompt
If hero collide with enemy game over
User prompt
Bullet despawn in 0.5s
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'height')' in this line: 'thumbstick.y = 2732 - shootButton.height - 100;' Line Number: 300
User prompt
Move thumbstick control to same height as shoot button
User prompt
Reduce hero speed movement
User prompt
Make thumbstick can be controlled inside thumvbstick outer only
User prompt
Limit hero movement to stay within the screen bounds
User prompt
Hero can only move horiz
User prompt
Fix Bug: 'TypeError: hero.update is not a function' in this line: 'hero.update();' Line Number: 451
User prompt
Fix Bug: 'TypeError: hero.update is not a function' in this line: 'hero.update();' Line Number: 451
User prompt
Add thumbstick control for hero
User prompt
Move hero a bit more up
User prompt
Remove thunbstick
User prompt
Put thumbstick to mid
User prompt
Add thumbstick to move hero verticallt
User prompt
Move shoot button a bit to upper left
User prompt
Put bullet shoot button near to right bottom corner
User prompt
Add bullet shooting button instead of auto shoot.
User prompt
Bullet lifetime decrease to 1
User prompt
Limit maximum bullet to 50 if more it will despawn
User prompt
Bullet lifetime for 2 second
User prompt
Remove fire rate upgrade button from screen after pressing it 4 timed
User prompt
Disable fire rate button after being pressed 4x
User prompt
Only can upgrade fire rate for 4 times max
/**** * Classes ****/ // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5); self.bulletCount = 1; // Initialize with 1 bullet self.shoot = function () { // Shooting logic will be implemented in the game logic section }; self.update = function () { // Update logic for the hero, if needed }; }); // 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 () { // Collection logic will be implemented in the game logic section }; }); // 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 = 2; self.move = function () { self.y += self.speed; }; }); // 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()); }; }); // FireRateUpgradeButton class var FireRateUpgradeButton = Container.expand(function () { var self = Container.call(this); var upgradeButtonGraphics = self.createAsset('fireRateUpgradeButton', 'Fire Rate Upgrade Button', 0.5, 0.5); self.cost = 5; self.on('down', function () { if (totalCoins >= self.cost && fireRate > 5) { fireRate = Math.max(5, fireRate - 5); totalCoins -= self.cost; coinsDisplay.updateCoins(totalCoins); } }); }); 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 bomb from the game after 3 seconds LK.setTimeout(function () { if (self.parent) { self.parent.removeChild(self); } }, 3000); }); // 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 totalDiamonds += 1; // Update the total diamonds display diamondsDisplay.updateDiamonds(totalDiamonds); // Increment total coins collected by diamond value totalCoins += diamond.value; // Update the total coins display coinsDisplay.updateCoins(totalCoins); diamond.destroy(); }); diamonds = []; // Clear the diamonds array LK.setTimeout(function () { self.cooldown = false; }, 3000); // 3-second cooldown } }); }); // MultiBulletUpgradeButton class var MultiBulletUpgradeButton = Container.expand(function () { var self = Container.call(this); var upgradeButtonGraphics = self.createAsset('multiBulletUpgradeButton', 'Multi Bullet Upgrade Button', 0.5, 0.5); self.cost = 5; self.on('down', function () { if (totalDiamonds >= self.cost) { hero.bulletCount = Math.min(5, hero.bulletCount + 1); totalDiamonds -= self.cost; diamondsDisplay.updateDiamonds(totalDiamonds); } }); }); /**** * Initialize Game ****/ // Create frenzy button instance var game = new LK.Game({ backgroundColor: 0xFFFFFF //Init game with white background }); /**** * Game Code ****/ // Create multi bullet upgrade button instance var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton()); multiBulletUpgradeButton.x = 100; var fireRateUpgradeButton = game.addChild(new FireRateUpgradeButton()); fireRateUpgradeButton.x = 100; fireRateUpgradeButton.y = 2732 / 2; var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton()); multiBulletUpgradeButton.x = 100; multiBulletUpgradeButton.y = fireRateUpgradeButton.y + fireRateUpgradeButton.height + 20; 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 fireRateUpgradeButton = game.addChild(new FireRateUpgradeButton()); fireRateUpgradeButton.x = 100; fireRateUpgradeButton.y = 2732 / 2; 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, and fire rate 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 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; // Position hero further down the screen // Game tick event LK.on('tick', function () { // 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 for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].move(); if (enemies[j].y > 2732) { LK.showGameOver(); } } // 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()); 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; 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); // Increment total coins collected by diamond value totalCoins += diamonds[d].value; // Update the total coins display coinsDisplay.updateCoins(totalCoins); 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 ? 30 : 120; // Halve the spawn rate during frenzy mode if (LK.ticks % enemySpawnRate == 0) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -50; enemies.push(newEnemy); game.addChild(newEnemy); } // Hero shooting if (LK.ticks % fireRate == 0) { for (var i = 0; i < hero.bulletCount; i++) { var newBullet = new Bullet(); // Calculate the distance between bullets based on the current bullet count var bulletSpacing = hero.bulletCount > 1 ? 2048 / (hero.bulletCount + 1) : 0; newBullet.x = hero.x + (i - Math.floor(hero.bulletCount / 2)) * bulletSpacing; newBullet.y = hero.y; bullets.push(newBullet); game.addChild(newBullet); } } // Update hero hero.update(); }); // Touch event to move hero game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); hero.x = pos.x; }); // Ensure the game is touchscreen compatible game.on('move', function (obj) { if (obj.event.data && obj.event.data.originalEvent.touches && obj.event.data.originalEvent.touches.length > 0) { var touch = obj.event.data.originalEvent.touches[0]; var pos = game.toLocal(new Point(touch.clientX, touch.clientY)); hero.x = pos.x; } });
/****
* Classes
****/
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5);
self.bulletCount = 1; // Initialize with 1 bullet
self.shoot = function () {
// Shooting logic will be implemented in the game logic section
};
self.update = function () {
// Update logic for the hero, if needed
};
});
// 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 () {
// Collection logic will be implemented in the game logic section
};
});
// 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 = 2;
self.move = function () {
self.y += self.speed;
};
});
// 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());
};
});
// FireRateUpgradeButton class
var FireRateUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var upgradeButtonGraphics = self.createAsset('fireRateUpgradeButton', 'Fire Rate Upgrade Button', 0.5, 0.5);
self.cost = 5;
self.on('down', function () {
if (totalCoins >= self.cost && fireRate > 5) {
fireRate = Math.max(5, fireRate - 5);
totalCoins -= self.cost;
coinsDisplay.updateCoins(totalCoins);
}
});
});
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 bomb from the game after 3 seconds
LK.setTimeout(function () {
if (self.parent) {
self.parent.removeChild(self);
}
}, 3000);
});
// 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
totalDiamonds += 1;
// Update the total diamonds display
diamondsDisplay.updateDiamonds(totalDiamonds);
// Increment total coins collected by diamond value
totalCoins += diamond.value;
// Update the total coins display
coinsDisplay.updateCoins(totalCoins);
diamond.destroy();
});
diamonds = []; // Clear the diamonds array
LK.setTimeout(function () {
self.cooldown = false;
}, 3000); // 3-second cooldown
}
});
});
// MultiBulletUpgradeButton class
var MultiBulletUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var upgradeButtonGraphics = self.createAsset('multiBulletUpgradeButton', 'Multi Bullet Upgrade Button', 0.5, 0.5);
self.cost = 5;
self.on('down', function () {
if (totalDiamonds >= self.cost) {
hero.bulletCount = Math.min(5, hero.bulletCount + 1);
totalDiamonds -= self.cost;
diamondsDisplay.updateDiamonds(totalDiamonds);
}
});
});
/****
* Initialize Game
****/
// Create frenzy button instance
var game = new LK.Game({
backgroundColor: 0xFFFFFF //Init game with white background
});
/****
* Game Code
****/
// Create multi bullet upgrade button instance
var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton());
multiBulletUpgradeButton.x = 100;
var fireRateUpgradeButton = game.addChild(new FireRateUpgradeButton());
fireRateUpgradeButton.x = 100;
fireRateUpgradeButton.y = 2732 / 2;
var multiBulletUpgradeButton = game.addChild(new MultiBulletUpgradeButton());
multiBulletUpgradeButton.x = 100;
multiBulletUpgradeButton.y = fireRateUpgradeButton.y + fireRateUpgradeButton.height + 20;
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 fireRateUpgradeButton = game.addChild(new FireRateUpgradeButton());
fireRateUpgradeButton.x = 100;
fireRateUpgradeButton.y = 2732 / 2;
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, and fire rate
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 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; // Position hero further down the screen
// Game tick event
LK.on('tick', function () {
// 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
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].move();
if (enemies[j].y > 2732) {
LK.showGameOver();
}
}
// 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());
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;
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);
// Increment total coins collected by diamond value
totalCoins += diamonds[d].value;
// Update the total coins display
coinsDisplay.updateCoins(totalCoins);
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 ? 30 : 120; // Halve the spawn rate during frenzy mode
if (LK.ticks % enemySpawnRate == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -50;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
// Hero shooting
if (LK.ticks % fireRate == 0) {
for (var i = 0; i < hero.bulletCount; i++) {
var newBullet = new Bullet();
// Calculate the distance between bullets based on the current bullet count
var bulletSpacing = hero.bulletCount > 1 ? 2048 / (hero.bulletCount + 1) : 0;
newBullet.x = hero.x + (i - Math.floor(hero.bulletCount / 2)) * bulletSpacing;
newBullet.y = hero.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
}
// Update hero
hero.update();
});
// Touch event to move hero
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
hero.x = pos.x;
});
// Ensure the game is touchscreen compatible
game.on('move', function (obj) {
if (obj.event.data && obj.event.data.originalEvent.touches && obj.event.data.originalEvent.touches.length > 0) {
var touch = obj.event.data.originalEvent.touches[0];
var pos = game.toLocal(new Point(touch.clientX, touch.clientY));
hero.x = pos.x;
}
});
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.