GithubHelp home page GithubHelp logo

benjamin-roger / 2d-car-game Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 3.0 130 KB

Next.js and React-powered 2D car game

Home Page: https://2d-car-game.vercel.app/

License: MIT License

CSS 5.13% SCSS 3.60% JavaScript 91.27%

2d-car-game's Introduction

This is a Next.js and React 2D car game created to test simultaneous React hooks, context and frame animations. It works on both desktop and mobile and use vocal controls.

Getting Started

First, clone this repository to your machine.

git clone https://github.com/Benjamin-Roger/2d-car-game.git

cd 2d-car-game

Then, install the packages:

npm i

Finally, run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

How does it work ?

Controls

There are 3 types of controls :

  • keyboard, managed by event listener in hook "useKeys"
  • mobile, managed with a set of buttons in the component "Mobile Controls" and the context "mobileControls"
  • vocal, managed with the hook "useVolume"

Render

There are 2 elements to render to animate the game: the canvas and the car. The game is refreshed 60 times per second with the use of setInterval method. Both the canvas and the car are refreshed in the same file (useCar hook), as it is not possible to have 2 intervals running concurrently in the same component.

The useWindows hook resizes the window on every window resize.

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform.

Deploy with Vercel

Credits

Car vector created by pch.vector - www.freepik.com Juha Lindstedt for the car physics and canvas logic

2d-car-game's People

Contributors

benjamin-roger avatar

Stargazers

Manel Escuer avatar Sireus avatar Elton Leão da Fé avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.