Skip to content

Commit 2a6295b

Browse files
committed
Cleaning code to skip conversion to degrees before conversion to radians. Also, inverted Y-axis logic because the code copied from the Scratch VM does not take into account the y-axis difference between Scratch VM and Leopard.
1 parent 0ff1916 commit 2a6295b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Sprite.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ export class Sprite extends SpriteBase {
484484
ifOnEdgeBounce() {
485485
const nearestEdge = this.nearestEdge();
486486
if (!nearestEdge) return;
487-
const rad = this.degToRad(this.scratchToDeg(this.direction));
487+
const rad = this.scratchToRad(this.direction);
488488
let dx = Math.cos(rad);
489-
let dy = -Math.sin(rad);
489+
let dy = Math.sin(rad);
490490
switch (nearestEdge) {
491491
case Sprite.Edge.LEFT:
492492
dx = Math.max(0.2, Math.abs(dx));
@@ -495,13 +495,13 @@ export class Sprite extends SpriteBase {
495495
dx = -Math.max(0.2, Math.abs(dx));
496496
break;
497497
case Sprite.Edge.TOP:
498-
dy = Math.max(0.2, Math.abs(dy));
498+
dy = -Math.max(0.2, Math.abs(dy));
499499
break;
500500
case Sprite.Edge.BOTTOM:
501-
dy = -Math.max(0.2, Math.abs(dy));
501+
dy = Math.max(0.2, Math.abs(dy));
502502
break;
503503
}
504-
this.direction = this.degToScratch(this.radToDeg(Math.atan2(dy, dx)));
504+
this.direction = this.radToScratch(Math.atan2(dy, dx));
505505
const { x, y } = this.keepInFence(this.x, this.y);
506506
this.goto(x, y);
507507
}

0 commit comments

Comments
 (0)