An open API service indexing awesome lists of open source software.

https://github.com/gimnathperera/snake-loop

๐Ÿ A classic Snake game built with React + TypeScript, featuring global state management using RTK Query. Smooth gameplay, modern UI, and efficient data handling for a fun coding twist on a nostalgic favorite.
https://github.com/gimnathperera/snake-loop

radix-ui react19 rtk-query typescript

Last synced: 9 months ago
JSON representation

๐Ÿ A classic Snake game built with React + TypeScript, featuring global state management using RTK Query. Smooth gameplay, modern UI, and efficient data handling for a fun coding twist on a nostalgic favorite.

Awesome Lists containing this project

README

          

# Snake Loop Game ๐Ÿ

A classic Snake game implementation with a modern twist, built with React, RTK Queries and TypeScript.

Snake Loop Game Demo
## Features

- ๐ŸŽฎ Smooth snake movement and keyboard controls
- ๐Ÿง  Collision detection with self and boundaries
- ๐Ÿ† Score tracking with real-time updates
- ๐Ÿ” Looping map for endless gameplay (snake can exit one side and reappear on the opposite side)
- ๐Ÿ“ฑ Responsive layout for mobile and desktop
- โš›๏ธ Built with modern React (v18+), using hooks and functional components
- ๐Ÿงฉ Modular, component-based architecture
- ๐Ÿ–ผ๏ธ HTML5 Canvas rendering for efficient performance
- ๐Ÿงช Easy to test and extend with TypeScript typings
- ๐Ÿ”„ Game restart/reset functionality
- ๐ŸŒ— Dark mode support (optional)
- ๐Ÿ”ง Easy configuration for grid size, speed, and difficulty

## Getting Started

### Prerequisites

- Node.js (v14 or higher)
- npm or yarn
- React.js (v18 or higher)

### Installation

1. Clone the repository:

```bash
git clone https://github.com/your-username/snake-loop-game.git
cd snake-loop-game
```

2. Install dependencies:

```bash
npm install
# or
yarn install
```

3. Run the development server:

```bash
npm run dev
# or
yarn dev
```

4. Open [http://localhost:8080](http://localhost:8080) in your browser to play the game.

## Scripts

- `npm run dev` โ€” Starts the development server
- `npm run build` โ€” Builds the production-ready app
- `npm run start` โ€” Serves the built app
- `npm run lint` โ€” Runs ESLint for code quality
- `npm run format` โ€” Formats code using Prettier

## Project Structure

```
/src
โ”œโ”€โ”€ components # Reusable UI components (GameBoard, ScoreBoard, etc.)
โ”œโ”€โ”€ hooks # Custom React hooks for game logic
โ”œโ”€โ”€ utils # Utility functions (e.g., collision detection, movement logic)
โ”œโ”€โ”€ types # TypeScript interfaces and types
โ”œโ”€โ”€ assets # Images, sounds, or other media
โ”œโ”€โ”€ styles # CSS or styled-components
โ””โ”€โ”€ App.tsx # Root component
```

## Customization

You can easily customize the game by tweaking the configuration options:

- Grid size
- Initial snake length
- Game speed
- Scoring logic
- Theme colors

These settings can be found in the `constants.ts` or `config.ts` file.

## Future Improvements

- ๐Ÿงฉ Power-ups and obstacles
- ๐ŸŒ Multiplayer mode
- ๐Ÿ“ˆ Leaderboard integration
- ๐Ÿ’พ Persistent high score with localStorage or backend
- ๐ŸŽต Sound effects and background music
- ๐ŸŽฎ Gamepad support

## Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

1. Fork the repo
2. Create a new branch (`git checkout -b feature-name`)
3. Commit your changes (`git commit -am 'Add new feature'`)
4. Push to the branch (`git push origin feature-name`)
5. Open a pull request

## License

MIT ยฉ Gimnath Perera

---

Made with โค๏ธ using React + TypeScript + Canvas