Skip to content

NewMatrix - Game Board

What is it?

NewMatrix is the game board - the 8×8 grid where you place blocks.

Think of it as a checkerboard with 64 squares, each can be empty or filled.

Where to find it?

In Scene Hierarchy → CanvasGameBoardNewMatrix

How it looks

  0 1 2 3 4 5 6 7  ← columns
0 □ □ □ □ □ □ □ □
1 □ ■ ■ □ □ ■ □ □
2 □ ■ □ □ □ ■ □ □
3 □ □ □ □ □ □ □ □
4 ■ ■ ■ ■ ■ ■ ■ ■  ← full row!
5 □ □ □ ■ □ □ □ □
6 □ □ □ ■ □ ■ □ □
7 □ □ □ ■ □ □ □ □
↑             ↑
rows      full column!

□ = empty cell
■ = filled cell

Inspector Settings

Basic Settings

┌─ NewMatrix ─────────────────────┐
│ Rows: 8                          │ ← Number of rows
│ Columns: 8                       │ ← Number of columns
│ Cell Size: 60                    │ ← Size of each cell
│ Spacing: 5                       │ ← Gap between cells
│                                  │
│ Cell Prefab: [CellPrefab]       │ ← Template for cells
│                                  │
│ Cell Color Empty: White          │ ← Empty cell color
│ Cell Color Filled: Blue          │ ← Filled cell color
│ Cell Color Highlight: Yellow     │ ← Preview color
└──────────────────────────────────┘

What do settings do?

Setting Effect Example
Rows Height of board 8 = classic, 10 = harder
Columns Width of board 8 = classic, 10 = harder
Cell Size Pixel size of each square 60 = medium, 80 = large
Spacing Gap between squares 5 = tight, 10 = loose
Cell Color Empty Color when nothing there White, gray, etc
Cell Color Filled Color when block placed Match your theme

How it works internally

Cell Storage

Board stores cells in 2D array:

// cells[row, column]
cells[0, 0] = top-left cell
cells[7, 7] = bottom-right cell

Cell States

Each cell can be:

  1. Empty (0) - nothing there
  2. Filled (1+) - has a block

Key Operations

1. Can Place Shape?

Before placing, checks if: - All shape cells fit on board (not outside) - All target cells are empty - Shape doesn't overlap existing blocks

Check each cell of shape:
  Is it inside board? ──→ No ──→ Can't place
    ↓ Yes
  Is target cell empty? ──→ No ──→ Can't place
    ↓ Yes
All checks passed ──→ Can place!

2. Place Shape

When shape is placed:

For each cell in shape:
  1. Mark board cell as filled
  2. Update visual (change color)
  3. Add to count

3. Check Lines

After each placement:

For each row:
  Count filled cells
  If count == 8 → Mark row for clearing

For each column:
  Count filled cells
  If count == 8 → Mark column for clearing

Clear all marked lines

4. Clear Lines

When line is full:

1. Animate cells (fade out)
2. Set cells to empty
3. Update visuals
4. Tell ScoreManager

Methods (for programmers)

CanPlaceShape(offsets, row, col)

Checks if shape can be placed at position.

// Returns true if:
- All cells fit inside board
- All target cells are empty

// Returns false if:
- Shape goes outside board
- Any cell already occupied

PlaceShape(offsets, row, col)

Places shape on board.

// What it does:
1. For each cell in shape
2. Mark that position as filled
3. Update cell visual
4. Increment filled count

CheckAndClearLines()

Finds and clears full lines.

// Process:
1. Check all rows for fullness
2. Check all columns for fullness
3. Collect full lines
4. Animate clearing
5. Reset cells to empty
6. Return count of cleared lines

IsGameOver(shapes)

Checks if any shape can be placed.

// For each shape:
//   For each possible position:
//     If can place → return false (game continues)
// If no shape fits anywhere → return true (game over)

Visual Feedback

Ghost Preview

When dragging a block over board:

1. Detect cursor position
2. Convert to board coordinates
3. Check if shape fits there
4. If yes → Show transparent preview
5. If no → Show red/invalid

Cell Animations

Different animations for: - Place - quick pop-in - Clear - fade out + scale - Highlight - pulse effect

Common Modifications

Change board size

// In Inspector or code:
Rows = 10;      // Make it taller
Columns = 10;   // Make it wider

// ⚠️ Warning: Must adjust UI layout!

Custom cell colors

// In Inspector:
Cell Color Empty = Light Gray
Cell Color Filled = Your brand color
Cell Color Highlight = Bright color for preview

Add cell effects

Want cells to glow or pulse? Modify:

// In NewMatrix.cs:
void UpdateCellVisual(int row, int col)
{
    // Add your effect here
    // Example: cell.GetComponent<Glow>().Activate();
}

Performance Notes

Board operations are very fast: - Placing shape: O(n) where n = cells in shape - Checking lines: O(rows + columns) = O(16) for 8×8 - Finding valid positions: O(rows × columns × shapes) but cached

No performance issues even on old devices! 📱

What's Next?


Quick Customization

Want a different look? Just change colors in Inspector! No coding needed.