/**
* @module block
*/
/**
* @typedef {object} block
* @property {function} if_colliding Returns whether the block is colliding with another one
*/
/**
* Representation of blocks
* @class
* @constructor
* @public
*/
class $block {
/**
* Creates a block from a number
* @param {number} number Block ID
* @param {boolean} [specific=true] Whether to disallow G.js from using that specific block again
*/
constructor(a, specific = true) {
this.value = a;
this.type = 'block';
if (specific && !all_known.blocks.includes(a)) all_known.blocks.push(a);
}
/**
* Returns a collision block object
* @param {block} b2 Other block to check for collision
* @param {number} x X coordinate of the collision block
* @param {number} y Y coordinate of the collision block
* @returns {object} Returned collision block
*/
collision_block(x, y) {
return object({
OBJ_ID: obj_ids.special.COLLISION_BLOCK,
X: x,
Y: y,
BLOCK_A: this,
})
}
/**
*
* @param {block} b2 Other block to check for collision
* @param {group} true_id Group to call if colliding with b2
* @param {group} false_id Group to call if not colliding with b2
*/
if_colliding(b2, true_id = group(0), false_id = group(0)) {
let j = {
OBJ_ID: 3609,
BLOCK_A: this,
BLOCK_B: b2
};
if (true_id) j.TRUE_ID = true_id;
if (false_id) j.FALSE_ID = false_id;
$.add(trigger(j));
}
}
module.exports = $block;