Skip to content

Iammade/Car_game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The provided code is an implementation of a simple 2D car racing game using HTML, CSS, and JavaScript. The game involves controlling a car using arrow keys and avoiding collisions with randomly moving enemy cars. Here's a brief description of the code:

  1. HTML (index.html):

    • Sets up the basic structure of an HTML document.
    • Includes meta tags for character set and viewport settings.
    • Links an external CSS file (app.css) and JavaScript file (car.js).
    • Defines a container for the game area, a score display, and a start screen.
  2. CSS (app.css):

    • Defines styles for the game, including the car, enemy cars, score display, and game area.
    • Uses background images for the car and enemy cars.
    • Utilizes absolute positioning for elements and responsive design.
  3. JavaScript (car.js):

    • Defines variables for player speed, score, and key states.
    • Sets up event listeners for keydown and keyup events to control player movement.
    • Defines functions to move game elements (lines and enemy cars), check for collisions, and update the score.
    • Uses the requestAnimationFrame function for smooth animation.
    • Implements functions for starting and ending the game.
    • The game starts when the player clicks on the start screen, and the player can control the car using the arrow keys.
    • The goal is to avoid collisions with enemy cars and maintain a high score.

How to play:

  1. Open the HTML file (index.html) in a web browser.
  2. Click on the start screen to initiate the game.
  3. Use the arrow keys (Up, Down, Left, Right) to control the car.
  4. Avoid collisions with enemy cars.
  5. The game ends when a collision occurs, and the final score is displayed on the screen.
  6. To play again, refresh the page and click on the start screen.

Note: Ensure that the HTML file and the associated CSS and JavaScript files are in the same directory. Also, make sure that the image files referenced in the CSS are available in the correct path.

About

Car Game usiing js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published