# Week 5: Midterm progress

For this midterm project, I decided to create a computer modification of a Ping Pong game. In this game, the two players control the two paddles on either side of the game window. They move the paddles up or down to hit the moving ball. The score of a player increases when he/she hits the ball.

Game features:

• Player must bounce the ball in order to score points
• Each player will have a paddle and an individual score counter
• Players can move the paddle only vertically (along the initially specified y-axis)
• Paddles will be in rectangular shape, the disc will be in circular shape
• The control key for the player 1 will be “W” and “S” keys, for the player 2 – “UP” and “DOWN” keys

The Most Complex Part:

The most complex  and time-consuming part of this project was writing the code for checking the collision the paddle with the disk and making it bounce off as in the real life. In order to achieve this goal, I decided to rely on the physic’s law of collision: when the disk hits the surface, it will bounce with the same speed as before in the opposite direction(conservation of impulse) and it will also bounce off with the same angle (angle of incidence = angle of reflection). After a few trials and error , I succeeded in implementing this collision check and bouncing correctly.

The below code is where I implemented this logical check:

```//Code for managing Disk movement
Disk_movement(){
this.disk_xc = this.disk_xc + this.disk_speed_x
this.disk_yc = this.disk_yc + this.disk_speed_y
}

//Code for managing Disk bouncing when it touches boundaries
Disk_bouncing(){

//Code for bouncing off if disk hits the boundaries
//this if statement will be executed if the disk touches right-side boundaries of the table
if(this.disk_xc + this.disk_w/2 > RES_W){

this.disk_speed_x = - this.disk_speed_x
}

//this if statement will be executed if the disk touches left-side boundaries of the table
else if(this.disk_xc - this.disk_w/2 < 0){

this.disk_speed_x = - this.disk_speed_x

}

//this if statement will be executed if the disk touches upper or lower boundaries of the table
if(this.disk_yc + this.disk_h/2 > RES_H || this.disk_yc - this.disk_h/2 < 0){
if(RES_H/2 + 100 < this.disk_yc  || this.disk_yc < RES_H/2 - 100){
this.disk_speed_y = - this.disk_speed_y
}

}

this.disk_xc = this.disk_xc + this.disk_speed_x
this.disk_yc = this.disk_yc + this.disk_speed_y
}

```

Future Improvements:

I still don’t have images and sounds, so I will work on integrating them to this game. Apart from the background music, I also want to add a collision sound for when the disk hits the paddle.  In addition, I’m still working on adding the restart feature to the game, and I also want to make this game consist of several rounds.