Skip to content

0badran/cs50-final-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏓 Pong Game

My CS50 final project

💡 Description:

It's a two-player game where two players compete to score the most goals against each other. To make the game's pace a little more challenging, I sped up the ball when it hit the wall, up and down, by 5% of the current ball speed. I used a simple algorithm that reverses the ball's position to make the ball move in a vertical (y-axis) curve (negative and positive) when it hits the wall and a horizontal (x-axis) curve when it hits the paddles. 🧲 Quick cheat while playing. The closer the ball is to a 90-degree angle when it hits the wall, the less range it will have :)

📚 About project & files structure

This game has been made with Lua and LÖVE engine.

In this project we have those archives:

  • main.lua: Contains instructions for merging project file parts to create the visual part of the game;

  • ball.lua: Creates a Ball object with properties and methods to control its movement, collision, and drawing;

  • paddle.lua: Creates a new Paddle object with given x, y coordinates and side ('l' for left, 'r' for right);

  • score.lua: Creates a new Score object;

  • button.lua: Creates a new Button object with given x, y coordinates and text for button;

  • conf.lua: Configures the game window properties;

  • font: Inside this folder, there is the font used;

  • image: Used image for background game image & file;

  • Video: This folder has the video of the game menu;

  • sound: Inside this folder, we can find the background sound used in the game;

🎮 About the game

  • Paddles

The paddles are moved using the keyboard keys. The paddle on the left is shown in red and moves using "w key" (up) and "s key" (down), and the paddle on the right is shown in blue and moves using "up key" (up) and "down key" (down). The paddle moves at 300 pixels per second times the frame rate. Its position on the y-axis is always checked not to exceed the window boundaries.

  • Ball

The ball initially moves from the center of the window at 150 pixels per second times the frame rate, the speed is increased by 5% of the current ball speed 150 + (150 * 0.05 = 7.5) 157.5 + (5% of current speed) and so on, this calculation occurs as the ball hits the upper and lower walls, so after twenty collisions the ball speed is about 100 pixels faster than the paddles. Don't worry, it resets to its original position after a goal is scored.

🐞 Interesting bug

When the ball hits the racket from below, the ball sticks to the racket (a continuous collision situation) and stops. I used AI to improve the algorithm (when the ball hits the racket, we move the ball slightly outside the racket to avoid the continuous collision that might cause the ball to stop).

🕹 Controls

W key: Move the left paddle up

S key: Move the left paddle down

Up key: Move the right paddle up

Down key: Move the right paddle down

🔉 Sound

The sounds have been made by: Survivor
You can download them in download

Hint

If you want to change the background sound, you can do so by placing the sound file in the sound folder and renaming it to background-sound If you don't want to, you can simply remove the folder
Note: that the file extension must be mb3

⚡ How to run

Linux

PPA (Ubuntu)

  1. Download and install Love 2d
sudo add-apt-repository ppa:bartbes/love-stable
sudo apt-get update
sudo apt-get install love
  1. Run game
git clone https://github.com/0badran/cs50-final-project.git
love cs50-final-project

AppImage

  1. Download AppImage: Love 2d
  2. Add execution permission to the file
chmod +x love.AppImage
  1. Run game
git clone https://github.com/0badran/cs50-final-project.git
./love.AppImage cs50-final-project

NOTE: replace love.AppImage by the name of your file

Download for Windows

Download the game file pong-game.v1.0.zip

Mac

  1. Download AppImage: Love 2d
  2. Check if Love has permission to execute
  3. Get game
git clone https://github.com/0badran/cs50-final-project.git
  1. Drag and drop the game folder (cs50-final-project) on the Love 2d shortcut

Screenshot from inside game

game screenshot

And..

this is cs50

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages