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: [
|
||||||
'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/pushable.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'
|
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();
|
const hedge = game.Entity();
|
||||||
hedge.addComponent(game.components.LoadPriority({priority: 6}));
|
hedge.addComponent(game.components.LoadPriority({priority: 6}));
|
||||||
hedge.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
hedge.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
hedge.addComponent(game.components.Stop({stop: true}));
|
||||||
hedge.sprite = game.sprites.hedge;
|
hedge.sprite = game.sprites.hedge;
|
||||||
return hedge;
|
return hedge;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWall = () => {
|
|||||||
const wall = game.Entity();
|
const wall = game.Entity();
|
||||||
wall.addComponent(game.components.LoadPriority({priority: 3}));
|
wall.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wall.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wall.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wall.addComponent(game.components.Stop({stop: true}));
|
||||||
wall.sprite = game.sprites.wall;
|
wall.sprite = game.sprites.wall;
|
||||||
return wall;
|
return wall;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordBigBlue = () => {
|
|||||||
const wordBigBlue = game.Entity();
|
const wordBigBlue = game.Entity();
|
||||||
wordBigBlue.addComponent(game.components.LoadPriority({priority: 3}));
|
wordBigBlue.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordBigBlue.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordBigBlue.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordBigBlue.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordBigBlue.sprite = game.sprites.wordBigBlue;
|
wordBigBlue.sprite = game.sprites.wordBigBlue;
|
||||||
return wordBigBlue;
|
return wordBigBlue;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordFlag = () => {
|
|||||||
const wordFlag = game.Entity();
|
const wordFlag = game.Entity();
|
||||||
wordFlag.addComponent(game.components.LoadPriority({priority: 3}));
|
wordFlag.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordFlag.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordFlag.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordFlag.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordFlag.sprite = game.sprites.wordFlag;
|
wordFlag.sprite = game.sprites.wordFlag;
|
||||||
return wordFlag;
|
return wordFlag;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordIs = () => {
|
|||||||
const wordIs = game.Entity();
|
const wordIs = game.Entity();
|
||||||
wordIs.addComponent(game.components.LoadPriority({priority: 3}));
|
wordIs.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordIs.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordIs.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordIs.addComponent(game.components.Stop({stop: true}));
|
||||||
wordIs.sprite = game.sprites.wordIs;
|
wordIs.sprite = game.sprites.wordIs;
|
||||||
return wordIs;
|
return wordIs;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordKill = () => {
|
|||||||
const wordKill = game.Entity();
|
const wordKill = game.Entity();
|
||||||
wordKill.addComponent(game.components.LoadPriority({priority: 3}));
|
wordKill.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordKill.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordKill.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordKill.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordKill.sprite = game.sprites.wordKill;
|
wordKill.sprite = game.sprites.wordKill;
|
||||||
return wordKill;
|
return wordKill;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ game.createWordLava = () => {
|
|||||||
const wordLava = game.Entity();
|
const wordLava = game.Entity();
|
||||||
wordLava.addComponent(game.components.LoadPriority({priority: 3}));
|
wordLava.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordLava.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordLava.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordLava.addComponent(game.components.Pushable({pushable: true}));
|
||||||
|
|
||||||
wordLava.sprite = game.sprites.wordLava;
|
wordLava.sprite = game.sprites.wordLava;
|
||||||
return wordLava;
|
return wordLava;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordPush = () => {
|
|||||||
const wordPush = game.Entity();
|
const wordPush = game.Entity();
|
||||||
wordPush.addComponent(game.components.LoadPriority({priority: 3}));
|
wordPush.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordPush.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordPush.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordPush.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordPush.sprite = game.sprites.wordPush;
|
wordPush.sprite = game.sprites.wordPush;
|
||||||
return wordPush;
|
return wordPush;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordRock = () => {
|
|||||||
const wordRock = game.Entity();
|
const wordRock = game.Entity();
|
||||||
wordRock.addComponent(game.components.LoadPriority({priority: 3}));
|
wordRock.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordRock.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordRock.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordRock.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordRock.sprite = game.sprites.wordRock;
|
wordRock.sprite = game.sprites.wordRock;
|
||||||
return wordRock;
|
return wordRock;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordSink = () => {
|
|||||||
const wordSink = game.Entity();
|
const wordSink = game.Entity();
|
||||||
wordSink.addComponent(game.components.LoadPriority({priority: 3}));
|
wordSink.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordSink.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordSink.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordSink.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordSink.sprite = game.sprites.wordSink;
|
wordSink.sprite = game.sprites.wordSink;
|
||||||
return wordSink;
|
return wordSink;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordStop = () => {
|
|||||||
const wordStop = game.Entity();
|
const wordStop = game.Entity();
|
||||||
wordStop.addComponent(game.components.LoadPriority({priority: 3}));
|
wordStop.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordStop.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordStop.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordStop.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordStop.sprite = game.sprites.wordStop;
|
wordStop.sprite = game.sprites.wordStop;
|
||||||
return wordStop;
|
return wordStop;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordWall = () => {
|
|||||||
const wordWall = game.Entity();
|
const wordWall = game.Entity();
|
||||||
wordWall.addComponent(game.components.LoadPriority({priority: 3}));
|
wordWall.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordWall.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordWall.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordWall.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordWall.sprite = game.sprites.wordWall;
|
wordWall.sprite = game.sprites.wordWall;
|
||||||
return wordWall;
|
return wordWall;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordWater = () => {
|
|||||||
const wordWater = game.Entity();
|
const wordWater = game.Entity();
|
||||||
wordWater.addComponent(game.components.LoadPriority({priority: 3}));
|
wordWater.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordWater.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordWater.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordWater.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordWater.sprite = game.sprites.wordWater;
|
wordWater.sprite = game.sprites.wordWater;
|
||||||
return wordWater;
|
return wordWater;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordWin = () => {
|
|||||||
const wordWin = game.Entity();
|
const wordWin = game.Entity();
|
||||||
wordWin.addComponent(game.components.LoadPriority({priority: 3}));
|
wordWin.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordWin.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordWin.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordWin.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordWin.sprite = game.sprites.wordWin;
|
wordWin.sprite = game.sprites.wordWin;
|
||||||
return wordWin;
|
return wordWin;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ game.createWordYou = () => {
|
|||||||
const wordYou = game.Entity();
|
const wordYou = game.Entity();
|
||||||
wordYou.addComponent(game.components.LoadPriority({priority: 3}));
|
wordYou.addComponent(game.components.LoadPriority({priority: 3}));
|
||||||
wordYou.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
wordYou.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100}));
|
||||||
|
wordYou.addComponent(game.components.Pushable({pushable: true}));
|
||||||
wordYou.sprite = game.sprites.wordYou;
|
wordYou.sprite = game.sprites.wordYou;
|
||||||
return wordYou;
|
return wordYou;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ game.system.GridSystem = ({ xDim, yDim }) => {
|
|||||||
entity.components.appearance.height = gridHeight;
|
entity.components.appearance.height = gridHeight;
|
||||||
}
|
}
|
||||||
if (entity.hasComponent("position")) {
|
if (entity.hasComponent("position")) {
|
||||||
const newGridCoords = gameCoordsToGrid(entity.components.position);
|
let newGridCoords = gameCoordsToGrid(entity.components.position);
|
||||||
const oldGridCoords = entity.components.gridPosition;
|
const oldGridCoords = entity.components.gridPosition;
|
||||||
if (!equivalence(newGridCoords, oldGridCoords)) {
|
if (!equivalence(newGridCoords, oldGridCoords)) {
|
||||||
const momentumVector = unitize({
|
const momentumVector = unitize({
|
||||||
@ -51,33 +51,38 @@ game.system.GridSystem = ({ xDim, yDim }) => {
|
|||||||
dy: newGridCoords.y - oldGridCoords.y,
|
dy: newGridCoords.y - oldGridCoords.y,
|
||||||
});
|
});
|
||||||
|
|
||||||
const proposed = {
|
const proposed = {...newGridCoords};
|
||||||
x: entity.components.gridPosition.x + momentumVector.dx,
|
|
||||||
y: entity.components.gridPosition.y + momentumVector.dy
|
|
||||||
};
|
|
||||||
|
|
||||||
const proposedCopy = {...proposed};
|
|
||||||
if (entity.hasComponent("controllable")) {
|
if (entity.hasComponent("controllable")) {
|
||||||
let found = false;
|
let found = false;
|
||||||
do {
|
do {
|
||||||
found = false;
|
found = false;
|
||||||
const entitiesInCell = entitiesGrid[proposedCopy.y][proposedCopy.x];
|
const entitiesInCell = entitiesGrid[proposed.y][proposed.x];
|
||||||
entitiesInCell.forEach((entity) => {
|
for (let entity of entitiesInCell.values()) {
|
||||||
if (entity.hasComponent("pushable")) {
|
if (entity.hasComponent("pushable")) {
|
||||||
entity.addComponent(game.components.Momentum({...momentumVector}));
|
|
||||||
found = true;
|
found = true;
|
||||||
|
entity.addComponent(game.components.Momentum({...momentumVector}));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
proposedCopy.x += momentumVector.dx;
|
proposed.x += momentumVector.dx;
|
||||||
proposedCopy.y += momentumVector.dy;
|
proposed.y += momentumVector.dy;
|
||||||
const proposedCopyInBounds = clamp(proposedCopy, xDim-1, yDim-1);
|
const proposedClampedInBounds = clamp(proposed, xDim-1, yDim-1);
|
||||||
if (!equivalence(proposedCopyInBounds, proposedCopy)) {
|
if (!equivalence(proposedClampedInBounds, proposed)) {
|
||||||
found = false;
|
found = false;
|
||||||
}
|
}
|
||||||
} while (found);
|
} 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 = {
|
||||||
...entity.components.position,
|
...entity.components.position,
|
||||||
|
Loading…
Reference in New Issue
Block a user