Froobtris/src/tetrisPieces.ts
2023-08-02 14:20:48 -04:00

107 lines
1.5 KiB
TypeScript

import { Point } from "./lib/util";
export const enum RotationStyle {
None, // Tetromino can not be rotated (2x2)
Center, // 3x3 rotation
BetweenCenter, // 4x4 rotation
}
export const enum TileColor {
Red,
Green,
Blue,
Purple,
Orange,
Cyan,
Yellow,
}
export type PieceSchema = {
tiles: [Point, Point, Point, Point];
rotation: RotationStyle;
color: TileColor;
};
export const TETRIS_PIECE: Record<string, PieceSchema> = {
O: {
tiles: [
[0, 0],
[0, 1],
[1, 1],
[1, 0],
],
rotation: RotationStyle.None,
color: TileColor.Red,
},
L: {
tiles: [
[1, 0],
[0, 0],
[-1, 0],
[-1, 1],
],
rotation: RotationStyle.Center,
color: TileColor.Green,
},
J: {
tiles: [
[1, 0],
[1, 1],
[0, 0],
[-1, 0],
],
rotation: RotationStyle.Center,
color: TileColor.Blue,
},
I: {
tiles: [
[0, 0],
[-1, 0],
[1, 0],
[2, 0],
],
rotation: RotationStyle.BetweenCenter,
color: TileColor.Purple,
},
T: {
tiles: [
[1, 0],
[0, 0],
[-1, 0],
[0, 1],
],
rotation: RotationStyle.Center,
color: TileColor.Orange,
},
S: {
tiles: [
[1, 0],
[0, 0],
[0, 1],
[-1, 1],
],
rotation: RotationStyle.Center,
color: TileColor.Cyan,
},
Z: {
tiles: [
[1, 1],
[0, 0],
[0, 1],
[-1, 0],
],
rotation: RotationStyle.Center,
color: TileColor.Yellow,
},
};
export const TETRIS_PIECE_LIST: Array<PieceSchema> = [
TETRIS_PIECE.O,
TETRIS_PIECE.S,
TETRIS_PIECE.Z,
TETRIS_PIECE.L,
TETRIS_PIECE.J,
TETRIS_PIECE.T,
TETRIS_PIECE.I,
];