User prompt
Establece inicial solarystem colo solarsystem 1
User prompt
agrega un display del numero del sistema encima
User prompt
Asigna una lista para los sistemas asi se organizan por numero
User prompt
arregla el bug que hace que no conecten los sistemas
User prompt
haz que la unión no sea directo con el sistema inicial si no del sistema de donde viene area
User prompt
haz que solo se cree una coneción por planeta para evitar retraso
User prompt
haz que se muestre los planetas disponibles para viajar dentro del rango de area, que se muestre con el asset conection uniendo un sistema de otro
User prompt
haz que solo sea 1 objeto y no cree más
User prompt
Please fix the bug: 'ReferenceError: connectionGraphics is not defined' in or related to this line: 'connection.scaleX = Math.sqrt(Math.pow(solarSystem.x - areaPunter.lastX, 2) + Math.pow(solarSystem.y - areaPunter.lastY, 2)) / connectionGraphics.width;' Line Number: 72
User prompt
cuando areapunter viaje de un sistema solar a otro que se crea una unión
Code edit (1 edits merged)
Please save this source code
User prompt
agrega una mecanica de conección
User prompt
haz que la transparencia de areapunter sea 0 mientras colisione con solarsystem
Code edit (2 edits merged)
Please save this source code
User prompt
create a BackgroundContainer, MidgroundContainer and ForegroundContainer in that order and attaching new instances to one of them, instead of attaching directly to the game Container and sorting them.
User prompt
suaviza la transición ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz el nuevo asset aparezca con 0 y escale a 1 su alpha ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
suaviza la transición para que no tenga cooldown en el cambio ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que la transición de cuando solarsystem llegue a 0 y empieza a aumentar el alpha sea inmediata
User prompt
haz que mientras solarsystem vaya a 0 visited vaya a 1 para que no aparezca un momento que se vea negro
User prompt
haz que no desaparezca el objeto
User prompt
agregale una transición al cambio entre solarSystem y VisitedSolarSystem ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
cuando este start menu, gameplay no es visible
User prompt
cuando se toque que cambie la pagina de gameplay -> start menu / viceversa
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Gameplay = Container.expand(function () {
var self = Container.call(this);
return self;
});
var SolarSystem = Container.expand(function () {
var self = Container.call(this);
var solarSystemGraphics = self.attachAsset('solarSystem', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var StartMenu = Container.expand(function () {
var self = Container.call(this);
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000010,
name: 'gameplay'
});
/****
* Game Code
****/
var gameplay = game.addChild(new Gameplay());
var startMenu = game.addChild(new StartMenu());
startMenu.visible = false; // Initially hide the start menu
// Function to toggle between gameplay and start menu
function toggleGameState() {
gameplay.visible = !gameplay.visible;
startMenu.visible = !startMenu.visible;
}
// Add touch event to toggle game state
game.down = function (x, y, obj) {
toggleGameState();
};
game.update = function () {
areaPunter.x = area.x;
areaPunter.y = area.y;
// Check for collision between areaPunter and each solarSystem
solarSystems.forEach(function (solarSystem) {
if (!solarSystem.visited && areaPunter.intersects(solarSystem)) {
// Change the sprite to visitedSolarSystem
solarSystem.removeChild(solarSystem.children[0]);
solarSystem.attachAsset('visitedSolarSystem', {
anchorX: 0.5,
anchorY: 0.5
});
solarSystem.visited = true; // Mark as visited
}
});
};
var initialSolarSystem = gameplay.addChild(LK.getAsset('initialSolarSystem', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Apply changeSizeOnTouch to the initialSolarSystem object
initialSolarSystem.down = function (x, y, touchedObj) {
changeAreaLocation(initialSolarSystem, area);
changeSizeOnTouch(initialSolarSystem, 0.9);
};
// Apply changeAreaLocation to the initialSolarSystem object
initialSolarSystem.down = function (x, y, touchedObj) {
changeAreaLocation(initialSolarSystem, area);
};
// Add multiple solar system objects
var solarSystems = [];
for (var i = 0; i < Math.floor(Math.random() * 6) + 15; i++) {
var x, y, validPosition;
do {
x = Math.random() * 3072;
y = Math.random() * 4098;
validPosition = true;
for (var j = 0; j < solarSystems.length; j++) {
var existingSystem = solarSystems[j];
var dx = existingSystem.x - x;
var dy = existingSystem.y - y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 400) {
validPosition = false;
break;
}
}
// Ensure solar systems do not appear within 600 pixels of the initial solar system
var dxInitial = initialSolarSystem.x - x;
var dyInitial = initialSolarSystem.y - y;
var distanceInitial = Math.sqrt(dxInitial * dxInitial + dyInitial * dyInitial);
if (distanceInitial < 600) {
validPosition = false;
}
} while (!validPosition);
var solarSystem = gameplay.addChild(LK.getAsset('solarSystem', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y
}));
solarSystems.push(solarSystem);
// Apply changeSizeOnTouch to each SolarSystem object
solarSystem.down = function (x, y, touchedObj) {
changeAreaLocation(solarSystem, area);
changeSizeOnTouch(solarSystem, 0.9);
};
}
// Function to change the size of an object when touched and restore it when released
// Also, mark the SolarSystem as visited when touched
function changeSizeOnTouch(obj, scale) {
var originalScaleX = obj.scaleX;
var originalScaleY = obj.scaleY;
obj.down = function (x, y, touchedObj) {
this.scaleX = originalScaleX * scale;
this.scaleY = originalScaleY * scale;
};
obj.up = function (x, y, touchedObj) {
this.scaleX = originalScaleX;
this.scaleY = originalScaleY;
};
}
// Function to enable optimized galaxy motion for a given object
function enableGalaxyMotion(obj) {
var dragNode = null;
var velocity = {
x: 0,
y: 0
};
var lastPosition = {
x: 0,
y: 0
};
obj.down = function (x, y, touchedObj) {
dragNode = obj;
lastPosition.x = x;
lastPosition.y = y;
};
obj.move = function (x, y, touchedObj) {
if (dragNode) {
velocity.x = (x - lastPosition.x) * 0.6 + velocity.x * 0.8;
velocity.y = (y - lastPosition.y) * 0.6 + velocity.y * 0.8;
dragNode.x += velocity.x;
dragNode.y += velocity.y;
lastPosition.x = x;
lastPosition.y = y;
}
};
obj.up = function (x, y, touchedObj) {
dragNode = null;
};
}
// Add an area to the galaxy
var area = gameplay.addChild(LK.getAsset('area', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
alpha: 0.6 // Add transparency to the area
}));
// Add a new object called areaPunter
var areaPunter = gameplay.addChild(LK.getAsset('areaPunter', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Add a smooth rotation to the area object in a loop
function rotateArea() {
tween(area, {
rotation: area.rotation + Math.PI * 2
}, {
duration: 35000,
easing: tween.linear,
onFinish: rotateArea
});
}
rotateArea();
// Function to make the area pulse smoothly
function pulseArea() {
tween(area, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(area, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: pulseArea
});
}
});
}
pulseArea();
// Apply galaxy motion to the entire game area
enableGalaxyMotion(game);
// Function to change the area's location to the touched solar system
function changeAreaLocation(solarSystem, area) {
if (area.isMoving) {
return;
} // Prevent relocation if already moving
// Check if the solar system is within the area
var dx = solarSystem.x - area.x;
var dy = solarSystem.y - area.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > area.width / 2) {
return; // Do not move if the solar system is outside the area
}
area.isMoving = true; // Set moving flag
var speed = 0.15; // Set a fixed speed for the movement
var duration = distance / speed; // Calculate duration based on distance and speed
tween(area, {
x: solarSystem.x,
y: solarSystem.y
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: function onFinish() {
area.isMoving = false; // Reset moving flag
}
});
}
// Apply changeAreaLocation to the SolarSystem object
// Apply changeAreaLocation to each SolarSystem object
solarSystems.forEach(function (solarSystem) {
solarSystem.down = function (x, y, touchedObj) {
changeAreaLocation(solarSystem, area);
};
});