User prompt
add a new utility function drawLine(x1,y1,x2,y2)
User prompt
Add another parameter to Bullet class isTop
Code edit (5 edits merged)
Please save this source code
User prompt
Add two other cannons
Code edit (11 edits merged)
Please save this source code
User prompt
when bullet reach center destroy it
User prompt
in Bullet, in _move_migrated, reduce the width progressively as the bullet get closer to the center (x=1024)
Code edit (1 edits merged)
Please save this source code
User prompt
bullets should spawn from the side canons and go far at the center of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'coords')' in or related to this line: 'debugText.setText('Coords: X=' + Math.round(spaceship.coords.x) + ', Y=' + Math.round(spaceship.coords.y) + ', Z=' + Math.round(spaceship.coords.z) + '\nAngles: H=' + Math.round(current3DSpaceAngles.horizontalAngle * (180 / Math.PI)) + '°, V=' + Math.round(current3DSpaceAngles.verticalAngle * (180 / Math.PI)) + '°');' Line Number: 94
User prompt
regroup all LK.on('tick',... ) functions
Code edit (1 edits merged)
Please save this source code
User prompt
only do ``` // Update angles current3DSpaceAngles.horizontalAngle += current3DSpaceAngles.deltaH; current3DSpaceAngles.verticalAngle += current3DSpaceAngles.deltaV; ``` at a lower rate, use modulo on ticks
Code edit (4 edits merged)
Please save this source code
User prompt
in debugText.setText('Coords: X=' ...) convert the angles to degrees
Code edit (3 edits merged)
Please save this source code
User prompt
update also horizontalAngle and verticalAngle when player move
Code edit (2 edits merged)
Please save this source code
User prompt
replace debugText.setText('Angles: ',...) by a display of 3D coordinates
User prompt
update also the z coordinate
User prompt
update the ship coords given that when horizontalAngle=0 and verticalAngle=0 ship is heading to y positive
User prompt
add a new property coords to the Spaceship with value {x:0,y:0,z:0}
/**** * Classes ****/ // Bullet class for the spaceship var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('3D_bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.move = function () { self.y -= self.speed; }; }); // Cockpit representation class for the spaceship 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 }); // Enemy class removed as per task requirement. // Assets will be automatically generated based on usage in the code. // Player's 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 () { 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); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Debug text to display current 3D space angles var debugText = new Text2('Angles: 0, 0', { size: 50, fill: "#ffffff" }); debugText.x = 10; // Position at top left debugText.y = 10; LK.gui.topLeft.addChild(debugText); // Update debug text every tick to reflect current angles LK.on('tick', function () { debugText.setText('Coords: X=' + Math.round(spaceship.coords.x) + ', Y=' + Math.round(spaceship.coords.y) + ', Z=' + Math.round(spaceship.coords.z) + '\nAngles: H=' + Math.round(current3DSpaceAngles.horizontalAngle * (180 / Math.PI)) + '°, V=' + Math.round(current3DSpaceAngles.verticalAngle * (180 / Math.PI)) + '°'); }); // Global object to hold the current horizontal and vertical angle in the 3D space var current3DSpaceAngles = { horizontalAngle: 0, verticalAngle: 0, deltaH: 0, deltaV: 0 }; // Removed drag movement system // Function to animate the star field for a dynamic background effect function starFieldImageAnimation() { // TODO : Move starField background to go with current movement } 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); // Limit width to 20 star.height = star.width; star.x += directionX * starsSpeed; // Increase speed to 10 for faster star movement star.y += directionY * starsSpeed; // 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; star.width = Math.random() * 10; // Limit width to 20 star.height = star.width; // Reset height to initial value } }); } var nbStars = 80; var starsSpeed = 10; var stars = []; for (var i = 0; i < nbStars; i++) { var star = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 2048, // Random position across the screen width y: Math.random() * 2732 // Random position across the screen height }); stars.push(star); game.addChild(star); } // Update the game tick to include starFieldAnimation LK.on('tick', function () { starFieldAnimation(); // Call the animation function within the game tick // Update spaceship coordinates and angles based on current3DSpaceAngles 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; // Move bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].move(); if (bullets[i].y < 0) { bullets[i].destroy(); bullets.splice(i, 1); } } // Move enemy bullets for (var k = enemyBullets.length - 1; k >= 0; k--) { enemyBullets[k].move(); if (enemyBullets[k].y > 2732) { enemyBullets[k].destroy(); enemyBullets.splice(k, 1); } } // Enemy movement and shooting logic removed as per task requirement. // Enemy and bullet collision detection logic removed as per task requirement. }); // Add starField as an independent asset var starField = LK.getAsset('starField', { anchorX: 0.0, anchorY: 0.0, scaleX: 1, scaleY: 1, x: 0, y: 0 }); var starField2 = LK.getAsset('starField2', { anchorX: 0.0, anchorY: 0.0, scaleX: 1, scaleY: 1, x: 0, y: 0 }); game.addChild(starField); game.addChild(starField2); starField.visible = false; // Initially hide the second starField starField2.visible = false; // Initially hide the second starField starField2.width = 2048 / 2; // Reset width to initial value starField2.height = 2732 / 2; // Reset height to initial value // White color for laser-like bullets // Light Slate Gray for the spaceship var 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 // Add the cockpit display to the game and rotate with ship X rotation var cockpitDisplay = game.addChild(new CockpitDisplay()); cockpitDisplay.x = 2048 / 2; // Center cockpit display horizontally // Rotate cockpitDisplay based on current3DSpaceAngles.horizontalAngle LK.on('tick', function () { // Adjust cockpitDisplay rotation for both horizontal and vertical movements //cockpitDisplay.cockpitBase.rotation += (-current3DSpaceAngles.deltaH - cockpitDisplay.cockpitBase.rotation) * 0.12; 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 + 0.1 * Math.sign(current3DSpaceAngles.deltaH))); 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 }); var bullets = []; // Player's bullets var enemyBullets = []; // Enemy's bullets var enemies = []; var rotationSpeed = 0.25; // Touch event to move and shoot game.on('down', function (obj) { var touchPosition = obj.event.getLocalPosition(game); console.log("touchPosition", touchPosition); if (touchPosition.x < game.width * 0.33) { // Pressing on the left side of the screen current3DSpaceAngles.deltaH += rotationSpeed; // Adjust horizontal angle to the left } else if (touchPosition.x > game.width * 0.66) { // Pressing on the right side of the screen current3DSpaceAngles.deltaH -= rotationSpeed; // Adjust horizontal angle to the right } else { console.log("centered"); current3DSpaceAngles.deltaH = 0; } if (touchPosition.y < game.height * 0.33) { // Pressing on the upper half of the screen current3DSpaceAngles.deltaV += rotationSpeed; // Adjust vertical angle upwards } else if (touchPosition.y > game.height * 0.66) { // Pressing on the lower half of the screen current3DSpaceAngles.deltaV -= rotationSpeed; // Adjust vertical angle downwards } else { current3DSpaceAngles.deltaV = 0; } spaceship.shoot(); }); // Stop movement when user releases touch game.on('up', function () { current3DSpaceAngles.deltaH = 0; current3DSpaceAngles.deltaV = 0; }); // Enemy spawning logic removed as per task requirement. // Game tick LK.on('tick', function () { // Update angles at a lower rate using modulo on ticks if (LK.ticks % 15 == 0) { current3DSpaceAngles.horizontalAngle += current3DSpaceAngles.deltaH; current3DSpaceAngles.verticalAngle += current3DSpaceAngles.deltaV; } // Move bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].move(); if (bullets[i].y < 0) { bullets[i].destroy(); bullets.splice(i, 1); } } // Move enemy bullets for (var k = enemyBullets.length - 1; k >= 0; k--) { enemyBullets[k].move(); if (enemyBullets[k].y > 2732) { enemyBullets[k].destroy(); enemyBullets.splice(k, 1); } } // Move enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].move(); enemies[j].startShooting(); // Start shooting when moving if (enemies[j].y > 2732) { // If the enemy goes off the bottom of the screen enemies[j].stopShooting(); // Stop shooting when destroyed enemies[j].destroy(); enemies.splice(j, 1); } } // 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 } }); }); });
===================================================================
--- original.js
+++ change.js
@@ -42,15 +42,8 @@
y: 0,
z: 0
};
self.speed = 0.01;
- self.move = function (direction) {
- if (direction === 'left' && self.x > 0) {
- self.x -= self.speed;
- } else if (direction === 'right' && self.x < 2048) {
- self.x += self.speed;
- }
- };
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - 50; // Start the bullet just above the spaceship
@@ -78,198 +71,213 @@
debugText.y = 10;
LK.gui.topLeft.addChild(debugText);
// Update debug text every tick to reflect current angles
LK.on('tick', function () {
- // Global object to hold the current horizontal and vertical angle in the 3D space
- var current3DSpaceAngles = {
- horizontalAngle: 0,
- verticalAngle: 0,
- deltaH: 0,
- deltaV: 0
- };
- // Update debug text with current coordinates and angles
debugText.setText('Coords: X=' + Math.round(spaceship.coords.x) + ', Y=' + Math.round(spaceship.coords.y) + ', Z=' + Math.round(spaceship.coords.z) + '\nAngles: H=' + Math.round(current3DSpaceAngles.horizontalAngle * (180 / Math.PI)) + '°, V=' + Math.round(current3DSpaceAngles.verticalAngle * (180 / Math.PI)) + '°');
- // Star field animation
- starFieldAnimation();
- // Update spaceship coordinates and angles
- // Global object to hold the current horizontal and vertical angle in the 3D space
- var current3DSpaceAngles = {
- horizontalAngle: 0,
- verticalAngle: 0,
- deltaH: 0,
- deltaV: 0
- };
- // Removed drag movement system
- // Function to animate the star field for a dynamic background effect
- function starFieldImageAnimation() {
- // TODO : Move starField background to go with current movement
- }
- 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); // Limit width to 20
- star.height = star.width;
- star.x += directionX * starsSpeed; // Increase speed to 10 for faster star movement
- star.y += directionY * starsSpeed;
- // 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;
- star.width = Math.random() * 10; // Limit width to 20
- star.height = star.width; // Reset height to initial value
- }
- });
- }
- var nbStars = 80;
- var starsSpeed = 10;
- var stars = [];
- for (var i = 0; i < nbStars; i++) {
- var star = LK.getAsset('star', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: Math.random() * 2048,
- // Random position across the screen width
- y: Math.random() * 2732 // Random position across the screen height
- });
- stars.push(star);
- game.addChild(star);
- }
- // Update the game tick to include starFieldAnimation
+});
+// Global object to hold the current horizontal and vertical angle in the 3D space
+var current3DSpaceAngles = {
+ horizontalAngle: 0,
+ verticalAngle: 0,
+ deltaH: 0,
+ deltaV: 0
+};
+// Removed drag movement system
+// Function to animate the star field for a dynamic background effect
+function starFieldImageAnimation() {
+ // TODO : Move starField background to go with current movement
+}
+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); // Limit width to 20
+ star.height = star.width;
+ star.x += directionX * starsSpeed; // Increase speed to 10 for faster star movement
+ star.y += directionY * starsSpeed;
+ // 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;
+ star.width = Math.random() * 10; // Limit width to 20
+ star.height = star.width; // Reset height to initial value
+ }
+ });
+}
+var nbStars = 80;
+var starsSpeed = 10;
+var stars = [];
+for (var i = 0; i < nbStars; i++) {
+ var star = LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: Math.random() * 2048,
+ // Random position across the screen width
+ y: Math.random() * 2732 // Random position across the screen height
+ });
+ stars.push(star);
+ game.addChild(star);
+}
+// Update the game tick to include starFieldAnimation
+LK.on('tick', function () {
+ starFieldAnimation(); // Call the animation function within the game tick
+ // Update spaceship coordinates and angles based on current3DSpaceAngles
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;
- // Adjust cockpitDisplay rotation and scale
+ // Move bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].move();
+ if (bullets[i].y < 0) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ }
+ }
+ // Move enemy bullets
+ for (var k = enemyBullets.length - 1; k >= 0; k--) {
+ enemyBullets[k].move();
+ if (enemyBullets[k].y > 2732) {
+ enemyBullets[k].destroy();
+ enemyBullets.splice(k, 1);
+ }
+ }
// Enemy movement and shooting logic removed as per task requirement.
// Enemy and bullet collision detection logic removed as per task requirement.
- // Add starField as an independent asset
- var starField = LK.getAsset('starField', {
- anchorX: 0.0,
- anchorY: 0.0,
- scaleX: 1,
- scaleY: 1,
- x: 0,
- y: 0
- });
- var starField2 = LK.getAsset('starField2', {
- anchorX: 0.0,
- anchorY: 0.0,
- scaleX: 1,
- scaleY: 1,
- x: 0,
- y: 0
- });
- game.addChild(starField);
- game.addChild(starField2);
- starField.visible = false; // Initially hide the second starField
- starField2.visible = false; // Initially hide the second starField
- starField2.width = 2048 / 2; // Reset width to initial value
- starField2.height = 2732 / 2; // Reset height to initial value
- // White color for laser-like bullets
- // Light Slate Gray for the spaceship
- var 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
- // Add the cockpit display to the game and rotate with ship X rotation
- var cockpitDisplay = game.addChild(new CockpitDisplay());
- cockpitDisplay.x = 2048 / 2; // Center cockpit display horizontally
- // Rotate cockpitDisplay based on current3DSpaceAngles.horizontalAngle
+});
+// Add starField as an independent asset
+var starField = LK.getAsset('starField', {
+ anchorX: 0.0,
+ anchorY: 0.0,
+ scaleX: 1,
+ scaleY: 1,
+ x: 0,
+ y: 0
+});
+var starField2 = LK.getAsset('starField2', {
+ anchorX: 0.0,
+ anchorY: 0.0,
+ scaleX: 1,
+ scaleY: 1,
+ x: 0,
+ y: 0
+});
+game.addChild(starField);
+game.addChild(starField2);
+starField.visible = false; // Initially hide the second starField
+starField2.visible = false; // Initially hide the second starField
+starField2.width = 2048 / 2; // Reset width to initial value
+starField2.height = 2732 / 2; // Reset height to initial value
+// White color for laser-like bullets
+// Light Slate Gray for the spaceship
+var 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
+// Add the cockpit display to the game and rotate with ship X rotation
+var cockpitDisplay = game.addChild(new CockpitDisplay());
+cockpitDisplay.x = 2048 / 2; // Center cockpit display horizontally
+// Rotate cockpitDisplay based on current3DSpaceAngles.horizontalAngle
+LK.on('tick', function () {
+ // Adjust cockpitDisplay rotation for both horizontal and vertical movements
//cockpitDisplay.cockpitBase.rotation += (-current3DSpaceAngles.deltaH - cockpitDisplay.cockpitBase.rotation) * 0.12;
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 + 0.1 * Math.sign(current3DSpaceAngles.deltaH)));
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;
- var bullets = []; // Player's bullets
- var enemyBullets = []; // Enemy's bullets
- var enemies = [];
- var rotationSpeed = 0.25;
- // Touch event to move and shoot
- game.on('down', function (obj) {
- var touchPosition = obj.event.getLocalPosition(game);
- console.log("touchPosition", touchPosition);
- if (touchPosition.x < game.width * 0.33) {
- // Pressing on the left side of the screen
- current3DSpaceAngles.deltaH += rotationSpeed; // Adjust horizontal angle to the left
- } else if (touchPosition.x > game.width * 0.66) {
- // Pressing on the right side of the screen
- current3DSpaceAngles.deltaH -= rotationSpeed; // Adjust horizontal angle to the right
- } else {
- console.log("centered");
- current3DSpaceAngles.deltaH = 0;
- }
- if (touchPosition.y < game.height * 0.33) {
- // Pressing on the upper half of the screen
- current3DSpaceAngles.deltaV += rotationSpeed; // Adjust vertical angle upwards
- } else if (touchPosition.y > game.height * 0.66) {
- // Pressing on the lower half of the screen
- current3DSpaceAngles.deltaV -= rotationSpeed; // Adjust vertical angle downwards
- } else {
- current3DSpaceAngles.deltaV = 0;
- }
- spaceship.shoot();
- });
- // Stop movement when user releases touch
- game.on('up', function () {
+ cockpitDisplay.cockpitBase.scale.y = 1.5 + current3DSpaceAngles.deltaV * 0.5; // Illustrate vertical rotation by scaling the wheel
+});
+var bullets = []; // Player's bullets
+var enemyBullets = []; // Enemy's bullets
+var enemies = [];
+var rotationSpeed = 0.25;
+// Touch event to move and shoot
+game.on('down', function (obj) {
+ var touchPosition = obj.event.getLocalPosition(game);
+ console.log("touchPosition", touchPosition);
+ if (touchPosition.x < game.width * 0.33) {
+ // Pressing on the left side of the screen
+ current3DSpaceAngles.deltaH += rotationSpeed; // Adjust horizontal angle to the left
+ } else if (touchPosition.x > game.width * 0.66) {
+ // Pressing on the right side of the screen
+ current3DSpaceAngles.deltaH -= rotationSpeed; // Adjust horizontal angle to the right
+ } else {
+ console.log("centered");
current3DSpaceAngles.deltaH = 0;
+ }
+ if (touchPosition.y < game.height * 0.33) {
+ // Pressing on the upper half of the screen
+ current3DSpaceAngles.deltaV += rotationSpeed; // Adjust vertical angle upwards
+ } else if (touchPosition.y > game.height * 0.66) {
+ // Pressing on the lower half of the screen
+ current3DSpaceAngles.deltaV -= rotationSpeed; // Adjust vertical angle downwards
+ } else {
current3DSpaceAngles.deltaV = 0;
- });
- // Enemy spawning logic removed as per task requirement.
- // Game tick
+ }
+ spaceship.shoot();
+});
+// Stop movement when user releases touch
+game.on('up', function () {
+ current3DSpaceAngles.deltaH = 0;
+ current3DSpaceAngles.deltaV = 0;
+});
+// Enemy spawning logic removed as per task requirement.
+// Game tick
+LK.on('tick', function () {
// Update angles at a lower rate using modulo on ticks
if (LK.ticks % 15 == 0) {
current3DSpaceAngles.horizontalAngle += current3DSpaceAngles.deltaH;
current3DSpaceAngles.verticalAngle += current3DSpaceAngles.deltaV;
}
- // Move bullets and handle off-screen logic
+ // Move bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].move();
if (bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
- // Move enemy bullets and handle off-screen logic
+ // Move enemy bullets
for (var k = enemyBullets.length - 1; k >= 0; k--) {
enemyBullets[k].move();
if (enemyBullets[k].y > 2732) {
enemyBullets[k].destroy();
enemyBullets.splice(k, 1);
}
}
- // Move enemies and handle shooting and off-screen logic
+ // Move enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].move();
- enemies[j].startShooting();
+ enemies[j].startShooting(); // Start shooting when moving
if (enemies[j].y > 2732) {
- enemies[j].stopShooting();
+ // If the enemy goes off the bottom of the screen
+ enemies[j].stopShooting(); // Stop shooting when destroyed
enemies[j].destroy();
enemies.splice(j, 1);
}
}
- // Collision detection between bullets and enemies
+ // 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
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