User prompt
enhance `self.speed = Math.max(4, Math.min(20, self.speed * Math.pow(self.distanceToCenter / 1024, 2) * 4))` to be more progressive
Code edit (20 edits merged)
Please save this source code
User prompt
enhance `self.speed = Math.max(4, Math.min(20, self.speed * self.distanceToCenter * 4 / 1024));` to be more progressive
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
bullets are created when user fires so currently they appear above the spaceship and the cockpit. make the appear behind
User prompt
Please fix the bug: 'ReferenceError: distanceToCenter is not defined' in or related to this line: 'var widthReduction = Math.max(0, (1 - distanceToCenter / 1024) * self.width);' Line Number: 35
Code edit (1 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: Mth is not defined' in or related to this line: 'var star = LK.getAsset('star', {' Line Number: 473
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: 'Uncaught TypeError: Cannot set properties of undefined (setting 'startX')' in or related to this line: 'self.startX = x1;' Line Number: 357
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
implemente cube rotate function : update lines to make the cube rotate on itself
Code edit (2 edits merged)
Please save this source code
User prompt
in cube update, don't call drawEdges wich recreates new lines at each tick! call drawEdges only once at class creation, then update the existing lines
Code edit (2 edits merged)
Please save this source code
User prompt
make the cube rotate on itself
Code edit (2 edits merged)
Please save this source code
User prompt
add a new class Cube and use Shapes to draw the cube
Code edit (2 edits merged)
Please save this source code
User prompt
reimplement Fighter.buildShape() with a more 3d complex shape : body, wings, Cockpit, reactors and cannons
/**** * Classes ****/ /***********************************************************************************/ /********************************** BULLET CLASS ***********************************/ /***********************************************************************************/ var Bullet = Container.expand(function (isLeft, isTop) { var self = Container.call(this); self.isTop = isTop; var bulletGraphics = self.attachAsset('3D_bullet', { anchorX: 0.5, anchorY: 0.5 }); self.isLeft = isLeft; self.speed = 10; self._move_migrated = 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 var distanceToCenter = Math.abs(self.x - 1024); var widthReduction = Math.max(0, (1 - distanceToCenter / 1024) * self.width); self.width = Math.max(5, self.width - widthReduction); // Ensure width does not go below 5 }; }); /***********************************************************************************/ /********************************** COCKPIT CLASS ***********************************/ /***********************************************************************************/ var CockpitDisplay = Container.expand(function () { var self = Container.call(this); // Create a simple 2D representation of the ship's cockpit self.cockpitBase = self.attachAsset('flywheel', { anchorX: 0.5, anchorY: 0.5, // Anchor at the bottom center to simulate cockpit view scaleX: 1, // Scale down to fit within the screen appropriately scaleY: 1.5, y: 2732 - 400 // Position near the bottom of the screen }); // Additional cockpit elements can be added here }); /***********************************************************************************/ /******************************** SPACESHIP CLASS **********************************/ /***********************************************************************************/ var Spaceship = Container.expand(function () { var self = Container.call(this); var spaceshipGraphics = self.attachAsset('3D_spaceship', { anchorX: 0.5, anchorY: 0.5 }); self.coords = { x: 0, y: 0, z: 0 }; self.speed = 0.01; self.shoot = function () { // 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.25; game.addChild(leftBullet); 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.25; game.addChild(rightBullet); bullets.push(rightBullet); // Adding two more cannons var extraLeftBullet = new Bullet(true, true); extraLeftBullet.x = leftBullet.x + 100; // Slightly to the right of the left canon extraLeftBullet.y = self.y - 512 - 128; // Start the bullet just above the spaceship extraLeftBullet.rotation = Math.PI * 1.75; game.addChild(extraLeftBullet); bullets.push(extraLeftBullet); var extraRightBullet = new Bullet(false, true); extraRightBullet.x = rightBullet.x - 100; // Slightly to the left of the right canon extraRightBullet.y = self.y - 512 - 128; // Start the bullet just above the spaceship extraRightBullet.rotation = -Math.PI * 1.75; game.addChild(extraRightBullet); bullets.push(extraRightBullet); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Initialize game with a black background }); /**** * Game Code ****/ /* # 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 player = { lives: 3 }; var nbStars = 80; var starsSpeed = 10; var stars = []; var current3DSpaceAngles = { horizontalAngle: 0, verticalAngle: 0, deltaH: 0, deltaV: 0 }; var spaceship; var cockpitDisplay; var bullets = []; // Player's bullets var enemies = []; var rotationSpeed = 0.25; 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); } } /****************************************************************************************** */ /************************************** 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..."); cleanMenuState(); initStartingState(); } function gameStartingDown(x, y, obj) { // TEMPORARY : Avoid multiple clicks //cleanStartingState(); //initPlayingState(); } function gamePlayingDown(x, y, obj) { log("gamePlayingDown ..."); spaceship.shoot(); player.lives -= 1; cleanPlayingState(); if (player.lives > 0) { // Next round initMenuState(); } else { initScoreState(); } } /****************************************************************************************** */ /************************************* GAME FUNCTIONS **************************************** */ /****************************************************************************************** */ function initStars() { for (var i = 0; i < nbStars; i++) { var star = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, x: Math.random() * 2048, y: Math.random() * 2732 }); stars.push(star); game.addChild(star); } // Farther stars for (var i = 0; i < nbStars * 2; i++) { var star = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5, alpha: Math.random(), x: Math.random() * 2048, y: Math.random() * 2732, slow: true }); stars.push(star); game.addChild(star); } } 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 * 10; //.horizontalAngle; directionY += current3DSpaceAngles.deltaV * 10; //.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 ? Math.random() * 0.1 : 1); // Increase speed to 10 for faster star movement star.y += directionY * starsSpeed * (star.slow ? Math.random() * 0.1 : 1); star.alpha += 0.001; // 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() * 0.5; } }); // Move nebulas images here .x-=0.1 } /****************************************************************************************** */ /************************************* GAME STATES **************************************** */ /****************************************************************************************** */ function gameInitialize() { log("Game initialize..."); spaceship = game.addChild(new Spaceship()); spaceship.x = 2048 / 2; // Center spaceship horizontally spaceship.y = 2732 - spaceship.height / 2; // Position spaceship near the bottom of the screen cockpitDisplay = game.addChild(new CockpitDisplay()); cockpitDisplay.x = 2048 / 2; // Center cockpit display horizontally if (isDebug) { var debugMarker = LK.getAsset('debugMarker', { anchorX: 0.5, anchorY: 0.5, x: 2048 * 0.5, y: 2732 / 2 }); 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; } function handleMenuLoop() { // Menu animations here } function cleanMenuState() { log("cleanMenuState..."); } // STARTING function initStartingState() { log("initStartingState..."); gameState = GAME_STATE.STARTING; // Round preparation logic here. // TEMPORARY. cleanStartingState(); initPlayingState(); } function handleStartingLoop() { // Round Starting animations here } function cleanStartingState() { log("cleanStartingState..."); } // PLAYING function initPlayingState() { log("initPlayingState..."); gameState = GAME_STATE.PLAYING; } function handlePlayingLoop() { starFieldAnimation(); // Call the animation function within the game tick // Move bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i]._move_migrated(); // Check if bullet reaches the center of the screen and destroy it //var distanceToCenter = Math.max(0, Math.min(1024, bullets[i].x - 1024)); var distanceToCenter = bullets[i].isLeft ? 1024 - bullets[i].x : bullets[i].x - 1024; if (distanceToCenter <= 10) { // Assuming a small threshold around the center for destruction bullets[i].destroy(); bullets.splice(i, 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; // 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 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 } // 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
@@ -1,117 +1,408 @@
/****
* Classes
****/
-// Bullet class for the spaceship
-var Bullet = Container.expand(function () {
+/***********************************************************************************/
+/********************************** BULLET CLASS ***********************************/
+/***********************************************************************************/
+var Bullet = Container.expand(function (isLeft, isTop) {
var self = Container.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
+ self.isTop = isTop;
+ var bulletGraphics = self.attachAsset('3D_bullet', {
anchorX: 0.5,
anchorY: 0.5
});
+ self.isLeft = isLeft;
self.speed = 10;
self._move_migrated = function () {
- self.y -= self.speed;
+ 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
+ var distanceToCenter = Math.abs(self.x - 1024);
+ var widthReduction = Math.max(0, (1 - distanceToCenter / 1024) * self.width);
+ self.width = Math.max(5, self.width - widthReduction); // Ensure width does not go below 5
};
});
-// Enemy class
-var Enemy = Container.expand(function () {
+/***********************************************************************************/
+/********************************** COCKPIT CLASS ***********************************/
+/***********************************************************************************/
+var CockpitDisplay = Container.expand(function () {
var self = Container.call(this);
- var enemyGraphics = self.attachAsset('enemy', {
+ // Create a simple 2D representation of the ship's cockpit
+ self.cockpitBase = self.attachAsset('flywheel', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ // Anchor at the bottom center to simulate cockpit view
+ scaleX: 1,
+ // Scale down to fit within the screen appropriately
+ scaleY: 1.5,
+ y: 2732 - 400 // Position near the bottom of the screen
});
- self.speed = 2;
- self._move_migrated = function () {
- self.y += self.speed;
- };
+ // Additional cockpit elements can be added here
});
-// Assets will be automatically generated based on usage in the code.
-// Player's spaceship class
+/***********************************************************************************/
+/******************************** SPACESHIP CLASS **********************************/
+/***********************************************************************************/
var Spaceship = Container.expand(function () {
var self = Container.call(this);
- var spaceshipGraphics = self.attachAsset('spaceship', {
+ var spaceshipGraphics = self.attachAsset('3D_spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 5;
- self._move_migrated = function (direction) {
- if (direction === 'left' && self.x > 0) {
- self.x -= self.speed;
- } else if (direction === 'right' && self.x < 2048) {
- self.x += self.speed;
- }
+ self.coords = {
+ x: 0,
+ y: 0,
+ z: 0
};
+ self.speed = 0.01;
self.shoot = function () {
- var bullet = new Bullet();
- bullet.x = self.x;
- bullet.y = self.y - 50; // Start the bullet just above the spaceship
- game.addChild(bullet);
- bullets.push(bullet);
+ // 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.25;
+ game.addChild(leftBullet);
+ 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.25;
+ game.addChild(rightBullet);
+ bullets.push(rightBullet);
+ // Adding two more cannons
+ var extraLeftBullet = new Bullet(true, true);
+ extraLeftBullet.x = leftBullet.x + 100; // Slightly to the right of the left canon
+ extraLeftBullet.y = self.y - 512 - 128; // Start the bullet just above the spaceship
+ extraLeftBullet.rotation = Math.PI * 1.75;
+ game.addChild(extraLeftBullet);
+ bullets.push(extraLeftBullet);
+ var extraRightBullet = new Bullet(false, true);
+ extraRightBullet.x = rightBullet.x - 100; // Slightly to the left of the right canon
+ extraRightBullet.y = self.y - 512 - 128; // Start the bullet just above the spaceship
+ extraRightBullet.rotation = -Math.PI * 1.75;
+ game.addChild(extraRightBullet);
+ bullets.push(extraRightBullet);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Initialize game with a black background
});
/****
* Game Code
****/
-var spaceship = game.addChild(new Spaceship());
-spaceship.x = 1024; // Start in the middle of the screen
-spaceship.y = 2500; // Start near the bottom of the screen
-var bullets = [];
+/*
+# 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 player = {
+ lives: 3
+};
+var nbStars = 80;
+var starsSpeed = 10;
+var stars = [];
+var current3DSpaceAngles = {
+ horizontalAngle: 0,
+ verticalAngle: 0,
+ deltaH: 0,
+ deltaV: 0
+};
+var spaceship;
+var cockpitDisplay;
+var bullets = []; // Player's bullets
var enemies = [];
-// Touch event to move and shoot
+var rotationSpeed = 0.25;
+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);
+ }
+}
+/****************************************************************************************** */
+/************************************** INPUT HANDLERS ************************************ */
+/****************************************************************************************** */
game.on('down', function (x, y, obj) {
- var touchPosition = game.toLocal(obj.global);
- if (touchPosition.x < 1024) {
- spaceship._move_migrated('left');
- } else {
- spaceship._move_migrated('right');
+ 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;
}
- spaceship.shoot();
});
-// Spawn enemies
-LK.setInterval(function () {
- var enemy = new Enemy();
- enemy.x = Math.random() * 2048; // Random position across the screen width
- enemy.y = 0; // Start at the top of the screen
- game.addChild(enemy);
- enemies.push(enemy);
-}, 2000); // Spawn an enemy every 2 seconds
-// Game tick
-LK.on('tick', function () {
+function gameMenuDown(x, y, obj) {
+ log("gameMenuDown...");
+ cleanMenuState();
+ initStartingState();
+}
+function gameStartingDown(x, y, obj) {
+ // TEMPORARY : Avoid multiple clicks
+ //cleanStartingState();
+ //initPlayingState();
+}
+function gamePlayingDown(x, y, obj) {
+ log("gamePlayingDown ...");
+ spaceship.shoot();
+ player.lives -= 1;
+ cleanPlayingState();
+ if (player.lives > 0) {
+ // Next round
+ initMenuState();
+ } else {
+ initScoreState();
+ }
+}
+/****************************************************************************************** */
+/************************************* GAME FUNCTIONS **************************************** */
+/****************************************************************************************** */
+function initStars() {
+ for (var i = 0; i < nbStars; i++) {
+ var star = LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.5,
+ x: Math.random() * 2048,
+ y: Math.random() * 2732
+ });
+ stars.push(star);
+ game.addChild(star);
+ }
+ // Farther stars
+ for (var i = 0; i < nbStars * 2; i++) {
+ var star = LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: Math.random(),
+ x: Math.random() * 2048,
+ y: Math.random() * 2732,
+ slow: true
+ });
+ stars.push(star);
+ game.addChild(star);
+ }
+}
+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 * 10; //.horizontalAngle;
+ directionY += current3DSpaceAngles.deltaV * 10; //.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 ? Math.random() * 0.1 : 1); // Increase speed to 10 for faster star movement
+ star.y += directionY * starsSpeed * (star.slow ? Math.random() * 0.1 : 1);
+ star.alpha += 0.001;
+ // 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() * 0.5;
+ }
+ });
+ // Move nebulas images here .x-=0.1
+}
+/****************************************************************************************** */
+/************************************* GAME STATES **************************************** */
+/****************************************************************************************** */
+function gameInitialize() {
+ log("Game initialize...");
+ spaceship = game.addChild(new Spaceship());
+ spaceship.x = 2048 / 2; // Center spaceship horizontally
+ spaceship.y = 2732 - spaceship.height / 2; // Position spaceship near the bottom of the screen
+ cockpitDisplay = game.addChild(new CockpitDisplay());
+ cockpitDisplay.x = 2048 / 2; // Center cockpit display horizontally
+ if (isDebug) {
+ var debugMarker = LK.getAsset('debugMarker', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2048 * 0.5,
+ y: 2732 / 2
+ });
+ 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;
+}
+function handleMenuLoop() {
+ // Menu animations here
+}
+function cleanMenuState() {
+ log("cleanMenuState...");
+}
+// STARTING
+function initStartingState() {
+ log("initStartingState...");
+ gameState = GAME_STATE.STARTING;
+ // Round preparation logic here.
+ // TEMPORARY.
+ cleanStartingState();
+ initPlayingState();
+}
+function handleStartingLoop() {
+ // Round Starting animations here
+}
+function cleanStartingState() {
+ log("cleanStartingState...");
+}
+// PLAYING
+function initPlayingState() {
+ log("initPlayingState...");
+ gameState = GAME_STATE.PLAYING;
+}
+function handlePlayingLoop() {
+ starFieldAnimation(); // Call the animation function within the game tick
// Move bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i]._move_migrated();
- if (bullets[i].y < 0) {
+ // Check if bullet reaches the center of the screen and destroy it
+ //var distanceToCenter = Math.max(0, Math.min(1024, bullets[i].x - 1024));
+ var distanceToCenter = bullets[i].isLeft ? 1024 - bullets[i].x : bullets[i].x - 1024;
+ if (distanceToCenter <= 10) {
+ // Assuming a small threshold around the center for destruction
bullets[i].destroy();
bullets.splice(i, 1);
}
}
- // Move enemies
- for (var j = enemies.length - 1; j >= 0; j--) {
- enemies[j]._move_migrated();
- if (enemies[j].y > 2732) {
- // If the enemy goes off the bottom of the screen
- enemies[j].destroy();
- enemies.splice(j, 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;
+ // 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
+ 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;
}
}
- // Collision detection (simplified)
- bullets.forEach(function (bullet) {
- enemies.forEach(function (enemy, index) {
- if (bullet.intersects(enemy)) {
- enemy.destroy();
- enemies.splice(index, 1);
- bullet.destroy();
- bullets.splice(bullets.indexOf(bullet), 1);
- // Increase score or trigger explosion effect here
- }
- });
- });
-});
\ No newline at end of file
+}
+function cleanPlayingState() {
+ log("cleanPlayingState...");
+ // TODO Remove elements
+}
+// 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
\ No newline at end of file
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