Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

INTERACTIVE SNAKE GAME

CHAPTER-1
INTRODUCTION

1.1 INTRODUCTION TO COMPUTER GRAPHICS:


Computer Graphics is concerned with all aspects of producing pictures or images using a
computer. We can create images that are indistinguishable from photographs of real objects. In
other terms, Computer Graphics are the graphics created by the computers, and more generally,
the representation and manipulation of image data by a computer. The development of computer
graphics has been driven both by the needs of the user community and by advances in hardware
and software.

Typically, the term Computer Graphics refers to several different things;

i. The representation and manipulation of image data by a computer.


ii. The various technologies used to create and manipulate images.
iii. The images so produced, and manipulating visual content.

1.2 HISTORY OF COMPUTER GRAPHICS:


The phrase Computer Graphics was coined in 1960 by William Fetter, a graphic designer
for Boeing. The field of Computer Graphics developed with the emergence of computer graphics
hardware. Early projects like the Whirlwind and SAGE projects introduced the CRT as a viable
display and interaction interface and introduced the light pen as an input device. Further
advances in computing led to greater advancements in interactive computer graphics. In 1959,
the TX-2 computer was developed at MIT Lincoln Laboratory. A light pen could be used to draw
sketches on the computer using Ivan Sutherland’s revolutionary Sketchpad software.

Also in 1961 another student at MIT, Steve Russell, created the first video game, Space
war. E. E. Zajac, a scientist at Bell Telephone Laboratory (BTL), created a film called
“Simulation of a two-giro gravity attitude control system” in 1963. In this computer generated
film, Zajac showed how the attitude of a satellite could be altered as it orbits the Earth. Many of
the most important early breakthroughs in computer graphics research occurred at the University
of Utah in the 1970s.

The first major advance in 3D computer graphics was created at UU by these early
pioneers, the hidden-surface algorithm. In order to draw a representation of a 3D object on the

Dept of CSE, JCET, Hubballi 2022-23 Page 1


INTERACTIVE SNAKE GAME

screen, the computer must determine which surfaces are “behind” the object from the viewer’s
perspective, and thus should be “hidden” when the computer creates (or renders) the image.

Graphics and application processing were increasingly migrated to the intelligence in the
workstation, rather than continuing to rely on central mainframe and mini-computers. 3D
graphics became more popular in the 1990s in gaming, multimedia and animation. Computer
graphics used in films and video games gradually began to be realistic to the point of entering the
uncanny valley. Examples include the later Final Fantasy games and animated films like The
Polar Express.

1.3 INTRODUCTION TO OpenGL:


OpenGL is a software interface to graphics hardware. This interface consists of about 150
distinct commands that are used to specify the objects and operations needed to produce
interactive three-dimensional applications. OpenGL is designed as a streamlined hardware
independent interface to be implemented on many different hardware platforms.

These are certain characteristics of OpenGL;

 OpenGL is a better documented API.


 OpenGL is much easier to learn and program.
 OpenGL has the best demonstrated 3D performance for any API.

The OpenGL specification describes an abstract API for drawing 2D and 3D graphics.
Although it's possible for the API to be implemented entirely in software, it's designed to be
implemented mostly or entirely in hardware.

In addition to being language-independent, OpenGL is also platform-independent. The


specification says nothing on the subject of obtaining, and managing, an OpenGL context,
leaving this as a detail of the underlying windowing system. For the same reason, OpenGL is
purely concerned with rendering, providing no APIs related to input, audio, or windowing.

OpenGL is an evolving API. New versions of the OpenGL specification are regularly
released by the Khronos Group, each of which extends the API to support various new features.
In addition to the features required by the core API, GPU vendors may provide additional
functionality in the form of extensions.

Extensions may introduce new functions and new constants, and may relax or remove
restrictions on existing OpenGL functions. Vendors can use extensions to expose custom APIs
without needing support from other vendors or the Khronos Group as a whole, which greatly
increases the flexibility of OpenGL. All extensions are collected in, and defined by, the OpenGL
Registry.

Dept of CSE, JCET, Hubballi 2022-23 Page 2


INTERACTIVE SNAKE GAME

Fig. 1.3: OpenGL Pipeline.

1.4 INTRODUCTION TO GLUT:


GLUT is the OpenGL utility toolkit, a window system independent toolkit for writing
OpenGL programs. It implements a simple windowing API for OpenGL. GLUT makes it easier
to learn about and explore OpenGL programming. GLUT provides a portable API so you can
write a single OpenGL program that works across all PC and workstation OS platforms. GLUT
is designed for constructing small to medium sized OpenGL programs.

While GLUT is well-suited to learning OpenGL and developing simple OpenGL


applications, GLUT is not a full-featured toolkit so large applications requiring sophisticated
user interfaces are better off using native window system toolkits. The GLUT library has both C,
C++ (same as C), FORTRAN, and ADA programming bindings. The GLUT source code
distribution is portable to nearly all OpenGL implementations and platforms.

Fig. 1.4: Library Organization of OpenGL.

Dept of CSE, JCET, Hubballi 2022-23 Page 3


INTERACTIVE SNAKE GAME

1.5 APPLICATIONS OF COMPUTER GRAPHICS:


The development of computer graphics has been driven both by the needs of the user
community and by advances in hardware and software. The applications of computer graphics
are many and varied. We can however divide them into four major areas;

 DISPLAY OF INFORMATION: More than 4000 years ago, the Babylonians developed
floor. plans of buildings on stones. Today, the same type of information is generated by
architects using computers. Over the past 150 years, workers in the field of statistics have
explored techniques for generating plots. Now, we have computer plotting packages.
Supercomputers now allow researchers in many areas to solve previously intractable
problems. Thus, Computer Graphics has innumerable applications.

 DESIGN: Professions such as engineering and architecture are concerned with design.
Today, the use of interactive graphical tools in CAD, in VLSI circuits, characters for
animation have developed in a great way.

 SIMULATION AND ANIMATION: One of the most important uses has been in pilots‟
training. Graphical flight simulators have proved to increase safety and reduce expenses.
Simulators can be used for designing robots, plan it’s path, etc. Video games and
animated movies can now be made with low expenses.

 USER INTERFACES: Our interaction with computers has become dominated by a visual
paradigm. The users’ access to internet is through graphical network browsers. Thus
Computer Graphics plays a major role in all fields.

1.6 APPLICATIONS OF OpenGL:


 OpenGL (Open Graphics Library)is a cross-language, multi-platform API for rendering
2D and 3D computer graphics.

 The API is typically used to interact with a GPU, to achieve hardware accelerated
rendering.

 It is widely used in CAD, virtual reality, scientific visualization, information 


visualization, flight simulation, and video games.

Dept of CSE, JCET, Hubballi 2022-23 Page 4


INTERACTIVE SNAKE GAME

1.7 OpenGL PRIMITIVES:


OpenGL supports two classes of primitives;

i. Geometric Primitives.
ii. Image(Raster) Primitives.

Geometric primitives are specified in the problem domain and include points, line segments,
polygons, curves and surfaces.

Raster primitives, such as arrays of pixels pass through a separate parallel pipeline on their
way to the frame buffer.

There are ten basic OpenGL primitives;

Fig. 1.7: OpenGL Primitives.

Dept of CSE, JCET, Hubballi 2022-23 Page 5


INTERACTIVE SNAKE GAME

CHAPTER-2
REQUIREMENT SPECIFICATION
The graphics editor has been programmed in C. It makes use of Turbo C Graphics library
package for creating the user interface. This is a subroutine library for terminal independent
screen painting and input event handling.

2.1 HARDWARE REQUIREMENTS:


The standard output device is assumed to be a Color Monitor. It is quite essential for any
graphics package to have this, as provision of color options to the user is a must. The mouse, the
main input device, has to be functional i.e. used to give input in the game. A keyboard is used for
controlling and inputting data in the form of characters, numbers i.e. to change the user views.
Minimum Requirements expected are cursor movement, creating objects like lines, squares,
rectangles, polygons, etc. Transformations on objects/selected area should be possible. Filling of
area with the specified color should be possible.

i. Processor: Intel dual core i5.


ii. RAM: 1GB RAM or above.
iii. Input devices: Keyboard.
iv. Output devices: Monitor.

2.2 SOFTWARE REQUIREMENTS:


The editor has been implemented on the OpenGL platform and mainly requires the
appropriate version of Microsoft Visual Studio.

i. Operating System: Microsoft Windows 10.


ii. Microsoft Visual Studio 2010.
iii. glut.h header file.
iv. glut.dll library file.

Dept of CSE, JCET, Hubballi 2022-23 Page 6


INTERACTIVE SNAKE GAME

CHAPTER-3
ABOUT THE PROJECT
INTRODUCTION TO THE PROJECT:
“INTERACTIVE SNAKE GAME” is a single-player puzzle video game. The objective
of the game is to clear a rectangular board containing hidden “MINES” or bombs without
detonating any of them, with help from clues about the number of neighboring mines in each
field. The game originates from the 1960’s, and has been written for many computing platforms
in use today. It has many variations abd offshoots.

The Interactive Snake Game is a mini project that aims to recreate the classic game of
Snake using the OpenGL graphics library. The project focuses on providing an immersive and
visually appealing gaming experience while incorporating user interaction and game mechanics
to enhance the gameplay.

DESCRIPTION:
The Interactive Snake Game project utilizes the power of OpenGL to create a dynamic
and engaging gaming environment. The game screen is rendered using OpenGL's graphics
functions, which allows for smooth animations and vibrant visuals. The game consists of a
snake, represented by a series of connected spheres, and food items that appear at random
locations on the screen.

It has a very basic gameplay style. In its original form, mines are scattered throughout a
board. This board is divided into cells, which have two stages: uncovered and covered. A
covered cell is blank and clickable, while an uncovered cell is exposed, either containing a
number or a mine. When a cell is uncovered by a player click, and it bears a bomb a mine, the
game ends.

The player controls the snake's movement using arrow keys. As the snake moves, it
continuously grows in length, and the player's objective is to guide the snake to eat the food
items, increasing its score. The game incorporates collision detection mechanisms to ensure that
the snake does not collide with itself, which would result in the game ending.

Dept of CSE, JCET, Hubballi 2022-23 Page 7


INTERACTIVE SNAKE GAME

CHAPTER-4
DESIGN
INITIALIZATION:
System design is the process of defining the architecture, components, modules,
interfaces, and data for a system to satisfy specified requirements. Systems design could see it as
the application of systems theory to product development. There is some overlap with the
disciplines of analysis, system and systems engineering.

The system design of a system pertains to an abstract representation of the data flows,
inputs and outputs of the system. This is often conducted via modeling, using an over abstract
(and sometimes graphical) model of the actual system. It relates to the actual input and output
processes of the system. This is laid down in terms of how data is input into a system, how it is
verified/authenticated, how it is processed, and how it is displayed as output. Systems design can
generally be broken down into three sub-tasks;

 User Interface Design


 Data Design
 Process Design

User Interface Design is concerned with how users add information to the system and with
how the system presents information back to them. Data Design is concerned with how the data
is represented and stored within the system. Finally, Process Design is concerned with how data
moves through the system, and with how and where it is validated, secured and/or transformed as
it flows into, through and out of the system. At the end of the systems design phase,
documentation describing the three sub-tasks is produced and made available for use in the next
phase.

This project aims to demonstrate the user interface by using keyboard and mouse I/O
devices. When a predefined key is pressed, the corresponding action takes place. In an OpenGL
project we would like to create a scene through which we are demonstration of Minesweeper.

Dept of CSE, JCET, Hubballi 2022-23 Page 8


INTERACTIVE SNAKE GAME

FLOWCHART:

Fig. 4.1: Flowchart representing the working of Snake Game.

Dept of CSE, JCET, Hubballi 2022-23 Page 9


INTERACTIVE SNAKE GAME

CHAPTER-5
IMPLEMENTATION
5.1 BUILT-IN FUNCTIONS:
1) glColor3f() - Used to display color.

2) glBegin() - Used to accept a single argument.

3) glVertex2f() - Used to specify a line a line, point.

4) glutPostRedisplay() - Marks the current window as needing to be redisplayed.

5) glClearColor(0.0,0.0,0.0,0.0) - Specifies clear values for the color buffers.

6) glEnable(GL_DEPTH_TEST) - Enables the OpenGL capabilities, Specifies the


conditions under which the pixels will be drawn.

7) glLoadIdentity() - Replaces current matrix with identity matrix.

8) glViewport() - Sets the view port.

9) glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB) - Sets the initial display mode.

10) glutInitWindowSize(500,500) and glutInitWindowPosition(50,50) - Set the initial


window size and position respectively.

11) glutCreateWindow() - Creates a top level window with the window name as specified.

12) glutDisplayFunc(display) - Sets the display call back for the current window.

13) glutReshapeFunc(reshape) - Sets the reshape call back for the current window.

14) glutMainLoop() - Enters the GLUT event processing loop. This routine should be called
atmost once in a GLUT program. Once called, this routine will never return. It will calls
necessary any callbacks that have been registered.

Dept of CSE, JCET, Hubballi 2022-23 Page 10


INTERACTIVE SNAKE GAME

5.2 SOURCE CODE:


#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <gl/glut.h>

#define UP 1
#define Down 2
#define LEFT 3
#define RIGHT 4

// Status Variables
GLint lvl = 1;
GLint points = 0;
GLint size = 0;
GLbyte gameOver = true;
GLbyte EnableLight = true;

// Snake Variables
GLint bodyPos[2][100] = {{}};
GLint _x = 5;
GLint _z = 10;
GLint _oldX[2] = {};
GLint _oldZ[2] = {};
GLbyte direction = 0;

// Food Variables
GLint _bx = 0;
GLint _bz = 0;

// Screen variables
GLint _w = 800;
GLint _h = 550;
GLint _Giw = 0;
GLint _Gih = 0;
GLint _Gfw = 150;
GLint _Gfh = 150;

//Variables for the Camera Angle


static GLfloat view_rotx=45.0F ;
static GLfloat view_roty=0.0F ;
static GLfloat view_rotz=0.0F ;

static GLfloat headRotation=90.0F ;


static GLfloat zoom=-300.0f;

Dept of CSE, JCET, Hubballi 2022-23 Page 11


INTERACTIVE SNAKE GAME

//Configure the lightning


void initLight()
{
//Add ambient light
GLfloat ambientColor[] = {0.3f, 0.4f, 0.8f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
//Add positioned light
GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
//Add directed light
GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f};
//Coming from the direction (-1, 0.5, 0.5)
GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f};
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
}
//initialize the first configurations
void Initialize(void)
{
glEnable(GL_DEPTH_TEST);
glClearColor(0.4f, 0.8f, 1.0f, 1.0f); //Change the background to sky blue
if(EnableLight){
glEnable(GL_COLOR_MATERIAL); //Enable color
glEnable(GL_LIGHTING); //Enable lighting
glEnable(GL_LIGHT0); //Enable light #0
glEnable(GL_LIGHT1); //Enable light #1
glEnable(GL_NORMALIZE); //Automatically normalize normals
}
}
//Configure window resize
void resize (int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h,1, 800.0);
}
void Write(char *string){//Write string on the screen
while(*string)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *string++);
}
//This Function will rotate the object according to the Angles
void ManipulateViewAngle() {
glRotatef(view_rotx,1.0,0.0,0.0);//Rotate Around X axis

Dept of CSE, JCET, Hubballi 2022-23 Page 12


INTERACTIVE SNAKE GAME

glRotatef(view_roty,0.0,1.0,0.0);//Rotate Around Y axis


glRotatef(view_rotz,0.0,0.0,1.0);//Rotate Around Z axis
}
//This Function will reset the snake size and location...
void Reset(){
_x = 5;
_z = 10;
direction = 0;
lvl = 1;
points = 0;
size = 0;
gameOver = false;
view_rotx=45.0F ;
view_roty=0.0F ;
view_rotz=0.0F ;
headRotation=90.0F ;
}
//Display a welcome screen
void WelcomeScreen(){
char tmp_str[40];

glRasterPos2f(-60, 20);
Write("WELCOME");
glRasterPos2f(-60, 10);
Write("Simulation of Snake Game");
glRasterPos2f(-60, 0);
Write("To Start Playing please press 'S' or 's' ");
}
void DrawSnake(){
int i;
//Drawing the head & the plane
glPushMatrix();
ManipulateViewAngle();
//This will draw the plane that the snake will run on.
glPushMatrix();
//glColor3f(1, 0.7, 0.2);
glColor3f(0.0, 0.6, 0.2);
glTranslatef(75.0, -16.0, 75.0);
glScalef(155,5.0,155);
glutSolidCube(1);
glPopMatrix();
//Here we will draw the Head of the snake
glColor3f(1,0,0);//Color it red
glTranslatef(_x,-10.0,_z);//Give it the location according to _x & _z
glScalef(0.5,0.5,0.5);
glutSolidSphere(10,20,20);//Draw the head as a sphere a litle bit bigger than the body spheres

Dept of CSE, JCET, Hubballi 2022-23 Page 13


INTERACTIVE SNAKE GAME

glRotatef(headRotation, 0.0, 1.0, 0.0);


glColor3f(1,0,0);
glTranslatef(0,0.0,6.0);
glScalef(0.8,1.0,1.0);
glutSolidCone(10,10,20,20);
glColor3f(1,1,1);
glTranslatef(-4.0,10.0,0.0);
glScalef(0.3,0.3,0.3);
glutSolidSphere(10,20,20);
glTranslatef(26.0,0.0,0.0);
glutSolidSphere(10,20,20);
glPopMatrix();

//Drawing the body


for(i=0; i<size; i++){//Loop throw the size and draw spheres representing the body
glPushMatrix();
ManipulateViewAngle();
glTranslatef(bodyPos[0][i],-10.0,bodyPos[1][i]);//this will locate the spheres
glColor3f(1,0,0);//Color Red
glScalef(0.5,0.5,0.5);
glutSolidSphere(7,20,20);
glPopMatrix();
}
}
void DrawFood()
{
//Draw the Sphere representing the Food for the snake
glPushMatrix();
ManipulateViewAngle();
glTranslatef(_bx,-10.0,_bz);
glColor3f(1, 1, 0);
glScalef(0.5,0.5,0.5);
glutSolidSphere(7,20,20);
glPopMatrix();
}
void GameStatus(){
char tmp_str[40];
glColor3f(0.8, 0.2, 0);
glRasterPos2f(5, 20);
sprintf(tmp_str, "Snake Game");
Write(tmp_str);
// Print the status of the game on the screen
glColor3f(0, 0, 0);
glRasterPos2f(5, 10);
sprintf(tmp_str, "Level: %d Points: %d", lvl, points);
Write(tmp_str);

Dept of CSE, JCET, Hubballi 2022-23 Page 14


INTERACTIVE SNAKE GAME

}
//Generates Random Numbers for the location of the food that the snake will eat
int RandomNumber(int high, int low)
{
return (rand() % (high-low))+low;
}
//Generate the New Food that the snake will eat
void newFood(){
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
_bx = RandomNumber(_Gfw-_Giw, _Giw+10);
_bz = RandomNumber(_Gfh-_Gih, _Gih+10);
}
//This Function Will Check for Collision
bool collision(){
int i;
for(i=0; i<size; i++){
if((bodyPos[0][i] == _x && bodyPos[1][i] == _z) ||
//((bodyPos[0][i] >= _x) && (bodyPos[0][i] <= _x + 5) && (bodyPos[1][i] >= _z) &&
(bodyPos[1][i] <= _z + 5)) ||
//((bodyPos[0][i] <= _x) && (bodyPos[0][i] >= _x - 5) && (bodyPos[1][i] <= _z) &&
(bodyPos[1][i] >= _z - 5)) ||
//((bodyPos[0][i] <= _x) && (bodyPos[0][i] >= _x - 5) && (bodyPos[1][i] >= _z) &&
(bodyPos[1][i] <= _z + 5)) ||
((bodyPos[0][i] >= _x) && (bodyPos[0][i] <= _x + 5) && (bodyPos[1][i] <= _z) &&
(bodyPos[1][i] >= _z - 5)))
return true;
}
return false;
}
//This Function will move the snake according to the directions
//Taken from the Keyboard keys
void Run(int value){
int i;
_oldX[1] = _x;
_oldZ[1] = _z;
switch(direction){
case RIGHT:
headRotation =90;
_x += 6;
if(_x > _Gfw-2) _x = _Giw-1;//This will check if the snake is going into the border so it
will appear on the other side
break;
case LEFT:
headRotation =-90;

Dept of CSE, JCET, Hubballi 2022-23 Page 15


INTERACTIVE SNAKE GAME

_x -= 6;
if(_x < 0) _x = _Gfw-2;//This will check if the snake is going into the border so it will
appear on the other side
break;
case UP:
headRotation =0;
_z += 6;
if(_z > _Gfh-2) _z = _Gih-1;//This will check if the snake is going into the border so it will
appear on the other side
break;
case Down:
headRotation =180;
_z -= 6;
if(_z < 2) _z = _Gfh-2;//This will check if the snake is going into the border so it will
appear on the other side
break;
}
//Checks for Collisoin if yes Game Over
if(collision()) gameOver = true;
//Checks if the snake ate the food (check the X and Y)
// If yes it will increase the points & the size of the snake & create a new food
if((_x == _bx && _z == _bz) ||
((_x >= _bx) && (_x <= _bx + 4) && (_z >= _bz) && (_z <= _bz + 4)) ||
((_x <= _bx) && (_x >= _bx - 4) && (_z <= _bz) && (_z >= _bz - 4)) ||
((_x <= _bx) && (_x >= _bx - 4) && (_z >= _bz) && (_z <= _bz + 4)) ||
((_x >= _bx) && (_x <= _bx + 4) && (_z <= _bz) && (_z >= _bz - 4))){
points++;
if(points < 100) size++;
if(points%5 == 0 && lvl < 15) lvl++;
newFood();
}

for(i = 0; i<size; i++){// Save the positions of the body parts


_oldX[0] = _oldX[1];
_oldZ[0] = _oldZ[1];
_oldX[1] = bodyPos[0][i];
_oldZ[1] = bodyPos[1][i];
bodyPos[0][i] = _oldX[0];
bodyPos[1][i] = _oldZ[0];
}

//Set the Timer


glutTimerFunc(130, Run, 0);
}

void Display(void){//Draw Function

Dept of CSE, JCET, Hubballi 2022-23 Page 16


INTERACTIVE SNAKE GAME

// Clear screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(EnableLight) initLight();

glTranslatef (-60.0, 40.0, zoom);


//Check if the value of the Flag "Game Over is not True it will continue the game"
if(!gameOver){
GameStatus();
DrawFood();
DrawSnake();
}
else
WelcomeScreen();
// Updates the screen
glutPostRedisplay();
glutSwapBuffers();
}
void Special(int key, int x, int y){
switch(key){
case GLUT_KEY_RIGHT :
if(direction != LEFT)
direction = RIGHT;
break;
case GLUT_KEY_LEFT :
if(direction != RIGHT)
direction = LEFT;
break;
case GLUT_KEY_UP :
if(direction != UP)
direction = Down;
break;
case GLUT_KEY_DOWN :
if(direction != Down)
direction = UP;
break;
}
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'S' : Reset() ;
glutPostRedisplay();
break;
case 's' : Reset() ;

Dept of CSE, JCET, Hubballi 2022-23 Page 17


INTERACTIVE SNAKE GAME

glutPostRedisplay();
break;
//ESC to Exit
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(_w,_h);
glutInitWindowPosition(80,80);
glutCreateWindow("Snake Game");
Initialize();
glutSpecialFunc(Special);
glutKeyboardFunc(keyboard);
glutDisplayFunc(Display);
glutReshapeFunc(resize);
newFood();
Run(0);
glutMainLoop();
}

Dept of CSE, JCET, Hubballi 2022-23 Page 18


INTERACTIVE SNAKE GAME

CHAPTER-6
RESULT
SNAPSHOTS:

Fig. 6.1: Snapshot Showing the Instructions before Starting the Game.

Fig. 6.2: Snapshot Showing the Start of the Game.

Dept of CSE, JCET, Hubballi 2022-23 Page 19


INTERACTIVE SNAKE GAME

Fig. 6.3: Snake catching the first Food piece.

Fig. 6.4: Snapshot taken during the Gameplay.

Dept of CSE, JCET, Hubballi 2022-23 Page 20


INTERACTIVE SNAKE GAME

Fig. 6.5: Snapshot of the Snake after eating several Food pieces.

Fig. 6.6: Game Ends after the Snake Collides with itself.

Dept of CSE, JCET, Hubballi 2022-23 Page 21


INTERACTIVE SNAKE GAME

CONCLUSION
This project is an effort in the development of a Graphical Software package which is the
building block of graphical application. During the development of this package effort lead to
understanding the display of geometric primitives like rectangles, lines, line loops, polygon,
modes of display, features like translation were also designed. Various functions and operations
of the graphical library provide the learning platform to get the maximum performance of the
OpenGL functions.

The project “INTERACTIVE SNAKE GAME” has been successfully implemented using
OpenGL. The illustration of graphical principles and OpenGL features are included and
application program is efficiently developed.

This project enlightens the basic idea of scaling, rotation and translation of the objects.
Since it uses interaction with both keyboard and mouse it is sufficiently easy for any kind of end
user to run it.

However user requirement changes and provision for changes in design has been
allowed. If no major requirements are demanded from the user the current design holds. Thus
this project meets the basic requirements successfully and is flexible in all respects to one and
all. On conclusion this mini project is implemented with the standard OpenGL functions.

FUTURE ENHANCEMENTS
An attempt has been made to develop a Graphical Software package, which meets the
necessary requirement of the user successfully. The objects in the project can be flagged so that
we get a chance to be saved from a mine, we can also change the color and provide more effects.

Implementation of the other graphical effects will definitely enhance the representation
and view of the project. The mini project can further be enhanced to demonstrate the use of other
OpenGL functions of higher degree.

Since it is user friendly it enables the user to interact efficiently and easily. Thus the
package designed demonstrates the Basic Structures Orientation of some objects to the user.

Dept of CSE, JCET, Hubballi 2022-23 Page 22


INTERACTIVE SNAKE GAME

REFERENCES

[1] Computer Graphics–Principals And Practice (Foley, VanDam, Fenier and Hughes) helped me
to understand graphics generation algorithms, user interface and dialogue design.

[2] OpenGL Programming Guide(Addison-Wesley Publishing Company)helped me to get


through all OpenGL functions and Commands and understandings of all aspects of them.

[3] www.cplusplus.com:-provided references regarding all C++ functions and their uses.

[4] www.stackoverflow.com:-help to get rid of all types of error occurred regarding uses of
OpenGL functions.

[5] www.lighthouse3d.com:-OpenGL tutorial for implementing the OpenGL functions in Source


code.

Dept of CSE, JCET, Hubballi 2022-23 Page 23

You might also like