Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/assets/switch-base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/switch-pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/switch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
<a href="/game?stage=2">Stage 2</a>
<a href="/game?stage=3">Stage 3</a>
<a href="/game?stage=4">Stage 4</a>
<a href="/game?stage=5">Stage 5</a>
<a href="/game?stage=6">Stage 6</a>
<a href="/game?stage=7">Stage 7</a>
<a href="/game?stage=8">Stage 8</a>
21 changes: 15 additions & 6 deletions src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export function copy(cx: Context) {
const movableObject = cx.grid.getMovableObject(cx, x, y);
if (!movableObject) return;

movableObject.objectId = Math.random().toString();

History.record(cx);

cx.state.update((prev) => {
Expand Down Expand Up @@ -100,7 +102,7 @@ export function paste(cx: Context) {
const positionX = x + i.x;
const positionY = y + i.y;
const target = cx.grid.getBlock(cx, positionX, positionY);
if (target !== Block.air) {
if (target !== Block.air && target !== Block.switch) {
// すでに何かある場合は、ペーストできない
return;
}
Expand All @@ -126,7 +128,11 @@ export function cut(cx: Context) {
const y = focus.y;
const target = cx.grid.getBlock(cx, x, y);
// removable 以外はカットできない
if (!target || target !== Block.movable) return;
if (
!target ||
(target !== Block.movable && target !== Block.switchWithObject)
)
return;
const movableObject = cx.grid.getMovableObject(cx, x, y);
if (!movableObject) return;

Expand All @@ -136,9 +142,12 @@ export function cut(cx: Context) {
prev.inventory = movableObject;
return prev;
});
cx.grid.update(cx, (prev) =>
prev.objectId === movableObject.objectId ? { block: Block.air } : prev,
);
cx.grid.update(cx, (prev) => {
if (prev.objectId !== movableObject.objectId) return prev;
if (prev.block === Block.switchWithObject)
return { block: Block.switch, switchId: prev.switchId };
return { block: Block.air };
});

printCells(createSnapshot(cx).game.cells, "cut");
History.record(cx);
Expand All @@ -156,7 +165,7 @@ export function placeMovableObject(
const positionX = x + i.x;
const positionY = y + i.y;
const target = grid.getBlock(cx, positionX, positionY);
if (target !== Block.air) {
if (target !== Block.air && target !== Block.switch) {
// すでに何かある場合は、ペーストできない
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export enum Block {
air = "air",
block = "block",
movable = "movable",
switch = "switch",
switchBase = "switch-base",
switchWithObject = "switch-with-object",
switchingBlockOFF = "switching-block-off",
switchingBlockON = "switching-block-on",
switchPressed = "switch-pressed",
}
export enum Facing {
left = "left",
Expand Down
Loading