-
Notifications
You must be signed in to change notification settings - Fork 0
Client
The main client-files in this project can be categorized into three categories.
Index file with all Javascript files references and the Canvases which the graphics are drawn on.
Contains four main classes which are:
Handles and calculate how much the player paddle should move up and down depending on mouse or touch drag and key presses. One input locks the other so that it is not possible to use mouse and keyboard at the same time.
Plays a file, stored in the Sound folder, which is requested in other parts of the code.
Handles the calculation of each graphical elements that makes it possible to play the game with any screen ratio, independent on the opponents ratio. Also draws the graphic and text, as the countdown effect in the beginning of a game.
Keeps track of where the paddles and the ball are and how the ball's path is effected by the walls and paddles. If the paddle bounces of the local player paddle, the new direction and speed is calculated and send to the opponent. If the ball bounces on the opponent paddle the ball's direction is estimated and the game continues. When the opponent signal from the bounce is reached the program has the definitive angle and speed and calculate where the ball should be taking latency between the players into consideration.
The reason that the ball's position is altered is that the opponent paddle positions is delayed with the latency between the players and therefore a minor difference of the ball's position on the game board can occur and increase over time.
This file contains listeners for the server responses and handels them.
The sound files is located in the Sound folder and consists of five sounds. Mung.js handles then sound should be played.
- countdown.mp3 for each beep which is played three times before each new game start.
- fail.mp3 which is played if the local player lets in a goal.
- paddle.mp3 sounds each time the ball hits one of the players paddle.
- score.mp3 is played when the local player scored a goal.
- wall.mp3 played when ball bounces in one of the two walls, top or bottom.