User prompt
Add button to increase fire rate for 5 coins
User prompt
Remove shop
User prompt
Add shop for spending coins for upgrade like more hero fire rate or more coins earning
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toString')' in this line: 'var coinTxt = new Text2(game.coins.toString(), {' Line Number: 97
User prompt
Display coin value the total youve collected so far
User prompt
Add coins as currency for game, coins are used to buy something
User prompt
Frenzy button cooldown to 30 second
User prompt
Frenzy mode only lasts 5 sec
User prompt
Make a button that rain down 10 bullets to enemies
User prompt
Make frenzy mode only lasts for 10 seconds
User prompt
Put frenzy button near to right down corner
User prompt
Add button that makes frenzy time happen with 30 second cooldown, frenzy is increasing enemy spawn rate and bullet spawn rate
User prompt
Fix Bug: 'Uncaught TypeError: LK.getHighScore is not a function' in this line: 'var highScoreTxt = new Text2('High Score: ' + LK.getHighScore().toString(), {' Line Number: 53
User prompt
Fix Bug: 'Uncaught TypeError: LK.getHighscore is not a function' in this line: 'var highScoreTxt = new Text2('High Score: ' + LK.getHighscore().toString(), {' Line Number: 53
User prompt
Fix Bug: 'Uncaught TypeError: LK.getHighScore is not a function' in this line: 'var highScoreTxt = new Text2('High Score: ' + LK.getHighScore().toString(), {' Line Number: 53
User prompt
Add high score display
User prompt
Score display font color to black
User prompt
Change background color to something brighter
User prompt
Add scorr display that increases everytime enemy killrd
Initial prompt
Test game2
/****
* 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.fireRateLevel = 0; // Initialize hero's fire rate level
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;
};
});
// 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;
};
});
// FrenzyButton class
var FrenzyButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.createAsset('frenzyButton', 'Frenzy Mode Button', 0.5, 0.5);
self.cooldown = false;
self.activateFrenzy = function () {
if (!self.cooldown) {
game.frenzyMode = true;
LK.setTimeout(function () {
game.frenzyMode = false;
}, 5000); // Frenzy mode lasts for 5 seconds
self.cooldown = true;
LK.setTimeout(function () {
self.cooldown = false;
}, 30000); // 30 second cooldown
}
};
self.on('down', function () {
self.activateFrenzy();
});
});
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.createAsset('coin', 'Game Coin', 0.5, 0.5);
self.value = 1; // Default value, can be increased by shop upgrades
self.collect = function () {
game.coins += self.value;
coinTxt.setText(game.coins.toString()); // Update the coin display text
self.destroy();
};
self.on('down', function () {
self.collect();
});
});
// FireRateUpgradeButton class
var FireRateUpgradeButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.createAsset('fireRateUpgradeButton', 'Fire Rate Upgrade Button', 0.5, 0.5);
self.on('down', function () {
if (game.coins >= 5) {
game.coins -= 5;
hero.fireRateLevel += 1;
coinTxt.setText(game.coins.toString());
}
});
});
/****
* Initialize Game
****/
// Create fire rate upgrade button instance
// Create frenzy button instance
// Create frenzy button instance
var game = new LK.Game({
backgroundColor: 0xFFFFFF,
// Init game with white background
frenzyMode: false
// Track frenzy mode status
});
/****
* Game Code
****/
game.coins = 0; // Initialize coins as a number before creating coinTxt
// Initialize important asset arrays and score
var bullets = [];
var enemies = [];
var score = 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 coin display
var coinTxt = new Text2(game.coins.toString(), {
size: 100,
fill: "#ffd700"
});
coinTxt.anchor.set(0.5, 0);
coinTxt.y = scoreTxt.height + 20; // Position below the score display
LK.gui.top.addChild(coinTxt);
// Create hero instance
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 100; // Position hero near the bottom of 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);
enemies[e].destroy();
enemies.splice(e, 1);
break;
}
}
}
// Spawn coins
if (LK.ticks % 300 == 0) {
// Spawn a coin every 5 seconds
var newCoin = new Coin();
newCoin.x = Math.random() * 2048;
newCoin.y = Math.random() * (2732 - 100);
game.addChild(newCoin);
}
// Spawn enemies
var enemySpawnRate = game.frenzyMode ? 60 : 120; // Increased spawn rate during frenzy
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
var bulletSpawnRate = game.frenzyMode ? 15 : 30 - hero.fireRateLevel * 5; // Increased spawn rate during frenzy and further increased by hero's fire rate level
if (LK.ticks % bulletSpawnRate == 0) {
var newBullet = new Bullet();
newBullet.x = hero.x;
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.touches && obj.event.touches.length > 0) {
var touch = obj.event.touches[0];
var pos = touch.getLocalPosition(game);
hero.x = pos.x;
}
});
// Create frenzy button instance
var frenzyButton = game.addChild(new FrenzyButton());
frenzyButton.x = LK.gui.right.x - 100;
frenzyButton.y = LK.gui.bottom.y - 200;
// Create fire rate upgrade button instance
var fireRateUpgradeButton = game.addChild(new FireRateUpgradeButton());
fireRateUpgradeButton.x = LK.gui.right.x - 100;
fireRateUpgradeButton.y = LK.gui.bottom.y - 100; ===================================================================
--- original.js
+++ change.js
@@ -65,12 +65,25 @@
self.on('down', function () {
self.collect();
});
});
+// FireRateUpgradeButton class
+var FireRateUpgradeButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonGraphics = self.createAsset('fireRateUpgradeButton', 'Fire Rate Upgrade Button', 0.5, 0.5);
+ self.on('down', function () {
+ if (game.coins >= 5) {
+ game.coins -= 5;
+ hero.fireRateLevel += 1;
+ coinTxt.setText(game.coins.toString());
+ }
+ });
+});
/****
* Initialize Game
****/
+// Create fire rate upgrade button instance
// Create frenzy button instance
// Create frenzy button instance
var game = new LK.Game({
backgroundColor: 0xFFFFFF,
@@ -182,5 +195,9 @@
});
// Create frenzy button instance
var frenzyButton = game.addChild(new FrenzyButton());
frenzyButton.x = LK.gui.right.x - 100;
-frenzyButton.y = LK.gui.bottom.y - 100;
\ No newline at end of file
+frenzyButton.y = LK.gui.bottom.y - 200;
+// Create fire rate upgrade button instance
+var fireRateUpgradeButton = game.addChild(new FireRateUpgradeButton());
+fireRateUpgradeButton.x = LK.gui.right.x - 100;
+fireRateUpgradeButton.y = LK.gui.bottom.y - 100;
\ No newline at end of file
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.