battlecore::motion

The motion module says how the player is moving, from the accelerometer in the tagger: still, walking or running, and which way the tagger points. Include its declarations with include "./battlecore/motion.bst";.

The changes arrive as events on module MOTION: the player starting to move, changing speed and stopping, and four gestures (shake, impact, point and turn). See MOTION events. These natives answer "what now".

The thresholds behind them (how hard a step is, how fast running is) are settings on the tagger, so they can be tuned without changing a game. The headband has no accelerometer: motion comes from the tagger only.

Enums

enum MotionSpeedEnum { STILL = 0, WALKING = 1, RUNNING = 2 }
enum PointEnum { LEVEL = 0, UP = 1, DOWN = 2 }
enum TurnEnum { LEFT = 0, RIGHT = 1 }
native bool battlecore::motion.hasSensor ();

Whether this tagger has an accelerometer that answered when it started. Without one the speed is always STILL and no MOTION events come.

native int battlecore::motion.getSpeed ();

The player’s speed now, as MotionSpeedEnum: STILL, WALKING or RUNNING.

native int battlecore::motion.getMsInState ();

How long the player has been at this speed, in milliseconds.

native float battlecore::motion.getPitch ();

How far the tagger is tipped up or down, in degrees, from a slow estimate of gravity, so a footfall does not flick it. Past +60 is what POINT calls UP.

native float battlecore::motion.getRoll ();

How far the tagger is rolled, in degrees, from the same estimate.

Example

A zombie only growls while it is moving, so one hiding still stays quiet. When a growl falls due and the zombie is still, it waits for the next START:

include "./battlecore/motion.bst";

bool growlDue = false;

void growlIfDue () {
	if (battlecore::motion.hasSensor() && battlecore::motion.getSpeed() == MotionSpeedEnum.STILL) {
		growlDue = true; // played by the next START
		return;
	}
	growlDue = false;
	battlecore::audio.trackStart("growl-1.wav", 200);
}

module ModuleEnum.MOTION {
	event EventEnum.START (EventData evt) => {
		if (growlDue) {
			growlIfDue();
		}
	}
}

Add MOTION to the game's ModuleEnum, and the event names it handles to its EventEnum.