Skip to content

Commit 9093ca5

Browse files
committed
fallableを追加
1 parent ac2bb44 commit 9093ca5

File tree

6 files changed

+101
-5
lines changed

6 files changed

+101
-5
lines changed

public/assets/woodenbox.png

145 KB
Loading

src/ability.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ 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 (
69+
!target ||
70+
(target !== Block.movable &&
71+
target !== Block.switchWithObject &&
72+
target !== Block.fallable)
73+
)
74+
return;
6975
const movableObject = cx.grid.getMovableObject(cx, x, y);
7076
if (!movableObject) return;
7177

@@ -130,7 +136,9 @@ export function cut(cx: Context) {
130136
// removable 以外はカットできない
131137
if (
132138
!target ||
133-
(target !== Block.movable && target !== Block.switchWithObject)
139+
(target !== Block.movable &&
140+
target !== Block.switchWithObject &&
141+
target !== Block.fallable)
134142
)
135143
return;
136144
const movableObject = cx.grid.getMovableObject(cx, x, y);
@@ -176,6 +184,7 @@ export function placeMovableObject(
176184
grid.setBlock(cx, positionX, positionY, {
177185
block: object.block,
178186
objectId: object.objectId,
187+
dy: 0,
179188
});
180189
}
181190
}

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum Block {
1010
air = "air",
1111
block = "block",
1212
movable = "movable",
13+
fallable = "fallable",
1314
switch = "switch",
1415
switchBase = "switch-base",
1516
switchWithObject = "switch-with-object",

src/grid.ts

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
MovableObject,
1010
} from "./public-types.ts";
1111
import {
12+
fallableTexture,
1213
rockTexture,
1314
switchBaseTexture,
1415
switchPressedTexture,
@@ -30,6 +31,11 @@ export type GridCell =
3031
block: Block.movable;
3132
objectId: string;
3233
}
34+
| {
35+
block: Block.fallable;
36+
objectId: string;
37+
dy: number; // in pixels
38+
}
3339
| {
3440
block: Block.air;
3541
objectId?: unknown;
@@ -99,6 +105,12 @@ export class Grid {
99105
spriteRow.push({ sprite, block });
100106
break;
101107
}
108+
case Block.fallable: {
109+
const sprite = createSprite(cellSize, block, x, y, this.marginY);
110+
stage.addChild(sprite);
111+
spriteRow.push({ sprite, block });
112+
break;
113+
}
102114
case Block.block: {
103115
const sprite = createSprite(cellSize, block, x, y, this.marginY);
104116
stage.addChild(sprite);
@@ -289,7 +301,11 @@ export class Grid {
289301
const cells = get(cx.state).cells;
290302
const cell = cells[y]?.[x];
291303
if (!cell) return undefined;
292-
if (cell.block !== Block.movable && cell.block !== Block.switchWithObject)
304+
if (
305+
cell.block !== Block.movable &&
306+
cell.block !== Block.switchWithObject &&
307+
cell.block !== Block.fallable
308+
)
293309
return undefined;
294310
const objectId = cell.objectId;
295311
const retrievedBlocks: { x: number; y: number }[] = [];
@@ -308,7 +324,7 @@ export class Grid {
308324
.reduce((a, b) => Math.max(a, b), 0);
309325

310326
const retrievedObject: MovableObject = {
311-
block: Block.movable,
327+
block: cell.block === Block.fallable ? Block.fallable : Block.movable,
312328
objectId,
313329
relativePositions: retrievedBlocks.map((block) => ({
314330
x: block.x - minX,
@@ -357,6 +373,7 @@ export class Grid {
357373
if (
358374
cell.block !== Block.movable &&
359375
cell.block !== Block.switchWithObject &&
376+
cell.block !== Block.fallable &&
360377
cell.objectId
361378
) {
362379
console.warn("Cell is not movable but has an objectId");
@@ -419,7 +436,8 @@ export class Grid {
419436
else if (prev.block === Block.switch) {
420437
if (
421438
cell.block !== Block.movable &&
422-
cell.block !== Block.switchWithObject
439+
cell.block !== Block.switchWithObject &&
440+
cell.block !== Block.fallable
423441
) {
424442
console.warn(
425443
"No block other than movable cannot be placed on the switch",
@@ -441,6 +459,9 @@ export class Grid {
441459
prevCell.block === Block.switchWithObject,
442460
"block is not switch",
443461
);
462+
if (cell.block === Block.fallable) {
463+
console.warn("TODO: switchWithFallable is not implemented");
464+
}
444465
cells[y][x] = {
445466
block: Block.switchWithObject,
446467
switchId: prevCell.switchId,
@@ -609,6 +630,28 @@ export class Grid {
609630
prev.block = cell.block;
610631
break;
611632
}
633+
case Block.fallable: {
634+
const movableSprite = createSprite(
635+
blockSize,
636+
cell.block,
637+
x,
638+
y,
639+
marginY,
640+
);
641+
stage.addChild(movableSprite);
642+
assert(
643+
cell.objectId !== undefined,
644+
"movable block must have objectId",
645+
);
646+
cells[y][x] = {
647+
block: cell.block,
648+
objectId: cell.objectId,
649+
dy: 0,
650+
};
651+
prev.sprite = movableSprite;
652+
prev.block = cell.block;
653+
break;
654+
}
612655
default:
613656
// cell satisfies never;
614657
}
@@ -644,6 +687,19 @@ export function createCellsFromStageDefinition(
644687

645688
break;
646689
}
690+
case Block.fallable: {
691+
const group = stageDefinition.blockGroups.find(
692+
(b) => b.x === x && b.y === y,
693+
);
694+
const objectId = group ? group.objectId : Math.random().toString();
695+
const cell: GridCell = {
696+
block,
697+
objectId,
698+
dy: 0,
699+
};
700+
row.push(cell);
701+
break;
702+
}
647703
case Block.block:
648704
case Block.air: {
649705
const cell: GridCell = {
@@ -706,6 +762,8 @@ export function blockFromDefinition(n: string) {
706762
return Block.block;
707763
case "m":
708764
return Block.movable;
765+
case "f":
766+
return Block.fallable;
709767
case "s":
710768
return Block.switch;
711769
case "S":
@@ -737,6 +795,12 @@ function createSprite(
737795
updateSprite(movableSprite, blockSize, x, y, marginY);
738796
return movableSprite;
739797
}
798+
case Block.fallable: {
799+
const movableSprite = new Sprite(fallableTexture);
800+
// movableSprite.tint = 0xff0000;
801+
updateSprite(movableSprite, blockSize, x, y, marginY);
802+
return movableSprite;
803+
}
740804
case Block.switch: {
741805
const switchSprite = new Sprite(switchTexture);
742806
if (switchColor) switchSprite.tint = switchColor;
@@ -807,6 +871,8 @@ export function printCells(cells: GridCell[][], context?: string) {
807871
return "b";
808872
case Block.movable:
809873
return "m";
874+
case Block.fallable:
875+
return "m";
810876
case Block.switch:
811877
return "s";
812878
case Block.switchBase:

src/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Assets } from "pixi.js";
33
// assets
44
export const bunnyTexture = await Assets.load("/assets/bunny.png");
55
export const rockTexture = await Assets.load("/assets/block.png");
6+
export const fallableTexture = await Assets.load("/assets/woodenbox.png");
67
export const switchTexture = await Assets.load("/assets/switch.png");
78
export const switchBaseTexture = await Assets.load("/assets/switch-base.png");
89
export const switchPressedTexture = await Assets.load(

src/stages.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,23 @@ export const stages = new Map<string, StageDefinition>([
405405
],
406406
},
407407
],
408+
[
409+
"3-2",
410+
{
411+
stage: [
412+
"bbbbbbbbbbbbbbbbbb",
413+
"..................",
414+
"..................",
415+
".............bbbbb",
416+
".........f...bbbbb",
417+
".........f...bbbbb",
418+
".........f...bbbbb",
419+
"bbbbbbbbbbbbbbbbbb",
420+
],
421+
initialPlayerX: 1,
422+
initialPlayerY: 7,
423+
blockGroups: [],
424+
switchGroups: [],
425+
},
426+
],
408427
]);

0 commit comments

Comments
 (0)