Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: rainbowGraphics is not defined' in or related to this line: 'rainbowGraphics.tint = '0xffffff';' Line Number: 59
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of null (reading 'alpha')' in or related to this line: 'powerupText.alpha -= 1 / fadeStep;' Line Number: 248
User prompt
Fix Bug: 'Timeout.tick error: LK.effects.fadeOut is not a function' in or related to this line: 'LK.effects.fadeOut(powerupText, 3000, function () {' Line Number: 243
User prompt
Fix Bug: 'Timeout.tick error: LK.effects.fadeObject is not a function' in or related to this line: 'LK.effects.fadeObject(powerupText, 0, 3000, function () {' Line Number: 243
User prompt
Fix Bug: 'Timeout.tick error: LK.effects.fadeOut is not a function' in or related to this line: 'LK.effects.fadeOut(powerupText, 3000, function () {' Line Number: 243
User prompt
once added in showpoweruptext, poweruptext should fade out over the course of 3 seconds
Code edit (2 edits merged)
Please save this source code
User prompt
make poweruptext disappear on click, if it exists
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: ball is not defined' in or related to this line: 'console.log('collision occurred: (obstacle:', t.radius, t.angle, t.x, t.y, ') , (player: ', ball.radius, ball.angle, ball.x, ball.y);' Line Number: 345
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: localToGlobal is not defined' in or related to this line: 'var globalPos1 = localToGlobal(object1);' Line Number: 271
Code edit (6 edits merged)
Please save this source code
User prompt
update the getglobalposition function to account for parent objects having been scaled up or down
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getChildAt')' in or related to this line: 'LK.effects.flashScreen(obstacles[i].parent.getChildAt(0).getTint(), 1000);' Line Number: 342
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getChildAt')' in or related to this line: 'LK.effects.flashScreen(obstacles[i].parent.getChildAt(0).tint, 1000);' Line Number: 342
Code edit (9 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'orbitGraphics')' in or related to this line: 'LK.effects.flashScreen(obstacles[i].parent.orbitGraphics.tint, 1000);' Line Number: 342
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -1,63 +1,7 @@
/****
* Classes
-****/
-/****
-TODO:
-* Maybe player should change orbit direction (and/or speed) with the orbit he jumps into?
-* Make sure orbits don't have too many obstacles.
-* Maybe skip player and obstacle updating while scaling?
-* Current min and max speeds of obstacles should be closer to each other.
-* Maybe background should tint with an offset on the colorwheel?
-* Rotate orbits with obstacles statically distributed on them instead of calculating obstacle positions (for performance).
-* Would also be cool to be able to jump in AND out of orbits, but hard to implement. Or maybe just tap on the orbit to go to?
-****/
-// 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', {
@@ -76,24 +20,8 @@
self.x = self.radius * Math.cos(self.angle);
self.y = self.radius * Math.sin(self.angle);
};
});
-// Powerup class
-var Powerup1 = Container.expand(function () {
- var self = Container.call(this);
- var powerup1Graphics = self.attachAsset('powerup1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- //self.angleSpeed = 0.01;
- self.orbitSpeed = 0.075;
- self.move = function () {
- self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width) + 10;
- 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', {
@@ -118,8 +46,9 @@
// Add powerup to some orbits
if (orbitsCreated % 17 == 0) {
this.numBarriers = 0;
self.addPowerup(0);
+ rainbowGraphics.tint = '0xffffff';
}
//self.barrierSpeed = Math.random() * currentOrbitIndex + 1 / 20;
self.barrierSpeed = 0.01 + Math.random() * 0.015 * self.direction;
for (var j = 0; j < this.numBarriers; j++) {
@@ -141,9 +70,9 @@
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);
@@ -157,19 +86,91 @@
self.addChild(powerup);
obstacles.push(powerup);
};
});
+/****
+TODO:
+* Maybe player should change orbit direction (and/or speed) with the orbit he jumps into?
+* Make sure orbits don't have too many obstacles.
+* Maybe skip player and obstacle updating while scaling?
+* Current min and max speeds of obstacles should be closer to each other.
+* Maybe background should tint with an offset on the colorwheel?
+* Rotate orbits with obstacles statically distributed on them instead of calculating obstacle positions (for performance).
+* Would also be cool to be able to jump in AND out of orbits, but hard to implement. Or maybe just tap on the orbit to go to?
+****/
+// 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);
+ };
+});
+// Powerup class
+var Powerup1 = Container.expand(function () {
+ var self = Container.call(this);
+ var powerup1Graphics = self.attachAsset('powerup1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ //self.angleSpeed = 0.01;
+ self.orbitSpeed = 0.075;
+ self.move = function () {
+ self.radius = self.parent.width / 2 * (1900 / self.parent.width) - self.width / 2 * (100 / self.width) + 10;
+ self.angle = (self.angle || 0) + self.orbitSpeed;
+ self.x = self.radius * Math.cos(self.angle);
+ self.y = self.radius * Math.sin(self.angle);
+ };
+});
/****
* 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;
@@ -255,12 +256,12 @@
var obstacles = [];
var currentOrbitIndex = 0;
var scaling = false;
var scalingCounter = 0;
-var scalingSpeed = 50; //25;
+var scalingSpeed = 50;
var scalingTarget = 500;
var numColors = 18;
-var orbitsCreated = Math.floor(Math.random() * numColors); //0;
+var orbitsCreated = Math.floor(Math.random() * numColors);
var rainbowColors = function () {
var colors = [];
for (var i = 0; i < numColors; i++) {
var hue = i * (360 / numColors) % 360;
@@ -304,15 +305,14 @@
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 (powerupText) {
game.removeChild(powerupText);
powerupText = null;
- //return;
}
if (!scaling) {
player.jump(currentOrbitIndex);
LK.gui.top.removeChild(instructionText);
@@ -349,14 +349,14 @@
game.setChildIndex(player, game.children.length - 1);
player.width = 100;
player.height = 100;
//game.setBackgroundColor(rainbowColors[(10 + currentOrbitIndex) % 15] + 0xdddddd);
- /*
+ /*
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--) {