From 92e1f040c37dbf67f5fb79455fcede50ecef3e44 Mon Sep 17 00:00:00 2001 From: Valerie Young Date: Thu, 10 Jan 2019 11:56:37 -0500 Subject: [PATCH] Add when jumped and is free falling --- src/extensions/scratch3_gdx_for/index.js | 42 ++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/extensions/scratch3_gdx_for/index.js b/src/extensions/scratch3_gdx_for/index.js index ef71c9e0..81917c5f 100644 --- a/src/extensions/scratch3_gdx_for/index.js +++ b/src/extensions/scratch3_gdx_for/index.js @@ -145,7 +145,9 @@ class GdxFor { // will be fixed in a future @vernier/godirect release. sensor.on('value-changed', changedSensor => { if (changedSensor.values.length > 1000) { + const val = changedSensor.value; changedSensor.clear(); + changedSensor.setValue(val); } }); }); @@ -482,6 +484,15 @@ class Scratch3GdxForBlocks { } } }, + { + opcode: 'whenJumped', + text: formatMessage({ + id: 'gdxfor.whenJumped', + default: 'when jumped', + description: 'when the device has jumped' + }), + blockType: BlockType.HAT, + }, { opcode: 'getAcceleration', text: formatMessage({ @@ -554,6 +565,15 @@ class Scratch3GdxForBlocks { defaultValue: 'up' } } + }, + { + opcode: 'isFreeFalling', + text: formatMessage({ + id: 'gdxfor.isFreeFalling', + default: 'free falling?', + description: 'is the device in freefall?' + }), + blockType: BlockType.BOOLEAN, } ], menus: { @@ -575,7 +595,6 @@ class Scratch3GdxForBlocks { return Math.sqrt((x * x) + (y * y) + (z * z)); } - whenAccelerationCompare (args) { const currentVal = this.magnitude( this._peripheral.getAccelerationX(), @@ -593,6 +612,14 @@ class Scratch3GdxForBlocks { return false; } } + whenJumped () { + const currentVal = this.magnitude( + this._peripheral.getAccelerationX(), + this._peripheral.getAccelerationY(), + this._peripheral.getAccelerationZ() + ); + return currentVal < .5; + } whenSpinSpeedCompare (args) { const currentVal = this.magnitude( this._peripheral.getSpinSpeedX(), @@ -655,6 +682,9 @@ class Scratch3GdxForBlocks { log.warn(`Unknown direction in getTilt: ${args.TILT}`); } } + getForce () { + return this._peripheral.getForce(); + } isFacing (args) { switch (args.FACING) { case 'up': @@ -665,8 +695,14 @@ class Scratch3GdxForBlocks { log.warn(`Unknown direction in isFacing: ${args.FACING}`); } } - getForce () { - return this._peripheral.getForce(); + isFreeFalling () { + const currentVal = this.magnitude( + this._peripheral.getAccelerationX(), + this._peripheral.getAccelerationY(), + this._peripheral.getAccelerationZ() + ); + + return currentVal < .5; } }