#[no_std, cache_output]
events = import "events.spwn"
on = (
event: @event,
function: @trigger_function
){
event.on_triggered(function)
}
extract import "util.spwn"
impl @block {
_range_: create_range_macro(@block),
create_tracker_item: #[desc("Returns an item ID that is 1 when the blocks are colliding and 0 when they are not") example("
// in some minigame
player = @player::{ block: 1b, group: 1g}
ground = 2b
on_ground = counter(player.block.create_tracker_item(ground))
on(touch(), !{
//jump
if on_ground == 1 { // player can only jump while touching the ground
player.jump()
}
})
")]
(
self,
#[desc("Block ID to check against")] other: @block
) {
item = ?i
on(events.collision(self, other), !{
item.add(1)
})
on(events.collision_exit(self, other), !{
item.add(-1)
})
return item
}
}