Skip to content

Instantly share code, notes, and snippets.

@ndugger
Created July 4, 2017 02:41
Show Gist options
  • Save ndugger/655adbf88539186eda6b557a078319eb to your computer and use it in GitHub Desktop.
Save ndugger/655adbf88539186eda6b557a078319eb to your computer and use it in GitHub Desktop.
import engine from '../engine';
import system from '../system';
import input from '../components/input';
import position from '../components/position';
import velocity from '../components/velocity';
export default system([ input, position, velocity ], entity => {
const { keyboard } = engine;
const { controls } = input.of(entity);
const { x, y } = position.of(entity);
if (keyboard.get(controls.up)) {
velocity.update(entity, { y: -1 });
}
if (keyboard.get(controls.right)) {
velocity.update(entity, { x: 1 });
}
if (keyboard.get(controls.down)) {
velocity.update(entity, { y: 1 });
}
if (keyboard.get(controls.left)) {
velocity.update(entity, { x: -1 });
}
const { x: vx, y: vy } = velocity.of(entity);
position.update(entity, {
x: x + vx,
y: y + vy
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment