npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

blocky-game

v0.0.1

Published

Core functionalities for block game

Downloads

5

Readme

blocky-game

blocky-game is a custom hook designed to simplify the implementation of block games in React. By using this hook, you can easily manage the core logic and state of the game.

Install

npm install @yoshikouki/blocky-game

or

bun add @yoshikouki/blocky-game

Usage

First, wrap your application with the BlockyGameProvider component. Then, use the useBlockyGame hook to get the game state and controls.

import { BlockyGameProvider } from "blocky-game";
import { BlockyGame } from "@/components/BlockyGame";

export default function HomePage() {
  return (
    <BlockyGameProvider>
      <BlockyGame />
    </BlockyGameProvider>
  );
}

Custom Hook API

Below is a list of the main functions and variables provided by the useBlockyGame hook in a table format:

| Variable/Function | Description | |-------------------------|------------------------------------------------| | board | The current state of the game board | | queuedBlocks | The list of upcoming blocks in the queue | | result | The current game result (score, etc.) | | boardRef | Reference to the game board | | tickRunnerRef | Reference to the tick runner | | startBlockyGame | Function to start the game | | finishBlockyGame | Function to finish the game | | pauseBlockyGame | Function to pause the game | | resumeBlockyGame | Function to resume the game | | readyBlockyGame | Function to set the game to the ready state | | detectCellVariant | Function to detect the variant of a cell |

Using this hook, you can quickly implement the core functionality of a block game. Refer to the code example above for more details on how to use it.

BlockyGame Component Example

Here is an example of using the BlockyGame component. This component contains the main elements of the game and uses the useBlockyGame hook to manage the game state.

import { useBlockyGame } from "blocky-game";
import { Button } from "@/components/ui/button";
import { Board, BoardCell, TickRunner, GameControlButton, GameControlContainer, BlockViewer, ResultViewer } from "@/components/ui";

export const BlockyGame = () => {
  const {
    board,
    queuedBlocks,
    result,
    boardRef,
    tickRunnerRef,
    startBlockyGame,
    finishBlockyGame,
    pauseBlockyGame,
    resumeBlockyGame,
    readyBlockyGame,
    detectCellVariant,
  } = useBlockyGame();

  return (
    <div className="relative z-10 flex h-svh w-full flex-col items-center justify-center overscroll-none">
      <TickRunner tickRunnerRef={tickRunnerRef} />

      {/* Game Header */}
      <div className="flex w-full max-w-xs justify-between pt-4 pb-1 opacity-100 transition-all duration-200">
        <div className="flex h-10 items-center justify-center gap-2 whitespace-nowrap font-medium text-sm">
          {queuedBlocks[0] && (
            <>
              <div className="text-primary/50">Next</div>
              <BlockViewer block={queuedBlocks[0]} />
            </>
          )}
        </div>
        <div className="flex h-10 items-center justify-center gap-2 whitespace-nowrap font-medium text-sm">
          <div className="text-primary/50">{result.score}</div>
          <Button type="button" variant="ghost" size="icon" onClick={pauseBlockyGame}>
            <Pause className="fill-primary stroke-1 stroke-primary" />
          </Button>
        </div>
      </div>

      {/* Game Board */}
      <Board boardRef={boardRef} boardConfig={board.config}>
        {board.rows.map((row, rowIndex) =>
          row.cells.map((cell, cellIndex) => (
            <BoardCell key={cell.id} variant={detectCellVariant(cell, cellIndex, rowIndex)} />
          ))
        )}
      </Board>

      {/* Game Controller */}
      <div className="absolute inset-0 flex flex-col items-center justify-center bg-background/30 opacity-100 transition-all duration-200">
        {/* Ready to play */}
        <GameControlContainer isVisible={board.status === "ready"}>
          <GameControlButton onClick={startBlockyGame} className="group">
            <Play className="fill-primary-foreground stroke-primary-foreground group-hover:fill-primary group-hover:stroke-primary" size="40" />
            Play
          </GameControlButton>
        </GameControlContainer>

        {/* Pause */}
        <GameControlContainer isVisible={board.status === "pause"} className="rounded border bg-background p-4">
          <div className="py-8">
            <Pause className="fill-primary stroke-primary" size="40" />
          </div>
          <div className="flex w-full gap-2">
            <GameControlButton onClick={resumeBlockyGame} className="group py-10">
              <Play className="fill-primary-foreground stroke-primary-foreground group-hover:fill-primary group-hover:stroke-primary" size="40" />
            </GameControlButton>
            <GameControlButton onClick={finishBlockyGame} variant="outline" className="aspect-square flex-1 py-10">
              <Square className="fill-primary" size="40" />
            </GameControlButton>
          </div>
        </GameControlContainer>

        {/* Finish result */}
        <GameControlContainer isVisible={board.status === "finished"}>
          <ResultViewer score={result.score} filledCellsNumber={result.filledRowsNumber * board.config.colsNumber} />
          <div className="flex w-full gap-2">
            <GameControlButton onClick={startBlockyGame} className="group py-10">
              <StepForward className="stroke-primary-foreground group-hover:fill-primary group-hover:stroke-primary" size="40" />
            </GameControlButton>
            <GameControlButton onClick={readyBlockyGame} variant="outline" className="aspect-square flex-1 py-10">
              <DoorOpen className="stroke-primary" size="40" />
            </GameControlButton>
          </div>
        </GameControlContainer>
      </div>
    </div>
  );
};