Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Error: [object Object]addChildAt: The index 1 supplied is out of bounds 0' in or related to this line: 'middleLayer.addChildAt(leftBullet, 1);' Line Number: 759
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: math is not defined' in or related to this line: 'self.dirX = 6 * math.abs(deltaX) / distance;' Line Number: 268
Code edit (1 edits merged)
Please save this source code
Code edit (15 edits merged)
Please save this source code
User prompt
in flyMode == 2, adapt self.dirX = 3; self.dirY = 3; to ensure that the fighter passes close to the center
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'energyBarFill')' in or related to this line: 'self.energyBarFill.alpha = 0.5 + 0.5 * Math.sin(currentTime) * 10;' Line Number: 1385
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
animate the setText of missionText by writing missionLabel character by character
Code edit (14 edits merged)
Please save this source code
User prompt
in gameMenuDown, if !startButton.visible , make startButton & startText fade in
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in or related to this line: 'debugText.setText("Deltas: " + deltaX.toFixed(0) + "," + deltaY.toFixed(0) + " => " + (self.pointerHud.rotation * 180 / Math.PI).toFixed(0));' Line Number: 544
Code edit (15 edits merged)
Please save this source code
User prompt
make energyBarFill blink when health is under 33
/**** * Classes ****/ /***********************************************************************************/ /********************************** BULLET CLASS ***********************************/ /***********************************************************************************/ var Bullet = Container.expand(function (isLeft, isTop) { var self = Container.call(this); self.isTop = isTop; var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5, width: 10, height: 250, tint: 0x00FF00, alpha: 0.9 }); self.distanceToCenter = 1024; self.isLeft = isLeft; self.speed = 10; self.update = function () { self.x += self.isLeft ? self.speed : -self.speed; self.y += self.isTop ? self.speed * 0.6 : -self.speed * 0.6; // Calculate distance to center and adjust width accordingly self.distanceToCenter = Math.abs(self.x - 1024); var shrinkRatio = 0.1 + Math.pow(self.distanceToCenter, 1.2) * 5 / Math.pow(1024, 1.2); self.width = Math.max(0.5, 6 * Math.pow(shrinkRatio, 1.1)); self.height = Math.max(10, 250 * Math.pow(shrinkRatio, 1.1)); self.speed = Math.max(40, Math.min(100, 100 * Math.exp(self.distanceToCenter / 1024 - 1))); if (self.distanceToCenter <= 75) { self.checkForCollision(); } }; self.checkForCollision = function () { if (!currentFighter) { return; } log("Check collid", currentFighter.x, currentFighter.y); var touched = (currentFighter.x < 1024 && self.isLeft || currentFighter.x >= 1024 && !self.isLeft) && self.intersects(currentFighter); if (touched) { if (isDebug) { debugText.setText("Distance to Center: " + self.distanceToCenter.toFixed(0)); } // Handle collision: destroy bullet and enemy, update score, etc. self.destroy(); currentFighter.explode(); if (bullets.indexOf(self) !== -1) { bullets.splice(bullets.indexOf(self), 1); } // Update score LK.setScore(LK.getScore() + 1); } }; }); /***********************************************************************************/ /********************************** COCKPIT CLASS ***********************************/ /***********************************************************************************/ var CockpitDisplay = Container.expand(function () { var self = Container.call(this); self.cockpitButtonStand = self.attachAsset('fireButtonStand', { anchorX: 0.5, anchorY: 0.5, alpha: 0.9, y: 2732 + 300 }); self.cockpitButtonBase = self.attachAsset('fireButtonBase', { anchorX: 0.5, anchorY: 0.5, alpha: 1, y: 2732 }); self.cockpitButton = self.attachAsset('fireButton', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 2732 - 570 }); self.cockpitButton.originalScaleX = self.cockpitButton.scale.x; self.cockpitButton.originalScaleY = self.cockpitButton.scale.y; self.cockpitButton.isAnimating = false; }); /***********************************************************************************/ /********************************** ENEMY BULLET CLASS *****************************/ /***********************************************************************************/ var EnemyBullet = Container.expand(function (isLeft) { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5, width: 2, height: 1, tint: 0xFF0000, alpha: 0.9 }); self.speed = 5; self.isLeft = isLeft; self.rotation = (isLeft ? -1 : 1) * Math.PI * 0.9; self.update = function () { self.speed += self.speed * 0.05; // Increase speed as it gets farther self.y += self.speed; self.x += (self.isLeft ? -1 : 1) * self.speed * 0.3; self.width = Math.min(60, self.width + 0.5); self.height = Math.min(512, self.height + 4); // Destroy bullet if it goes off screen if (self.y > 2732 || self.x < 0 || self.x > 2048) { self.destroy(); if (self.isLeft) { spaceship.struck(); } } }; }); /***********************************************************************************/ /********************************** FIGHTER CLASS **********************************/ /***********************************************************************************/ var Fighter = Container.expand(function (index) { var self = Container.call(this); self.baseSize = 512; var outOffset = 512; self.fighterGraphics = self.attachAsset('fighter', { anchorX: 0.5, anchorY: 0.5, width: self.baseSize, height: self.baseSize }); self.fighterGraphics2 = self.attachAsset('fighter2', { anchorX: 0.5, anchorY: 0.5, width: self.baseSize, height: self.baseSize, visible: false }); self.fighterGraphics2r = self.attachAsset('fighter2r', { anchorX: 0.5, anchorY: 0.5, width: self.baseSize, height: self.baseSize, visible: false }); var passingSound = LK.getSound('fighterPassing'); self.index = index; self.isActive = false; self.hasShot = false; self.hasPassed = false; self.speedX = 4; self.speedY = 4; self.speedZ = 1; self.dirX = 0; self.dirY = 0; self.sizeRatio = 1; self.finalSpeedY = 0; self.finalSpeedZ = 0; self.isDestroyed = false; self.speedYModifier = 1; self.flyMode = 1; self.update = function () { if (!self.isActive) { return; } // Update size on z distance self.sizeRatio = initialFighterZ / (Math.abs(self.z) * 20 + 0.1); self.sizeRatio = Math.max(0.1, Math.min(2, self.sizeRatio)); self.width = self.baseSize * self.sizeRatio; self.height = self.baseSize * self.sizeRatio; //log("iniZ=" + initialFighterZ, "z=" + self.z.toFixed(0), "sizeRatio=" + self.sizeRatio, " baseSize" + self.baseSize, " => w=h=" + self.width); // Update speed on z distance if (self.flyMode == 1 || self.flyMode == 2) { if (self.sizeRatio <= 1) { self.speedZ = self.speedZ + 0.015; } else { self.speedZ = self.speedZ * self.sizeRatio * 0.90; } } // Fix speed when destroyed if (self.isDestroyed) { // Stop increase speed when destroyed if (!self.finalSpeedY) { self.finalSpeedY = self.speedY * 0.5; self.finalSpeedZ = self.speedZ * 0.5; } self.speedY = self.finalSpeedY; self.speedZ = self.finalSpeedZ; } if (self.flyMode == 1) { self.dirY = Math.sign(self.y); var length = Math.sqrt(self.dirX * self.dirX + self.dirY * self.dirY); if (length === 0) { length = 1; } self.dirX /= length; self.dirY /= length; if (self.z > 1024) { self.dirX += current3DSpaceAngles.deltaH * 10; self.dirY += current3DSpaceAngles.deltaV * self.speedYModifier; } else { self.y += self.dirY * (self.sizeRatio > 0.3 ? 50 * Math.pow(self.sizeRatio, 2) : 0.5); if (!self.isDestroyed && !self.hasShot) { self.hasShot = true; self.shoot(); } } var distanceFromCenter = self.x - 1024; // Calculate the rotation based on the distance from the center self.rotation = distanceFromCenter / 1024 * Math.PI * 0.25; } if (self.flyMode == 2) { self.speedZ = 3; var centerX = 1024; var centerY = 1366; var deltaX = centerX - self.x; var deltaY = centerY - self.y; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); if (self.speedX > 0 && deltaX > 42 || self.speedX < 0 && deltaX < -42) { self.dirX = 6 * Math.abs(deltaX) / distance; self.dirY = 6 * deltaY / distance; //self.dirX = Math.max(self.dirX, self.dirY); //self.dirY = Math.max(self.dirX, self.dirY); } else { self.dirX = 3; self.dirY = 3; } /* if (self.z > 1024) { self.dirX += current3DSpaceAngles.deltaH * 1; self.dirY += current3DSpaceAngles.deltaV * 1; } else { // Accelerate y move when close self.x += self.dirX * (self.sizeRatio > 0.3 ? 10 * Math.pow(self.sizeRatio, 2) : 0.5) * Math.sign(self.speedX); self.y += self.dirY * (self.sizeRatio > 0.3 ? 10 * Math.pow(self.sizeRatio, 2) : 0.5); } */ } // Update position self.x += self.dirX * self.speedX; self.y += self.dirY * self.speedY; self.z -= self.speedZ; // Passing sound if (!self.isDestroyed && !self.hasPassed && self.z < 512) { self.hasPassed = true; passingSound.play(); } // Remove when out of screen if (!self.isDestroyed && (self.z <= 0 || self.x < -outOffset || self.y < -outOffset || self.x > 2048 + outOffset || self.y > 2732 + outOffset)) { log(self.index + ") Fighter passed behind. cleaning currentFighter..."); self.reset(); currentFighter = null; } }; self.reset = function () { var rand = Math.random() * 0.5 + 0.5; // TEMP DEBUG !! self.visible = false; self.isActive = false; self.hasShot = false; self.hasPassed = false; self.speedX = 1; self.speedY = 1; self.speedZ = 1; self.sizeRatio = 1; self.width = self.baseSize * self.sizeRatio; self.height = self.baseSize * self.sizeRatio; log(self.index + ") Reseting width to :" + (self.baseSize * self.sizeRatio).toFixed(0), " => " + self.width); self.finalSpeedY = 0; self.finalSpeedZ = 0; self.speedYModifier = Math.random() * 3; self.isDestroyed = false; self.flyMode = 2; switch (self.flyMode) { case 2: self.fighterGraphics.visible = false; self.fighterGraphics2.visible = rand <= 0.5; self.fighterGraphics2r.visible = rand > 0.5; self.x = rand > 0.5 ? 1800 + 42 * rand : -42 - rand * 128; self.z = initialFighterZ - 1024 * rand; self.y = 512 - 512 * rand; self.speedX = Math.sign(-1 * self.x); break; default: self.fighterGraphics.visible = true; self.fighterGraphics2.visible = false; self.fighterGraphics2r.visible = false; self.x = rand > 0.5 ? -512 : 2048 + 512; self.z = initialFighterZ; self.y = 768 - 512 * rand; self.scaleX = 1; } }; self.activate = function () { self.visible = true; self.isActive = true; }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y; bulletsOfEnemy.push(bullet); middleLayer.addChildAt(bullet, 2); var bullet2 = new EnemyBullet(true); bullet2.x = self.x; bullet2.y = self.y; bulletsOfEnemy.push(bullet2); middleLayer.addChildAt(bullet2, 2); LK.getSound('laserShot2').play(); LK.setTimeout(function () { LK.getSound('laserShot2').play(); }, 128); }; self.explode = function (callback) { if (self.isDestroyed) { return; } self.isDestroyed = true; passingSound.stop(); log(self.index + ") Killed"); var explosion = self.attachAsset('explosion1', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, width: 256, height: 256, rotation: Math.PI * 2 * Math.random() }); var explosion2 = self.attachAsset('explosion2', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, width: 128, height: 128, rotation: Math.PI * 2 * Math.random() }); // Play explosion sound LK.getSound('explosion').play(); var growInterval = LK.setInterval(function () { explosion.width += 50; explosion.height += 50; if (explosion.width >= self.fighterGraphics.width) { if (explosion.width >= 512) { self.fighterGraphics.visible = false; } if (explosion.width >= 1024) { explosion2.width += 50; explosion2.height += 50; explosion.alpha -= 0.05; } if (explosion2.width >= 2048) { explosion2.alpha -= 0.05; } if (explosion2.width >= 4096 * 2) { LK.clearInterval(growInterval); explosion.destroy(); explosion2.destroy(); lastFighterKillTime = Date.now(); currentNbEnnemies--; if (!currentNbEnnemies) { log("All enemies cleared => Next level"); cleanPlayingState(); } else { log(currentNbEnnemies + " Enemy to go"); currentFighter = null; } } } }, 16); // 60 FPS }; // Reset the fighter's properties self.reset(); }); /***********************************************************************************/ /********************************** SPACE OBJECT CLASS *****************************/ /***********************************************************************************/ var SpaceObject = Container.expand(function (index) { var self = Container.call(this); index = Math.min(nbSpaceObjects - 1, Math.max(0, index || 0)); var spaceObjectGraphics = self.attachAsset('spaceObject' + index, { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0.25; self.update = function () { self.x += (current3DSpaceAngles.deltaH || Math.sign(self.x - 1024)) * self.speed; self.y += (current3DSpaceAngles.deltaV || Math.sign(self.y - 1366)) * self.speed; //background.x += current3DSpaceAngles.deltaH; //background.y += current3DSpaceAngles.deltaV; }; }); /***********************************************************************************/ /******************************** SPACESHIP CLASS **********************************/ /***********************************************************************************/ var Spaceship = Container.expand(function () { var self = Container.call(this); var canonLeft = self.attachAsset('canon', { anchorX: 0.5, anchorY: 0.5, x: -1100, y: 650, rotation: -Math.PI * 0.01 }); var canonRight = self.attachAsset('canon', { anchorX: 0.5, anchorY: 0.5, scaleX: -1, x: 1100, y: 650, rotation: Math.PI * 0.01 }); self.centralHud = self.attachAsset('aimingCentralHud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.6, y: -100, tint: 0x00FF00 }); self.pointerHud = self.attachAsset('pointerHud', { anchorX: 0.5, anchorY: 4, alpha: 0.5, x: 0, y: -100, tint: 0xFF0000, rotation: Math.PI * 0.5 }); var spaceshipGraphics = self.attachAsset('spaceship', { anchorX: 0.5, anchorY: 0.5 }); var spaceshipDeco1 = self.attachAsset('shipDeco1', { anchorX: 0.5, anchorY: 0.5, x: -955, y: 1185, alpha: 0.8, rotation: -0.35, tint: 0xFFFFFF }); self.energyBar = new Container(); self.energyBar.alpha = 0.75; self.energyBarY = 490; self.energyBarFrame = self.energyBar.attachAsset('energyBarFrame', { anchorX: 0.5, anchorY: 0.5, width: 460, height: 20, x: 8, y: self.energyBarY }); self.energyBarFill = self.energyBar.attachAsset('energyBar', { anchorX: 0, anchorY: 0.5, width: 435, height: 10, x: -210, y: self.energyBarY }); self.energyBarMask = self.energyBar.attachAsset('energyBarMask', { anchorX: 0, anchorY: 0.5, width: 435, height: 10, x: 225, y: self.energyBarY }); self.addChild(self.energyBar); self.damageScreen = new Container(); self.damageScreenBack = self.damageScreen.attachAsset('boardBlackScreen', { anchorX: 0.5, anchorY: 0.5, width: 215, height: 290, x: -350, y: 1020 }); self.damageScreenBack = self.damageScreen.attachAsset('spaceshipSchema', { anchorX: 0.5, anchorY: 0.5, width: 200, height: 250, x: -350, y: 1020, alpha: 0.8 }); self.addChild(self.damageScreen); self.radarScreen = new Container(); self.radarScreenBack = self.radarScreen.attachAsset('boardBlackScreen', { anchorX: 0.5, anchorY: 0.5, width: 235, height: 310, x: 352, y: 1020 }); self.radarScreenHud = self.radarScreen.attachAsset('radarHud', { anchorX: 0.5, anchorY: 0.5, width: 170, height: 170, x: 360, y: 1050, alpha: 0.8 }); self.radarBarHud = self.radarScreen.attachAsset('radarBar', { anchorX: 0.5, anchorY: 0, width: 4, height: 80, x: 360, y: 1050, alpha: 0.8 }); self.radarScreenFoeHud = self.radarScreen.attachAsset('fighter', { anchorX: 0.5, anchorY: 0.5, width: 150, height: 150, x: 360, y: 1050, alpha: 0.8, visible: true }); self.radarScreenLevel = new Text2('SCANNING', { size: 50, fill: "#FFFFFF", font: "Impact", visible: false }); self.radarScreenLevel.x = 250; self.radarScreenLevel.y = 880; self.radarScreenLevel.alpha = 0.8; //self.radarScreenLevel.anchor.set(2, 1); self.radarScreen.addChild(self.radarScreenLevel); self.addChild(self.radarScreen); self.coords = { x: 0, y: 0, z: 0 }; self.speed = 0.01; self.energy = 100; self.health = 100; self.isShooting = false; self.update = function () { // Blink energyBarFill when health is under 33 if (self.health < 33) { var currentTime = Date.now(); self.energyBarFill.alpha = 0.5 + 0.5 * Math.sin(currentTime / ((self.health || 1) * 10)); } else { self.energyBarFill.alpha = 1; } // Update space coordinates spaceship.coords.x += Math.sin(current3DSpaceAngles.horizontalAngle) * spaceship.speed; spaceship.coords.y += Math.cos(current3DSpaceAngles.verticalAngle) * spaceship.speed; spaceship.coords.z += Math.sin(current3DSpaceAngles.verticalAngle) * Math.cos(current3DSpaceAngles.horizontalAngle) * spaceship.speed; self.updateCentralHud(); self.updatePointerHud(); self.animateDeco(); self.radarBarHud.rotation += 0.01; }; self.updateCentralHud = function () { var targetLocked = false; if (currentFighter && !currentFighter.isDestroyed) { targetLocked = self.centralHud.intersects(currentFighter); self.radarScreenFoeHud.rotation = currentFighter.rotation; if (self.radarScreenHud.visible) { self.radarScreenFoeHud.visible = true; self.radarScreenHud.visible = false; self.radarBarHud.visible = false; self.radarScreenLevel.tint = 0xFF0000; self.radarScreenLevel.setText("INCOMING"); } } else { if (!self.radarScreenHud.visible) { self.radarScreenHud.visible = true; self.radarBarHud.visible = true; self.radarScreenFoeHud.visible = false; self.radarScreenLevel.tint = 0x00FF00; self.radarScreenLevel.setText("SCANNING"); } } self.centralHud.tint = targetLocked ? 0x00FF00 : 0xFFFFFF; }; self.updatePointerHud = function () { //directionX += current3DSpaceAngles.deltaH * 4; //.horizontalAngle; //directionY += current3DSpaceAngles.deltaV * 4; //.verticalAngle; var deltaX = current3DSpaceAngles.deltaH; var deltaY = current3DSpaceAngles.deltaV; var currentTime = Date.now(); if (currentFighter && !currentFighter.isDestroyed) { self.pointerHud.tint = 0xFF0000; deltaX = currentFighter.x - self.x; deltaY = currentFighter.y - self.y; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); if (Math.abs(deltaX) > 256) { self.pointerHud.y += Math.sin(currentTime / 100) * 1; // Sinusoidal movement self.pointerHud.alpha = 0.3 + Math.sin(currentTime / 100) * 0.7; // Sinusoidal movement if (currentTime - lastSearchBeepTime > targetFoundBeepDelay) { lastSearchBeepTime = Date.now(); LK.getSound('targetFoundBeep').play(); } } else { self.pointerHud.alpha = 0.5; self.pointerHud.y = -100; } var targetRotation = Math.atan2(deltaY, deltaX) + Math.PI * 0.5; var currentRotation = self.pointerHud.rotation; var rotationDifference = targetRotation - currentRotation; // Normalize the rotation difference to the range [-PI, PI] if (rotationDifference > Math.PI) { rotationDifference -= 2 * Math.PI; } else if (rotationDifference < -Math.PI) { rotationDifference += 2 * Math.PI; } // Apply a fraction of the rotation difference to make the rotation progressive self.pointerHud.rotation += rotationDifference * 0.1; } else { self.pointerHud.tint = 0xFFFFFF; var targetRotation = deltaY || deltaX ? Math.atan2(deltaY, deltaX) + Math.PI * 1.5 : 0; if ((deltaY || deltaX) && currentTime - Math.max(lastSearchBeepTime, lastFighterKillTime) > searchBeepDelay) { lastSearchBeepTime = Date.now(); LK.getSound('detectionBeep1').play(); } var currentRotation = self.pointerHud.rotation; var rotationDifference = targetRotation - currentRotation; // Normalize the rotation difference to the range [-PI, PI] if (rotationDifference > Math.PI) { rotationDifference -= 2 * Math.PI; } else if (rotationDifference < -Math.PI) { rotationDifference += 2 * Math.PI; } // Apply a fraction of the rotation difference to make the rotation progressive self.pointerHud.rotation += rotationDifference * 0.1; } if (isDebug) { debugText.setText("Deltas: " + deltaX.toFixed(0) + "," + deltaY.toFixed(0) + " => " + (self.pointerHud.rotation * 180 / Math.PI).toFixed(0)); } }; self.shoot = function () { if (self.isShooting) { return; } self.isShooting = true; // Recoil effect for left canon var originalLeftX = canonLeft.x; var originalLeftY = canonLeft.y; var recoilDistance = 40; var recoilSpeed = 5; var energySpeed = 10; var recoilLeftInterval = LK.setInterval(function () { canonLeft.x -= recoilSpeed; canonLeft.y += recoilSpeed; self.energy -= energySpeed; canonLeft.tint = 0xccFFcc; if (canonLeft.x <= originalLeftX - recoilDistance) { LK.clearInterval(recoilLeftInterval); var returnLeftInterval = LK.setInterval(function () { canonLeft.x += recoilSpeed; canonLeft.y -= recoilSpeed; self.energy += energySpeed; if (canonLeft.x >= originalLeftX) { canonLeft.x = originalLeftX; canonLeft.y = originalLeftY; self.energy = 100; canonLeft.tint = 0xFFFFFF; LK.clearInterval(returnLeftInterval); self.isShooting = false; } }, 16); } }, 16); // Recoil effect for right canon var originalRightX = canonRight.x; var originalRightY = canonRight.y; var recoilRightInterval = LK.setInterval(function () { canonRight.x += recoilSpeed; canonRight.y += recoilSpeed; canonRight.tint = 0xccFFcc; if (canonRight.x >= originalRightX + recoilDistance) { LK.clearInterval(recoilRightInterval); var returnRightInterval = LK.setInterval(function () { canonRight.x -= recoilSpeed; canonRight.y -= recoilSpeed; if (canonRight.x <= originalRightX) { canonRight.x = originalRightX; canonRight.y = originalRightY; canonRight.tint = 0xFFFFFF; LK.clearInterval(returnRightInterval); } }, 16); } }, 16); // Play laserShot sound LK.getSound('laserShot').play(); LK.setTimeout(function () { LK.getSound('laserShot').play(); }, 128); // Spawn bullets from side canons var leftBullet = new Bullet(true); leftBullet.x = 0; // Adjust for left canon position leftBullet.y = self.y + 512; // Start the bullet just above the spaceship leftBullet.rotation = Math.PI * 0.30; middleLayer.addChildAt(leftBullet, 1); bullets.push(leftBullet); var rightBullet = new Bullet(false); rightBullet.x = game.width; // Adjust for right canon position rightBullet.y = self.y + 512; // Start the bullet just above the spaceship rightBullet.rotation = -Math.PI * 0.30; middleLayer.addChildAt(rightBullet, 1); bullets.push(rightBullet); }; self.struck = function () { log("struck!"); LK.getSound('damage').play(); LK.setTimeout(function () { LK.getSound('damage').play(); }, 128); LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second // Shake animation var originalX = self.x; var originalY = self.y; var shakeIntensity = 30; var shakeDuration = 600; // in milliseconds var shakeInterval = 16; // roughly 60 FPS var elapsedTime = 0; var shakeAnimation = LK.setInterval(function () { if (elapsedTime >= shakeDuration) { LK.clearInterval(shakeAnimation); self.x = originalX; self.y = originalY; return; } self.x = originalX + (Math.random() - 0.5) * shakeIntensity; self.y = originalY + (Math.random() - 0.5) * shakeIntensity; elapsedTime += shakeInterval; }, shakeInterval); self.decreaseHealth(); }; self.decreaseHealth = function () { // Handle health self.health -= minDamage + Math.random() * (currentLevel - 1); self.energyBarMask.scale.x = -(100 - self.health) / 100; log("New health =", self.health); if (self.health <= 0) { cleanPlayingState(); } else { self.energyBarFill.alpha = 1; } if (self.health < 33) { LK.setTimeout(function () { LK.getSound('warning').play(); if (self.health < 15) { LK.setTimeout(function () { LK.getSound('warning').play(); }, 2000); } }, 256); } }; self.animateDeco = function () { var currentTime = Date.now(); spaceshipDeco1.alpha = Math.max(0, Math.min(1, 0.75 + 0.25 * Math.sin(currentTime / 500))); }; self.init = function () { self.energyBarMask.scale.x = -(100 - self.health) / 100; self.radarScreenHud.visible = true; self.radarScreenFoeHud.visible = false; self.radarScreenLevel.tint = 0x00FF00; self.radarScreenLevel.setText("SCANNING"); }; self.init(); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Initialize game with a black background }); /**** * Game Code ****/ function animateCockpitButton() { if (cockpitDisplay.cockpitButton.isAnimating) { return; } cockpitDisplay.cockpitButton.isAnimating = true; var moveDown = true; var originalY = cockpitDisplay.cockpitButton.y; var originalBaseY = cockpitDisplay.cockpitButtonBase.y; var animationInterval = LK.setInterval(function () { if (moveDown) { cockpitDisplay.cockpitButton.y += 15; cockpitDisplay.cockpitButtonBase.y += 2; if (cockpitDisplay.cockpitButton.y >= originalY + 20) { moveDown = false; } } else { cockpitDisplay.cockpitButton.y -= 15; cockpitDisplay.cockpitButtonBase.y -= 2; if (cockpitDisplay.cockpitButton.y <= originalY) { cockpitDisplay.cockpitButton.y = originalY; cockpitDisplay.cockpitButtonBase.y = originalBaseY; cockpitDisplay.cockpitButton.isAnimating = false; LK.clearInterval(animationInterval); } } }, 16); // 60 FPS } /* # Space Strike ### Game Design and Planning 1. **Game Objectives**: Defeating all enemy fighters. 2. **Game Levels**: Random map with an increasing number of ennemy figthers per level. 3. **Game Assets**: 4. **Game Mechanics**: 1. **Player Interaction**: 1st person view. Tap to shoot. 4. **Game Loop and Events**: Objects updates occur in the game loop. Input events are handled in input functions. 5. **Scoring and Progression**: Player's score is updated when killing ennemies. When no more ennemies game switches to next level. 6. **Game Over and Reset**: The game is over when player's lives reaches zero. */ /****************************************************************************************** */ /************************************** GLOBAL VARIABLES ********************************** */ /****************************************************************************************** */ // Enumeration for game states var GAME_STATE = { INIT: 'INIT', MENU: 'MENU', HELP: 'HELP', STARTING: 'STARTING', NEW_ROUND: 'NEW_ROUND', PLAYING: 'PLAYING', SCORE: 'SCORE' }; var gameState = GAME_STATE.INIT; var currentLevel = 0; var currentNbEnnemies = 0; var minDamage = 10; var nbStars = 50; var starsSpeed = 10; var stars = []; var starsFixed = []; var current3DSpaceAngles = { horizontalAngle: 0, verticalAngle: 0, deltaH: 0, deltaV: 0 }; var backgroundLayer = new Container(); var middleLayer = new Container(); var foregroundLayer = new Container(); var background; var currentSpaceObject; var spaceObjectOffset = 32; var lastSpaceObjectChangeTime = 0; var nbSpaceObjects = 7; var initialFighterZ = 2048; var spaceship; var cockpitDisplay; var reachedTargetAngle = false; var bullets = []; // Player's bullets var bulletsOfEnemy = []; // Enemies' bullets var enemies = {}; // Ennemy fighters var lastFighterKillTime = 0; var nextFigtherSpawnDelay = 2000; var fighterPool = []; var rotationSpeed = 0.25; var isChangingDirection = false; var currentFighter = null; var lastAngleChangeTime = Date.now(); var lastSearchBeepTime = lastAngleChangeTime; var searchBeepDelay = 2000; var targetFoundBeepDelay = 512; var nextAngleChangeDelay = 3000; var currentIndex = 0; // UI var title; var titleOne; var startText; var startButton; var bgMusic; var missionText; var foeText; var foeAsset; var animateMissionTextEnded = false; var startingStateTime = 0; var startingStateDelay = 3000; // Debug var isDebug = true; var fpsText; var lastTick; var frameCount; var debugText; /****************************************************************************************** */ /*********************************** UTILITY FUNCTIONS ************************************ */ /****************************************************************************************** */ function log() { if (isDebug) { var _console; (_console = console).log.apply(_console, arguments); } } function getNextIndex() { currentIndex++; return currentIndex; } function animateMissionText(missionText, missionLabel) { var currentIndex = 0; var interval = LK.setInterval(function () { if (currentIndex < missionLabel.length) { missionText.setText(missionText.getContent().text + missionLabel[currentIndex]); currentIndex++; } else { animateMissionTextEnded = true; LK.clearInterval(interval); } }, 120); // Adjust the speed of the animation by changing the interval time } /****************************************************************************************** */ /************************************** INPUT HANDLERS ************************************ */ /****************************************************************************************** */ game.on('down', function (x, y, obj) { switch (gameState) { case GAME_STATE.MENU: gameMenuDown(x, y, obj); break; case GAME_STATE.STARTING: gameStartingDown(x, y, obj); break; case GAME_STATE.PLAYING: gamePlayingDown(x, y, obj); break; case GAME_STATE.SCORE: // Handle score display logic here break; } }); function gameMenuDown(x, y, obj) { log("gameMenuDown..."); if (!startButton.visible) { startButton.visible = true; startText.visible = true; var fadeInInterval = LK.setInterval(function () { startButton.alpha += 0.05; startText.alpha += 0.05; if (startButton.alpha >= 1) { LK.clearInterval(fadeInInterval); startButton.alpha = 1; startText.alpha = 1; } }, 16); // 60 FPS if (bgMusic) { // Start music after 1st user interaction (mobile) bgMusic.play(); } } else { cleanMenuState(); } } function gameStartingDown(x, y, obj) { if (animateMissionTextEnded) { cleanStartingState(); initPlayingState(); } } function gamePlayingDown(x, y, obj) { log("gamePlayingDown ..."); spaceship.shoot(); animateCockpitButton(); } /****************************************************************************************** */ /************************************* GAME FUNCTIONS **************************************** */ /****************************************************************************************** */ function initStars() { for (var i = 0; i < nbStars; i++) { var star = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5, alpha: 0.9, x: Math.random() * 2048, y: Math.random() * 2732 }); stars.push(star); middleLayer.addChild(star); } // Farther stars for (var i = 0; i < nbStars * 2; i++) { var star = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 + Math.random() * 0.5, x: Math.random() * 2048, y: Math.random() * 2732, slow: true }); stars.push(star); backgroundLayer.addChildAt(star, 0); } // Fixed stars for (var i = 0; i < nbStars * 4; i++) { var star = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 + Math.random() * 0.5, x: Math.random() * 2048, y: Math.random() * 2732, fixed: true }); starsFixed.push(star); backgroundLayer.addChildAt(star, 0); //game.addChildAt(star, game.children.length); } } function starFieldAnimation() { stars.forEach(function (star) { // Calculate direction vector from center to star var directionX = star.x - 1024; // 1024 is half the width of the screen var directionY = star.y - 1366; // 1366 is half the height of the screen // Normalize direction var length = Math.sqrt(directionX * directionX + directionY * directionY); if (length === 0) { // Prevent division by zero length = 1; } directionX /= length; directionY /= length; // Add offset based on current3DSpaceAngles directionX += current3DSpaceAngles.deltaH * 4 * (star.slow ? 0.25 : 1); //.horizontalAngle; directionY += current3DSpaceAngles.deltaV * 4 * (star.slow ? 0.25 : 1); //.verticalAngle; // Move star away from center // Increase star size as it moves away to simulate faster movement var sizeIncrease = Math.min(Math.abs(directionX * 2), Math.abs(directionY * 2)); star.width = Math.min(20, star.width + sizeIncrease * 0.05 * (star.slow ? 0 : 1)); // Limit width to 20 star.height = star.width; star.x += directionX * starsSpeed * (star.slow ? 0.05 : 1); // Increase speed to 10 for faster star movement star.y += directionY * starsSpeed * (star.slow ? 0.05 : 1); if (star.alpha < 1) { star.alpha = Math.min(1, star.alpha + 0.01); } // Reset star position if it moves off screen if (star.x < 0 || star.x > 2048 || star.y < 0 || star.y > 2732) { star.x = Math.random() * 2048; star.y = Math.random() * 2732; // Reset height to initial value star.width = Math.random() * 10; star.height = star.width; star.alpha = Math.random() * (star.slow ? Math.random() * 0.5 : 1); } }); // Move nebulas images here .x-=0.1 } function mapZtoScale(z) { if (z <= 0) { return 2; // Handle non-positive inputs (optional) } // Adjusted base function (linear decay) var base = -z / 512 + 4; // Adjust coefficients for better fit // Smoothing term (optional, remove for strictly increasing function) var smoothTerm = Math.exp(-Math.pow(z - 2048, 2) / 10000); // Combine base and smoothing term with an adjustable weight var weight = 0.8; // Adjust weight between 0 (no smoothing) and 1 (full smoothing) return weight * base + (1 - weight) * smoothTerm; } function loopBgMusic() { if (bgMusic && Date.now() - bgMusic.lastPlayTime > 10000) { bgMusic.lastPlayTime = Date.now(); bgMusic.play(); } } function handleGlobalMovement() { if (currentFighter) { if (Date.now() - lastAngleChangeTime < 512) { return; } // Calculate the difference in position between the spaceship and the currentFighter var deltaX = currentFighter.x - 1024; //spaceship.x; var deltaY = currentFighter.y - 1366; //spaceship.y; // Normalize the deltas to get the direction var length = Math.sqrt(deltaX * deltaX + deltaY * deltaY); //log("Aiming at fighter ", currentFighter.x.toFixed(0), currentFighter.y.toFixed(0), "=> deltas=", deltaX.toFixed(0), deltaY.toFixed(0), " / l=" + length.toFixed(0)); /*if (length !== 0) { current3DSpaceAngles.deltaH = -deltaX / length; current3DSpaceAngles.deltaV = -deltaY / length; } */ //!reachedTargetAngle && // TEMP DEBUG if (length !== 0 && Math.abs(length) > 8 && currentFighter.z > 512) { current3DSpaceAngles.deltaH = -deltaX / length; current3DSpaceAngles.deltaV = -deltaY / length; //lastAngleChangeTime = Date.now(); } else { reachedTargetAngle = true; current3DSpaceAngles.deltaH = 0; current3DSpaceAngles.deltaV = 0; } } else { // Space ride if (Date.now() - lastAngleChangeTime < nextAngleChangeDelay) { return; } reachedTargetAngle = false; var newDeltaH = 0; var newDeltaV = 0; isChangingDirection = false; if (current3DSpaceAngles.deltaH == 0 & current3DSpaceAngles.deltaH == 0) { var rH = Math.random(); var rV = Math.random(); var dirH = rH < 0.33 ? 1 : rH > 0.66 ? -1 : 0; var dirV = rV < 0.33 ? 1 : rV > 0.66 ? -1 : 0; newDeltaH = rH * 0.5 * dirH; newDeltaV = rV * 0.8 * dirV; isChangingDirection = true; } current3DSpaceAngles.deltaH = newDeltaH; current3DSpaceAngles.deltaV = newDeltaV; lastAngleChangeTime = Date.now(); nextAngleChangeDelay = 1000 + 2000 * Math.random(); } } function handleBulletsLifeCycle() { for (var i = bullets.length - 1; i >= 0; i--) { if (bullets[i].distanceToCenter <= 4) { // Assuming a small threshold around the center for destruction bullets[i].destroy(); bullets.splice(i, 1); } } for (var i = bulletsOfEnemy.length - 1; i >= 0; i--) { if (bulletsOfEnemy[i].x < 0 || bulletsOfEnemy[i].x > 2048 || bulletsOfEnemy[i].y > 2732) { // Assuming a small threshold around the center for destruction bulletsOfEnemy[i].destroy(); bulletsOfEnemy.splice(i, 1); } } } function getFighter() { return new Fighter(getNextIndex()); // No pooling for now } function handleFightersLifeCycle() { if (isChangingDirection || currentFighter != null) { return; } if (Date.now() - lastFighterKillTime < nextFigtherSpawnDelay) { return; } log("Setting currentFighter..."); log("enemies:", enemies); var keys = Object.keys(enemies); // Select random inactive enemy for (var i = 0; i < keys.length; i++) { if (!enemies[keys[i]].isDestroyed && !enemies[keys[i]].isActive) { log("selecting " + i + "/" + keys.length); currentFighter = enemies[keys[i]]; break; } } if (currentFighter) { currentFighter.reset(); middleLayer.addChild(currentFighter); currentFighter.activate(); } log("=> currentFighter=", currentFighter); } function handleSpaceObjectsLifeCycle() { if (!currentSpaceObject) { currentSpaceObject = backgroundLayer.addChild(new SpaceObject(Math.floor(Math.random() * nbSpaceObjects))); currentSpaceObject.x = 2048 * Math.random(); currentSpaceObject.y = 2732 * Math.random(); currentSpaceObject.alpha = 0.9; } else { // Check if currentSpaceObject is completely out of the screen var xMin = -currentSpaceObject.width / 2 - spaceObjectOffset; var xMax = 2048 + currentSpaceObject.width / 2 + spaceObjectOffset; var yMin = -currentSpaceObject.height / 2 - spaceObjectOffset; var yMax = 2732 + currentSpaceObject.height / 2 + spaceObjectOffset; if (Date.now() - lastSpaceObjectChangeTime > 1000 && (currentSpaceObject.x < xMin || currentSpaceObject.x > xMax || currentSpaceObject.y < yMin || currentSpaceObject.y > yMax)) { lastSpaceObjectChangeTime = Date.now(); var oldX = currentSpaceObject.x; var oldY = currentSpaceObject.y; // Destroy the current space object currentSpaceObject.destroy(); // Create a new space object with another index currentSpaceObject = backgroundLayer.addChild(new SpaceObject(Math.floor(Math.random() * nbSpaceObjects))); currentSpaceObject.alpha = 0.9; xMin = -currentSpaceObject.width / 2 - spaceObjectOffset; xMax = 2048 + currentSpaceObject.width / 2 + spaceObjectOffset; yMin = -currentSpaceObject.height / 2 - spaceObjectOffset; yMax = 2732 + currentSpaceObject.height / 2 + spaceObjectOffset; var nextX = Math.max(xMin, Math.min(2048 - oldX, xMax)); var nextY = Math.max(yMin, Math.min(2732 - oldY, yMax)); log("old:", oldX.toFixed(0), oldY.toFixed(0), "new=", nextX.toFixed(0), nextY.toFixed(0)); currentSpaceObject.x = nextX; currentSpaceObject.y = nextY; currentSpaceObject.alpha = 0.9; } } } /****************************************************************************************** */ /************************************* GAME STATES **************************************** */ /****************************************************************************************** */ function gameInitialize() { log("Game initialize..."); log(LK.Game); log("Game", game); //backgroundLayer = new Container(); backgroundLayer.alpha = 1; //middleLayer = new Container(); //foregroundLayer = new Container(); game.addChild(backgroundLayer); game.addChild(middleLayer); game.addChild(foregroundLayer); background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2, alpha: 1 }); //backgroundLayer.width = 2048; //backgroundLayer.heigth = 2732; //backgroundLayer.addChild(background); //game.addChildAt(background, 0); bgMusic = LK.getSound('bgMusic'); bgMusic.lastPlayTime = 0; handleSpaceObjectsLifeCycle(); initStars(); spaceship = foregroundLayer.addChild(new Spaceship()); //spaceship = game.addChild(new Spaceship()); //enemies[0].z = 1024; // TEMP DEEBUG spaceship.x = 2048 / 2; // Center spaceship horizontally spaceship.y = 2732 - spaceship.height / 2; // Position spaceship near the bottom of the screen spaceship.visible = false; cockpitDisplay = foregroundLayer.addChild(new CockpitDisplay()); //cockpitDisplay = game.addChild(new CockpitDisplay()); cockpitDisplay.x = 2048 / 2; // Center cockpit display horizontally cockpitDisplay.visible = false; if (isDebug) { var debugMarker = LK.getAsset('debugMarker', { anchorX: 0.5, anchorY: 0.5, x: 2048 * 0.5, y: 2732 }); game.addChild(debugMarker); fpsText = new Text2('FPS: 0', { size: 50, fill: "#ffffff" }); // Position FPS text at the bottom-right corner fpsText.anchor.set(1, 1); // Anchor to the bottom-right LK.gui.bottomRight.addChild(fpsText); // Update FPS display every second lastTick = Date.now(); frameCount = 0; // Debug text to display cube information debugText = new Text2('Debug Info', { size: 50, fill: "#ffffff" }); debugText.anchor.set(0.5, 0); // Anchor to the bottom-right LK.gui.top.addChild(debugText); } initMenuState(); } // GAME MENU function initMenuState() { log("initMenuState..."); gameState = GAME_STATE.MENU; log("bgMusic volume", bgMusic.volume); title = LK.getAsset('title', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 - 780 }); titleOne = LK.getAsset('titleOne', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 - 240 }); startText = LK.getAsset('startText', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 + 640, alpha: 0, visible: false }); game.addChild(title); startButton = LK.getAsset('startButton', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 + 640, alpha: 0, visible: false }); game.addChild(title); game.addChild(titleOne); game.addChild(startText); game.addChild(startButton); cleanMenuState(); // TEMP DEBUG !!!! } function handleMenuLoop() { // Menu animations here starFieldAnimation(); // Call the animation function within the game tick loopBgMusic(); } function cleanMenuState() { log("cleanMenuState..."); // Animate start button press var originalScaleX = startButton.scale.x; var originalScaleY = startButton.scale.y; LK.getSound('startSound').play(); var animationInterval = LK.setInterval(function () { startButton.scale.x *= 0.99; startButton.scale.y *= 0.99; startText.scale.x *= 0.99; startText.scale.y *= 0.99; if (startButton.scale.x <= originalScaleX * 0.9) { LK.clearInterval(animationInterval); // Big scale up and slow fade animation var fadeInterval = LK.setInterval(function () { startButton.scale.x *= 1.05; startButton.scale.y *= 1.05; startText.scale.x *= 1.05; startText.scale.y *= 1.05; startButton.alpha -= 0.01; startText.alpha -= 0.01; title.alpha -= 0.02; titleOne.alpha -= 0.02; if (startButton.alpha <= 0) { LK.clearInterval(fadeInterval); // Remove start button and text startButton.destroy(); startText.destroy(); title.destroy(); titleOne.destroy(); initStartingState(); } }, 16); // 60 FPS } }, 16); // 60 FPS } // STARTING function initStartingState() { log("initStartingState..."); spaceship.visible = true; cockpitDisplay.visible = true; animateMissionTextEnded = false; gameState = GAME_STATE.STARTING; // Round preparation logic here. currentLevel++; log("Level:" + currentLevel); currentNbEnnemies = currentLevel; for (var i = 0; i < currentNbEnnemies; i++) { // Initialize first enemy fighter var newFighter = getFighter(); enemies[newFighter.index] = newFighter; } currentFighter = null; // Show Mission objectives var missionLabel = 'MISSION #' + currentLevel; missionText = new Text2('', { size: 200, fill: "#00FF00", font: "Impact" }); missionText.alpha = 0.6; missionText.x = 512; missionText.y = 256; game.addChild(missionText); animateMissionText(missionText, missionLabel); startingStateTime = Date.now(); // TEMPORARY. //cleanStartingState(); //initPlayingState(); } function handleStartingLoop() { // Round Starting animations here loopBgMusic(); starFieldAnimation(); if (animateMissionTextEnded && !foeText) { foeText = new Text2('FOE:', { size: 200, fill: "#FF0000", font: "Impact" }); foeText.alpha = 0.6; foeText.x = 700; foeText.y = 600; game.addChild(foeText); foeAsset = LK.getAsset('fighter', { anchorX: 0.5, anchorY: 0.5, width: 200, height: 200 }); foeAsset.x = 1150; foeAsset.y = 720; game.addChild(foeAsset); } if (foeAsset) { var currentTime = Date.now(); foeAsset.alpha = 0.75 + 0.25 * Math.sin(currentTime / 100); if (currentTime - startingStateTime > startingStateDelay) { cleanStartingState(); initPlayingState(); } } } function cleanStartingState() { log("cleanStartingState..."); foeAsset.destroy(); foeText.destroy(); missionText.destroy(); } // PLAYING function initPlayingState() { log("initPlayingState..."); lastFighterKillTime = Date.now(); // Prevent direct enemy spawn gameState = GAME_STATE.PLAYING; } function handlePlayingLoop() { loopBgMusic(); handleGlobalMovement(); starFieldAnimation(); handleBulletsLifeCycle(); handleFightersLifeCycle(); handleSpaceObjectsLifeCycle(); // Update angles at a lower rate using modulo on ticks if (LK.ticks % 15 == 0) { current3DSpaceAngles.horizontalAngle += current3DSpaceAngles.deltaH; current3DSpaceAngles.verticalAngle += current3DSpaceAngles.deltaV; } // Rotate cockpitDisplay based on current3DSpaceAngles.horizontalAngle if (cockpitDisplay.cockpitBase) { cockpitDisplay.cockpitBase.rotation += -current3DSpaceAngles.deltaH - cockpitDisplay.cockpitBase.rotation >= 0.02 ? 0.1 : 0; cockpitDisplay.cockpitBase.rotation += -current3DSpaceAngles.deltaH - cockpitDisplay.cockpitBase.rotation <= -0.02 ? -0.1 : 0; cockpitDisplay.cockpitBase.rotation = Math.min(Math.PI * 0.3, Math.max(-Math.PI * 0.3, cockpitDisplay.cockpitBase.rotation)); cockpitDisplay.cockpitBase.scale.y = 1.5 + current3DSpaceAngles.deltaV * 0.5; // Illustrate vertical rotation by scaling the wheel } if (isDebug) { //debugText.setText("lives: " + player.lives); // FPS var now = Date.now(); frameCount++; if (now - lastTick >= 1000) { // Update every second fpsText.setText('FPS: ' + frameCount); frameCount = 0; lastTick = now; } } } function cleanPlayingState() { log("cleanPlayingState..."); // TODO Remove elements enemies = {}; if (spaceship.health > 0) { initStartingState(); } else { initScoreState(); } } // SCORE function initScoreState() { log("initScoreState..."); gameState = GAME_STATE.SCORE; // TODO add score elements // TEMPORARY : Avoid multiple clicks cleanScoreState(); } function handleScoreLoop() { // Score display logic here } function cleanScoreState() { log("cleanScoreState..."); LK.showGameOver(); } /***********************************************************************************/ /******************************** MAIN GAME LOOP ***********************************/ /***********************************************************************************/ game.update = function () { switch (gameState) { case GAME_STATE.MENU: handleMenuLoop(); break; case GAME_STATE.STARTING: handleStartingLoop(); break; case GAME_STATE.PLAYING: handlePlayingLoop(); break; case GAME_STATE.SCORE: handleScoreLoop(); break; } }; gameInitialize(); // Initialize the game
===================================================================
--- original.js
+++ change.js
@@ -209,11 +209,13 @@
var centerY = 1366;
var deltaX = centerX - self.x;
var deltaY = centerY - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- if (self.speedX > 0 && deltaX > 100 || self.speedX < 0 && deltaX > 100) {
- self.dirX = deltaX / distance * 3;
- self.dirY = deltaY / distance * 3;
+ if (self.speedX > 0 && deltaX > 42 || self.speedX < 0 && deltaX < -42) {
+ self.dirX = 6 * Math.abs(deltaX) / distance;
+ self.dirY = 6 * deltaY / distance;
+ //self.dirX = Math.max(self.dirX, self.dirY);
+ //self.dirY = Math.max(self.dirX, self.dirY);
} else {
self.dirX = 3;
self.dirY = 3;
}
starfield.
remove
elongated futuristic laser canon gun green. top view
explosion from top. zenith view
white triangle.
black background ethereal blue gas.
black background ethereal centered galaxy.
black background ethereal centered galaxy.
black background ethereal centered planet.
close up of a giant red star. black background
planet with rings. black background. full, with margin.
metalic oval border with bevel. Black. Electronic style. empty inside. no background
futuristic space fighter.. full front view
Space scene with full earth (europe and africa side). High definition
elegant white rose in a long transparent futuristic glass tube.
laserShot
Sound effect
bgMusic
Sound effect
explosion
Sound effect
laserShot2
Sound effect
detectionBeep1
Sound effect
fighterPassing
Sound effect
targetFoundBeep
Sound effect
damage
Sound effect
warning
Sound effect
startSound
Sound effect
acceleration
Sound effect
teamKill
Sound effect
finalExplosion
Sound effect