Skip to content

Commit

Permalink
update package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Reinstein committed Apr 18, 2019
1 parent b12863a commit 0514e45
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2,319 deletions.
52 changes: 27 additions & 25 deletions README.md
Expand Up @@ -31,43 +31,45 @@ ECS.addComponentToEntity(world, PLAYER, MOVEABLE)

// update entity velocity based on key pressed
function keyboardControlSystem (world) {
const moveableFilter = ECS.createFilter(world, [ MOVEABLE ])
// declare a filter that is used at run time to choose which entities to operate on
// the 2nd argument is all of the required component types the entity must have to
// be included
const moveableFilter = ECS.createFilter(world, [ MOVEABLE ])

// called each game loop
const onUpdate = function () {
// get all of the entities in the world that have a moveable component
for (const entity of ECS.getEntities(world, moveFilter)) {
// update the entity position according to what is pressed
if (Keyboard.keyPressed('up'))
entity.moveable.dy -= 1;
if (Keyboard.keyPressed('down'))
entity.moveable.dy += 1;
if (Keyboard.keyPressed('left'))
entity.moveable.dx -= 1;
if (Keyboard.keyPressed('right'))
entity.moveable.dx += 1;

entity.moveable.dx = clamp(entity.moveable.dx, -10, 10);
entity.moveable.dy = clamp(entity.moveable.dy, -10, 10);
}
// get all of the entities in the world that pass the filter
for (const entity of ECS.getEntities(world, moveFilter)) {
// update the entity position according to what is pressed
if (Keyboard.keyPressed('up'))
entity.moveable.dy -= 1;
if (Keyboard.keyPressed('down'))
entity.moveable.dy += 1;
if (Keyboard.keyPressed('left'))
entity.moveable.dx -= 1;
if (Keyboard.keyPressed('right'))
entity.moveable.dx += 1;

entity.moveable.dx = clamp(entity.moveable.dx, -10, 10);
entity.moveable.dy = clamp(entity.moveable.dy, -10, 10);
}
}

return { onUpdate }
}


function movementSystem (world) {
const moveFilter = ECS.createFilter(world, [ POSITION, MOVEABLE ])
const moveFilter = ECS.createFilter(world, [ POSITION, MOVEABLE ])

const onUpdate = function () {
// get all of the entities in the world that can be moved
for (const entity of ECS.getEntities(world, moveFilter)) {
entity.position.x += entity.moveable.dx
entity.position.y += entity.moveable.dy
}
}
const onUpdate = function () {
for (const entity of ECS.getEntities(world, moveFilter)) {
entity.position.x += entity.moveable.dx
entity.position.y += entity.moveable.dy
}
}

return { onUpdate }
return { onUpdate }
}


Expand Down

0 comments on commit 0514e45

Please sign in to comment.