Fix moveable components when multiple moveable entities

This commit is contained in:
Logan Hunt 2022-04-04 15:30:56 -06:00
parent 8cdffd7915
commit 14ddb31441
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1
2 changed files with 2 additions and 3 deletions

View File

@ -29,14 +29,13 @@ game.initialize = () => {
Array(10).fill(null).forEach((_, i) => { Array(10).fill(null).forEach((_, i) => {
const bigBlue = game.createBigBlue(); const bigBlue = game.createBigBlue();
bigBlue.addComponent(game.components.GridPosition({x: Math.floor(Math.random() * 15), y: Math.floor(Math.random() * 13)})); bigBlue.addComponent(game.components.GridPosition({x: Math.floor(Math.random() * 15), y: Math.floor(Math.random() * 13)}));
bigBlue.addComponent(game.components.Pushable()); bigBlue.addComponent(game.components.Controllable({controls: ['left', 'right', 'up', 'down']}));
game.entities[bigBlue.id] = bigBlue; game.entities[bigBlue.id] = bigBlue;
}); });
game.rock = game.createRock(); game.rock = game.createRock();
game.rock.addComponent(game.components.Position({x: 200, y: 200})); game.rock.addComponent(game.components.Position({x: 200, y: 200}));
game.rock.addComponent(game.components.GridPosition({x: 0, y: 0})); game.rock.addComponent(game.components.GridPosition({x: 0, y: 0}));
game.rock.addComponent(game.components.Controllable({controls: ['left', 'right', 'up', 'down']}));
game.rock.addComponent(game.components.Pushable()); game.rock.addComponent(game.components.Pushable());
game.entities[game.rock.id] = game.rock; game.entities[game.rock.id] = game.rock;

View File

@ -21,9 +21,9 @@ game.system.KeyboardInput = () => {
entity.addComponent(game.components.Momentum({ dx: 0, dy: 1 })); entity.addComponent(game.components.Momentum({ dx: 0, dy: 1 }));
} }
Object.keys(keys).map((key) => delete keys[key]);
} }
} }
Object.keys(keys).map((key) => delete keys[key]);
}; };
window.addEventListener("keydown", keyPress); window.addEventListener("keydown", keyPress);
return { keys, update }; return { keys, update };