kopia lustrzana https://github.com/backface/turtlestitch
enhance the bounce at edge block
enable the turtle to bounce back at the edge in any scale or zoomFactor.pull/98/head
rodzic
ae22178bc1
commit
11654cd38a
|
@ -2309,34 +2309,32 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
||||||
SpriteMorph.prototype.bounceOffEdge = function () {
|
SpriteMorph.prototype.bounceOffEdge = function () {
|
||||||
// taking nested parts into account
|
// taking nested parts into account
|
||||||
var stage = this.parentThatIsA(StageMorph),
|
var stage = this.parentThatIsA(StageMorph),
|
||||||
fb = this.nestingBounds(),
|
|
||||||
dirX,
|
dirX,
|
||||||
dirY;
|
dirY;
|
||||||
|
|
||||||
if (!stage) {return null; }
|
if (!stage) {return null; }
|
||||||
if (stage.bounds.containsRectangle(fb)) {return null; }
|
|
||||||
|
|
||||||
dirX = Math.cos(radians(this.heading - 90));
|
dirX = Math.cos(radians(this.heading - 90));
|
||||||
dirY = -(Math.sin(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);
|
dirX = Math.abs(dirX);
|
||||||
}
|
}
|
||||||
if (fb.right() > stage.right()) {
|
if (this.xPosition() > stage.reportX(stage.right())) {
|
||||||
dirX = -(Math.abs(dirX));
|
dirX = -(Math.abs(dirX));
|
||||||
}
|
}
|
||||||
if (fb.top() < stage.top()) {
|
if (this.yPosition() > stage.reportY(stage.top())) {
|
||||||
dirY = -(Math.abs(dirY));
|
dirY = -(Math.abs(dirY));
|
||||||
}
|
}
|
||||||
if (fb.bottom() > stage.bottom()) {
|
if (this.yPosition() < stage.reportY(stage.bottom())) {
|
||||||
dirY = Math.abs(dirY);
|
dirY = Math.abs(dirY);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setHeading(degrees(Math.atan2(-dirY, dirX)) + 90);
|
this.setHeading(degrees(Math.atan2(-dirY, dirX)) + 90);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ########################################################################
|
// ########################################################################
|
||||||
/* STAGE */
|
/* STAGE */
|
||||||
// ########################################################################
|
// ########################################################################
|
||||||
|
@ -3084,7 +3082,23 @@ StageMorph.prototype.userMenu = function () {
|
||||||
StageMorph.prototype.toggleIgnoreWarnings = function () {
|
StageMorph.prototype.toggleIgnoreWarnings = function () {
|
||||||
StageMorph.prototype.ignoreWarnings = !StageMorph.prototype.ignoreWarnings;
|
StageMorph.prototype.ignoreWarnings = !StageMorph.prototype.ignoreWarnings;
|
||||||
this.turtleShepherd.ignoreWarning = 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
|
// Caches
|
||||||
|
|
Ładowanie…
Reference in New Issue