summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-05 14:54:34 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-05 14:54:34 -0600
commit545e129c7411714e7b40c742a23409629c9f767f (patch)
tree7576214f20d35230a1769843d06dfb9ed2b09af6
parentdee568c51dbf2393aa7bd75f4241602af8022a2c (diff)
downloadbbiy-545e129c7411714e7b40c742a23409629c9f767f.tar.gz
bbiy-545e129c7411714e7b40c742a23409629c9f767f.zip
Add stop component; entites are stackable when they arrive at a stop component. Maybe this is wrong?
-rw-r--r--assets/.DS_Storebin8196 -> 8196 bytes
-rw-r--r--src/bootstrap.js2
-rw-r--r--src/components/stop.js1
-rw-r--r--src/entities/hedge.js1
-rw-r--r--src/entities/wall.js1
-rw-r--r--src/entities/wordBigBlue.js1
-rw-r--r--src/entities/wordFlag.js1
-rw-r--r--src/entities/wordIs.js1
-rw-r--r--src/entities/wordKill.js1
-rw-r--r--src/entities/wordLava.js2
-rw-r--r--src/entities/wordPush.js1
-rw-r--r--src/entities/wordRock.js1
-rw-r--r--src/entities/wordSink.js1
-rw-r--r--src/entities/wordStop.js1
-rw-r--r--src/entities/wordWall.js1
-rw-r--r--src/entities/wordWater.js1
-rw-r--r--src/entities/wordWin.js1
-rw-r--r--src/entities/wordYou.js1
-rw-r--r--src/systems/gridSystem.js37
19 files changed, 39 insertions, 17 deletions
diff --git a/assets/.DS_Store b/assets/.DS_Store
index 004359a..d6f9c0b 100644
--- a/assets/.DS_Store
+++ b/assets/.DS_Store
Binary files differ
diff --git a/src/bootstrap.js b/src/bootstrap.js
index 489ad8d..b1fd62e 100644
--- a/src/bootstrap.js
+++ b/src/bootstrap.js
@@ -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'
},
diff --git a/src/components/stop.js b/src/components/stop.js
new file mode 100644
index 0000000..a269183
--- /dev/null
+++ b/src/components/stop.js
@@ -0,0 +1 @@
+game.components.Stop = ({stop}) => game.Component("stop", {stop});
diff --git a/src/entities/hedge.js b/src/entities/hedge.js
index 1e5d482..ab5ef35 100644
--- a/src/entities/hedge.js
+++ b/src/entities/hedge.js
@@ -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;
}
diff --git a/src/entities/wall.js b/src/entities/wall.js
index d5167c4..73c3adb 100644
--- a/src/entities/wall.js
+++ b/src/entities/wall.js
@@ -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;
}
diff --git a/src/entities/wordBigBlue.js b/src/entities/wordBigBlue.js
index b9ebb5e..d21e15c 100644
--- a/src/entities/wordBigBlue.js
+++ b/src/entities/wordBigBlue.js
@@ -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;
}
diff --git a/src/entities/wordFlag.js b/src/entities/wordFlag.js
index a2e1ca1..0a23da4 100644
--- a/src/entities/wordFlag.js
+++ b/src/entities/wordFlag.js
@@ -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;
}
diff --git a/src/entities/wordIs.js b/src/entities/wordIs.js
index 41263f4..02b31bd 100644
--- a/src/entities/wordIs.js
+++ b/src/entities/wordIs.js
@@ -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;
}
diff --git a/src/entities/wordKill.js b/src/entities/wordKill.js
index 1835f59..7bc0972 100644
--- a/src/entities/wordKill.js
+++ b/src/entities/wordKill.js
@@ -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;
}
diff --git a/src/entities/wordLava.js b/src/entities/wordLava.js
index 8c7780b..573dd29 100644
--- a/src/entities/wordLava.js
+++ b/src/entities/wordLava.js
@@ -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;
}
diff --git a/src/entities/wordPush.js b/src/entities/wordPush.js
index c4294e6..bd4c267 100644
--- a/src/entities/wordPush.js
+++ b/src/entities/wordPush.js
@@ -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;
}
diff --git a/src/entities/wordRock.js b/src/entities/wordRock.js
index 66f4efb..be303c4 100644
--- a/src/entities/wordRock.js
+++ b/src/entities/wordRock.js
@@ -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;
}
diff --git a/src/entities/wordSink.js b/src/entities/wordSink.js
index 604d630..298778d 100644
--- a/src/entities/wordSink.js
+++ b/src/entities/wordSink.js
@@ -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;
}
diff --git a/src/entities/wordStop.js b/src/entities/wordStop.js
index ee43e38..30907d8 100644
--- a/src/entities/wordStop.js
+++ b/src/entities/wordStop.js
@@ -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;
}
diff --git a/src/entities/wordWall.js b/src/entities/wordWall.js
index ba97cec..6d4678b 100644
--- a/src/entities/wordWall.js
+++ b/src/entities/wordWall.js
@@ -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;
}
diff --git a/src/entities/wordWater.js b/src/entities/wordWater.js
index a33d8f3..ae4bb7c 100644
--- a/src/entities/wordWater.js
+++ b/src/entities/wordWater.js
@@ -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;
}
diff --git a/src/entities/wordWin.js b/src/entities/wordWin.js
index 67fbc41..f6386b9 100644
--- a/src/entities/wordWin.js
+++ b/src/entities/wordWin.js
@@ -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;
}
diff --git a/src/entities/wordYou.js b/src/entities/wordYou.js
index 574ba4d..2fe97d3 100644
--- a/src/entities/wordYou.js
+++ b/src/entities/wordYou.js
@@ -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;
}
diff --git a/src/systems/gridSystem.js b/src/systems/gridSystem.js
index ef5a6e1..e8a6c82 100644
--- a/src/systems/gridSystem.js
+++ b/src/systems/gridSystem.js
@@ -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,