Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: center is not defined' in or related to this line: 'var instructionText = new Text2('Tap to jump to the next orbit.\nDon\'t hit the red obstacles.', {' Line Number: 227
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'gui')' in or related to this line: 'scoreTxt.LK.gui.top.addChild(scoreTxt);' Line Number: 216
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'bottom')' in or related to this line: 'LK.top.bottom.addChild(instructionText);' Line Number: 236
Code edit (6 edits merged)
Please save this source code
User prompt
make sure instructionscreen is visible on stage at start
Code edit (1 edits merged)
Please save this source code
Code edit (19 edits merged)
Please save this source code
User prompt
At start, display white instruction text at screen bottom: "Tap to jump to the next orbit. Don't hit the red obstacles."
Code edit (1 edits merged)
Please save this source code
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
/**** * Classes ****/ /**** TODO: * 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 (and/or speed) with the orbit he jumps into? * Make sure orbits don't have too many obstacles (as currently possible). * Maybe pause player and obstacle updating while scaling? * Maybe make jumping faster to allow faster consecutive jumps. * Current min and max speeds of obstacles should be closer to each other. * Some rings could contain a single powerup (static, so player would always be able to circle around and get it.) * Or maybe just no obstacles, as a breather. * Every play should start at a different index of the rainbow color wheel. * Player could be a white dot for max contrast. * Make check of circular collision, considering actual display size and stage coordinates of obstacles. * Maybe background should tint with an offset on the colorwheel? ****/ // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.radius = 900; self.angle = 0; self.jump = function () { currentOrbitIndex++; var targetOrbit = orbits[currentOrbitIndex]; 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); } else { self.radius = 0; // Fallback radius if targetOrbit is not defined } self.x = 2048 / 2 + self.radius * Math.cos(self.angle); self.y = 2732 / 2 + self.radius * Math.sin(self.angle); //self.scale.x = 0.70; //self.scale.y = 0.70; self.width = 70; self.height = self.width; scaling = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); /* var orbit = game.addChild(new Orbit()); orbit.positionOrbit(4); orbits.push(orbit); // Move player to the topmost z-index game.setChildIndex(player, game.children.length - 1); */ }; self.update = function () { var centerX = 2048 / 2; var centerY = 2732 / 2; self.angleSpeed = 0.01; self.angle = (self.angle || 0) + self.angleSpeed; self.x = centerX + self.radius * Math.cos(self.angle); self.y = centerY + self.radius * Math.sin(self.angle); }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); //self.angleSpeed = 0.01; self.orbitSpeed = -0.01; self.move = function () { // Obstacle move logic //var angleSpeed = -0.01 * self.parent.direction; //self.orbitSpeed; //self.radius = self.parent.width / 2 - self.width / 2; self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width); self.angle = (self.angle || 0) + self.orbitSpeed; self.x = self.radius * Math.cos(self.angle); self.y = self.radius * Math.sin(self.angle); }; }); // Orbit class var Orbit = Container.expand(function () { var self = Container.call(this); var orbitGraphics = self.attachAsset('orbit1', { anchorX: 0.5, anchorY: 0.5, //tint: Math.floor(Math.random() * 16777215) tint: rainbowColors[orbitsCreated % rainbowColors.length] }); orbitsCreated++; orbitGraphics.alpha = 0.5; self.direction = Math.random() < 0.5 ? 1 : -1; self.positionOrbit = function (i) { self.x = 2048 / 2; self.y = 2732 / 2; this.width = 1900 - i * 500; this.height = 1900 - i * 500; if (i !== 0) { this.numBarriers = 1 + Math.floor(Math.random() * (i + currentOrbitIndex)); if (this.numBarriers > 20) { this.numBarriers = 20; } //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); } } }; var orbitGraphicsMask = self.attachAsset('blackSphere', { anchorX: 0.5, anchorY: 0.5, tint: 0x000000 }); orbitGraphicsMask.width = self.width - 200; orbitGraphicsMask.height = self.height - 200; self.addBarrier = function (speed, index) { var barrier = new Obstacle(); barrier.orbitSpeed = speed; //barrier.angle = index * (Math.PI * 2 / 20); barrier.angle = Math.random() * (Math.PI * 2); /* barrier.move = function () { barrier.angle += barrier.orbitSpeed * (self.direction === 1 ? 1 : -1); barrier.x = self.x + (self.width - barrier.width) / 2 * Math.cos(barrier.angle); barrier.y = self.y + (self.height - barrier.height) / 2 * Math.sin(barrier.angle); };*/ self.addChild(barrier); obstacles.push(barrier); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * 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 rainbowColors = function () { var colors = []; for (var i = 0; i < 15; i++) { var hue = i * 24 % 360; colors.push(hsvToHex(hue / 360, 1, 1)); } return colors; }(); //console.log(rainbowColors); // Initialize assets used in this game. // Game variables var player; var orbits = []; var obstacles = []; var currentOrbitIndex = 0; var scaling = false; var scalingCounter = 0; var scalingSpeed = 25; //5; var scalingTarget = 500; var orbitsCreated = 0; // Initialize player var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize orbits function createOrbits() { for (var i = 0; i < 5; i++) { var orbit = game.addChild(new Orbit()); orbit.positionOrbit(i); orbits.push(orbit); } } createOrbits(); game.setBackgroundColor(rainbowColors[12]); player = game.addChild(new Player()); //player.x = 2048 / 2; //player.y = 2732 / 2 - 200; // Start the player 200px above the center /* 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); } }); LK.on('tick', function () { player.update(); if (scaling) { scalingCounter++; for (var i = 0; i < orbits.length; i++) { orbits[i].width += scalingSpeed; orbits[i].height += scalingSpeed; //player.radius += scalingSpeed * 0.1; } player.radius = orbits[currentOrbitIndex].width / 2 - 50; if (player.width < 100) { player.width += 0.3; player.height = player.width; } //player.scale.x = player.scale.y = if (scalingCounter == scalingTarget / scalingSpeed) { scaling = false; scalingCounter = 0; var orbit = game.addChild(new Orbit()); orbit.positionOrbit(4); 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); var orb = orbits[i]; //if (orb && orb.width > 2700) { if (orb && orb.width > 3500) { for (var j = 0; j < orb.children.length; j++) { var child = orb.children[j]; if (child instanceof Obstacle) { // child is an instance of YourClass, do something with it child._destroyed = true; } } orbits[i].destroy(); // Splice alters jump logic, so alter currentTargetOrbit too. orbits.splice(i, 1); currentOrbitIndex--; } } // Update obstacles for (var i = obstacles.length - 1; i > 0; i--) { if (obstacles[i] && !obstacles[i]._destroyed) { obstacles[i].move(); if (player.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } else { obstacles.splice(i, 1); //console.log('obstacles.length is now: ' + obstacles.length); } } });
===================================================================
--- original.js
+++ change.js
@@ -11,8 +11,11 @@
* Current min and max speeds of obstacles should be closer to each other.
* Some rings could contain a single powerup (static, so player would always be able to circle around and get it.)
* Or maybe just no obstacles, as a breather.
* Every play should start at a different index of the rainbow color wheel.
+* Player could be a white dot for max contrast.
+* Make check of circular collision, considering actual display size and stage coordinates of obstacles.
+* Maybe background should tint with an offset on the colorwheel?
****/
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
@@ -175,10 +178,10 @@
return '0x' + toHex(r) + toHex(g) + toHex(b);
}
var rainbowColors = function () {
var colors = [];
- for (var i = 0; i < 30; i++) {
- var hue = i * 12 % 360;
+ for (var i = 0; i < 15; i++) {
+ var hue = i * 24 % 360;
colors.push(hsvToHex(hue / 360, 1, 1));
}
return colors;
}();
@@ -209,8 +212,9 @@
orbits.push(orbit);
}
}
createOrbits();
+game.setBackgroundColor(rainbowColors[12]);
player = game.addChild(new Player());
//player.x = 2048 / 2;
//player.y = 2732 / 2 - 200; // Start the player 200px above the center
/*