Skip to content

Commit ff4789c

Browse files
authored
fallableを追加 (#7)
* fallableを追加 * highlight周りのtick関数を名前変更&移動 * Revert "highlight周りのtick関数を名前変更&移動" This reverts commit 9f8c188. * grid.tick()とfallableの落下処理を実装 * pasteやredo時にdyをリセット * switchWithObjectを削除し、movableとfallableにswitchIdを追加 * tick()とctrl+Z時の動作をfallable+スイッチに対応 * fallableの速度が保存されていなかった
1 parent ff80c7e commit ff4789c

File tree

8 files changed

+230
-66
lines changed

8 files changed

+230
-66
lines changed

public/assets/woodenbox.png

145 KB
Loading

routes/+page.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@
1111
<a href="/game?stage=6">Stage 6</a>
1212
<a href="/game?stage=7">Stage 7</a>
1313
<a href="/game?stage=8">Stage 8</a>
14+
15+
<p>
16+
<a href="/game?stage=3-1">Stage 3-1</a>
17+
<a href="/game?stage=3-2">Stage 3-2</a>
18+
</p>

src/ability.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export function copy(cx: Context) {
6565
const x = focus.x;
6666
const y = focus.y;
6767
const target = cx.grid.getBlock(cx, x, y);
68-
if (!target || target !== Block.movable) return;
68+
if (!target || (target !== Block.movable && target !== Block.fallable))
69+
return;
6970
const movableObject = cx.grid.getMovableObject(cx, x, y);
7071
if (!movableObject) return;
7172

@@ -128,10 +129,7 @@ export function cut(cx: Context) {
128129
const y = focus.y;
129130
const target = cx.grid.getBlock(cx, x, y);
130131
// removable 以外はカットできない
131-
if (
132-
!target ||
133-
(target !== Block.movable && target !== Block.switchWithObject)
134-
)
132+
if (!target || (target !== Block.movable && target !== Block.fallable))
135133
return;
136134
const movableObject = cx.grid.getMovableObject(cx, x, y);
137135
if (!movableObject) return;
@@ -144,7 +142,10 @@ export function cut(cx: Context) {
144142
});
145143
cx.grid.update(cx, (prev) => {
146144
if (prev.objectId !== movableObject.objectId) return prev;
147-
if (prev.block === Block.switchWithObject)
145+
if (
146+
(prev.block === Block.movable || prev.block === Block.fallable) &&
147+
prev.switchId !== undefined
148+
)
148149
return { block: Block.switch, switchId: prev.switchId };
149150
return { block: Block.air };
150151
});
@@ -176,6 +177,7 @@ export function placeMovableObject(
176177
grid.setBlock(cx, positionX, positionY, {
177178
block: object.block,
178179
objectId: object.objectId,
180+
switchId: undefined,
179181
});
180182
}
181183
}

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export enum Block {
1010
air = "air",
1111
block = "block",
1212
movable = "movable",
13+
fallable = "fallable",
1314
switch = "switch",
1415
switchBase = "switch-base",
15-
switchWithObject = "switch-with-object",
1616
switchingBlockOFF = "switching-block-off",
1717
switchingBlockON = "switching-block-on",
1818
switchPressed = "switch-pressed",

0 commit comments

Comments
 (0)