source-code/
snakey
Public
codeCodeinfoIssues 0call_splitPull Requestsplay_circleActions
snakey/src/Game.tsx
typescript38 lines1005 B
import { useEffect, useRef } from 'react';
import Phaser from 'phaser';
import { SnakeScene } from './game/SnakeScene';

export default function Game({ onScoreUpdate }: { onScoreUpdate: (score: number) => void }) {
  const gameRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (!gameRef.current) return;

    const config: Phaser.Types.Core.GameConfig = {
      type: Phaser.AUTO,
      width: 800,
      height: 600,
      parent: gameRef.current,
      transparent: true,
      physics: {
        default: 'arcade',
        arcade: {
          gravity: { x: 0, y: 0 }
        }
      },
      scene: SnakeScene
    };

    const game = new Phaser.Game(config);

    game.events.on('score-update', onScoreUpdate);

    return () => {
      game.events.off('score-update', onScoreUpdate);
      game.destroy(true);
    };
  }, [onScoreUpdate]);

  return <div ref={gameRef} id="phaser-game-container" className="w-full h-full relative flex items-center justify-center overflow-hidden" />;
}

About

Snakey Web Game is the official hub and sandbox playground for the Snakey project. Built with React 19, Phaser 3, and Tailwind CSS, it offers a central playable zone alongside a Sandbox Playground that lets visitors test eating custom HTML elements. It also hosts and serves self-compiled browser extension packages (ZIP) for Chrome and Firefox, as well as a dynamically-generated bookmarklet installer that enables users to drag-and-drop a shortcut to run the game on any external website.

Web GamePhaserReactTypeScriptTailwind CSSViteBookmarklet

Contributors

1