mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Add boolean “seeing color brick?”
This commit is contained in:
parent
bd5bc7947b
commit
1381d2c4c0
1 changed files with 30 additions and 0 deletions
|
@ -1308,6 +1308,22 @@ class Scratch3BoostBlocks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
opcode: 'seeingColor',
|
||||||
|
text: formatMessage({
|
||||||
|
id: 'boost.seeingColor',
|
||||||
|
default: 'seeing [COLOR] brick?',
|
||||||
|
description: 'is the color sensor seeing a certain color?'
|
||||||
|
}),
|
||||||
|
blockType: BlockType.BOOLEAN,
|
||||||
|
arguments: {
|
||||||
|
COLOR: {
|
||||||
|
type: ArgumentType.STRING,
|
||||||
|
menu: 'COLOR',
|
||||||
|
defaultValue: COLOR_ID_ANY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
opcode: 'whenTilted',
|
opcode: 'whenTilted',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
|
@ -1925,6 +1941,20 @@ class Scratch3BoostBlocks {
|
||||||
return this._isColor(args.COLOR);
|
return this._isColor(args.COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the vision sensor is detecting a certain color.
|
||||||
|
* @param {object} args - the block's arguments.
|
||||||
|
* @return {boolean} - true when the color sensor senses the specified color.
|
||||||
|
*/
|
||||||
|
seeingColor (args) {
|
||||||
|
switch (args.COLOR) {
|
||||||
|
case COLOR_ID_ANY:
|
||||||
|
return this._peripheral.color !== COLOR_ID_NONE;
|
||||||
|
default:
|
||||||
|
return args.COLOR === this._peripheral.color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the vision sensor is detecting a certain color.
|
* Test whether the vision sensor is detecting a certain color.
|
||||||
* @param {string} colorId - the id of the color to test.
|
* @param {string} colorId - the id of the color to test.
|
||||||
|
|
Loading…
Reference in a new issue