Add stop component; entites are stackable when they arrive at a stop component. Maybe this is wrong?
This commit is contained in:
parent
dee568c51d
commit
545e129c74
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
2
src/bootstrap.js
vendored
2
src/bootstrap.js
vendored
@ -7,7 +7,7 @@ game.bootstrap = (() => {
|
||||
src: [
|
||||
'src/components/position.js', 'src/components/momentum.js', 'src/components/gridPosition.js',
|
||||
'src/components/appearence.js', 'src/components/controllable.js', 'src/components/pushable.js',
|
||||
'src/components/loadPriority.js',
|
||||
'src/components/loadPriority.js', 'src/components/stop.js'
|
||||
],
|
||||
id: 'components'
|
||||
},
|
||||
|
1
src/components/stop.js
Normal file
1
src/components/stop.js
Normal file
@ -0,0 +1 @@
|
||||
game.components.Stop = ({stop}) => game.Component("stop", {stop});
|
@ -2,6 +2,7 @@ game.createHedge = () => {
|
||||
const hedge = game.Entity();
|
||||
hedge.addComponent(game.components.LoadPriority({priority: 6}));
|
||||
hedge.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
hedge.addComponent(game.components.Stop({stop: true}));
|
||||
hedge.sprite = game.sprites.hedge;
|
||||
return hedge;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWall = () => {
|
||||
const wall = game.Entity();
|
||||
wall.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wall.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wall.addComponent(game.components.Stop({stop: true}));
|
||||
wall.sprite = game.sprites.wall;
|
||||
return wall;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordBigBlue = () => {
|
||||
const wordBigBlue = game.Entity();
|
||||
wordBigBlue.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordBigBlue.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordBigBlue.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordBigBlue.sprite = game.sprites.wordBigBlue;
|
||||
return wordBigBlue;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordFlag = () => {
|
||||
const wordFlag = game.Entity();
|
||||
wordFlag.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordFlag.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordFlag.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordFlag.sprite = game.sprites.wordFlag;
|
||||
return wordFlag;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordIs = () => {
|
||||
const wordIs = game.Entity();
|
||||
wordIs.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordIs.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordIs.addComponent(game.components.Stop({stop: true}));
|
||||
wordIs.sprite = game.sprites.wordIs;
|
||||
return wordIs;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordKill = () => {
|
||||
const wordKill = game.Entity();
|
||||
wordKill.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordKill.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordKill.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordKill.sprite = game.sprites.wordKill;
|
||||
return wordKill;
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ game.createWordLava = () => {
|
||||
const wordLava = game.Entity();
|
||||
wordLava.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordLava.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordLava.addComponent(game.components.Pushable({pushable: true}));
|
||||
|
||||
wordLava.sprite = game.sprites.wordLava;
|
||||
return wordLava;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordPush = () => {
|
||||
const wordPush = game.Entity();
|
||||
wordPush.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordPush.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordPush.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordPush.sprite = game.sprites.wordPush;
|
||||
return wordPush;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordRock = () => {
|
||||
const wordRock = game.Entity();
|
||||
wordRock.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordRock.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordRock.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordRock.sprite = game.sprites.wordRock;
|
||||
return wordRock;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordSink = () => {
|
||||
const wordSink = game.Entity();
|
||||
wordSink.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordSink.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordSink.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordSink.sprite = game.sprites.wordSink;
|
||||
return wordSink;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordStop = () => {
|
||||
const wordStop = game.Entity();
|
||||
wordStop.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordStop.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordStop.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordStop.sprite = game.sprites.wordStop;
|
||||
return wordStop;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordWall = () => {
|
||||
const wordWall = game.Entity();
|
||||
wordWall.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordWall.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordWall.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordWall.sprite = game.sprites.wordWall;
|
||||
return wordWall;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordWater = () => {
|
||||
const wordWater = game.Entity();
|
||||
wordWater.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordWater.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordWater.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordWater.sprite = game.sprites.wordWater;
|
||||
return wordWater;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordWin = () => {
|
||||
const wordWin = game.Entity();
|
||||
wordWin.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordWin.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordWin.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordWin.sprite = game.sprites.wordWin;
|
||||
return wordWin;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ game.createWordYou = () => {
|
||||
const wordYou = game.Entity();
|
||||
wordYou.addComponent(game.components.LoadPriority({priority: 3}));
|
||||
wordYou.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||
wordYou.addComponent(game.components.Pushable({pushable: true}));
|
||||
wordYou.sprite = game.sprites.wordYou;
|
||||
return wordYou;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ game.system.GridSystem = ({ xDim, yDim }) => {
|
||||
entity.components.appearance.height = gridHeight;
|
||||
}
|
||||
if (entity.hasComponent("position")) {
|
||||
const newGridCoords = gameCoordsToGrid(entity.components.position);
|
||||
let newGridCoords = gameCoordsToGrid(entity.components.position);
|
||||
const oldGridCoords = entity.components.gridPosition;
|
||||
if (!equivalence(newGridCoords, oldGridCoords)) {
|
||||
const momentumVector = unitize({
|
||||
@ -51,33 +51,38 @@ game.system.GridSystem = ({ xDim, yDim }) => {
|
||||
dy: newGridCoords.y - oldGridCoords.y,
|
||||
});
|
||||
|
||||
const proposed = {
|
||||
x: entity.components.gridPosition.x + momentumVector.dx,
|
||||
y: entity.components.gridPosition.y + momentumVector.dy
|
||||
};
|
||||
|
||||
const proposedCopy = {...proposed};
|
||||
const proposed = {...newGridCoords};
|
||||
if (entity.hasComponent("controllable")) {
|
||||
let found = false;
|
||||
do {
|
||||
found = false;
|
||||
const entitiesInCell = entitiesGrid[proposedCopy.y][proposedCopy.x];
|
||||
entitiesInCell.forEach((entity) => {
|
||||
const entitiesInCell = entitiesGrid[proposed.y][proposed.x];
|
||||
for (let entity of entitiesInCell.values()) {
|
||||
if (entity.hasComponent("pushable")) {
|
||||
entity.addComponent(game.components.Momentum({...momentumVector}));
|
||||
found = true;
|
||||
entity.addComponent(game.components.Momentum({...momentumVector}));
|
||||
}
|
||||
});
|
||||
proposedCopy.x += momentumVector.dx;
|
||||
proposedCopy.y += momentumVector.dy;
|
||||
const proposedCopyInBounds = clamp(proposedCopy, xDim-1, yDim-1);
|
||||
if (!equivalence(proposedCopyInBounds, proposedCopy)) {
|
||||
}
|
||||
proposed.x += momentumVector.dx;
|
||||
proposed.y += momentumVector.dy;
|
||||
const proposedClampedInBounds = clamp(proposed, xDim-1, yDim-1);
|
||||
if (!equivalence(proposedClampedInBounds, proposed)) {
|
||||
found = false;
|
||||
}
|
||||
} while (found);
|
||||
}
|
||||
|
||||
entity.components.gridPosition = {...entity.components.gridPosition, ...proposed};
|
||||
if (entity.hasComponent("pushable") || entity.hasComponent("controllable")) {
|
||||
for (let e of entitiesGrid[newGridCoords.y][newGridCoords.x].values()) {
|
||||
if (e.hasComponent("stop")) {
|
||||
newGridCoords = oldGridCoords;
|
||||
break;
|
||||
}
|
||||
}
|
||||
entity.addComponent(game.components.Momentum({...momentumVector}));
|
||||
}
|
||||
|
||||
entity.components.gridPosition = {...entity.components.gridPosition, ...newGridCoords};
|
||||
|
||||
entity.components.position = {
|
||||
...entity.components.position,
|
||||
|
Loading…
Reference in New Issue
Block a user