GithubHelp home page GithubHelp logo

pong-game's Introduction

pong-game

https://calebjoshuapaul.github.io/pong-game/

  • The code starts by creating a new Ball object and then creates two Paddle objects.
  • The first is for the player, and the second is for the computer.
  • It also creates an element to hold their scores in.
  • The update function will be called every time there's a change in time (i.e., when it changes from 0 seconds to 1 second).
  • In this case, it checks if lastTime has been set before calling itself with delta as its argument.
  • If so, it calculates how much time has passed since lastTime was set and updates the score accordingly using document query selectors that are created specifically for this purpose: one for each player's score and one for each computer's score.
  • The code is an example of a function that will update the score.
  • The first line creates a variable called lastTime, which is used to keep track of the time in milliseconds.
  • The second line checks if there is already a value for lastTime, and if so it subtracts delta from it.
  • The code starts by creating a ball and then sets the x-coordinate to be 0.
  • The code then creates a computer paddle, which is set to have an initial position of (0,0) and an initial angle of 0 degrees.
  • The code then updates the computerPaddle with delta time steps so that it moves towards the ball in increments of 1 degree per update step.
  • The next line calculates the hue value for this particular frame using getComputedStyle() .
  • It uses parseFloat() to convert this value into a number between 0 and 360 degrees.
  • Then it changes the color property on documentElement from --hue=255 to --hue=360 + delta * 0.01 , where delta is calculated as one degree per update step taken by computerPaddle .
  • The code is written in a way that the computer paddle is updated with the ball's movement and then it updates itself.
  • The computerPaddle.update(delta, ball.y); function sets the position of the computer paddle to be equal to the ball's current position minus its previous position plus delta * 0.01
  • The code starts by declaring variables for the ball and player paddle.
  • The variable "time" is used to keep track of how long it has been since the game started.
  • The function handleLose() is called when the user clicks on the lose button in order to reset both players' paddles and score.
  • The code is an example of how to implement a game of Pong.

pong-game's People

Contributors

calebjoshuapaul avatar

Stargazers

 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.