Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'backgroundColor')' in or related to this line: 'game.set.backgroundColor = rainbowColors[12];' Line Number: 224
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parent')' in or related to this line: 'if (obstacles[i].parent) {' Line Number: 276
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parent')' in or related to this line: 'if (obstacles[i].parent) {' Line Number: 276
Code edit (4 edits merged)
Please save this source code
User prompt
modify ranbowcolors function to only create an array of 30 evenly distributed colors on a seamless rainbow
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: i is not defined' in or related to this line: 'var orbitGraphics = self.attachAsset('orbit1', {' Line Number: 89
User prompt
set each new orbit on creation to the tint that is the next index in the rainbow colors array.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: rainbowColors is not a function' in or related to this line: 'var colors = rainbowColors();' Line Number: 189
Code edit (13 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: utils is not defined' in or related to this line: 'colors.push(utils.rgb2hex(utils.hsv2rgb(hue / 360, 1, 1)));' Line Number: 150
User prompt
make a global variable which is an array containing 60 values representing an even and looping rainbow of colors.
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'width')' in or related to this line: 'if (orbits[i].width > 2700) {' Line Number: 216
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: angleSpeed is not defined' in or related to this line: 'self.angle = (self.angle || 0) + angleSpeed;' Line Number: 72
User prompt
Fix Bug: 'ReferenceError: angleSpeed is not defined' in or related to this line: 'self.angle = (self.angle || 0) + angleSpeed;' Line Number: 72
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: obstacleGraphics is not defined' in or related to this line: 'barrier.y = self.y + (self.height - obstacleGraphics.height) / 2 * Math.sin(barrier.angle);' Line Number: 109
User prompt
Fix Bug: 'ReferenceError: obstacleGraphics is not defined' in or related to this line: 'barrier.x = self.x + (self.width - obstacleGraphics.width) / 2 * Math.cos(barrier.angle);' Line Number: 108
===================================================================
--- original.js
+++ change.js
@@ -6,8 +6,10 @@
* Make sure orbits are removed when they scale up enough. (to avoid lag)
* Make sure obstacles can't spawn directly on player angle with same speed at start, making first jump impossible.
* Maybe player should change orbit direction with the orbit he jumps into?
* Make colors nicer, maybe cycle through them rainbow like instead of just random colors?
+* Make sure orbits don't have too many obstacles (as currently possible).
+* Maybe pause player and obstacle updating while scaling?
****/
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
@@ -23,9 +25,9 @@
self.angle = Math.atan2(self.y - 2732 / 2, self.x - 2048 / 2);
if (targetOrbit) {
//self.radius = (targetOrbit.width - 100) / 2;
self.radius = targetOrbit.width / 2;
- console.log('self.radius after setting it to targetOrbits: ' + self.radius);
+ //console.log('self.radius after setting it to targetOrbits: ' + self.radius);
} else {
self.radius = 0; // Fallback radius if targetOrbit is not defined
}
self.x = 2048 / 2 + self.radius * Math.cos(self.angle);
@@ -96,9 +98,9 @@
//self.barrierSpeed = Math.random() * currentOrbitIndex + 1 / 20;
self.barrierSpeed = 0.01 + Math.random() * 0.02 * self.direction;
for (var j = 0; j < this.numBarriers; j++) {
self.addBarrier(self.barrierSpeed, j);
- console.log('adding barrier: ', j);
+ //console.log('adding barrier: ', j);
}
}
};
var orbitGraphicsMask = self.attachAsset('blackSphere', {
@@ -132,8 +134,16 @@
/****
* Game Code
****/
+var rainbowColors = function () {
+ var colors = [];
+ for (var i = 0; i < 60; i++) {
+ var hue = i * 6 % 360;
+ colors.push(utils.rgb2hex(utils.hsv2rgb(hue / 360, 1, 1)));
+ }
+ return colors;
+}();
// Initialize assets used in this game.
// Game variables
var player;
var orbits = [];
@@ -161,13 +171,15 @@
createOrbits();
player = game.addChild(new Player());
//player.x = 2048 / 2;
//player.y = 2732 / 2 - 200; // Start the player 200px above the center
-// Game logic
+/*
console.log('Player radius is now: ' + player.radius);
console.log('Orbits.length is now: ' + orbits.length);
console.log('CurrentOrbitIndex is now: ' + currentOrbitIndex);
console.log('width of currentorbit is now: ' + orbits[currentOrbitIndex].width);
+*/
+// Game logic
game.on('down', function (obj) {
if (!scaling) {
player.jump(currentOrbitIndex);
}
@@ -195,19 +207,24 @@
orbits.push(orbit);
game.setChildIndex(player, game.children.length - 1);
player.width = 100;
player.height = 100;
+ /*
console.log('Player radius is now: ' + player.radius);
console.log('Orbits.length is now: ' + orbits.length);
console.log('CurrentOrbitIndex is now: ' + currentOrbitIndex);
console.log('width of currentorbit is now: ' + orbits[currentOrbitIndex].width);
+ */
}
}
// Update orbits
for (var i = orbits.length - 1; i > 0; i--) {
//orbits[i].positionOrbit(i);
if (orbits[i] && orbits[i].width > 2700) {
orbits[i].destroy();
+ // Splice alters jump logic, so alter currentTargetOrbit too.
+ orbits.splice(i, 1);
+ currentOrbitIndex--;
}
}
// Update obstacles
for (var i = 0; i < obstacles.length; i++) {