Input Actions & Collision Systems
Bind logical gameplay actions with InputManager and detect overlaps, layers,
enter/stay/exit events, and raycasts using CollisionSystem.
1. Action-Mapped Input (game.Input)
Bind multiple keys or mouse buttons to one logical action name. Query isActionPressed,
isActionJustPressed, and isActionJustReleased cleanly inside onUpdate.
import { GameMouseButtons } from 'maverick';
// In onReady():
this.Input.bindAction('move_right', ['ArrowRight', 'd', 'D']);
this.Input.bindAction('attack', [' ', { mouseButton: GameMouseButtons.left }]);
// In onUpdate(dt):
if (this.Input.isActionPressed('move_right')) {
player.Config.pos!.x += 180 * dt;
}
if (this.Input.isActionJustPressed('attack')) {
player.triggerAttack();
}
2. Collision Layers, Events & Spatial Queries
import { CollisionBox, CollisionSets, CollisionSystem } from 'maverick';
const LAYER_PLAYER = 0b001;
const LAYER_ENEMY = 0b010;
const playerCol = new CollisionSets(LAYER_PLAYER, LAYER_ENEMY);
playerCol.Active = true;
playerCol.onCollisionEnter = (other) => console.log('Hit:', other.Config.name);
playerCol.onCollisionExit = (other) => console.log('Left:', other.Config.name);
playerCol.addBox(new CollisionBox(player, { xOffset: 0, yOffset: 0, width: 24, height: 32, color: '#0f0' }));
player.Config.collisions = playerCol;
const collisions = new CollisionSystem(64);
// Each fixed step:
collisions.step(this.Elements.All);
// Raycast & area queries:
const hit = collisions.raycast(this.Elements.All, 100, 100, 1, 0, 300, LAYER_ENEMY);
const nearby = collisions.queryRect(this.Elements.All, { x: 80, y: 80, width: 64, height: 64 }, LAYER_ENEMY);