Coder Social home page Coder Social logo

driving-game's People

Contributors

thebearingedge avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

gitrkaplan

driving-game's Issues

User can see their car.

๐Ÿš— Motivation

Users will want to control the car, but they have to be able to see it!

๐ŸŽ Implementation

  • Source a graphic for the car.
  • Create an HTML element to represent the car and append it to the DOM.

User can stop their car.

๐Ÿš— Motivation

Once the user starts the car, they'll need to be able to stop it!

๐ŸŽ Implementation

  • Add an instance method to the Car to stop it.
  • Add a computed instance property to the Car to check if the car is started.
  • When the spacebar is pressed, conditionally start the car based on whether it is started, else stop it.

User can accelerate.

๐Ÿš— Motivation

Users will expect the car to accelerate to full speed rather than abruptly begin moving across the screen.

๐ŸŽ Implementation

  • Move start/stop controls to the "s" key.
  • Enhance car class with properties for topSpeed and isAccelerating.
  • Enhance car class with an accelerate method.
  • Enhance car class with a decelerate method.
  • Update ' ' (spacebar) control to toggle acceleration.
  • Update speed property to be currentSpeed.
  • Rename move method to update for better semantics.
  • Add an acceleration property to the Car.
  • Enhance car's move method to account for whether the car is isAccelerating.
    • If the car's currentSpeed is 0 and not isAccelerating, do nothing.
    • If the car's currentSpeed is below its topSpeed and the car isAccelerating, update the car's position and increase its currentSpeed by its acceleration.
    • Add a traction property to the car.
    • If the car's currentSpeed is above zero and not isAccelerating decrease its currentSpeed by its traction.
  • Refactor.
    • Declare variables in move method closer to their use.
    • Rename decelerate method to coast.
  • Change isStarted to a Boolean value.
  • Car can only be isAccelerating if it isStarted.
  • Decouple changes in car's currentSpeed from whether it isStarted.
  • Keep track of overlapping intervals between cycling of start/stop.

User can apply brakes.

๐Ÿš— Motivation

Releasing the accelerator may not slow the car down fast enough.

๐ŸŽ Implementation

  • Add an isBraking property to the car.
  • Add a control to toggle the state of isBraking.
  • Add a brakes property to the car.
  • Enhance update method to account for whether the car isBraking.

User can turn their car.

๐Ÿš— Motivation

Once their car is started, the user will want to steer it.

๐ŸŽ Implementation

  • Add an instance method to Car that updates its direction and marker rotation.
  • Update the move instance method to account for direction.
  • Update keypress listener to also turn the car when arrows are pressed.
  • Prevent the user from turning the car if it's not started.

User can start their car.

๐Ÿš— Motivation

The user will want to drive their car, so they need to start it.

๐ŸŽ Implementation

  • Fix the position of the car image element.
  • Define a Car class that takes a marker element, direction, speed, and location.
  • Add a move method to the Car that updates its location and its marker position.
  • Add a start method to the Car that continuously updates its location and its marker position.
  • Add an event listener for spacebar presses to start the car instance.

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.