Add when jumped and is free falling
This commit is contained in:
1 parent
a62f5b9b0e
commit
92e1f040c3
1 file changed
+39
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user