Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

VISVESVARAYA TECHNOLOGY UNIVERSITY

BELGAVI

A Computer Graphics and Visualization


Mini-Project Report
On
“Aeroplane Game”
A Mini-project report submitted in partial fulfilment of the requirements for the award of the
degree of Bachelor of Engineering in Computer Science and Engineering of Visvesvaraya
Technological University, Belgaum.

Submitted by:
MEGHANA K (1JS18CS080)
AND
PRAGATHI M R(1JS18CS107)

Under the Guidance of:


MR. VIKHYATH
AND
MR. SHARAN
(Asst. prof, Dept. of CSE)

Department of Computer Science and Engineering


JSS ACADEMY OF TECHNICAL EDUCATION
Dr. Vishnuvardhan Road, Uttarahalli
Bangalore-61
2020-2021
JSS ACADEMY OF TECHNICAL EDUCATION
Dr. Vishnuvardhan Road, Uttarahalli

DEPARTMENT OF COMPUTER SCIENCE &


ENGINEERING
(Accredited by NBA, New Delhi)

CERTIFICATE
This is to certify that the Mini-Project on Computer Graphics and Visualization
work entitled “Aeroplane Game” has been successfully carried out by Meghana
K (1JS18CS080) and Pragathi M R(1JS18CS107) a bonafide students of JSS
Academy of Technical Education in partial fulfilment of the requirements for
the award of degree in Bachelor of Engineering in Computer Science and
Engineering of Visvesvaraya Technological University, Belgaum during
academic year 2020-2021. It is certified that all corrections/suggestions
indicated for Internal Assessment have been incorporated in the report
deposited in the departmental library. The mini project report has been approved as
it satisfies the academic requirements in respect of project work for the said degree.

Prof. VIKHYATH K B Dr. NAVEEN N C


Prof. SHARAN (HOD, Dept. of CSE)
ACKNOWLEDGEMENT

We express our humble pranams to His Holiness Jagadguru Sri Sri Sri Shivaratri
Deshikendra Mahaswamiji for showering his blessings on us to receive good
education and have a successful career.

The completion of any project involves the efforts of many people. We have been lucky
enough to have received a lot of support from all ends during the course of this project.
So, we take this opportunity to express our gratitude to all whose guidance and
encouragement helped us emerge successful.

We are thankful for the resourceful guidance, timely assistance and graceful gesture of
our guide Mr. Vikhyath K B and Mr. Sharan, Assistant professor, Department of
Computer Science and Engineering, who helped us in every aspect of our project work.

We are also forever grateful to Dr. Naveen N. C., Head of the Department, Computer
Science and Engineering, for his unending support, guidance and encouragements in all
our ventures.

We express our sincere thanks to our beloved principal, Dr. Mrityunjaya V. Latte for
having supported us in all our academic endeavors.

Last but not the least; we would be immensely pleased to express our heartfelt thanks to
all the teaching and non-teaching staff of the department of CSE and our friends for
their timely help, support and guidance.

Meghana K (1JS18CS080)
Pragathi M (1JS18CS107)
ABSTRACT

The main theme of this project is to display the Aeroplane flying from one end to
another end or to reach the destination successfully with basic computer graphics.
This graphics package is based on the OpenGL library functions. The
programming language used here is C using OpenGL libraries.
In this game an Aeroplane flying from one end to another end and reach the
destination successfully by crossing all the obstacles which occur in the path of the
plane, the player has to control the plane upwards and downwards using the
keyboard to avoid the collision with obstacles.
This game consists of three levels in each level the speed of the plane as well as
the speed of the obstacles going to increase, if a collision occurs between plane and
obstacles then the game will be over. And in the end, it will show us the number of
levels successfully completed by the player.
TABLE OF CONTENTS
CHAPTER NO. CHAPTER NAME PAGE NO.
1. INTRODUCTION .....................................1
1.1 Introduction To OpenGL.................................... 1
1.2 Computer Graphics............................................. 1
1.3 A Brief History of OpenGL ................................. 2
1.3.1 What is OpenGL ..................................... 3
1.3.2 Programming using OpenGL………...4
1.4 OpenGL(Open Graphics Library)………….……4
2 REQUIREMENT SPECIFICATION……...5
2. 1 Hardware Requirements……………………………5
2. 2 Software Requirements………………………….5
3 SYSTEM DESIGN………………………..6
3.1 System Architecture…………………………….6

4 IMPLEMENTATION…………………….7
4.1 Implementation of OpenGL Built in functions used…..7
4. 2 Implementation of User Defined functions……..9
5 SNAPSHOTS……………………………11
5.1 Introduction………………………………………11
5.2 Menu…………………………………………….12
5.3 Moving Aeroplane…………………………….13
5.4 level completed…………………………………….13
5.5 Game over…………………………………………16
5.6 All levels Completion…………………………….16

6 FUCTURE ENHANCEMENT…………....…15
References…………………………………………...16
Appendix A.1:Source code…………………………..17
A.2: User Manual…………………………31
Aero-plane Game

CHAPTER 1
INTRODUCTION

1.1 INTRODUCTION TO OPEN-GL

Computer Graphics is a complex and diversified technology. To technology it is


necessary to subdivide it into manageable Parts. This can be accomplished by
considering that the end product of computer graphics is a picture. The picture may, of
course, be used for a large variety of purposes; e.g., it may be an engineering drawing,
an exploded parts illustration for a service manual, a business graph, an architectural
rendering for a proposed construction or design project, an advertising illustration, or
a single frame from an animated movie. The picture is the c2 fundamental cohesive
concept in computer graphics.
Consider how: Pictures are represented in computer graphics.
 Pictures are prepared for presentation.
 Previously prepared pictures are presented.
 Interaction with the picture is accomplished.
Here “picture” is used in its broadest sense to mean any collection of lines, points,
text, etc. displayed on a graphics device.

1.2 COMPUTER GRAPHICS


The totality of computer graphics software encompasses the concepts from data
structures, from data base design and management, from the psychology,
ergonometric of the man-machine interface, from programming languages and
operating system.
Numerous computer graphics standards can be grouped following categories.
 First is the graphics application interface, where ideas are translated into a
form that is understandable by a computer system. Current representative

[CSE, JSSATE] 2020-21 Page 1


Aero-plane Game

GKS-3D, and the Programmer’s Hierarchical Interactive Graphics Standards


(PHIGS).

 The Second is concerned with the storage and transmission of data between
graphics manufacturing systems. The current standard in this area is the
Initial Graphics Exchange Specification (IGES).
A computer graphics system is a computer system with all the components of the
general purpose computer system. There are five major elements in system: input
devices, processor, memory, frame buffer, output devices.

Fig. 1.1: A Graphics System

1.3 A BRIEF HISTORY OF OPENGL

OpenGL was developed by Silicon Graphics and is popular in the video games
industry where it competes with Direct3D on Microsoft Windows IrisGL, a
proprietary graphics API, is the precursor of OpenGL. It is developed by Silicon
Graphics Inc. (SGI). IrisGL was used as the starting point of an open standard for
computer graphics that would save time porting applications by avoiding direct
hardware access. After SGI cleaned up IrisGL and opened up the standard to other
companies, OpenGL was born.

[CSE, JSSATE] 2020-21 Page 2


Aero-plane Game

In 1992 the OpenGL Architectural Review Board (OpenGL ARB) was established.
The OpenGL ARB is a group of companies that maintain and update the OpenGL
standard.
In 2003 the first OpenGL (Exchange Specification) ES specification was released.
OpenGL ES is a subset of OpenGL designed for mobile phones, embedded devices and
video game systems.

In 2004 the OpenGL 2.0 specification was released, including the GLSL (OpenGL
Shading).
1.3.1. WHAT IS OPEN-GL?

 OpenGL is a Software Interface to Graphics Hardware


 OpenGL is designed as a streamlined, hardware-independent interface to be
implemented on many different hardware platforms
 It Consists of about 250 Distinct Commands.
 It is Hardware-independent Interface
o No command for windows or user input handling
o Does not include low-level I/O management
 It is developed primarily by SGI
 It consists of 2D/3D graphics, lower-level primitives (polygons)
 It is basis for higher-level libraries.
 What does it do?
 Main purpose is to render two and three dimensional objects into a frame
buffer. These objects are described as sequences of vertices (which define
geometric objects) or pixels (which define images).

[CSE, JSSATE] 2020-21 Page 3


Aero-plane Game

1.3.2 PROGRAMMING USING OPEN GL

OpenGL is an API Application programmers


interface.
It is a link between:
 low-level: graphics hardware
 high-level: application program you write
OpenGLisa

It is Library for 2D and 3D graphics programming.

 200+ functions for building application programs


 Portable to many platforms (Win, Mac, Unix, Linux)
 Callable from many programming languages (C,
Java,Perl, Python)

Operations
 Specify camera, light, color, texture information, etc.
 No windowing or (platform-specific) input/interaction
 functions— these are the jobs of GLUT
 Apply geometric transformations.
 Specify geometric primitives (lines, pixels, polygons ...)

1.4 OPENGL-RELATED LIBRARIES

OpenGL provides a powerful but primitive set of rendering commands, and all
higher-level drawing must be done in terms of these commands. Also, OpenGL
programs have to use the underlying mechanisms of the windowing system.
A number of libraries exist to allow you to simplify your programming tasks,
including the following:

 The OpenGL Utility Library (GLU) contains several routines that use lower-
level OpenGL commands to perform such tasks as setting up matrices for
[CSE, JSSATE] 2020-21 Page 4
Aero-plane Game
specific viewing orientations and projections, performing polygon tessellation,
and rendering surfaces. GLU routines use the prefix glu.
 The OpenGL Utility Toolkit (GLUT) is a window system-independent
toolkit, written by Mark Kilgard, to hide the complexities of differing
window system APIs.
 GLUT is the subject of the next section, and it’s described in more detail in
Mark Kilgard’s book OpenGL Programming for the X Window System
(ISBN 0-201-48359-9).
 GLUT routines use the prefix glut. "How to Obtain the Sample Code" in the
Preface describes how to obtain the source code for GLUT, using ftp.

[CSE, JSSATE] 2020-21 Page 5


Aero-plane Game

CHAPTER 2

REQUIREMENTS SPECIFICATION

2.1 HARDWARE REQUIREMENTS:


 Intel® Pentium 4 CPU or higher versions
 128 MB or more RAM.
 A standard keyboard, and Microsoft compatible mouse
 VGA monitor.

2.2 SOFTWARE REQUIREMENTS:


 The graphics package has been designed for OpenGL; hence the
machine must Have code blocks
 Software installed preferably 6.0 or later versions with mouse driver installed.

 GLUT libraries, Glut utility toolkit must be available.


 Operating System: Windows
 Language: C

2.3 MISCELLANEOUS REQUIREMENTS:


All the required library and header files should be available in the include
directories. The files associated with this editor should be placed in either the same
folder or in a specified folder.

2.4 LANGUAGE USED IN CODING:


C/C++ and OpenGL as an API.

[CSE, JSSATE] 2020-21 Page 6


Aero-plane Game

CHAPTER 3
SYSTEM DESIGN
Design of any software depends on the architecture of the machine on which that
software runs, for which the designer needs to know the system architecture. Design
process involves design of suitable algorithms, modules, subsystems, interfaces etc.

3.1 SYSTEM ARCHITECTURE

CONTROL FLOW DIAGRAM

Fig. 3.1: System Control flow diagram

[CSE, JSSATE] 2020-21 Page 7


Aero-plane Game

CHAPTER 4
IMPLEMENTATION

The implementation stage of this model involves the following phases.


 Implementation of OpenGL built in functions.
 User defined function Implementation.

4.1 IMPLEMENTATION OF OPENGL BUILT IN FUNCTIONS


USED:

1. glutInit():
 glutInit is used to initialize the GLUT Library.
 Usage: void glutInit(int *argcp, char **argv);
 Description: glutInit will initialize the GLUT library and negotiate a session
with the window system.

2. glutInitDisplayMode():
 glutInitDisplayMode sets the initial display mode.
 Usage: void glutInitDisplayMode(unsigned int mode);
 Mode-Display mode, normally the bitwise OR-ing of GLUT display mode bit
masks.
 Description: The initial display mode is used when creating top-level
windows, sub windows, and overlays to determine the OpenGL display mode
for the to-be-created window or overlay.

3. glutCreateWindow():
 It creates top level window.
 Usage: int glutCreateWindow(char *name);
 Name - ASCII character string for use as window name.
 Description: glutCreateWindow creates a top-level window. The name will
be provided to the window system as the window's name. The intent is that
the window system will label the window with the name. Implicitly, the
current window is set to the newly created window. Each created window
has a unique associated OpenGL context.
[CSE, JSSATE] 2020-21 Page 7
Aero-plane Game

4. glutDisplayFunc():
 glutDisplayFunc sets the display callback for the current window.
 Usage: void glutDisplayFunc(void (*func)(void));
 Func – The new display callback function.
 Description: glutDisplayFunc sets the display callback for the current
window. When GLUT determines that the normal plane for the window
needs to be redisplayed, the display callback for the window is called. Before
the callback, the current window is set to the window needing to be
redisplayed and the layer in use is set to the normal plane. The display
callback is called with no parameters. The entire normal plane region should
be redisplayed in response to the callback.

5. glutMainLoop():
 glutMainLoop() enters the GLUT event processing loop.
 Usage: void glutMainLoop(void);
 Description: glutMainLoop enters the GLUT event processing loop. This
routine should be called at most once in a GLUT program. Once called,
this routine will never return. It will call as necessary any callbacks that
have been registered.

6. glMatrixMode( ):
The two most important matrices are the model-view and projection matrix. At
any time, the state includes values for both of these matrices, which are initially set
to identity matrices. There is only a single set of functions that can be applied to
any type of matrix. Select the matrix to which the operations apply by first set in
the matrix mode, a variable that is set to one type of matrix and is also part of the
state.

7. glutTimerFunc();

 glutTimerFunc registers a timer callback to be triggered in a specified number of


milliseconds.
 Usage: void glutTimerFunc(unsigned int msecs, void (*func)(int value), value);

CSE, JSSATE 2020-21 Page 8


Aero-plane Game

Description: glutTimerFunc registers the timer callback func to be triggered in


at least msecs milliseconds. The value parameter to the timer callback will be the
value of the value parameter to glutTimerFunc. Multiple timer callbacks at same
or differing times may be registered simultaneously. The number of milliseconds
is a lower bound on the time before the callback is generated. GLUT attempts to
deliver the timer callback as soon as possible after the expiration of the callback's
time interval. There is no support for canceling a registered callback. Instead,
ignore a callback based on its value parameter when it is triggered.

4.2 IMPLEMENTATION OF USER DEFINED FUNCTIONS:


1. void Init():

Here the initialization function init() is used to set the OpenGL state variables
dealing with viewing and attributes-parameters that is prefered to set once,
independently of the display function.

2. void plane():

Here the function plane() is used to draw the elements of plane it basically uses
OpenGL glVertex() having ‘x’ and ‘y’ attributes specifying ‘x’ and ‘y’ co-ordinate
position respectively and we use glColor3f() to give color to the plane.

3. void obstacles():

Basically this function is used to draw blocks on the Screen by calling glVertex()
function and we use glColor3f() to give color to the blocks.

4. void mov():

This function contains the logic for the movement of planes and obstacles. we use
some of flags to implement it. This also contains the logic for collision between
plane and obstacle.
5. void moveup(void):
This function is used to move the aeroplane upwards. Here we have used
glLoadIdentity() function.
CSE, JSSATE 2020-21 Page 9
Aero-plane Game

6.void movedown(void):
This function is used to move the aeroplane upwards. Here we have used
glLoadIdentity() function.

8. void screen():

This functions is used to style main page of our game. This page contains
drawstring() and glColor3f() function .

8.msg(),msg1(),msg2(),msg3():
These function gives “LEVEL COMPLETED", "GAME OVER RETRY",
"Player completed 1 level", "Player completed 2 level" respectively. These
contains drawstring() and glColor3f() function .

9.Display():
In this function we have used the flag and depending on the flag the corresponding
frame is displayed on the screen.

10. void key( unsigned char key, int x, int y ):


This function has following parameters char which represents the the character on
the keyboard depending up the character we have pressed the corresponding flag
bit is enabled and the content is displayed accordingly x and y are the pixel position.

11. int main(argc, char ** argv):


This is the function from where the execution of the program begins. In this function we
have certain “gl” functions used to initialize the basic glut window with desired
properties. After initialization the display function is called with respect to the window
and finally the last statement of this section is the glutMainLoop(). Which is an event
processing function that enters into an infinite loop.

CSE, JSSATE 2020-21 Page 10


Aero-plane Game

CHAPTER 5
SNAPSHOTS

Fig. 5.1: Introduction


Explanation of the figure:
This figure shows the Project title, name of the team members along with their USN
and the department name. It also suggest how to continue by “PRESS ‘a’ TO START
GAME”.

CSE, JSSATE 2020-21 Page 11


Aero-plane Game

Fig. 5.2: Menu

This figure shows the menu of the project in which,

 By pressing ‘a’ we can start the game and also resume the movement of blocks.
 By pressing ‘w’ for moving aeroplane upwards.
 By pressing ‘s’ for moving aeroplane downwards.
 By pressing ‘m’ we can stop movement of blocks.
 By pressing ‘l’ or ’L’ we can go to next level.
 By pressing ‘e’ to exit.

CSE, JSSATE 2020-21 Page 12


Aero-plane Game

This figure shows the movement of blocks and aeroplane.

Fig. 5.3: Moving Aeroplane

This figure shows message for level completion.

Fig. 5.4: Level completed

CSE, JSSATE 2020-21 Page 13


Aero-plane Game

This figure shows the message for game over.

Fig. 5.5: Game Over

This figure shows the message for game completion.

Figure5.6: All Level completion

CSE, JSSATE 2020-21 Page 14


Aero-plane Game

CHAPTER 6

FUTURE ENHANCEMENT

We have implemented the essential features of collision in Aeroplane Game of our best
knowledge. Even still, we would like to enhance the quality and appearance of the
game in the following ways:

 3D View
 Design of Aeroplane
 Lighting and shading
 Background modification and speed modification

CSE, JSSATE 2020-21 Page 15


Aero-plane Game

REFERENCES
Books:
 Computer Graphics with OpenGL Version,3rd Edition, Donald Hearn &
Pauline Baker
 Interactive Computer Graphics-A Top Down approach with OpenGL,5rd
Edition,Edward Angel

Websites:
1. http://www.amazon.in/Computer-Graphics-

Multimedia-Udit-
Agarwal/dp/935014316X?tag=googinhydr18418-
21
2. http://en.wikipedia.org/wiki/Computer_graphics
3. http://stackoverflow.com/questionsquickly
4. http://www.opengl-tutorial.org/intermediate-tutorials/
5. http://www.opengl-tutorial.org/
6. https://open.gl/

7. http://www.cs.uccs.edu/~ssemwal/indexGLTutorial.html
8. http://www.videotutorialsrock.com/
9. http://ogldev.atspace.co.uk/
10. https://www.opengl.org/sdk/docs/tutorials/

11. http://learnopengl.com/
12. http://lazyfoo.net/tutorials/OpenGL/
13. http://en.wikibooks.org/wiki/OpenGL_Programming
14. https://youtu.be/khergS0bZIk

CSE, JSSATE 2020-21 Page 16


Aero-plane Game

A.1 SOURCE CODE


#include<stdio.h>
#include<stdlib.h>
#include<GL/glut.h>
#include<math.h>
GLfloat a=0,b=5,c=10,d=40,e=45,f=40,g=15,h=20,i=15,j=15,k=20,l=15; //x-co-ordinate of plane
GLfloat
a1=310,b1=270,c1=290,d1=290,e1=280,f1=270,g1=290,h1=290,i1=310,p1=270,k1=270,l1=250; //y
co-ordinates of plane
GLfloat
x11=470,x12=480,x13=600,x14=620,x15=590,x16=600,x17=650,x18=660,x19=610,x20=630,x21=5
80,x22=600; //x co-ordinates of obstacles
GLfloat
y11=270,y12=290,y13=230,y14=250,y15=330,y16=350,y17=450,y18=470,y19=490,y20=510,y21=1
70,y22=190; // y co-ordinates of obstacles
GLint flag=0,flag1=0,flag2=0,flag3=0,flag5=1,flag4=0,flag6=0;
GLfloat sp1=0.05,sp2=0.07,sp3=0.0625;
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,600,0,600);
glMatrixMode(GL_MODELVIEW);
}
void drawstring(float x,float y,float z,char *string)
{
char *c;
glRasterPos3f(x,y,z);
for(c=string;*c!='\0';c++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*c);
}
}
void screen()
{
glColor3f(0.0,0.8,1.0);
drawstring(207,525,0.0,"CG MINI PROJECT ON AEROPLANE GAME");
glColor3f(1.0,0.0,1.0);
drawstring(200,460,0.0,"NAME");

CSE, JSSATE 2020-21 Page 17


Aero-plane Game

drawstring(346,460,0,"USN");
glColor3f(1.0,1.0,1.2);
drawstring(180,420,0.0,"MEGHANA K");
drawstring(340,420,0,"1JS18CS080");
drawstring(180,370,0.0,"PRAGATHI M R");
drawstring(340,370,0.0,"1JS18CS107");

glColor3f(1.0,0.0,1.0);
drawstring(450,460,0.0,"Key");
drawstring(500,460,0,"Description");
glColor3f(1.0,1.0,1.2);
drawstring(450,420,0.0,"a");
drawstring(500,420,0,"To start the game ");
drawstring(450,370,0.0,"w");
drawstring(500,370,0.0,"To move up");
drawstring(450,320,0.0,"s");
drawstring(500,320,0,"To move down");
drawstring(450,270,0.0,"m");
drawstring(500,270,0.0,"To stop movement of blocks");
drawstring(450,230,0.0,"a");
drawstring(500,230,0.0,"To start movement of blocks");
drawstring(450,190,0.0,"L");
drawstring(500,190,0.0,"Next level");
drawstring(450,140,0.0,"e");
drawstring(500,270,0.0,"To exit");
glColor3f(1.0,0.0,1.0);
drawstring(240,310,0.0,"UNDER THE GUIDENCE OF");
glColor3f(1.0,1.0,1.2);
drawstring(260,270,0.0,"Prof: VIKHYATH K
B"); drawstring(260,230,0.0,"Prof: SHARAN");
glColor3f(0.0,0.8,1.0);
drawstring(175,130,0.0,"DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING");
drawstring(240,80,0.0,"ACADEMIC YEAR: 2020-2021");
glColor3f(rand()%2,rand()%3,rand()%2);
drawstring(245,35,0.0,"Press 'a' to start the game");
glFlush();
}
void msg()
{

CSE, JSSATE 2020-21 Page 18


Aero-plane Game

glColor3f(1.0,0.2,0.0);
drawstring(250,300,0.0,"CONGRATULATIONS");
drawstring(250,250,0.0,"LEVEL COMPLETED");
drawstring(250,200,0.0,"Press 'L' to start Next Level");
}
void msg1()
{
glColor3f(1.0,0.6,0.6);
drawstring(250,300,0.0,"GAME OVER RETRY");
drawstring(250,270,0.0,"PRESS 'e' TO EXIT");
}
void msg2()
{
glColor3f(1.0,0.6,0.6);
drawstring(250,320,0.0,"GAME OVER");
drawstring(250,280,0.0,"Player completed 1 level");
drawstring(250,250,0.0,"PRESS 'e' TO EXIT");
}
void msg3()
{
glColor3f(1.0,0.6,0.6);
drawstring(250,320,0.0,"GAME OVER");
drawstring(250,280,0.0,"Player completed 2 level");
drawstring(250,250,0.0,"PRESS 'e' TO EXIT");
}

void plane()
{

glColor3f(1.0,0.5,0.0);
glBegin(GL_POLYGON);
glVertex2f(a,a1);
glVertex2f(b,b1);
glVertex2f(c,c1);
glEnd();
glColor3f(0.5,0.5,1.0);
glBegin(GL_POLYGON);
glVertex2f(c,c1);
glVertex2f(d,d1);
glVertex2f(e,e1);
CSE, JSSATE 2020-21 Page 19
Aero-plane Game

glVertex2f(f,f1);
glVertex2f(b,b1);
glEnd();
glColor3f(0.6,0.0,0.0);
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(g,g1);
glVertex2f(i,i1);
glVertex2f(h,h1);
glEnd();
glColor3f(0.6,0.0,0.0);
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(j,p1);
glVertex2f(l,l1);
glVertex2f(k,k1);
glEnd();
glColor3f(1.0,0.5,0.0);
glBegin(GL_POLYGON);
glVertex2f(a,d1);
glVertex2f(b,b1);
glVertex2f(c,f1);
glEnd();
glutPostRedisplay();
}
void obstacle()
{
glColor3f(rand()%100,0.44,rand()%50);
glBegin(GL_POLYGON);
glVertex2f(x11,y11);
glVertex2f(x12,y11);
glVertex2f(x12,y12);
glVertex2f(x11,y12);
glEnd();
glColor3f(rand()%100,rand()%50,0.65);
glBegin(GL_POLYGON);
glVertex2f(x13,y13);
glVertex2f(x14,y13);
glVertex2f(x14,y14);
glVertex2f(x13,y14);
glEnd();
glColor3f(0.7,rand()%100,rand()%200);
CSE, JSSATE 2020-21 Page 20
Aero-plane Game

glBegin(GL_POLYGON);
glVertex2f(x15,y15);
glVertex2f(x16,y15);
glVertex2f(x16,y16);
glVertex2f(x15,y16);
glEnd();
glColor3f(rand()%60,0.6,rand()%100);
glBegin(GL_POLYGON);
glVertex2f(x17,y17);
glVertex2f(x18,y17);
glVertex2f(x18,y18);
glVertex2f(x17,y18);
glEnd();
glColor3f(rand()%70,rand()%200,rand()%300);
glBegin(GL_POLYGON);
glVertex2f(x19,y19);
glVertex2f(x20,y19);
glVertex2f(x20,y20);
glVertex2f(x19,y20);
glEnd();
glColor3f(rand()%70,rand()%200,rand()%300);
glBegin(GL_POLYGON);
glVertex2f(x21,y21);
glVertex2f(x22,y21);
glVertex2f(x22,y22);
glVertex2f(x21,y22);
glEnd();

glutPostRedisplay();

void moveup(void)
{
glLoadIdentity();
a1=a1+20;
b1=b1+20;
c1=c1+20;
d1=d1+20;
e1=e1+20;
CSE, JSSATE 2020-21 Page 21
Aero-plane Game

f1=f1+20;
g1=g1+20;
h1=h1+20;
i1=i1+20;
p1=p1+20;
k1=k1+20;
l1=l1+20;
if(a1>600)
flag2=1;
glutPostRedisplay();
}
void movedown(void)
{
glLoadIdentity();
a1=a1-20;
b1=b1-20;
c1=c1-20;
d1=d1-20;
e1=e1-20;
f1=f1-20;
g1=g1-20;
h1=h1-20;
i1=i1-20;
p1=p1-20;
k1=k1-20;
l1=l1-20;
if(b1<0||f1<0)
flag2=1;
glutPostRedisplay();
}

void key(unsigned char k,int x,int y)


{
switch(k)
{

case 'w':
if(k=='w')
moveup();
break;
CSE, JSSATE 2020-21 Page 22
Aero-plane Game

case 's': if(k=='s')


movedown();
break;
case 'a':flag=1;
flag1=1;
flag6=0;
break;
case 'm':if(k=='m')
flag6=1;
break;
case 'e':
exit(0);
case 'l':
flag5=1;
flag1=1;
break;
}
}

void mov()
{ //PLANE MOV
if(flag1==1)
{

if(a<600||b<600||c<600||d<600||e<600||f<600||g<600||h<600||i<600||j<600||k<600||l<600)
{
a=a+sp3;
b=b+sp3;
c=c+sp3;
d=d+sp3;
e=e+sp3;
f=f+sp3;
g=g+sp3;
h=h+sp3;
i=i+sp3;
j=j+sp3;
k=k+sp3;
l=l+sp3;

}
CSE, JSSATE 2020-21 Page 23
Aero-plane Game

//OBSTACLE MOV
if(flag6!=1)
{
if(x11>=0||x12>=0)
{
x11=x11-sp1;
x12=x12-sp1;
}
else
{
x11=600;
x12=610;
if(y11<590)
{
y11=y11+40;
y12=y12+40;
}
else
{
y11=270;
y12=290;
}
}
if(x13>=0||x14>=0)
{
x13=x13-sp2;
x14=x14-sp2;
}
else
{
x13=600;
x14=620;
if(y13<590)
{
y13=y13+40;
y14=y14+40;
}
else
{

CSE, JSSATE 2020-21 Page 24


Aero-plane Game

y13=230;
y14=250;
}
}
if(x15>=0||x16>=0)
{
x15=x15-sp1;
x16=x16-sp1;
}
else
{
x15=590;
x16=600;
if(y15<610)
{
y15+=40;
y16+=40;
}
else
{
y15=330;
y16=350;
}
}
if(x17>=0||x18>=0)
{
x17=x17-sp1;
x18=x18-sp1;
}
else
{
x17=650;
x18=660;
if(y17<610)
{
y17+=40;
y18+=40;
}
else
{
CSE, JSSATE 2020-21 Page 25
Aero-plane Game

y17=230;
y18=250;
}
}
if(x19>=0||x20>=0)
{
x19=x19-sp2;
x20=x20-sp2;
}
else
{
x19=580;
x20=600;
if(y19<570)
{
y19+=40;
y20+=40;
}
else
{
y19=170;
y20=190;
}
}
if(x21>=0||x22>=0)
{
x21=x21-sp2;
x22=x22-sp2;
}
else
{
x21=580;
x22=600;
if(y21<610)
{
y21+=40;
y22+=40;
}
else
{
CSE, JSSATE 2020-21 Page 26
Aero-plane Game

y21=170;y22=190;
}
//COLISSION
if((d>x11&&d1==y12&&d<x12)||(f>x11&&f1==y11&&f<x12)||(d>x11&&d1==y11&&d<x12
)||(f>x11&&f1==y12&&f<x12)||(c>x11&&c1==y12&&c<x12)||(b>x11&&b1==y12&&b<x12)||(c>x
11&&c1==y11&&c<x12)||(b>x11&&b1==y12&&b<x12)||(a>x11&&a1==y11&&a<x12))
flag2=1;

else
if((d>x13&&d1==y14&&d<x14)||(f>x13&&f1==y13&&f<x14)||(d>x13&&d1==y13&&d<x14)||(f>x
13&&f1==y14&&f<x14)||(c>x13&&c1==y14&&c<x14)||(b>x13&&b1==y14&&b<x14)||(c>x13&&
c1==y13&&c<x14)||(b>x13&&b1==y13&&b<x14)||(a>x13&&a1==y13&&a<x14))
flag2=1;

else
if((d>x15&&d1==y16&&d<x16)||(f>x15&&f1==y15&&f<x16)||(d>x15&&d1==y15&&d<x16)||(f>x
15&&f1==y16&&f<x16)||(c>x15&&c1==y16&&c<x16)||(b>x15&&b1==y16&&b<x16)||(c>x15&&
c1==y15&&c<x16)||(b>x15&&b1==y15&&b<x16)||(a>x15&&a1==y15&&a<x16))
flag2=1;

else
if((d>x17&&d1==y18&&d<x18)||(f>x17&&f1==y17&&f<x18)||(d>x17&&d1==y17&&d<x18)||(f>x
17&&f1==y18&&f<x18)||(c>x17&&c1==y18&&c<x18)||(b>x17&&b1==y18&&b<x18)||(c>x17&&
c1==y17&&c<x18)||(b>x17&&b1==y17&&b<x18)||(a>x17&&a1==y17&&a<x18))
flag2=1;

else
if((d>x19&&d1==y20&&d<x20)||(f>x19&&f1==y19&&f<x20)||(d>x19&&d1==y19&&d<x20)||(f>x
19&&f1==y20&&f<x20)||(c<x19&&c1==y20&&c>x20)||(b>x19&&b1==y20&&b<x20)||(c>x19&&
c1==y19&&c<x20)||(b>x19&&b1==y19&&b<x20)||(a>x19&&a1==y19&&a<x20))
flag2=1;

else
if((d>x21&&d1==y21&&d<x22)||(f>x21&&f1==y21&&f<x22)||(d>x21&&d1==y21&&d<x22)||(f>x
21&&f1==y22&&f<x22)||(c<x21&&c1==y22&&c>x22)||(b>x21&&b1==y22&&b<x20)||(c>x21&&
c1==y22&&c<x22)||(b>x21&&b1==y21&&b<x22)||(a>x21&&a1==y21&&a<x22))
flag2=1;

CSE, JSSATE 2020-21 Page 27


Aero-plane Game

if(a>=600)
{
sp3=sp3+0.03125;
sp1=sp1+0.07;
sp2=sp2+0.08;
if(sp3>0.125)
{
flag4=1;
}
a=0,b=5;c=10;d=40;e=45;f=40;g=15;h=20;i=15,j=15,k=20,l=15;
a1=310;b1=270;c1=290;d1=290;e1=280;f1=270;g1=290;h1=290;i1=310,p1=270,k1=270,l1=250;

x11=470;x12=480;x13=520;x14=540;x15=590;x16=600;x17=650;x18=660;x19=610;x20=630,
x21=580;x22=600;

y11=270;y12=290;y13=230;y14=250;y15=330;y16=350;y17=450;y18=470;y19=490;y20=510;
y21=170;y22=190;
flag3=0;
flag5=0;
}
}

glutPostRedisplay();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,0.0,0.0,0.0);

if(flag==0)
{
screen();
}
if(flag1==1)
{
plane();

CSE, JSSATE 2020-21 Page 28


Aero-plane Game

obstacle();
}
if(flag2==1&&sp3==0.0625)
{
flag1=0;
msg1();
}
if(flag2==1&&sp3==0.09375)
{
flag1=0;
msg2();
}
if(flag2==1&&sp3==0.125)
{
flag1=0;
msg3();
}
if(flag5==0)
{
flag1=0;
msg();
flag3=1;
}
if(flag4==1)
{
flag=1;
flag1=0;
flag2=0;
flag5=1;
drawstring(250,330,0.0,"Congrats");
drawstring(210,300,0.0,"Player Completes All 3 Levels");
}
glFlush(); }
int main (int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1366, 400);

CSE, JSSATE 2020-21 Page 29


Aero-plane Game

glutInitWindowPosition(0,0);
glutCreateWindow("plane");
init();

glutDisplayFunc(display);
glutIdleFunc(mov);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}

CSE, JSSATE 2020-21 Page 30


Aero-plane Game

A.2 USER MANUAL


Enter ‘a’ key on the visualizer window, you can start the game.

1. ‘1’ and ‘0’ for move up and down respectively


2. ‘m’ to stop movement of block
3. ‘l’ or ‘L’ to move to next level
4. ‘e’ to Quit

Depending on the selection the corresponding output will be displayed.

CSE, JSSATE 2020-21 Page 31

You might also like