User prompt
Still, nothing add a starting page, where you can name the pilot and it will store your score using this name for normal building, or regular van, decrease points ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
The primary change needed is to move the line that updates lastKeys to the very beginning of your game.update function. Here's why and how: The Problem Currently, your code updates the lastKeys object (which stores the state of keys from the previous frame) at the end of the game.update function. This means that when you check if (keys['Digit2'] && !lastKeys['Digit2']), lastKeys['Digit2'] might already be true if you pressed and released the key quickly within the same frame. This causes the condition !lastKeys['Digit2'] to be false, and thus the weapon doesn't switch. The Solution By moving the lastKeys update to the start of the game.update function, you ensure that lastKeys always accurately reflects the state of the keys from the immediately preceding frame. This allows the !lastKeys['Digit2'] check to correctly detect when the '2' key is initially pressed down.
User prompt
flares doesnt work pressing 2 doesnt change the weapon fix the input from keyboard
User prompt
Pressing 2 or 1 doesnt change the weapon. Only firing with left click works flares still doesnt work while pressing spacebar
User prompt
Flares doesnt work. Also the bombing. Only the regular cannon work. Lets do it like this: You have 2 states. One is normal cannon, the other is bombing. You choose using pressing 1\2. bombing will be also using click. when you are on the bombing, you have a circle in front of the jet, showing the area that will damage with the bomb. cooldown of 5 seconds. and fix the flare, still doesnt work
User prompt
The flare and the bombing doesnt work, make the backround looks like a desert
User prompt
make the target building way more rare and the normal bulding rare too S-300 a little bit more rare make the bombing usable via button B, and not tighr click flares using spacebar, now the flares doesnt work
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'button')' in or related to this line: 'if (obj.event.button === 0) {' Line Number: 270
Code edit (1 edits merged)
Please save this source code
User prompt
Fighter Jet Strike
Initial prompt
An fighter jet attack game. You control a fighter jet, with the mouse. Where the mouse is where the jet. You have regular cannon that fire in strait line, that fire pressing left mouse. Bombing, that drop under the jet, using right click. There are S-300 AA on the ground sometimes, that fires to your jet. Uisng spacebar you can shoot flames that makes thr AA miss you. Its reload over time. There are regular buildings, target buldings, normal cars, army vans. Target buildings and AA the player destroy using bombing. Army cars, using normal cannon. It spawns while you fly forward. You have 3 lives, every taget you kill you get some score, after killing 5 AA you gain +1 live butno more than 3.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.update = function () { self.y += self.speed; }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -12; self.update = function () { self.y += self.speed; }; return self; }); var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); self.lifespan = 30; self.update = function () { self.lifespan--; self.alpha = self.lifespan / 30; if (self.lifespan <= 0) { self.destroy(); } }; return self; }); var FighterJet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('fighterJet', { anchorX: 0.5, anchorY: 0.5 }); self.lives = 3; self.flareCount = 3; self.maxFlares = 3; self.flareRechargeTimer = 0; self.aaSystemsDestroyed = 0; self.update = function () { // Recharge flares over time if (self.flareCount < self.maxFlares) { self.flareRechargeTimer++; if (self.flareRechargeTimer >= 300) { // 5 seconds at 60fps self.flareCount++; self.flareRechargeTimer = 0; updateFlareDisplay(); } } }; return self; }); var Flare = Container.expand(function () { var self = Container.call(this); var flareGraphics = self.attachAsset('flare', { anchorX: 0.5, anchorY: 0.5 }); self.lifespan = 180; // 3 seconds self.update = function () { self.lifespan--; if (self.lifespan <= 0) { self.destroy(); } }; return self; }); var GroundTarget = Container.expand(function (targetType) { var self = Container.call(this); var targetGraphics = self.attachAsset(targetType, { anchorX: 0.5, anchorY: 0.5 }); self.targetType = targetType; self.points = getPointsForTarget(targetType); self.canShootMissiles = targetType === 's300System'; self.missileTimer = 0; self.update = function () { self.y += scrollSpeed; // S-300 systems shoot missiles at the player if (self.canShootMissiles && self.y > 200 && self.y < 2000) { self.missileTimer++; if (self.missileTimer >= 180) { // Every 3 seconds self.fireMissile(); self.missileTimer = 0; } } }; self.fireMissile = function () { var missile = new Missile(); missile.x = self.x; missile.y = self.y; missile.targetX = fighterJet.x; missile.targetY = fighterJet.y; missiles.push(missile); game.addChild(missile); LK.getSound('missile').play(); }; return self; }); var Missile = Container.expand(function () { var self = Container.call(this); var missileGraphics = self.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 6; self.targetX = 0; self.targetY = 0; self.update = function () { // Move towards target (fighter jet) var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xd2b48c }); /**** * Game Code ****/ var fighterJet = game.addChild(new FighterJet()); fighterJet.x = 1024; fighterJet.y = 2200; var bullets = []; var bombs = []; var flares = []; var missiles = []; var groundTargets = []; var explosions = []; var scrollSpeed = 3; var spawnTimer = 0; var gameSpeed = 1; // UI Elements var scoreText = new Text2('Score: 0', { size: 60, fill: '#ffffff' }); scoreText.anchor.set(0, 0); scoreText.x = 150; scoreText.y = 50; LK.gui.topLeft.addChild(scoreText); var livesText = new Text2('Lives: 3', { size: 60, fill: '#ffffff' }); livesText.anchor.set(1, 0); LK.gui.topRight.addChild(livesText); var flareText = new Text2('Flares: 3', { size: 60, fill: '#ffffff' }); flareText.anchor.set(0.5, 0); LK.gui.top.addChild(flareText); var weaponText = new Text2('Weapon: Cannon (1/2)', { size: 50, fill: '#ffffff' }); weaponText.anchor.set(0.5, 0); weaponText.y = 80; LK.gui.top.addChild(weaponText); function updateWeaponDisplay() { var cooldownText = ''; if (weaponMode === 'bombing' && bombCooldownTimer > 0) { cooldownText = ' (Cooldown: ' + Math.ceil(bombCooldownTimer / 60) + 's)'; } weaponText.setText('Weapon: ' + (weaponMode === 'cannon' ? 'Cannon' : 'Bombing') + ' (1/2)' + cooldownText); } function updateScore() { scoreText.setText('Score: ' + LK.getScore()); } function updateLivesDisplay() { livesText.setText('Lives: ' + fighterJet.lives); } function updateFlareDisplay() { flareText.setText('Flares: ' + fighterJet.flareCount); } function getPointsForTarget(targetType) { switch (targetType) { case 'building': return 10; case 'targetBuilding': return 25; case 'car': return 15; case 'armyVan': return 20; case 's300System': return 50; default: return 10; } } function spawnGroundTarget() { var rand = Math.random(); var randomType; // Weighted spawn system - much more rare buildings and target buildings if (rand < 0.4) { randomType = 'car'; } else if (rand < 0.7) { randomType = 'armyVan'; } else if (rand < 0.85) { randomType = 's300System'; } else if (rand < 0.95) { randomType = 'building'; } else { randomType = 'targetBuilding'; } var target = new GroundTarget(randomType); target.x = Math.random() * 1800 + 124; // Keep within screen bounds target.y = -100; groundTargets.push(target); game.addChild(target); } function createExplosion(x, y) { var explosion = new Explosion(); explosion.x = x; explosion.y = y; explosions.push(explosion); game.addChild(explosion); LK.getSound('explosion').play(); } function checkMissileFlareCollision(missile) { for (var f = flares.length - 1; f >= 0; f--) { var flare = flares[f]; if (missile.intersects(flare)) { // Missile destroyed by flare createExplosion(missile.x, missile.y); missile.destroy(); flare.destroy(); flares.splice(f, 1); return true; } } return false; } // Event handlers game.move = function (x, y, obj) { fighterJet.x = x; fighterJet.y = y; // Update bomb target circle position if (bombTargetCircle) { bombTargetCircle.x = x; bombTargetCircle.y = y + 100; // Position circle below jet } }; game.down = function (x, y, obj) { if (weaponMode === 'cannon') { // Fire bullet var bullet = new Bullet(); bullet.x = fighterJet.x; bullet.y = fighterJet.y - 50; bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); } else if (weaponMode === 'bombing' && bombCooldownTimer <= 0) { // Drop bomb var bomb = new Bomb(); bomb.x = fighterJet.x; bomb.y = fighterJet.y + 50; bombs.push(bomb); game.addChild(bomb); LK.getSound('bomb').play(); bombCooldownTimer = bombCooldownTime; // Start cooldown } }; // Weapon system variables var weaponMode = 'cannon'; // 'cannon' or 'bombing' var bombCooldownTimer = 0; var bombCooldownTime = 300; // 5 seconds at 60fps var bombTargetCircle = null; // Initialize bomb target circle bombTargetCircle = LK.getAsset('explosion', { anchorX: 0.5, anchorY: 0.5, alpha: 0.3 }); bombTargetCircle.visible = false; game.addChild(bombTargetCircle); // Keyboard event handling using game.key game.key = function (event) { if (event.key === '1') { weaponMode = 'cannon'; bombTargetCircle.visible = false; } else if (event.key === '2') { weaponMode = 'bombing'; bombTargetCircle.visible = true; } else if (event.key === ' ' && fighterJet.flareCount > 0) { // Deploy flare var flare = new Flare(); flare.x = fighterJet.x + (Math.random() - 0.5) * 100; flare.y = fighterJet.y + (Math.random() - 0.5) * 100; flares.push(flare); game.addChild(flare); fighterJet.flareCount--; updateFlareDisplay(); LK.getSound('flare').play(); } }; game.update = function () { spawnTimer++; // Handle bomb cooldown if (bombCooldownTimer > 0) { bombCooldownTimer--; } // Update bomb target circle visibility based on weapon mode and cooldown if (bombTargetCircle) { bombTargetCircle.visible = weaponMode === 'bombing'; if (weaponMode === 'bombing' && bombCooldownTimer > 0) { bombTargetCircle.alpha = 0.1; // Dim during cooldown } else if (weaponMode === 'bombing') { bombTargetCircle.alpha = 0.3; // Normal visibility when ready } } // Spawn new ground targets if (spawnTimer >= 60) { // Every second spawnGroundTarget(); spawnTimer = 0; } // Update bullets for (var b = bullets.length - 1; b >= 0; b--) { var bullet = bullets[b]; if (bullet.y < -50) { bullet.destroy(); bullets.splice(b, 1); continue; } // Check bullet vs ground targets (only cars and army vans) for (var gt = groundTargets.length - 1; gt >= 0; gt--) { var target = groundTargets[gt]; if (bullet.intersects(target) && (target.targetType === 'car' || target.targetType === 'armyVan')) { createExplosion(target.x, target.y); LK.setScore(LK.getScore() + target.points); updateScore(); bullet.destroy(); bullets.splice(b, 1); target.destroy(); groundTargets.splice(gt, 1); break; } } } // Update bombs for (var bo = bombs.length - 1; bo >= 0; bo--) { var bomb = bombs[bo]; if (bomb.y > 2800) { bomb.destroy(); bombs.splice(bo, 1); continue; } // Check bomb vs ground targets (buildings and S-300 systems) for (var gt = groundTargets.length - 1; gt >= 0; gt--) { var target = groundTargets[gt]; if (bomb.intersects(target) && (target.targetType === 'building' || target.targetType === 'targetBuilding' || target.targetType === 's300System')) { createExplosion(target.x, target.y); LK.setScore(LK.getScore() + target.points); updateScore(); if (target.targetType === 's300System') { fighterJet.aaSystemsDestroyed++; if (fighterJet.aaSystemsDestroyed >= 5 && fighterJet.lives < 3) { fighterJet.lives++; fighterJet.aaSystemsDestroyed = 0; updateLivesDisplay(); } } bomb.destroy(); bombs.splice(bo, 1); target.destroy(); groundTargets.splice(gt, 1); break; } } } // Update missiles for (var m = missiles.length - 1; m >= 0; m--) { var missile = missiles[m]; // Update missile target to current fighter jet position missile.targetX = fighterJet.x; missile.targetY = fighterJet.y; // Check if missile was intercepted by flare if (checkMissileFlareCollision(missile)) { missiles.splice(m, 1); continue; } // Check missile vs fighter jet if (missile.intersects(fighterJet)) { createExplosion(fighterJet.x, fighterJet.y); fighterJet.lives--; updateLivesDisplay(); if (fighterJet.lives <= 0) { LK.showGameOver(); return; } missile.destroy(); missiles.splice(m, 1); continue; } // Remove missiles that go off screen if (missile.y > 2800 || missile.y < -50 || missile.x < -50 || missile.x > 2100) { missile.destroy(); missiles.splice(m, 1); } } // Update ground targets for (var gt = groundTargets.length - 1; gt >= 0; gt--) { var target = groundTargets[gt]; if (target.y > 2800) { target.destroy(); groundTargets.splice(gt, 1); } } // Update flares for (var f = flares.length - 1; f >= 0; f--) { var flare = flares[f]; if (flare.destroyed) { flares.splice(f, 1); } } // Update explosions for (var e = explosions.length - 1; e >= 0; e--) { var explosion = explosions[e]; if (explosion.destroyed) { explosions.splice(e, 1); } } // Update weapon display updateWeaponDisplay(); };
===================================================================
--- original.js
+++ change.js
@@ -184,8 +184,22 @@
fill: '#ffffff'
});
flareText.anchor.set(0.5, 0);
LK.gui.top.addChild(flareText);
+var weaponText = new Text2('Weapon: Cannon (1/2)', {
+ size: 50,
+ fill: '#ffffff'
+});
+weaponText.anchor.set(0.5, 0);
+weaponText.y = 80;
+LK.gui.top.addChild(weaponText);
+function updateWeaponDisplay() {
+ var cooldownText = '';
+ if (weaponMode === 'bombing' && bombCooldownTimer > 0) {
+ cooldownText = ' (Cooldown: ' + Math.ceil(bombCooldownTimer / 60) + 's)';
+ }
+ weaponText.setText('Weapon: ' + (weaponMode === 'cannon' ? 'Cannon' : 'Bombing') + ' (1/2)' + cooldownText);
+}
function updateScore() {
scoreText.setText('Score: ' + LK.getScore());
}
function updateLivesDisplay() {
@@ -256,51 +270,82 @@
// Event handlers
game.move = function (x, y, obj) {
fighterJet.x = x;
fighterJet.y = y;
+ // Update bomb target circle position
+ if (bombTargetCircle) {
+ bombTargetCircle.x = x;
+ bombTargetCircle.y = y + 100; // Position circle below jet
+ }
};
game.down = function (x, y, obj) {
- if (obj.event && obj.event.button === 0) {
- // Left click - fire bullet
+ if (weaponMode === 'cannon') {
+ // Fire bullet
var bullet = new Bullet();
bullet.x = fighterJet.x;
bullet.y = fighterJet.y - 50;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
- } else if (!obj.event) {
- // Default action for touch/tap (no event object) - fire bullet
- var bullet = new Bullet();
- bullet.x = fighterJet.x;
- bullet.y = fighterJet.y - 50;
- bullets.push(bullet);
- game.addChild(bullet);
- LK.getSound('shoot').play();
+ } else if (weaponMode === 'bombing' && bombCooldownTimer <= 0) {
+ // Drop bomb
+ var bomb = new Bomb();
+ bomb.x = fighterJet.x;
+ bomb.y = fighterJet.y + 50;
+ bombs.push(bomb);
+ game.addChild(bomb);
+ LK.getSound('bomb').play();
+ bombCooldownTimer = bombCooldownTime; // Start cooldown
}
};
-// Keyboard handlers for spacebar (flares) and B key (bombing)
-LK.on('keydown', function (event) {
- if (event.key === ' ' && fighterJet.flareCount > 0) {
+// Weapon system variables
+var weaponMode = 'cannon'; // 'cannon' or 'bombing'
+var bombCooldownTimer = 0;
+var bombCooldownTime = 300; // 5 seconds at 60fps
+var bombTargetCircle = null;
+// Initialize bomb target circle
+bombTargetCircle = LK.getAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.3
+});
+bombTargetCircle.visible = false;
+game.addChild(bombTargetCircle);
+// Keyboard event handling using game.key
+game.key = function (event) {
+ if (event.key === '1') {
+ weaponMode = 'cannon';
+ bombTargetCircle.visible = false;
+ } else if (event.key === '2') {
+ weaponMode = 'bombing';
+ bombTargetCircle.visible = true;
+ } else if (event.key === ' ' && fighterJet.flareCount > 0) {
+ // Deploy flare
var flare = new Flare();
flare.x = fighterJet.x + (Math.random() - 0.5) * 100;
flare.y = fighterJet.y + (Math.random() - 0.5) * 100;
flares.push(flare);
game.addChild(flare);
fighterJet.flareCount--;
updateFlareDisplay();
LK.getSound('flare').play();
- } else if (event.key === 'b' || event.key === 'B') {
- // B key - drop bomb
- var bomb = new Bomb();
- bomb.x = fighterJet.x;
- bomb.y = fighterJet.y + 50;
- bombs.push(bomb);
- game.addChild(bomb);
- LK.getSound('bomb').play();
}
-});
+};
game.update = function () {
spawnTimer++;
+ // Handle bomb cooldown
+ if (bombCooldownTimer > 0) {
+ bombCooldownTimer--;
+ }
+ // Update bomb target circle visibility based on weapon mode and cooldown
+ if (bombTargetCircle) {
+ bombTargetCircle.visible = weaponMode === 'bombing';
+ if (weaponMode === 'bombing' && bombCooldownTimer > 0) {
+ bombTargetCircle.alpha = 0.1; // Dim during cooldown
+ } else if (weaponMode === 'bombing') {
+ bombTargetCircle.alpha = 0.3; // Normal visibility when ready
+ }
+ }
// Spawn new ground targets
if (spawnTimer >= 60) {
// Every second
spawnGroundTarget();
@@ -411,5 +456,7 @@
if (explosion.destroyed) {
explosions.splice(e, 1);
}
}
+ // Update weapon display
+ updateWeaponDisplay();
};
\ No newline at end of file
B-2 bombing jet. In-Game asset. 2d. High contrast. No shadows
S-300 Anti Air system from the bird view. In-Game asset. 2d. High contrast. No shadows
Hi-Teck buikding. In-Game asset. 2d. High contrast. No shadows
Tiny missile pointing up. In-Game asset. 2d. High contrast. No shadows
Strait anti air missile. In-Game asset. 2d. High contrast. No shadows
strait flare missile. In-Game asset. 2d. High contrast. No shadows
WW2 bomb. In-Game asset. 2d. High contrast. No shadows
Army building. In-Game asset. 2d. High contrast. No shadows
רכב צבאי ארוך וגדול, כמו תובלתית, מכוסה בברזנט, מבט מהפרופיל.
Missiles storage. In-Game asset. 2d. High contrast. No shadows
מתקן ענק לשיגור טיל שעליו מוכן טיל גרעיני. In-Game asset. 2d. High contrast. No shadows