0% found this document useful (0 votes)
9 views11 pages

Samarth College of Engineering and Management, Belhe: Second Year (IV Sem.)

The document is a report on the development of a 2D Ping Pong game and a 2D Platformer game using SFML in C++. It outlines the objectives, implementation details, and future scope of the projects, highlighting key features such as player controls, scoring systems, and collision detection. The report concludes that the project successfully demonstrates essential game development concepts and provides a foundation for more complex game development.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Samarth College of Engineering and Management, Belhe: Second Year (IV Sem.)

The document is a report on the development of a 2D Ping Pong game and a 2D Platformer game using SFML in C++. It outlines the objectives, implementation details, and future scope of the projects, highlighting key features such as player controls, scoring systems, and collision detection. The report concludes that the project successfully demonstrates essential game development concepts and provides a foundation for more complex game development.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SAMARTH COLLEGE OF ENGINEERING AND

MANAGEMENT, BELHE

“REPORT WRITING”
UNDER THE SUBJECT

COMPUTER GRAPHICS ( 210657)


ON
2D PING PONG GAME

Second Year (IV sem.)


DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING (DATA SCIENCE)

SEMESTER – IV

Name of Faculty: Prof. Varhadi V. S.

Name of Student: Katkar Om Santosh

1
SAMARTH COLLEGE OF ENGINEERING AND
MANAGEMENT, BELHE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


(DATA SCIENCE) CERTIFICATE
This is to certify that the
“Report Writing” Under
the subject
“Computer Graphics (210657)”
ON
2D PING PONG GAME

SUBMITTED BY: - Katkar Om Santosh


Exam Seat No. S400920398
Is a Bonafide work carried out by students under the supervision of Prof. Varhadi
V.S. and it is submitted towards the partial fulfilment of the requirement of second
year of Computer Science & Engineering.

Prof. Varhadi V.S. Prof. Shelake.S. D


Subject Teacher HOD OF CS & Engg.
Principal
SCOE&M,BELHE

2
ACKNOWLEDGEMENT

I would like to thank my Computer Graphics subject teacher Prof. Varhadi V.S.
for their guidance and continual encouragement throughout. I am heartily
thankful for their time-to-time suggestion and guidance which helped me a lot
during this works. I would like to thank Principal Samarth College of Engineering
and Management, for their cooperation and suggestions throughout the works.

I am giving gratitude to all the staff of the Data Science department for their
help and guidance. I would like to thank my all classmates to motivate me
throughout the work

Yours faithfully,
Katkar Om

3
INDEX

SR.NO Index Page No.

1 Title 5

2 Objective 5

3 Introduction 5

4 Future Scope 6

5 Implementation 7-9

6 Output 10

7 Conclusion 10

4
THEORY

1. Title:

• 2D Ping Pong Game and 2D Platformer Game

2. Objective:
The objective of this project is to develop a simple 2D Ping Pong game and a 2D
Platformer game using SFML (Simple and Fast Multimedia Library) in C++.
Both games feature basic game mechanics and involve:
For the 2D Ping Pong Game:
• Player-controlled paddles moving vertically and horizontally using
keyboard controls.
• A bouncing ball that reacts to player input and the game boundaries.
• Scoring system based on ball passing the opponent's paddle.
For the 2D Platformer Game:
• Player movement where the character can move left and right using
keyboard controls (A, D keys).
• Jumping and gravity mechanics that simulate realistic physics (W key for
jump).
• Collision detection with platforms and boundaries to prevent falling off the
screen.

3. Introduction:
• Ping Pong Game: A two-player game where players control paddles to
bounce a ball back and forth across a screen, aiming to score points by
getting the ball past the opponent’s paddle. This project demonstrates the
creation of a simple 2D game using basic physics for ball movement,
paddle controls, and scoring.
• Platformer Game: A classic genre where the player controls a character that
navigates through a level by jumping and avoiding obstacles. The project

5
uses SFML for managing graphics and input. The player can move left and
right, jump, and interact with static platforms. Gravity affects the player’s
movement, and collision detection ensures the player cannot fall through
the ground or platforms.

4. Future Scope:
• For the Ping Pong Game:
o Power-ups: Add special power-ups that temporarily enhance the
paddles or speed of the ball.
o AI Opponent: Implement an AI opponent that can challenge the
player.
o Sound Effects and Music: Include sound effects for ball bounce and
scoring to enhance the gameplay.
• For the Platformer Game:
o Multiple Platforms: Add different platforms at varying heights and
positions to make the game more challenging.
o Enhanced Controls: Introduce double jumps, wall jumps, or
crouching for more dynamic gameplay.
o Enemies and Obstacles: Add moving obstacles or enemies to
increase difficulty.
o Scoring System: Implement a point system based on how long the
player survives or how many levels they complete.
o Sound Effects and Music: Add background music and sound effects
for jumps, collisions, and other game actions.
o Mobile Version: Create a version for mobile devices with touch
controls.

6
5. Implementation:
• Technologies Used:
o Programming Language: C++
o Library Used: SFML (Simple and Fast Multimedia Library)
o Concepts Applied: Game physics (gravity, collision detection),
player input handling, scoring systems.
• Code Implementation (C++ Using SFML/Graphics.h): The core mechanics
of the games are developed using SFML, which handles window creation,
event management, graphics rendering, and input processing. The games
involve the manipulation of rectangles for paddles, circles for the ball, and
a series of basic logic checks for collisions and scoring.

#include <GL/glut.h>

float paddle1Y = 0, paddle2Y = 0, ballX = 0, ballY = 0, ballVelX = 0.02, ballVelY = 0.02;

void drawPaddle(float x, float y) {


glBegin(GL_QUADS);
glVertex2f(x - 0.1, y - 0.3);
glVertex2f(x + 0.1, y - 0.3);
glVertex2f(x + 0.1, y + 0.3);
glVertex2f(x - 0.1, y + 0.3);
glEnd();
}

void drawBall() {
glBegin(GL_QUADS);
glVertex2f(ballX - 0.05, ballY - 0.05);
glVertex2f(ballX + 0.05, ballY - 0.05);
glVertex2f(ballX + 0.05, ballY + 0.05);

7
glVertex2f(ballX - 0.05, ballY + 0.05);
glEnd();
}

void display() {
glClear(GL_COLOR_BUFFER_BIT);

drawPaddle(-0.9, paddle1Y); // Left Paddle


drawPaddle(0.9, paddle2Y); // Right Paddle
drawBall();

// Ball movement logic


ballX += ballVelX;
ballY += ballVelY;

// Ball collision with top and bottom walls


if (ballY > 1.0 || ballY < -1.0) ballVelY = -ballVelY;

// Ball collision with paddles


if ((ballX - 0.05 < -0.8 && ballY < paddle1Y + 0.3 && ballY > paddle1Y - 0.3) ||
(ballX + 0.05 > 0.8 && ballY < paddle2Y + 0.3 && ballY > paddle2Y - 0.3)) {
ballVelX = -ballVelX;
}

// Ball out of bounds


if (ballX > 1.0 || ballX < -1.0) {
ballX = 0;
ballY = 0;
ballVelX = -ballVelX;
}

8
glutSwapBuffers();
}

void keyPress(int key, int x, int y) {


if (key == GLUT_KEY_UP) paddle2Y += 0.1;
if (key == GLUT_KEY_DOWN) paddle2Y -= 0.1;
if (key == GLUT_KEY_W) paddle1Y += 0.1;
if (key == GLUT_KEY_S) paddle1Y -= 0.1;
}

void init() {
glClearColor(0.0, 0.0, 0.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}

int main(int argc, char** argv) {


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutCreateWindow("2D Ping Pong Game");
init();
glutDisplayFunc(display);
glutSpecialFunc(keyPress);
glutMainLoop();
return 0;
}

9
6. Output:-

7. Conclusion:-
The 2D Ping Pong game project represents a successful implementation of the
classic arcade game using SFML (Simple and Fast Multimedia Library). This
project showcases smooth, responsive graphics, realistic physics for ball
movement and paddle interaction, and intuitive gameplay. The game incorporates
essential elements such as player control, score tracking, and collision detection,
providing a highly engaging experience. The use of SFML allows for efficient
handling of graphics, sound, and input, enhancing the overall performance and
user experience. This project not only highlights the fundamental aspects of game
development, including game loop mechanics, event handling, and real-time
rendering, but also provides a solid foundation for further development of more
complex games and interactive multimedia applications.

10
11

You might also like