Skip to content

moadan/FAC-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FAC-Game

Pong game task 2/2

Game

This document will explain the code and provide some insight into my learning during the game development.

  • HTML: The (canvas) element is a container which allows for the drawing of graphics and animations, using JavaScript. (h1) for title. addEventListener for keyup event,
    (W, S) to control player1
    (UpKey, DownKey) to control player2

  • CSS: (canvas id="board") background-color, & border-top, bottom, styles.

Project, my understanding of the code.

Image-1: show's the dimentions of canvas starting at (0.0) point or X, Y. width & height of 500px. Also the positioning of the player paddle, which is boarderheight/2, size of the paddle is stored in a variable (playerHeight = 100;)

Image-2: Ball starting point center, when ever the ball touches the boardHeight it reverse.

// if ball touches top or bottom of canvas
if (ball.y <= 0 || (ball.y + ball.height >= boardHeight)) {
ball.velocityY *= -1; //reverse direction
}

Image-3: Detection of ball and paddle contact.

Project in hindsight

This task was a gradual learning curve, i had great difficulty visualizing the project at start and rushed into producing the game, without any planning and research.

Learning resource: https://www.youtube.com/watch?v=LTtfoyHxAVU