summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCode WvS <code-wvs@quantentunnel.de>2015-02-27 18:54:01 +0100
committerCode WvS <code-wvs@quantentunnel.de>2015-02-27 18:54:01 +0100
commit4a0c39c1d2249dca7ff0eff02ac8ed7789d84b57 (patch)
treee4e8f811afa3fb54e8da73487b2d125b4995ab66
parent5eeee705bcd55d375c0be9e113abd6481c3a570d (diff)
downloadsnap-yow-4a0c39c1d2249dca7ff0eff02ac8ed7789d84b57.tar.gz
snap-yow-4a0c39c1d2249dca7ff0eff02ac8ed7789d84b57.zip
add marker movements
-rw-r--r--objects.js59
1 files changed, 22 insertions, 37 deletions
diff --git a/objects.js b/objects.js
index 845a274..c99e9af 100644
--- a/objects.js
+++ b/objects.js
@@ -237,6 +237,13 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'map',
spec: 'move to %l'
},
+ forward: {
+ only: SpriteMorph,
+ type: 'command',
+ category: 'map',
+ spec: 'move %n meters',
+ defaults: [2]
+ },
turn: {
only: SpriteMorph,
type: 'command',
@@ -265,13 +272,6 @@ SpriteMorph.prototype.initBlocks = function () {
},
// Motion
- forward: {
- only: SpriteMorph,
- type: 'command',
- category: 'motion',
- spec: 'move %n steps',
- defaults: [10]
- },
doFaceTowards: {
only: SpriteMorph,
type: 'command',
@@ -1802,6 +1802,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
//}
blocks.push('-');
+ blocks.push(block('forward'));
blocks.push(block('turn'));
blocks.push(block('turnLeft'));
blocks.push(block('setHeading'));
@@ -1809,25 +1810,11 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('direction'));
} /* else if (cat === 'motion') {
- blocks.push(block('forward'));
- blocks.push('-');
blocks.push(block('doFaceTowards'));
blocks.push('-');
- blocks.push(block('gotoXY'));
blocks.push(block('doGotoObject'));
blocks.push(block('doGlide'));
blocks.push('-');
- blocks.push(block('changeXPosition'));
- blocks.push(block('setXPosition'));
- blocks.push(block('changeYPosition'));
- blocks.push(block('setYPosition'));
- blocks.push('-');
- blocks.push(block('bounceOffEdge'));
- blocks.push('-');
- blocks.push(watcherToggle('xPosition'));
- blocks.push(block('xPosition'));
- blocks.push(watcherToggle('yPosition'));
- blocks.push(block('yPosition'));
} */ else if (cat === 'looks') {
@@ -3383,6 +3370,20 @@ SpriteMorph.prototype.reportMyLocation = function () {
return new List([this.geoposition.lat, this.geoposition.lng]);
};
+SpriteMorph.prototype.forward = function (meters) {
+ // geoposition[0] is lat, geoposition[1] is lon
+ // FIXME this is an approximation
+ var kilometers = meters / 1000;
+ var diffLat, diffLon;
+ diffLat = Math.cos(radians(this.heading)) * (1 / 110.54 * kilometers);
+ diffLon = Math.sin(radians(this.heading))
+ * (1 / (111.32 * Math.cos(radians(this.geoposition[0]))) * kilometers);
+
+ this.geoposition = [this.geoposition[0] + diffLat,
+ this.geoposition[1] + diffLon];
+ this.updateMarker();
+};
+
// SpriteMorph motion primitives
Morph.prototype.setPosition = function (aPoint, justMe) {
@@ -3394,22 +3395,6 @@ Morph.prototype.setPosition = function (aPoint, justMe) {
}
};
-SpriteMorph.prototype.forward = function (steps) {
- var dest,
- dist = steps * this.parent.scale || 0;
-
- if (dist >= 0) {
- dest = this.position().distanceAngle(dist, this.heading);
- } else {
- dest = this.position().distanceAngle(
- Math.abs(dist),
- (this.heading - 180)
- );
- }
- this.setPosition(dest);
- this.positionTalkBubble();
-};
-
SpriteMorph.prototype.setHeading = function (degrees) {
var x = this.xPosition(),
y = this.yPosition(),