0% found this document useful (0 votes)
45 views17 pages

Darshancg

Uploaded by

Darshan Manju
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)
45 views17 pages

Darshancg

Uploaded by

Darshan Manju
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/ 17

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

“JnanaSangama”, Belgaum-590018

A Mini Project Report On


2D GAME
SUBMITTED IN PARTIAL FULFILMENT FOR 6TH SEMESTER
BACHELOR OF ENGINEERING
IN

COMPUTER SCIENCE AND ENGINEERING


SUBMITTED BY
DARSHAN M [1JB21CS036]
UNDER THE GUIDANCE OF

Dr. Krishna A N
Professor & Head
Dept. of CSE, SJBIT

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SJB INSTITUTE OF TECHNOLOGY
#67, BGS HEALTH & EDUCATION CITY, DR.VISHNUVARDHAN ROAD, KENGERI, BENGALURU-
560060, KARNATAKA, INDIA.
2023 - 2024

Marks
Sl No. Assignment No. Total Marks
Obtained

1 Assignment 1 10
2 Assignment 2 10
Total Marks:

Student Signature: Faculty Signature


TABLE OF CONTENTS

CHAPTER NO. DESCRIPTION PAGE NO.

Chapter 1 Introduction to OpenGL 1


Chapter 2 Introduction to Project 2
Chapter 3 Hardware & Software requirements 3
Chapter 4 System Design 4
Chapter 5 Implementation 7
Various functions 7
Chapter 6 Results 9
Conclusion 12
Future Scope 13
References 14
LIST OF FIGURES

FIGURE NO. DESCRIPTION PAGE NO.


6.1 Welcome Page 9
6.2 Instructions 10
6.3 Initial stage of the game 10
6.4 Scorecard 11
Computer Graphics and Image Processing – 21CS63 2023-24

CHAPTER 1

Introduction to OpenGL

1.1 Introduction to OpenGL :

OpenGL is the most widely adopted 2D and 3D graphics API in the industry, bringing
thousands of applications to a wide variety of computer platforms. It is designed to be a low-level
API, focusing on the rendering of 2D and 3D graphics, and does not include commands for
windowing tasks or obtaining user input. OpenGL is responsible for rendering 2D and 3D graphics,
but it does not provide high-level commands for describing models of three-dimensional objects.
Instead, it requires the programmer to build up their desired model from a small set of geometric
primitives such as points, lines, and polygons [1].

1.2 What OpenGL Does and Doesn't Do:


OpenGL is a powerful tool for creating interactive three-dimensional applications. Its low-
level API provides flexibility and customization but requires a good understanding of computer
graphics and the OpenGL programming model. By mastering the basics of OpenGL, programmers
can create complex and visually stunning graphics that push the boundaries of what is possible in
computer graphics.

1.3 OpenGL as a State Machine

OpenGL operates as a state machine, where the state of the system is modified by a
sequence of commands. The state variables in OpenGL are used to track the current settings and
configurations of the graphics pipeline. Commands are provided for querying, enabling, and
disabling states, allowing for precise control over the rendering process. Understanding the
rendering pipeline is crucial for optimizing graphics performance and creating complex graphics
effects [2].

Dept. of CSE, SJBIT Page 1


Computer Graphics and Image Processing – 21CS63 2023-24

CHAPTER 2

Introduction to Project

2D GAME Mini-Project with OpenGL:

In the project “ 2D GAME”, the project is programmed using c++. Oops concepts are explored
and the project involves the Bat and Ball on which basis game is built. In this game there will be two
players . PC will be the First player and USER will be the second player. This program contains Functions
to drag the ball, draw the bat etc.

This project includes the multiple windows, menus and submenus using which color of the bat & ball,
screen color, ball size will be changed. These all actions are assigned to keyboard and mouse.

User-interface is provided by means of both Keyboard and Mouse. By using arrow keys bat can be moved.
Mouse interaction is achieved by means of a menu which is operational only with the “right mouse
button” through which bat , ball , screen color changing , speed settings are enabled.

Our game is a simple ball with bat game. The bat will be moved according to the movement of the mouse.
And the ball will move randomly in the created window. When the ball hits the right, left, or top wall –
we will refer to the window border as a wall - it will return back. When it hits the bottom wall it will not
only return back but it will increase the score of the computer, but if the player can hold it by the bat, his
score will be increased.

Dept. of CSE, SJBIT Page 2


Computer Graphics and Image Processing – 21CS63 2023-24

CHAPTER 3

Hardware and Software Requirements


3.1 Software:

• Visual Studio (C++ compiler)


• OpenGL libraries (GL/glut.h)
• Compiler – C Compiler
• Operating System – Linux operating System

3.2 Hardware:

• Dual Core Processor


• At least 2 GB of RAM (8 GB or more recommended)
• DVD drive
• Keyboard
• Mouse and Other Pointing Devices
• 40 GB Hard disk

Dept. of CSE, SJBIT Page 3


Computer Graphics and Image Processing – 21CS63 2023-24

CHAPTER 4

System Design
4.1 Components:

4.1.1 Game Objects:

• Player: Controlled by user input, with movement, animation, and collision detection.
• Enemies: Automated entities with AI for movement and interaction.
• Collectibles/Power-ups: Items to be collected by the player.
• Backgrounds/Layers: Parallax scrolling for depth effect.

4.1.2 Game State Management:

• OpenGL Initialization: Set up OpenGL context, viewport, and necessary buffers.


• Shader Programs: Create vertex and fragment shaders for rendering.
• Vertex Buffer Objects (VBOs) and Vertex Array Objects (VAOs): Store vertex
data and attribute pointers.
• Texture Loading: Load images for sprites and backgrounds into OpenGL textures.
• Rendering Function: Use shaders to render sprites, backgrounds, UI elements, etc.

4.1.3 User Interaction:

• Keyboard and Mouse: Capture user input for player control and interaction.
• Game Controllers: Optionally, support for gamepads/joysticks for input.

Dept. of CSE, SJBIT Page 4


Computer Graphics and Image Processing – 21CS63 2023-24

4.1.4 Audio:

• Sound Effects: Implement audio playback for actions such as jumping,


shooting, etc.
• Background Music: Continuous playback of music that fits the game's
theme.

4.2 Detailed Design:

4.2.1 Planning and Design:

• Define game mechanics, levels, and overall gameplay flow.


• Create sprite sheets and define sprite animations.
• Design game objects and their behaviors (e.g., movement patterns, AI).

4.2.2 Implementation:

• Set up OpenGL context and initialize necessary libraries.


• Implement game loop and manage game state transitions.
• Develop rendering pipeline using shaders and VBOs/VAOs.
• Code collision detection algorithms and integrate with game objects.
• Implement input handling for player control.
• Integrate audio playback for sound effects and music.
• Develop UI elements and manage game states.

4.2.3 Testing and Debugging:

• Test gameplay mechanics thoroughly, ensuring smooth interaction and


responsiveness.
• Debug issues related to rendering, collision detection, and input handling.
• Optimize performance where necessary (e.g., batch rendering, efficient
collision checks).

Dept. of CSE, SJBIT Page 5


Computer Graphics and Image Processing – 21CS63 2023-24

4.2.4 Updates:
• Add visual effects (e.g., particle systems, screen shakes).
• Fine-tune gameplay parameters (e.g., movement speed, enemy behaviors).
• Implement game transitions (e.g., level completion, game over).
• Enhance UI/UX for clarity and usability.

4.3 User Interactions:


4.3.1 Mouse Functions:

• glutCreateMenu(): Creates a new menu.


• glutAttachMenu(): Attaches the menu to a mouse button.

4.3.2 Keyboard Functions:

• keyboard() handles key presses to reset the game (using the 'r' key).

4.3.3 Menu Function:

• menu() provides a right-click menu for retrying the game or exiting..

4.4 Detailed Design:

4.4.1 Initialization:

The main () function initializes GLUT, sets up the window, and registers callback function
(display (), update(), mouse(), motion(), keyboard()).
Calls init () to set up the initial state.

4.4.2 Game Loop:

• The game runs within the GLUT main loop.


• update() is called periodically to update the game state.
• display() is called whenever the game state changes to render the updated state.
• User inputs (mouse and keyboard) are handled by their respective callback functions to
interact with the game.

Dept. of CSE, SJBIT Page 6


Computer Graphics and Image Processing – 21CS63 2023-24

CHAPTER 5

Implementation

5.1 Various functions used in this program


➢ glutInit() : interaction between the windowing system and OPENGL is
initiated

➢ glutInitDisplayMode() : used when double buffering is required and depth


information is required

➢ glutCreateWindow() : this opens the OPENGL window and displays the title
at top of the window

➢ glutInitWindowSize() : specifies the size of the window

➢ glutInitWindowPosition() : specifies the position of the window in screen co-


ordinates
➢ glutKeyboardFunc() : handles normal ascii symbols

➢ glutSpecialFunc() : handles special keyboard keys

➢ glutReshapeFunc() : sets up the callback function for reshaping the window

➢ glutIdleFunc() : this handles the processing of the background

➢ glutDisplayFunc() : this handles redrawing of the window

➢ glutMainLoop() : this starts the main loop, it never returns

➢ glViewport() : used to set up the viewport


Dept. of CSE, SJBIT Page 7
Computer Graphics and Image Processing – 21CS63 2023-24

➢ glVertex3fv() : used to set up the points or vertices in three dimensions

➢ glColor3fv() : used to render color to faces

➢ glFlush() : used to flush the pipeline

➢ glutPostRedisplay() : used to trigger an automatic redrawal of the object

➢ glMatrixMode() : used to set up the required mode of the matrix

➢ glLoadIdentity() : used to load or initialize to the identity matrix

➢ glTranslatef() : used to translate or move the rotation centre from one point to
another in three dimensions

➢ glRotatef() : used to rotate an object through a specified rotation angle

Dept. of CSE, SJBIT Page 8


Computer Graphics and Image Processing – 21CS63 2023-24

CHAPTER 6

Results

6.1 Snapshots:

Fig 6.1: Welcome Page

Dept. of CSE, SJBIT Page 9


Computer Graphics and Image Processing – 21CS63 2023-24

Fig 6.2: Instructions

Fig 6.3: Initial stage of the game.

Dept. of CSE, SJBIT Page 10


Computer Graphics and Image Processing – 21CS63 2023-24

Fig 6.4: Scorecard

Dept. of CSE, SJBIT Page 11


Computer Graphics and Image Processing – 21CS63 2023-24

Conclusion and Future Scope

Conclusion:

The Project was started with modest aim with no prior experience in any programming projects as
this, but ended up in learning many things, fine tuning the programming skills and getting into the
real world of software development with an exposure to corporate environment .During the
development of any software of significant utility , we are forced with the tradeoff between speed
of execution and amount of memory consumed . This is simple graphics project . It has an open
source and no security features has been included . The user is free to alter the code for feature
enhancement . Checking and verification of all possible types of the functions are taken care . Care
was taken to avoid bugs . Bugs may be reported to creator as the need .

Further this project can be enhanced by adding few more options i.e menus in game. Using this
we can design a 3D game which contains cube instead of single window and multiple number of
balls which are randomly moving and all faces of cube is considered as wall .

Dept. of CSE, SJBIT Page 12


Computer Graphics and Image Processing – 21CS63 2023-24

Future Scope:

1. Enhanced Graphics and Animations:


Improve the visual quality of the game by incorporating advanced OpenGL features such as
textures, shading, and lighting effects. This will make the game more visually appealing and
modern.

2. Game Levels and Challenges:


Develop a multiplayer mode where multiple players can either cooperate to complete levels or
compete against each other. This could be implemented through local multiplayer or online play.

3. User Interface Improvements:


A more interactive and user-friendly interface will greatly improve the overall user experience.
Future enhancements could include well-designed menus, scoreboards, and clear game
instructions. For mobile versions, implementing touch screen controls will provide a more intuitive
and accessible gaming experience. Additionally, creating customizable settings where players can
adjust the difficulty level, sound effects, and graphics quality will cater to a broader audience with
varying preferences and device capabilities.

4. Leaderboards and Achievements:


Implement leaderboards to track high scores and achievements for completing specific
challenges. This can motivate players to improve their performance and compete with others..

Dept. of CSE, SJBIT Page 13


Computer Graphics and Image Processing – 21CS63 2023-24

References

[1] https://www.opengl.org/documentation/
[2] https://www.opengl.org/documentation/red_book/
[3] https://www.opengl.org/resources/libraries/glut/
[4] https://www.crcpress.com/Real-Time-Rendering/Akenine-Moller-Haines-
Hoffman/p/book/9781138627000
[5] https://visualstudio.microsoft.com/downloads/
[6] https://learn.microsoft.com/en-us/visualstudio/releases/2022/system-requirements

Dept. of CSE, SJBIT Page 14

You might also like