Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: numColors is not defined' in or related to this line: 'for (var i = 0; i < numColors; i++) {' Line Number: 118
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 (6 edits merged)
Please save this source code
User prompt
fix it
User prompt
use the rainbowcolors array to set a new color for each star as it is created
Code edit (3 edits merged)
Please save this source code
User prompt
use next value from colorarray when assigning color to a new star
User prompt
colorarray values should be in the 0x?????? format
Code edit (1 edits merged)
Please save this source code
User prompt
write a function to convert rgb color to 0x?????? format
Code edit (2 edits merged)
Please save this source code
User prompt
instead of giving stars random colors, iterate the colorArray to give them successive colors from that array.
User prompt
Please fix the bug: 'ReferenceError: bgColor is not defined' in or related to this line: 'bgColor.r = Math.floor(Math.random() * 256);' Line Number: 113
User prompt
make an array with 200 color values that smoothly transition along a rainbow spectrum
Code edit (8 edits merged)
Please save this source code
User prompt
randomize each color channel separately , rgb
User prompt
instead of yoyo style background color changes, just make values surpassing 00 or FF wrap around, so 00 - 11 becomes FF instead of staying at 00, and ff + 11 becomes 00 instead of staying at ff
User prompt
so fix it, by cycling colors towards lighter colors until they hit white, and then towards darker until they hit black, in a yoyo style effect
User prompt
change the background color slightly every 60 frames
Code edit (1 edits merged)
Please save this source code
User prompt
make sure background color change happens in #?????? format, not the 0x?????? format
User prompt
every few ticks, change background color to a new tint close to the current background color
===================================================================
--- original.js
+++ change.js
@@ -22,36 +22,43 @@
// 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(20 + Math.random() * 10, 30); // Increase speed range for light-speed effect
+ self.speed = Math.min(40 + Math.random() * 40, 60); // Increase speed range for light-speed effect
//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;
+ 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.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) {
self.z = Math.random() * 1900 + 100; // Reset Z to simulate continuous flow with varied depth
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(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;
self.scale.x = scale;
self.scale.y = scale;
};
});
@@ -65,8 +72,9 @@
/****
* Game Code
****/
+/*
// 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",
@@ -78,41 +86,19 @@
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 stars = [];
-for (var i = 0; i < 1500; i++) {
+for (var i = 0; i < 500; i++) {
// Increase star count for denser starfield
var star = new Star();
stars.push(star);
game.addChild(star);
}
var score = 0;
-var rgbToHex = function rgbToHex(r, g, b) {
- return '0x' + [r, g, b].map(function (x) {
- var hex = x.toString(16);
- return hex.length === 1 ? '0' + hex : hex;
- }).join('');
-};
-// Create an array with 200 color values that smoothly transition along a rainbow spectrum
-var colorArray = [];
-for (var i = 0; i < 200; i++) {
- var red = Math.sin(0.03 * i + 0) * 127 + 128;
- var green = Math.sin(0.03 * i + 2) * 127 + 128;
- var blue = Math.sin(0.03 * i + 4) * 127 + 128;
- colorArray.push(parseInt(rgbToHex(red, green, blue)));
-}
-console.log(colorArray);
-var colorArrayCounter = 0;
-var colorChangeTick = 0; // Tick counter for color change
-var colorChangeInterval = 60; // Number of ticks between each color change
-var bgColor = {
- r: 0,
- g: 0,
- b: 0
-}; // Initialize the bgColor variable
// Score display
var scoreTxt = new Text2('0', {
size: 100,
fill: "#ffffff",
@@ -123,10 +109,10 @@
// Game tick
LK.on('tick', function () {
// Spawn obstacles and stars
// Update tick counter for background color change
- colorChangeTick++;
/*
+ colorChangeTick++;
if (colorChangeTick >= colorChangeInterval) {
// Adjust color components based on direction
// Randomize each color channel separately
bgColor.r = Math.floor(Math.random() * 256);
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.