enhance the bounce at edge block

enable the turtle to bounce back at the edge in any scale or zoomFactor.
pull/98/head
Simon-Mong 2021-08-23 22:29:53 +08:00 zatwierdzone przez GitHub
rodzic ae22178bc1
commit 11654cd38a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 22 dodań i 8 usunięć

Wyświetl plik

@ -2309,34 +2309,32 @@ SpriteMorph.prototype.blockTemplates = function (category) {
SpriteMorph.prototype.bounceOffEdge = function () {
// taking nested parts into account
var stage = this.parentThatIsA(StageMorph),
fb = this.nestingBounds(),
dirX,
dirY;
if (!stage) {return null; }
if (stage.bounds.containsRectangle(fb)) {return null; }
dirX = Math.cos(radians(this.heading - 90));
dirY = -(Math.sin(radians(this.heading - 90)));
if (fb.left() < stage.left()) {
if (this.xPosition() < stage.reportX(stage.left())) {
dirX = Math.abs(dirX);
}
if (fb.right() > stage.right()) {
if (this.xPosition() > stage.reportX(stage.right())) {
dirX = -(Math.abs(dirX));
}
if (fb.top() < stage.top()) {
if (this.yPosition() > stage.reportY(stage.top())) {
dirY = -(Math.abs(dirY));
}
if (fb.bottom() > stage.bottom()) {
if (this.yPosition() < stage.reportY(stage.bottom())) {
dirY = Math.abs(dirY);
}
this.setHeading(degrees(Math.atan2(-dirY, dirX)) + 90);
};
// ########################################################################
/* STAGE */
// ########################################################################
@ -3084,7 +3082,23 @@ StageMorph.prototype.userMenu = function () {
StageMorph.prototype.toggleIgnoreWarnings = function () {
StageMorph.prototype.ignoreWarnings = !StageMorph.prototype.ignoreWarnings;
this.turtleShepherd.ignoreWarning = StageMorph.prototype.ignoreWarnings;
}
}
StageMorph.prototype.reportX = function (x) {
return (x - this.center().x)
/ this.camera.zoomFactor
/ this.scale
* 2
+ this.controls.center.x;
};
StageMorph.prototype.reportY = function (y) {
return (this.center().y - y)
/ this.camera.zoomFactor
/ this.scale
* 2
+ this.controls.center.y;
};
// Caches