Giter Site home page Giter Site logo

jdecho1118 / bouncingball Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3 KB

HTML, CSS, and JS create a bouncing ball game. Two buttons adjust speed; ball color changes on impact. Minimalist design with interactive elements.

HTML 16.93% JavaScript 59.78% CSS 23.28%
bouncing-ball interactive javascript

bouncingball's Introduction

Bouncing Ball Game

This simple web-based Bouncing Ball Game showcases a ball bouncing within a canvas, with the ability to dynamically adjust its speed. The game provides buttons to increase or decrease the speed of the bouncing ball, and it displays the current speed on wall hit in kilometers per hour.

How to Play

  1. Open the HTML file (index.html) in a web browser.
  2. The canvas will display a bouncing ball with an initial speed.
  3. Use the "Increase Speed" and "Decrease Speed" buttons to adjust the ball's speed.
  4. Observe the ball bouncing off the walls, changing color on each collision.
  5. The "Speed on Ball" display shows the current speed of the ball in kilometers per hour.

Code Structure

HTML (index.html)

  • The HTML file defines the structure of the game, including a canvas, buttons to control speed, and a speed display.
  • It links to an external stylesheet (styles.css) for styling.
  • The JavaScript logic is included in an external script file (script.js).

CSS (styles.css)

  • The CSS file styles the layout, canvas, buttons, and speed display for a visually appealing game interface.

JavaScript (script.js)

  • The JavaScript file contains the game logic.
  • It initializes the canvas and ball properties, handles ball movement, wall collisions, and color changes on wall hits.
  • The speed of the ball can be adjusted using the "Increase Speed" and "Decrease Speed" buttons.
  • The game continuously updates and redraws the canvas using the draw function.
  • The updateSpeedDisplay function calculates and displays the ball's speed on wall hit in kilometers per hour.

Game Controls

  • Increase Speed Button: Click to increase the speed of the bouncing ball.
  • Decrease Speed Button: Click to decrease the speed of the bouncing ball.

Important Functions

  • drawBall: Draws the bouncing ball on the canvas.
  • draw: Handles the main game loop, including ball movement and wall collisions.
  • updateSpeedDisplay: Calculates and updates the displayed speed on wall hit.
  • increaseSpeed and decreaseSpeed: Functions to adjust the speed of the ball.

Notes

  • The ball changes color on each wall collision, providing a visually dynamic experience.
  • The speed is displayed in kilometers per hour on each wall hit.

Enjoy playing with the Bouncing Ball Game!

bouncingball's People

Contributors

jdecho1118 avatar

Watchers

 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.