Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: particleGraphics is not defined' in or related to this line: 'if (particleGraphics.alpha <= 0) {' Line Number: 247
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
please implement it that way
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: movetype is not defined' in or related to this line: 'if (movetype == 0) {' Line Number: 119
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 (12 edits merged)
Please save this source code
User prompt
use LK to increment score
User prompt
INcrement player score by 1 where it says '//TODO: Increment score.'
Code edit (1 edits merged)
Please save this source code
Code edit (23 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'tint')' in or related to this line: 'if (this.starGraphics.tint == currentPalette[currentRightColor]) {' Line Number: 118
Code edit (1 edits merged)
Please save this source code
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: Square is not defined' in or related to this line: 'var square = new Square(j);' Line Number: 187
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
tween towards new centerx and centery over 1 second when player taps. use the existing on tick listener
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
// Assets are automatically created based on usage in the code.
// Star class
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
//tint: Math.random() * 0xFFFFFF // Assign a random color tint to each star
//tint: colorArray[colorArrayCounter++ % colorArray.length]
tint: rainbowColors[Math.floor(Math.random() * rainbowColors.length - 1)]
});
//console.log(self.tint);
// Initialize star position closer to the center for a 3D effect
//self.z = Math.random() * 1900 + 100; // Adjusted Z position range to prevent very small values
self.z = 500;
self.x = (Math.random() - 0.5) * game.width * 2;
self.y = (Math.random() - 0.5) * game.height * 2;
self.vx = (self.x - centerX) / self.z;
self.vy = (self.y - centerY) / self.z;
// Calculate velocity based on z position to simulate speed increase as stars move closer
// Initialize velocities considering the deltaTime for consistent movement across different frame rates
// Removed static deltaTime, will calculate dynamically in the game tick
// Removed redundant initial velocity calculation
// Cap maximum speed to prevent stars from moving too fast
//self.speed = Math.min(40 + Math.random() * 40, 60); // Increase speed range for light-speed effect
self.speed = 300;
//self.speed = Math.min(2 + Math.random() * 2, 6); // Increase speed range for light-speed effect
self.move = function () {
/*
// Calculate the direction vector from the center to the star
var dx = self.x - centerX;
var dy = self.y - centerY;
// Normalize the direction vector
var length = Math.sqrt(dx * dx + dy * dy);
dx /= length;
dy /= length;
self.vx -= dx;
self.vy -= dy;
*/
// Update position based on velocity
self.z += self.speed;
// This code block is removed to prevent redundancy in position updates.
// Reset star position and properties for smooth re-entry
//if (self.z > 2000 || self.x < -game.width || self.x > game.width * 2 || self.y < -game.height || self.y > game.height * 2) {
//if (self.x < -game.width || self.x > game.width * 2 || self.y < -game.height || self.y > game.height * 2) {
if (self.x < 0 - self.width || self.x > game.width + self.width || self.y < 0 - self.height || self.y > game.height + self.height) {
//self.z = Math.random() * 1900 + 100; // Reset Z to simulate continuous flow with varied depth
self.z = 500;
self.x = (Math.random() - 0.5) * game.width * 2;
self.y = (Math.random() - 0.5) * game.height * 2;
self.vx = (self.x - centerX) / self.z;
self.vy = (self.y - centerY) / self.z;
//self.speed = Math.min(50 + Math.random() * 20, 70); // Increase speed range for enhanced light-speed effect
//self.speed = Math.min(5 + Math.random() * 20, 30); // Increase speed range for enhanced light-speed effect
//self.speed = Math.min(40 + Math.random() * 40, 60);
}
self.x = centerX + self.vx * self.z;
self.y = centerY + self.vy * self.z;
// Scale star based on z position to simulate 3D effect
var scale = Math.min(1000 / (1000 + self.z), 1.5); // Limit maximum scale to 1.5 to prevent abrupt size changes
//scale = Math.max((1000 + self.z) / 1000, 1.5); // Limit maximum scale to 1.5 to prevent abrupt size changes
scale = self.z / 5000;
//scale = Math.max(self.z / 10000, 1);
self.scale.x = scale;
self.scale.y = scale;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x002255 // Slightly lighter deep space black for contrast
});
/****
* Game Code
****/
function hsvToHex(h, s, v) {
var r, g, b, i, f, p, q, t;
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p;
break;
case 1:
r = q, g = v, b = p;
break;
case 2:
r = p, g = v, b = t;
break;
case 3:
r = p, g = q, b = v;
break;
case 4:
r = t, g = p, b = v;
break;
case 5:
r = v, g = p, b = q;
break;
}
var toHex = function toHex(x) {
var hex = Math.round(x * 255).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return '0x' + toHex(r) + toHex(g) + toHex(b);
}
var numColors = 36;
var rainbowColors = function () {
var colors = [];
for (var i = 0; i < numColors; i++) {
var hue = i * (360 / numColors) % 360;
colors.push(hsvToHex(hue / 360, 1, 1));
}
return colors;
}();
/*
// Create a text label with a warning message
var warningTxt = new Text2('Captain?! Please confirm order to keep accelerating!?\nWe are approaching very dangerous speeds!\nAnd where the HELL are we actually going?', {
size: 75,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0.5,
align: 'center'
});
// Center the text label on the screen
warningTxt.x = game.width / 2 - 900;
warningTxt.y = game.height / 2;
// Add the text label to the game
game.addChild(warningTxt);
*/
var centerX = 1024;
var centerY = game.height / 2;
var targetX,
targetY,
tweenDuration = 60,
tweenProgress = 0;
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
targetX = pos.x;
targetY = pos.y;
tweenProgress = 0;
});
LK.on('tick', function () {});
var stars = [];
for (var i = 0; i < 1500; i++) {
// Increase star count for denser starfield
var star = new Star();
stars.push(star);
game.addChild(star);
}
var score = 0;
// Score display
var scoreTxt = new Text2('0', {
size: 100,
fill: "#ffffff",
anchorX: 0.5
});
LK.gui.top.addChild(scoreTxt);
// Drag character
// Game tick
LK.on('tick', function () {
if (tweenProgress < tweenDuration) {
centerX += (targetX - centerX) / (tweenDuration - tweenProgress);
centerY += (targetY - centerY) / (tweenDuration - tweenProgress);
tweenProgress++;
}
// Spawn obstacles and stars
// Update tick counter for background color change
/*
colorChangeTick++;
if (colorChangeTick >= colorChangeInterval) {
// Adjust color components based on direction
// Randomize each color channel separately
bgColor.r = Math.floor(Math.random() * 256);
bgColor.g = Math.floor(Math.random() * 256);
bgColor.b = Math.floor(Math.random() * 256);
// Function to convert RGB to hexadecimal format
var newBgColor = rgbToHex(bgColor.r, bgColor.g, bgColor.b);
// Apply the new background color
game.setBackgroundColor(newBgColor);
// Reset tick counter
colorChangeTick = 0;
}*/
//centerX += Math.cos(colorChangeTick % 2000) * 3;
//centerY += Math.sin(colorChangeTick % 2000) * 3;
stars.forEach(function (star, index) {
/*
// Calculate the direction vector from the center to the star
var dx = star.x - centerX;
var dy = star.y - centerY;
// Normalize the direction vector
var length = Math.sqrt(dx * dx + dy * dy);
dx /= length;
dy /= length;
*/
// Set the star's velocity to the direction vector
// Incorporate deltaTime to ensure frame-rate independent movement
// Remove deltaTime calculation and directly update star position
star.move();
//star.move();
// R'eset star position and properties when it moves offscreen
// Correctly use star instead of self for resetting star properties
/*
if (star.z <= 0 || star.x < -game.width || star.x > game.width * 2 || star.y < -game.height || star.y > game.height * 2) {
star.z = Math.random() * 1900 + 100; // Ensure stars start further away
star.x = (Math.random() - 0.5) * game.width * 2;
star.y = (Math.random() - 0.5) * game.height * 2;
star.speed = Math.min(20 + Math.random() * 10, 30); // Adjust speed for a more dynamic effect
}
*/
});
});
A white triangle pointing down.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A colorful rectangular button with the text "Play Again" with each letter in a different color picked from a nice palette.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.