the mess that is pushable
This commit is contained in:
parent
aef3c05bc7
commit
cf4dbf91dd
2
src/bootstrap.js
vendored
2
src/bootstrap.js
vendored
@ -6,7 +6,7 @@ game.bootstrap = (() => {
|
|||||||
{
|
{
|
||||||
src: [
|
src: [
|
||||||
'src/components/position.js', 'src/components/momentum.js', 'src/components/gridPosition.js',
|
'src/components/position.js', 'src/components/momentum.js', 'src/components/gridPosition.js',
|
||||||
'src/components/appearence.js', 'src/components/controllable.js'
|
'src/components/appearence.js', 'src/components/controllable.js', 'src/components/pushable.js',
|
||||||
],
|
],
|
||||||
id: 'components'
|
id: 'components'
|
||||||
},
|
},
|
||||||
|
1
src/components/pushable.js
Normal file
1
src/components/pushable.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
game.components.Pushable = () => game.Component('pushable');
|
@ -29,6 +29,7 @@ game.initialize = () => {
|
|||||||
Array(400).fill(null).forEach((_, i) => {
|
Array(400).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());
|
||||||
game.entities[bigBlue.id] = bigBlue;
|
game.entities[bigBlue.id] = bigBlue;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ game.initialize = () => {
|
|||||||
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.Controllable({controls: ['left', 'right', 'up', 'down']}));
|
||||||
|
game.rock.addComponent(game.components.Pushable());
|
||||||
game.entities[game.rock.id] = game.rock;
|
game.entities[game.rock.id] = game.rock;
|
||||||
|
|
||||||
lastTimeStamp = performance.now()
|
lastTimeStamp = performance.now()
|
||||||
|
@ -52,6 +52,16 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Loop in momentum direction until we find an entity that does not have "push" component
|
// TODO: Loop in momentum direction until we find an entity that does not have "push" component
|
||||||
|
const proposed = {x: entity.components.gridPosition.x + momentumVector.dx, y: entity.components.gridPosition.y + momentumVector.dy}
|
||||||
|
|
||||||
|
const entitiesInCell = entitiesGrid[proposed.x][proposed.y];
|
||||||
|
|
||||||
|
for (let id in entitiesInCell) {
|
||||||
|
if (entitiesInCell[id].hasComponent("pushable")) {
|
||||||
|
entitiesInCell[id].addComponent(game.components.Momentum({...momentumVector}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entity.components.gridPosition.x = entity.components.gridPosition.x + momentumVector.dx;
|
entity.components.gridPosition.x = entity.components.gridPosition.x + momentumVector.dx;
|
||||||
entity.components.gridPosition.y = entity.components.gridPosition.y + momentumVector.dy;
|
entity.components.gridPosition.y = entity.components.gridPosition.y + momentumVector.dy;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user