Created
July 4, 2017 02:41
-
-
Save ndugger/655adbf88539186eda6b557a078319eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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