Giter Club home page Giter Club logo

traffic-simulation's Introduction

Traffic simulation with Phaser 3

This is a traffic simulation written just for fun. It is heavily inspired by an article from Bilal Himite.

It uses Phaser as the rendering engine.

Usage

Simply run npm run dev and open your browser.

To draw new graphs use the GraphBuilderScene scene in main.ts. The graph is logged in the console and can then be place in constants.ts instead of the default one.

Limitations

  • Cars can crash into each other and even go through other cars at intersections as they only monitor the lead car on their road.

TODO

  • Make car clickable to display position, speed and acceleration
  • Spawn vehicle manually
  • Prevent spawning vehicle on top of each other
  • Make cars aware of cars on the next road (to avoid crash)
  • Add ability to pause by pressing p
  • Add traffic signs
  • Adds a camera to the game allowing to zoom and move around.
  • Add buttons to toggle debug (road index, node index, node color, road direction)
  • Improve rendering
  • Make cars aware of cars going to the same next road on their path (to avoid crash)
  • Create a graph generator for random road layouts
  • Use delta time for accurate FPS
  • Make sure the simulation logic and rendering concerns are isolated
  • Reimplement the rendering using d3
  • Road speed limit
  • Add curved roads
  • Allow zooming on the map
  • Add tests
  • Rework vehicle logic to consider obstacles and not leading vehicle.
    • Traffic signs are obstacles just like vehicles. With a speed of 0
  • To prevent bugs, when the leading obstacles for a vehicle is too close, immediately stop the vehicle and stop relying on the acceleration.
  • Make a high level data structure that is then translated to low level Graph
    • Include road type (one way, number of lanes, speed limit)
    • Include intersection type (traffic signal or stop signs or right priority, give way)

traffic-simulation's People

Contributors

hwaterke avatar

Watchers

 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.