Ping-pong source code

On this page you will find the html, css and javascript source files that make up my pingpong game. This is my first attempt at writing js so my code is most likely pretty bad and I'm sure could be improved upon greatly.


NOTE : Since creating this I changed the colours but have not updated the images in source as they are functionally identical.


A number of improvement could be made to the game and the code -

  • Improved collision detection
  • More responsive controls
  • Change the code to use objects for the bat and ball
  • Resizable play area



HTML



This is the html code. It is saved in a file called ping-pong.html.


It's a picture of some code, I don't really understand it


CSS



This is the css code. It is saved in a file called ping-pong.css.


I'd wish I'd paid more attention at school


JS



This is the javascript code. It is saved in a file called ping-pong.js. After a lot of trial and error and searching I found that the script tag should be placed at the end of the body section for code that redraws the screen


Oh really! look at it this is just getting absurd. I'm sure you did this on purpose just to confuse us mortals Zaphod do you know where Marvin is? <i>Oh yeah man he in the garage</i> In the garage? He's not parking cars again? At that very moment a whale plummeted past the window Followed by a bowl of petunias Oh no, not this again! thought Arthur