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
User prompt
Fix Bug: 'ReferenceError: barrier is not defined' in or related to this line: 'barrier.angle = 0;' Line Number: 170
Code edit (7 edits merged)
Please save this source code
User prompt
when player taps, remove the instructiontext from gui
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 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
===================================================================
--- original.js
+++ change.js
@@ -4,9 +4,9 @@
/****
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 pause player and obstacle updating while scaling?
+* Maybe skip player and obstacle updating while scaling?
* Current min and max speeds of obstacles should be closer to each other.
* Make check of circular collision, considering actual display size and stage coordinates of obstacles. (Or even just a forgiving distanc check).
* 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).
@@ -238,8 +238,42 @@
orbits.push(orbit);
}
}
createOrbits();
+function getGlobalPosition(object) {
+ var position = {
+ x: object.x,
+ y: object.y
+ };
+ var parent = object.parent;
+ var scale = {
+ x: 1,
+ y: 1
+ };
+ while (parent) {
+ position.x = position.x * scale.x + parent.x;
+ position.y = position.y * scale.y + parent.y;
+ scale.x *= parent.scaleX || 1;
+ scale.y *= parent.scaleY || 1;
+ parent = parent.parent;
+ }
+ return position;
+}
+function calculateDistance(object1, object2) {
+ var globalPos1 = getGlobalPosition(object1);
+ var globalPos2 = getGlobalPosition(object2);
+ var dx = globalPos1.x - globalPos2.x;
+ var dy = globalPos1.y - globalPos2.y;
+ return Math.sqrt(dx * dx + dy * dy);
+}
+function radIntersects(a, b, m) {
+ /*
+ var dx = (a.x - b.x) * (a.x - b.x);
+ var dy = (a.y - b.y) * (a.y - b.y);
+ return dx + dy < m * m;*/
+ var dist = calculateDistance(a, b);
+ return dist < m ? true : false;
+}
// Add instruction text at the bottom of the screen
var instructionText = new Text2('Tap to jump to the next orbit.\nDon\'t hit the red obstacles.', {
size: 50,
fill: "#bbbbbb",
@@ -330,9 +364,10 @@
// 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])) {
+ //if (player.intersects(obstacles[i])) {
+ if (radIntersects(player, obstacles[i], 100)) {
if (obstacles[i] instanceof Powerup1) {
obstacles[i].destroy();
obstacles[i]._destroyed = true;
LK.effects.flashScreen(0xffffff, 1000);