User prompt
You are not fixing the issue o health bar
User prompt
Show health bar at to left corner
User prompt
Healt bar is not decreasing why
User prompt
Spawn new targets 30% less
User prompt
Make the game smooth and decrease our health when missile touch us
User prompt
Our health bar decrease with 20% when a missile touch us . If it becomes zero so we will lose. And our plane blasts
User prompt
Health bar have to decrease 20 % by the missile of our targets
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'healthBar.x = scoreTxt.x + scoreTxt.width / 2 + healthBar.width / 2 + 20; // Position health bar to the right of the score' Line Number: 143
User prompt
Increase the horizontal size of health bar and move it right from the score
User prompt
Health bar should be on top
User prompt
Our fighter also needs a health bar which decreases with the missile of our targets
User prompt
Missile of our target have to be different
User prompt
Less the amount of targets by 30%
User prompt
Our target can only launch 1 missile in 5second
User prompt
Our targets can also launch missile on us
User prompt
Big plane have another asset
User prompt
Also include big target that die with many bullets and give extra points
User prompt
Please fix the bug: 'Uncaught ReferenceError: shoot is not defined' in or related to this line: 'shoot(x, y);' Line Number: 126
User prompt
Bullets have to eject continuously without tapping
User prompt
We can also move our plane horizontally
User prompt
Insert a fighter plane by which we have to shoot bullets
Initial prompt
Headshot
/****
* Classes
****/
// BigTarget class for larger targets that require multiple hits
var BigTarget = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('bigTarget', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1; // Slower speed for big targets
self.hitPoints = 5; // Number of hits required to destroy
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.destroy();
}
};
self.hit = function () {
self.hitPoints--;
if (self.hitPoints <= 0) {
self.destroy();
return true; // Return true if destroyed
}
return false; // Return false if not yet destroyed
};
});
// Assets will be automatically initialized by the LK engine based on their usage in the code.
// Bullet class for the player's shots
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10; // Speed of the bullet
self.update = function () {
self.y += self.speed;
if (self.y < -50) {
self.destroy();
}
};
});
// FighterPlane class for the player's plane
var FighterPlane = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('fighterPlane', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2; // Center the plane horizontally
self.y = 2732 - 200; // Position the plane near the bottom of the screen
self.health = 100; // Initialize health
// Method to shoot bullets
self.shoot = function () {
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y - 50; // Position bullet in front of the plane
bullets.push(newBullet);
game.addChild(newBullet);
};
});
// HealthBar class for displaying health
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var barGraphics = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5
});
self.updateHealth = function (health) {
barGraphics.scaleX = health / 100; // Scale based on health percentage
};
});
// Missile class for enemy missiles
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed of the missile
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.destroy();
}
};
});
// Target class for the targets to be hit
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2; // Speed of the target
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Function to spawn a new big target
function spawnBigTarget() {
var newBigTarget = new BigTarget();
newBigTarget.x = Math.random() * 2048;
newBigTarget.y = -100; // Start higher to give more time to react
bigTargets.push(newBigTarget);
game.addChild(newBigTarget);
}
// Initialize variables
var bullets = [];
var targets = [];
var bigTargets = [];
var missiles = [];
var score = 0;
var fighterPlane = new FighterPlane();
game.addChild(fighterPlane);
// Initialize health bar
var healthBar = new HealthBar();
healthBar.x = fighterPlane.x;
healthBar.y = fighterPlane.y - 50; // Position health bar above the plane
game.addChild(healthBar);
// Create score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new target
function spawnTarget() {
var newTarget = new Target();
newTarget.x = Math.random() * 2048;
newTarget.y = -50;
targets.push(newTarget);
game.addChild(newTarget);
}
// Function to handle continuous shooting
LK.setInterval(function () {
fighterPlane.shoot();
}, 500); // Shoot every 500ms
// Game update loop
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
for (var j = targets.length - 1; j >= 0; j--) {
if (bullets[i].intersects(targets[j])) {
bullets[i].destroy();
targets[j].destroy();
bullets.splice(i, 1);
targets.splice(j, 1);
score++;
scoreTxt.setText(score);
break;
}
}
}
// Update targets
for (var k = targets.length - 1; k >= 0; k--) {
targets[k].update();
// Targets shoot missiles periodically, limited to one every 5 seconds
if (LK.ticks % 430 === 0) {
// 5 seconds at 60 FPS
if (!targets[k].lastMissileTime || LK.ticks - targets[k].lastMissileTime >= 300) {
var newMissile = new Missile();
newMissile.x = targets[k].x;
newMissile.y = targets[k].y + 50; // Position missile below the target
game.addChild(newMissile);
targets[k].lastMissileTime = LK.ticks;
}
}
}
// Update big targets
for (var l = bigTargets.length - 1; l >= 0; l--) {
bigTargets[l].update();
for (var m = bullets.length - 1; m >= 0; m--) {
if (bullets[m].intersects(bigTargets[l])) {
bullets[m].destroy();
bullets.splice(m, 1);
if (bigTargets[l].hit()) {
bigTargets.splice(l, 1);
score += 5; // Extra points for destroying big target
scoreTxt.setText(score);
break;
}
}
}
}
// Update missiles
for (var n = missiles.length - 1; n >= 0; n--) {
missiles[n].update();
if (missiles[n].intersects(fighterPlane)) {
missiles[n].destroy();
missiles.splice(n, 1);
// Reduce health
fighterPlane.health -= 10;
healthBar.updateHealth(fighterPlane.health);
// Flash screen if health is zero
if (fighterPlane.health <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
healthBar.x = fighterPlane.x;
healthBar.y = fighterPlane.y - 50; // Keep health bar above the plane
}
// Spawn new targets periodically
if (LK.ticks % 85 === 0) {
spawnTarget();
}
// Spawn big targets periodically
if (LK.ticks % 300 === 0) {
spawnBigTarget();
}
};
// Handle touch events for shooting and moving the plane
game.down = function (x, y, obj) {
// Move the plane horizontally based on touch position
fighterPlane.x = x;
// shoot(x, y); // Removed as continuous shooting is handled by setInterval
}; ===================================================================
--- original.js
+++ change.js
@@ -49,8 +49,9 @@
anchorY: 0.5
});
self.x = 2048 / 2; // Center the plane horizontally
self.y = 2732 - 200; // Position the plane near the bottom of the screen
+ self.health = 100; // Initialize health
// Method to shoot bullets
self.shoot = function () {
var newBullet = new Bullet();
newBullet.x = self.x;
@@ -58,8 +59,19 @@
bullets.push(newBullet);
game.addChild(newBullet);
};
});
+// HealthBar class for displaying health
+var HealthBar = Container.expand(function () {
+ var self = Container.call(this);
+ var barGraphics = self.attachAsset('healthBar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.updateHealth = function (health) {
+ barGraphics.scaleX = health / 100; // Scale based on health percentage
+ };
+});
// Missile class for enemy missiles
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
@@ -115,8 +127,13 @@
var missiles = [];
var score = 0;
var fighterPlane = new FighterPlane();
game.addChild(fighterPlane);
+// Initialize health bar
+var healthBar = new HealthBar();
+healthBar.x = fighterPlane.x;
+healthBar.y = fighterPlane.y - 50; // Position health bar above the plane
+game.addChild(healthBar);
// Create score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
@@ -188,12 +205,19 @@
missiles[n].update();
if (missiles[n].intersects(fighterPlane)) {
missiles[n].destroy();
missiles.splice(n, 1);
- // Handle player hit by missile (e.g., reduce life, end game, etc.)
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
+ // Reduce health
+ fighterPlane.health -= 10;
+ healthBar.updateHealth(fighterPlane.health);
+ // Flash screen if health is zero
+ if (fighterPlane.health <= 0) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
}
+ healthBar.x = fighterPlane.x;
+ healthBar.y = fighterPlane.y - 50; // Keep health bar above the plane
}
// Spawn new targets periodically
if (LK.ticks % 85 === 0) {
spawnTarget();
Missile 2d of a fighter plane. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d view of a fighter plane top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cargo plane from top view (2d) of orange colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A small real missile 2d view View of whole body vertically. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Explosion in 2d game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.