A defender ball is created with the class selector called "ball-1". Learn how to make games, using nothing but HTML and JavaScript. We use essential cookies to perform essential website functions, e.g. Add Tip Ask Question Comment Download. Learn more. // start in the middle of the game on the left side, // start in the middle of the game on the right side, // keep track of when need to reset the ball position, // ball velocity (start going to the top-right corner), // check for collision between two objects using axis-aligned bounding box (AABB), // prevent paddles from going through walls, // prevent ball from going through walls by changing its velocity, // reset ball if it goes past paddle (but only if we haven't already done so), // give some time for the player to recover before launching the ball again, // check to see if ball collides with paddle. There's no need to ask permission before using these. See. Third: Now Paste the codes into the notepad file and save it by the extension is Snake.html By finished above options, now you are ready to play the game. Example code for shooting game Simple Game