Chapter – 1:
Introduction
2) A snowman like doll will keep moving and the user has to target the doll.
3) If the user misses the target ten times the game is over.
4) At each level user has to get ten points to pass on to next level.
6) Scores are allocated on the basis of the number of times the user hits the target. One
point each for hitting the target once.
7) User can also take a break in between the game by right clicking the mouse button.
9) Scores and the level number will be displayed on the executable window to help the
user.
1.2 Input:
Input to this game is keyboard and mouse.
Keyboard for movement and zooming of render scene and provide the pause
and resume option.
Mouse for shoot the snowman
1.3 Output:
Output is nothing but game’s aim that is to show Scores and the level number
will be displayed on the executable window to help the user.
1
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
1.4 Goal:
demonstrates the shooting of snowman, which includes features like display
snowman, and shoot that snowman. Which includes different levels in each levels
speed increases and show Scores and the level number will be displayed on
the executable window to help the user.
2
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Chapter – 2:
Literature Survey
Chapter – 3:
Analysis
Requirements in detail
• Computer : IBM Compatible
• Micro Processor : Pentium 1 Onwards/amd
• CPU Clock : 166MHZ Onwards
• RAM : 32 MB or Higher
• Hard Disk Driver : 2 GB or Higher
• VGA Adapter : Intel 82810 graphics
controller(minimum)
• Monitor : Standard VGA Monitor
• Keyboard : 102 Keys Keyboard
• 3-Button mouse : yes
4
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
OPENGL uses a header file called GLUT.H which involves all primitive
functions, which helps in development of graphical packages, also no overhead in
implementing the manual graphical functions. GLUT is used to interface the window
system and to get input from external devices into our programs.
5
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Chapter – 4:
Design
STAR
T
Set window
system parameter
initScene(); A
glutDisplayFunc
(drawScene) B
glutMouseFunc
C
(inputMouse)
glutTimer
Func(10,timer,10 D
0)
STOP
6
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
A B
drawScene();
initScene();
drawSnowMan()
;
Set enabling features
using glEnable() R
glTranslatef(x+=speed
flag ,y,z)
L =?
glTranslatef(x-
RETURN =speed,y,z);
drawSnowMan()
;
RETURN
7
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
C D
inputMouse() timer()
drawScene();
If
button==GLUT_LE
FT_BUTTON&&stat
e==GLUT_DOWN
F
xp>=(posX-
0.75)&&(xp<=pos
X+0.75)&&posY> miss=miss-1
=0&&posY<=2.6
hit=hit+1
return()
8
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
This module:
initsScene()
drawScene()
changeSize()
inputMouse()
void drawScene(void)
This module:
9
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
void drawSnowMan(void)
This module:
void initScene()
This module:
GL_DEPTH_TEST
GL_LIGHTING
GL_LIGHT0
GL_COLOR_MATERIAL
10
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Chapter – 5:
Implementation
A Bitmap is a ones and zeros representation of points (pixels, short for ‘picture
elements’) on the screen. Bitmap graphics provide easy-to-use and inexpensive
graphics based applications
This allowed users to switch among multiple activities just by pointing at the
desired window, typically with the mouse. Graphics provides one of the most natural
means of communicating with the computer, since our highly developed 2D and 3D
pattern – recognition abilities allow us to perceive and process pictorial data rapidly
and efficiently. In many design, implementation, and construction processes, the
information pictures can give is virtually indispensable.
#include<windows.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
//lighting
GLfloat LightAmbient[]={0.2f,0.2f,0.2f,0.0f};
GLfloat LightDiffuse[]={0.8f,0.8f,0.8f,0.0f};
GLfloat LightPosition[]={1.0f,-0.5f,-0.5f,0.0f};
float angle=0.0;
float x=0.0f,y=2.0f,z=0.0f;
float lx=0.0f,ly=0.0f,lz=-1.0f;
13
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
float ratio;
char s[30];
float xp=-12,yp=0,zp=-25;
int mis=0,hit=0,hits;
int score[2];
float speed=0.08;
int i=1;
int state;
int game_over=0;
int ntpause=0;
int flag=0;
GLuint DLid;
GLuint createDL(void);
ratio = 1.0f * w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
14
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);
}
void initScene()
{
glEnable(GL_DEPTH_TEST);
////g_blighting=true;
//glLightfv(GL_LIGHT0,GL_AMBIENT,LightAmbient);
//glLightfv(GL_LIGHT0,GL_DIFFUSE,LightDiffuse);
//glLightfv(GL_LIGHT0,GL_POSITION,LightPosition);
//
//glLightfv(GL_LIGHT0,GL_POSITION,LightPosition);
////two the side
//glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
//glEnable (GL_LIGHTING);
// glEnable (GL_LIGHT0);
//
}
void drawSnowMan()
{
//glColor3f(0.7f, .8f, .0f);
glColor3f(.5f, .5f, .5f);
// Draw Body
glTranslatef(0.0f ,0.75f, 0.0f);
glutSolidSphere(0.75f,20,20);
// Draw Head
15
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
// Draw Eyes
glPushMatrix();
glColor3f(0.0f,0.0f,0.0f);
glTranslatef(0.05f, 0.10f, 0.18f);
glutSolidSphere(0.05f,10,10);
glTranslatef(-0.1f, 0.0f, 0.0f);
glutSolidSphere(0.05f,10,10);
glPopMatrix();
// Draw Nose
glColor3f(1.0f, 0.f , 0.f);
glRotatef(0.0f,1.0f, 0.0f, 0.0f);
glutSolidCone(0.08f,0.5f,10,2);
}
GLuint createDL()
{
GLuint snowManDL,loopDL;
snowManDL = glGenLists(1);
loopDL = glGenLists(1);
glNewList(snowManDL,GL_COMPILE);
drawSnowMan();
glEndList();
glNewList(loopDL,GL_COMPILE);
glPushMatrix();
if(xp>=12)
16
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
flag=1;
if(xp<=-12)
flag=0;
if(flag==0)
glTranslatef(xp+=speed,yp,zp); //from left to right.
if(flag==1)
glTranslatef(xp-=speed,yp,zp); //from right to left.
if(flag==-1)
glTranslatef(xp,yp,zp); //pause the game.
glCallList(snowManDL);
glPopMatrix();
glEndList();
return(loopDL);
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1.0f, 0.0f, 0.0f);
glTranslatef(9.0,1.0,-16.0);
glutSolidCube(1);
drawSnowMan(); //draw RIGHT stil doll
glPopMatrix();
glPushMatrix();
glColor3f(1.0f, 0.0f, 0.0f);
glTranslatef(-9.0,1.0,-16.0);
glutSolidCube(1);
drawSnowMan(); //draw LEFT stil doll
glPopMatrix();
17
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
// Draw ground
glColor3f(0.9f, 0.9f, 0.9f);
glBegin(GL_QUADS);
glVertex3f(-13.0f, 0.0f, -27.0f);
glVertex3f(-13.0f, 0.0f, 10.0f);
glVertex3f( 13.0f, 0.0f, 10.0f);
glVertex3f( 13.0f, 0.0f, -27.0f);
glEnd();
glColor3f(0.0f, 0.0f, 1.0f);
glColor3f(0.0f, 0.0f, 0.4f);
DLid = createDL();
glCallList(DLid);
glColor3f(1.0,0.0,0.0);
glRasterPos3i(-10,8,-20);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'S'); //To Display
the score..
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'C');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'O');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'R');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' ');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,':');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' ');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,score[1]+48);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,score[0]+48);
glRasterPos3i(-4,8,-20);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'L'); //To Display the
level.
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'V');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'L');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' ');
18
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,':');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' ');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,(i-1)+48);
glRasterPos3i(2,8,-20);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'M'); //To
Display the missed..
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'I');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'S');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'S');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'D');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,':');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' ');
if (mis==10)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,1+48);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,0+48);}
else
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,mis+48);
if(flag==-1 &&ntpause==0)
{
glRasterPos3i(7,8,-20);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'P');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'A');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'U');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'S');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'D');
}
if(game_over==1)
{
glRasterPos3i(7,8,-20);
19
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'G');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'A');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'M');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'E');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,' ');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'O');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'V');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'E');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'R');
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'!');
}
glutSwapBuffers();
}
void orientMe(float ang)
{
lx = sin(ang);
lz = -cos(ang);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);
}
void times(int p)
{
renderScene();
//glutPostRedisplay();
glutTimerFunc(10,times,p);
}
void moveMeFlat(int i) {
x = x + i*(lx)*0.1;
z = z + i*(lz)*0.1;
glLoadIdentity();
gluLookAt(x, y, z,
20
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
21
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
hit++;
printf("Your Score is %d\n\n",hit);
hits=hit;
if(hit==10*i)
{
speed+=0.03;
i++;
}
int j=0;
while(hits>0)
{
score[j]=hits%10;
hits/=10;
//printf("%d\n",score[j]);
j++;
}
}
else
{
mis++;
if(mis==10)
{
game_over=1;
flag=-1;
ntpause=1;
}
printf("Sorry..U missed it..\n\n");
}
}
22
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
}
}
void inputKey(unsigned char c, int x, int y) {
switch (c) {
case 'a' : angle -= 0.05f;orientMe(angle);break;
case 'd' : angle +=0.05f;orientMe(angle);break;
case 'w' : moveMeFlat(5);break;
case 's' : moveMeFlat(-5);break;
case 'p' : if(flag==0)
{
state=0; //paused when doll is moving right.
flag=-1;
}
else if(flag==1)
{
state=1;
flag=-1; //paused when doll is moving
right.
}
else if(flag==-1 && state==0) //resume right.
flag=0;
else if(flag==-1 && state==1) //resume left.
flag=1;
break;
}
}
23
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
glutInitWindowSize(640,400);
glutCreateWindow("Shooting game by Suhas and Sagar");
initScene();
glutKeyboardFunc(inputKey);
glutMouseFunc(inputMouse);
glutDisplayFunc(renderScene);
//glutIdleFunc(renderScene);
glutTimerFunc(10,times,100);
glutReshapeFunc(changeSize);
glutMainLoop();
return(0);
}
Chapter – 6:
24
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
6.1 Overview:
The objective of this chapter is to introduce techniques that may be used to test
programs to discover program faults In other words we can say that this chapter is
mainly based on:
• Understand a number of testing techniques that are used to discover program
faults.
• Has been introduced to guidelines that support the testing of component
interfaces;
• Understand specific approaches to component testing and integration testing
for object oriented systems;
• Understand the principles of operation of CASE tool support for testing,
25
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Keyboard function is tested for integration, it contains display, piece, clear and
mark functions.
Chapter – 7:
26
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Conclusion:
The “SHOOTING GAME” is developed to provide a GUI. The project is
designed and developed using OpenGL graphic package with the aid of VC++. The
project makes use of feature available in OpenGL which facilitates clarity,
extensibility and ease of maintenance.
Advantage:
• Easy to understand.
• Easy to implement.
• Fast processing.
Disadvantage:
• If we shoot the snowman it do not show the damaged area.
Future Enhancements:
This project which we have developed is a user friendly application but there is
still some scope for improvement like the following:
• More clear view to the user about whether the user has hit the target or not.
• The game can be made more complicated by making the snowman move in
different directions when we pass on to next level.
Bibliography
27
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
3. Computer Graphics- James D Foley, Andries Van Dam, Steven K Feiner, John
F Hughes, Addison-wesley 1997
28
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Snapshots
This is the snapshot when the user has just moved on to second level with a score of 09.
29
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
Appendix
Function Meaning
30
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
31
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
32
Dept. of CS&E
VVIET, MYSORE
SHOOTING OF SNOW MAN
GL_LINE_STIPPLE,
GL_POLYGON_STIPPLE, GL_NORMALIZE
33
Dept. of CS&E
VVIET, MYSORE