mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -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',
|
||||
text: formatMessage({
|
||||
|
@ -1925,6 +1941,20 @@ class Scratch3BoostBlocks {
|
|||
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.
|
||||
* @param {string} colorId - the id of the color to test.
|
||||
|
|
Loading…
Reference in a new issue