Gaurdians of Galaxy
Gaurdians of Galaxy
Gaurdians of Galaxy
#include<windows.h>
#endif
#include<stdio.h>
#include<stdlib.h>
#include<GL/glut.h>
#include<math.h>
#define GL_SILENCE_DEPRECATION
GLint m_viewport[4];
bool mButtonPressed = false;
float mouseX, mouseY;
enum view {INTRO, MENU, INSTRUCTIONS, GAME, GAMEOVER};
view viewPage = INTRO; // initial value
bool keyStates[256] = {false};
bool direction[4] = {false};
bool laser1Dir[2] = {false};
bool laser2Dir[2] = {false};
void init()
{
glClearColor(0.0,0.0,0.0,0);
glColor3f(1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
void introScreen()
{
glClear(GL_COLOR_BUFFER_BIT);
void startScreenDisplay()
{
glLineWidth(10);
//SetDisplayMode(MENU_SCREEN);
glColor3f(1,0,0);
glBegin(GL_LINE_LOOP); //Border
glVertex2f(-750 ,-500);
glVertex2f(-750 ,550);
glVertex2f(750 ,550);
glVertex2f(750 ,-500);
glEnd();
glLineWidth(1);
glColor3f(1, 1, 0);
glBegin(GL_POLYGON); //START GAME PLOYGON
glVertex2f(-200 ,300);
glVertex2f(-200 ,400);
glVertex2f(200 ,400);
glVertex2f(200 ,300);
glEnd();
void backButton() {
if(mouseX <= -450 && mouseX >= -500 && mouseY >= -275 && mouseY <= -250){
glColor3f(0, 0, 1);
if(mButtonPressed) {
viewPage = MENU;
mButtonPressed = false;
//instructionsGame = false;
glutPostRedisplay();
}
}
else glColor3f(1, 0, 0);
displayRasterText(-1000 ,-550 ,0, "Back");
}
void instructionsScreenDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//SetDisplayMode(MENU_SCREEN);
//colorBackground();
glColor3f(1, 0, 0);
displayRasterText(-900 ,550 ,0.4 ,"INSTRUCTIONS");
glColor3f(1, 0, 0);
displayRasterText(-1000 ,400 ,0.4 ,"PLAYER 1");
displayRasterText(200 ,400 ,0.4 ,"PLAYER 2");
glColor3f(1, 1, 1);
displayRasterText(-1100 ,300 ,0.4 ,"Key 'w' to move up.");
glColor3f(1.0,
displayRasterText(-1100
0.0, 0.0);,200
displayRasterText(-1100 ,100 ,0.4 ,"Key 'd' to move right.");
displayRasterText(-1100 ,0 ,0.4 ,"Key 'a' to move left.");
displayRasterText(100 ,300 ,0.4 ,"Key 'i' to move up.");
displayRasterText(100 ,200 ,0.4 ,"Key 'k' to move down.");
displayRasterText(100 ,100 ,0.4 ,"Key 'j' to move right.");
displayRasterText(100 ,0 ,0.4 ,"Key 'l' to move left.");
displayRasterText(-1100 ,-100 ,0.4 ,"Key 'c' to shoot, Use 'w' and 's' to
change direction.");
displayRasterText(100 ,-100 ,0.4 ,"Key 'm' to shoot, Use 'i' and 'k' to
change direction.");
//displayRasterText(-1100 ,-100 ,0.4 ,"The packet can be placed only when
's' is pressed before.");
displayRasterText(-1100, -300,0.4,"The Objective is to kill your opponent.");
displayRasterText(-1100 ,-370 ,0.4 ,"Each time a player gets shot, LIFE
decreases by 5 points.");
backButton();
//if(previousScreen)
// nextScreen = false ,previousScreen = false; //as set by backButton()
}
glBegin(GL_POLYGON);
for(int i=0;i<=42 ;i++)
glVertex2fv(ALienFace[i]);
glEnd();
glPushMatrix();
glRotated(-10,0,0,1);
glTranslated(-6,32.5,0); //Left eye
glScalef(2.5,4,0);
glutSolidSphere(1,20,30);
glPopMatrix();
glPushMatrix();
glRotated(-1,0,0,1);
glTranslated(-8,36,0); //Right eye
glScalef(2.5,4,0);
glutSolidSphere(1,100,100);
glPopMatrix();
}
void DrawAlien(bool isPlayer1)
{
DrawAlienBody(isPlayer1);
DrawAlienCollar();
DrawAlienFace(isPlayer1);
DrawAlienBeak();
DrawAlienEyes(isPlayer1);
}
void DrawSpaceshipBody(bool isPlayer1)
{
if(isPlayer1)
glColor3f(1, 0, 0); //BASE
else
glColor3f(0.5, 0, 0.5);
glPushMatrix();
glScalef(70,20,1);
glutSolidSphere(1,50,50);
glPopMatrix();
glPushMatrix(); //LIGHTS
glScalef(3,3,1);
glTranslated(-20,0,0); //1
glColor3fv(LightColor[(CI+0)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //2
glColor3fv(LightColor[(CI+1)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //3
glColor3fv(LightColor[(CI+2)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //4
glColor3fv(LightColor[(CI+0)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //5
glColor3fv(LightColor[(CI+1)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //6
glColor3fv(LightColor[(CI+2)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //7
glColor3fv(LightColor[(CI+0)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //8
glColor3fv(LightColor[(CI+1)%3]);
glutSolidSphere(1,1000,1000);
glTranslated(5,0,0); //9
glColor3fv(LightColor[(CI+2)%3]);
glutSolidSphere(1,1000,1000);
glPopMatrix();
}
void DrawSteeringWheel()
{
glPushMatrix();
glLineWidth(3);
glColor3f(0.20,0.,0.20);
glScalef(7,4,1);
glTranslated(-1.9,5.5,0);
glutWireSphere(1,8,8);
glPopMatrix();
}
void DrawSpaceshipDoom()
{
glColor4f(0.7,1,1,0.0011);
glPushMatrix();
glTranslated(0,30,0);
glScalef(35,50,1);
glutSolidSphere(1,50,50);
glPopMatrix();
}
void DisplayHealthBar1() {
char temp1[40];
glColor3f(1 ,1 ,1);
sprintf(temp1," LIFE = %d",alienLife1);
displayRasterText(-1100 ,600 ,0.4 ,temp1);
glColor3f(1 ,0 ,0);
}
void DisplayHealthBar2() {
char temp2[40];
glColor3f(1 ,1 ,1);
sprintf(temp2," LIFE = %d",alienLife2);
displayRasterText(800 ,600 ,0.4 ,temp2);
glColor3f(1 ,0 ,0);
}
void checkLaserContact(int x, int y, bool dir[], int xp, int yp, bool player1) {
int xend = -XMAX, yend = y;
xp += 8; yp += 8; // moving circle slightly up to fix laser issue
if(dir[0])
yend = YMAX;
else if(dir[1])
yend = -YMAX;
void gameScreenDisplay()
{
DisplayHealthBar1();
DisplayHealthBar2();
glScalef(2, 2 ,0);
if(alienLife2 > 0) {
glPushMatrix();
glScalef(-1, 1, 1);
SpaceshipCreate(xTwo, yTwo, false);
if(laser2) {
DrawLaser(xTwo, yTwo, laser2Dir);
checkLaserContact(xTwo, yTwo, laser2Dir, -xOne, yOne, false);
}
glPopMatrix();
}
else {
viewPage = GAMEOVER;
}
if(viewPage == GAMEOVER) {
xOne = xTwo = 500;
yOne = yTwo = 0;
}
}
void displayGameOverMessage() {
glColor3f(1, 1, 0);
char* message;
if(alienLife1 > 0)
message = "Game Over! Player 1 won the game";
else
message = "Game Over! Player 2 won the game";
void keyOperations() {
if(keyStates[13] == true && viewPage == INTRO) {
viewPage = MENU;
printf("view value changed to %d", viewPage);
printf("enter key pressed\n");
}
if(viewPage == GAME) {
laser1Dir[0] = laser1Dir[1] = false;
laser2Dir[0] = laser2Dir[1] = false;
if(keyStates['c'] == true) {
laser2 = true;
if(keyStates['w'] == true) laser2Dir[0] = true;
if(keyStates['s'] == true) laser2Dir[1] = true;
}
else {
laser2 = false;
if(keyStates['d'] == true) xTwo-=SPACESHIP_SPEED;
if(keyStates['a'] == true) xTwo+=SPACESHIP_SPEED;
if(keyStates['w'] == true) yTwo+=SPACESHIP_SPEED;
if(keyStates['s'] == true) yTwo-=SPACESHIP_SPEED;
}
if(keyStates['m'] == true) {
laser1 = true;
if(keyStates['i'] == true) laser1Dir[0] = true;
if(keyStates['k'] == true) laser1Dir[1] = true;
}
else {
laser1 = false;
if(keyStates['l'] == true) xOne+=SPACESHIP_SPEED;
if(keyStates['j'] == true) xOne-=SPACESHIP_SPEED;
if(keyStates['i'] == true) yOne+=SPACESHIP_SPEED;
if(keyStates['k'] == true) yOne-=SPACESHIP_SPEED;
}
}
}
void display()
{
//glClearColor(, 0 , 0, 1);
keyOperations();
glClear(GL_COLOR_BUFFER_BIT);
switch (viewPage)
{
case INTRO:
introScreen();
break;
case MENU:
startScreenDisplay();
break;
case INSTRUCTIONS:
instructionsScreenDisplay();
break;
case GAME:
gameScreenDisplay();
//reset scaling values
glScalef(1/2 ,1/2 ,0);
break;
case GAMEOVER:
displayGameOverMessage();
startScreenDisplay();
break;
}
glFlush();
glLoadIdentity();
glutSwapBuffers();
}
void refresh() {
glutPostRedisplay();
}