Skip to content

Commit bbfb48c

Browse files
committed
ゴールのブロックを追加
1 parent ac2bb44 commit bbfb48c

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

public/assets/goal.png

219 KB
Loading

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export enum Block {
1616
switchingBlockOFF = "switching-block-off",
1717
switchingBlockON = "switching-block-on",
1818
switchPressed = "switch-pressed",
19+
goal = "goal",
1920
}
2021
export enum Facing {
2122
left = "left",

src/grid.ts

Lines changed: 28 additions & 0 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+
goalTexture,
1213
rockTexture,
1314
switchBaseTexture,
1415
switchPressedTexture,
@@ -62,6 +63,10 @@ export type GridCell =
6263
block: Block.switchPressed;
6364
switchId?: string;
6465
objectId?: unknown;
66+
}
67+
| {
68+
block: Block.goal;
69+
objectId?: unknown;
6570
};
6671

6772
export class Grid {
@@ -166,6 +171,12 @@ export class Grid {
166171
});
167172
break;
168173
}
174+
case Block.goal: {
175+
const sprite = createSprite(cellSize, block, x, y, this.marginY);
176+
stage.addChild(sprite);
177+
spriteRow.push({ sprite, block });
178+
break;
179+
}
169180
default:
170181
block satisfies never;
171182
}
@@ -689,6 +700,13 @@ export function createCellsFromStageDefinition(
689700
row.push(cell);
690701
break;
691702
}
703+
case Block.goal: {
704+
const cell: GridCell = {
705+
block,
706+
};
707+
row.push(cell);
708+
break;
709+
}
692710
default:
693711
block satisfies never;
694712
}
@@ -712,6 +730,8 @@ export function blockFromDefinition(n: string) {
712730
return Block.switchBase;
713731
case "w":
714732
return Block.switchingBlockOFF;
733+
case "g":
734+
return Block.goal;
715735
default:
716736
throw new Error("no proper block");
717737
}
@@ -776,7 +796,13 @@ function createSprite(
776796
updateSprite(sprite, blockSize, x, y, marginY);
777797
return sprite;
778798
}
799+
case Block.goal: {
800+
const sprite = new Sprite(goalTexture);
801+
updateSprite(sprite, blockSize, x, y, marginY);
802+
return sprite;
803+
}
779804
default:
805+
block satisfies Block.air;
780806
throw new Error("no proper block");
781807
}
782808
}
@@ -819,6 +845,8 @@ export function printCells(cells: GridCell[][], context?: string) {
819845
return "w";
820846
case Block.switchPressed:
821847
return "s";
848+
case Block.goal:
849+
return "g";
822850
default:
823851
cell satisfies never;
824852
}

src/player.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export function tick(cx: Context, ticker: Ticker) {
164164
Block.switchPressed &&
165165
cx.grid.getBlock(cx, Math.floor(x), Math.floor(y)) !==
166166
Block.switchingBlockON &&
167+
cx.grid.getBlock(cx, Math.floor(x), Math.floor(y)) !== Block.goal &&
167168
cx.grid.getBlock(cx, Math.floor(x), Math.floor(y)) !== undefined;
168169
const isSwitchBase = (x: number, y: number) =>
169170
cx.grid.getBlock(cx, Math.floor(x), Math.floor(y)) === Block.switchBase;

src/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const switchBaseTexture = await Assets.load("/assets/switch-base.png");
88
export const switchPressedTexture = await Assets.load(
99
"/assets/switch-pressed.png",
1010
);
11+
export const goalTexture = await Assets.load("/assets/goal.png");
1112
export const highlightTexture = await Assets.load("/assets/highlight.svg");
1213
export const highlightHoldTexture = await Assets.load(
1314
"/assets/highlight-hold.webp",

src/stages.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const stages = new Map<string, StageDefinition>([
2323
stage: [
2424
"bbbbbbbbbbbbbbbbbb",
2525
".........b........",
26-
".........b........",
26+
".........b......g.",
2727
".........b...bbbbb",
2828
".........m...bbbbb",
2929
"bbbbbbbbbbbbbbbbbb",
@@ -40,7 +40,7 @@ export const stages = new Map<string, StageDefinition>([
4040
stage: [
4141
"bbbbbbbbbbbbbbbbbb",
4242
"..................",
43-
"..................",
43+
"...............g..",
4444
"m............bbbbb",
4545
"bb...........bbbbb",
4646
"bb.....m.....bbbbb",
@@ -57,7 +57,7 @@ export const stages = new Map<string, StageDefinition>([
5757
{
5858
stage: [
5959
"bbbbbbbbbbbbbbbbbb",
60-
"...b..............",
60+
"...b............g.",
6161
"...b....m......bbb",
6262
"...bm..........bbb",
6363
"...bbb.........bbb",
@@ -87,7 +87,7 @@ export const stages = new Map<string, StageDefinition>([
8787
stage: [
8888
"bbbbbbbbbbbbbbbbbbbbbb",
8989
"......................",
90-
"......................",
90+
"....................g.",
9191
"m..................bbb",
9292
"bb.................bbb",
9393
"bb..........m......bbb",
@@ -127,7 +127,7 @@ export const stages = new Map<string, StageDefinition>([
127127
".........b........",
128128
".........b........",
129129
".........w........",
130-
".s....m..w........",
130+
".s....m..w.....g..",
131131
"bSbbbbbbbbbbbbbbbb",
132132
],
133133
initialPlayerX: 3,
@@ -158,7 +158,7 @@ export const stages = new Map<string, StageDefinition>([
158158
stage: [
159159
"bbbbbbbbbbbbbbbbbbbbbbbbb",
160160
".........................",
161-
".........................",
161+
"......................g..",
162162
"...............wbbbbbbbbb",
163163
"m...............bbbbbbbbb",
164164
"bb..............w.....m..",
@@ -230,7 +230,7 @@ export const stages = new Map<string, StageDefinition>([
230230
stage: [
231231
"bbbbbbbbbbbbbbbbbb",
232232
"..................",
233-
"..................",
233+
"................g.",
234234
"........w......bbb",
235235
"........w.....wbbb",
236236
".....bm.w....w.bbb",
@@ -298,7 +298,7 @@ export const stages = new Map<string, StageDefinition>([
298298
stage: [
299299
"bbbbbbbbbbbbbbbbbbbbbbb",
300300
".........w...b.........",
301-
".........w...b...m.....",
301+
".........w.g.b...m.....",
302302
".........bbbbb.........",
303303
"m.......w.....w......m.",
304304
"mm.....w.......w.....mm",

0 commit comments

Comments
 (0)