/tetris.nvim

Pure Lua tetris game for Neovim

Primary LanguageLuaGNU General Public License v3.0GPL-3.0

🧱 tetris.nvim

Pure Lua tetris game for Neovim!

tetris.nvim

📦 Installation

Using lazy.nvim:

{
  "ActionScripted/tetris.nvim",
  cmd = { "Tetris" },
  keys = { { "<leader>T", "<cmd>Tetris<cr>", desc = "Tetris" } },
  opts = {
    -- your awesome configuration here
  },
}

⚙️ Configuration

These are the defaults:

{
  block = "",
  debug = false,
  mappings = {
    ["<Down>"] = "down",
    ["<Esc>"] = "quit",
    ["<Left>"] = "left",
    ["<LeftMouse>"] = "noop",
    ["<MiddleMouse>"] = "noop",
    ["<Mouse>"] = "noop",
    ["<Right>"] = "right",
    ["<RightMouse>"] = "noop",
    ["<Space>"] = "drop",
    ["<Up>"] = "rotate",
    h = "left",
    j = "down",
    k = "rotate",
    l = "right",
    p = "pause",
    q = "quit",
  },
}

You can override these or add your own, for example:

{
  -- Hey, get weird:
  -- https://symbl.cc/en/unicode/table/#block-elements
  block = "",
  mappings = {
    ["<Space>"] = "noop",
    a = "left",
    d = "right",
    s = "down",
    w = "rotate",
  },
}

Available events:

Event Description
down Move piece down
drop Drop piece
left Move piece left
noop Do nothing
pause Pause game
quit Quit game
right Move piece right
rotate Rotate piece

🚀 Usage

To start the game run :Tetris or <leader>T if you have the lazy.nvim config from above.

🛠️ Development

We're trying to follow the Super Rotation System (SRS) that dictates how pieces spawn and rotate. This also includes stuff like wall kicks, infinity and other tetromino-related terminology:

Leaning on Lua Language Server for annotations and docs.

📚 Resources