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.
- Host: GitHub
- URL: https://github.com/gimnathperera/snake-loop
- Owner: gimnathperera
- Created: 2025-04-11T11:07:55.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-04-11T11:55:30.000Z (9 months ago)
- Last Synced: 2025-04-11T12:54:06.883Z (9 months ago)
- Topics: radix-ui, react19, rtk-query, typescript
- Language: TypeScript
- Homepage: https://snake-loop.netlify.app
- Size: 445 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.
## 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