From 12a99c12d9a0530aec7504218220ba0ad55802d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Lind=C3=A9n?= Date: Thu, 25 May 2017 07:53:23 +0200 Subject: [PATCH] Add negative turning resulting in a negative (counterclockwise) direction. --- docs/API-Reference.md | 2 +- src/main/js/modules/drone/movement.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/API-Reference.md b/docs/API-Reference.md index fbfd45d54..8aaff3f4e 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -4138,7 +4138,7 @@ no parameter is given, the default is 1. To change direction use the `turn()` method which also takes a single optional parameter (numTurns) - the number of 90 degree turns to -make. Turns are always clock-wise. If the drone is facing north, then +make. Turns are clockwise unless numTurns is negative in which case they are counterclockwise. If the drone is facing north, then drone.turn() will make the turn face east. If the drone is facing east then drone.turn(2) will make the drone turn twice so that it is facing west. diff --git a/src/main/js/modules/drone/movement.js b/src/main/js/modules/drone/movement.js index 2d63d4a27..1abd7c9d4 100644 --- a/src/main/js/modules/drone/movement.js +++ b/src/main/js/modules/drone/movement.js @@ -93,6 +93,9 @@ function turn( n ) { } this.dir += n; this.dir %=4; + if (this.dir < 0) { + this.dir += 4; + } } function chkpt( name ) { this._checkpoints[ name ] = { x:this.x, y:this.y, z:this.z, dir:this.dir };