Here are the two files in question:
game_main.cpp
#include "game.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
ship::ship(GLfloat x, GLfloat y, GLColor3 color) {
alive = true;
lasers = 0;
this->x = x;
this->y = y;
this->color = color;
}
int ship::move(GLfloat x, GLfloat y) {
if (checkCollision(x, y)) {
this->x += x;
this->y += y;
}
}
int ship::checkCollision(GLfloat x, GLfloat y) {
if (x >= screenFromZero || x <= screenFromZero) {
return false;
}
else if (y >= screenFromZero || y <= screenFromZero) {
return false;
}
return true;
}
ship::~ship() {
alive = false;
}
laser::laser(GLfloat x, GLfloat y, GLColor3 color, int direction) {
alive = true;
lasers = 0;
this->x = x;
this->y = y;
this->color = color;
this->direction = direction;
}
int laser::move() {
if (!checkCollision(x, y + laserMoveRate))
return checkCollision(x, y + laserMoveRate);
y += laserMoveRate;
return -1;
}
shipStack::shipStack() {
currentX = 0;
currentY = 0;
ships = new ship[shipRows][shipColumns];
canCreate = true;
}
shipStack::killShip(ship * kShip) {
for (int i = 0; i < shipRows; i++) {
for (int j = 0; j < shipColumns) {
if (ships[i][j] == kShip)
ships[i][j] = NULL;
}
}
}
int shipStack::createShip(ship * cShip) {
if (!canCreate)
return false;
int newX = currentX;
int newY = currentY;
int create = false;
if (currentX < shipRows - 1) {
if (currentY == shipColumns - 1) {
newX += 1;
newY = 0;
create = true;
}
else if (currentY < shipColumns - 1) {
newY += 1;
create = true;
}
}
else if (currentX == shipRows - 1) {
if (currentY < shipColumns - 1) {
newY += 1;
create = true;
}
else if (currentY == shipColumns - 1) {
newX += 1;
newY = 0;
}
}
if (create)
ships[currentX][currentY] = cShip;
currentX = newX;
currentY = newY;
canCreate = create;
return create;
}
shipStack::~shipStack() {
delete [] ships;
}
and game.h
#ifndef GAME_H_
#define GAME_H_
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
const int ammo = 3;
const int maxShips = 50;
const int shipRows = 5;
const int shipColumns = maxShips / shipRows;
const GLfloat shipHeight = 2.0f;
const GLfloat shipWidth = 2.0f;
const GLfloat zoom = -20.0f; //Camera Z coordinate
const GLfloat screenFromZero = 20.0f; //Set this value to the zoom - this is the amount one can see.
const GLfloat laserMoveRate = 1.0f;
struct GLColor3 {
GLfloat red;
GLfloat blue;
GLfloat green;
};
struct ship {
bool alive;
int lasers;
GLfloat x;
GLfloat y;
GLColor3 color;
ship(GLfloat x, GLfloat y, GLColor3 color);
int checkCollision(GLfloat x, GLfloat y); //Coordinates of the leftmost pixel (lower left in case of triangles)
int move(GLfloat x, GLfloat y);
~ship();
};
struct laser {
GLfloat x;
GLfloat y;
GLColor3 color;
int direction; //Direction on the Y axis
laser(GLfloat x, GLfloat y, GLColor3 color);
int move(); //Returns which ship collided with or -1 if none
int checkCollision(GLfloat x, GLfloat y);
};
struct shipStack {
int currentX;
int currentY;
int canCreate;
ship * ships;
shipStack();
int createShip(ship * cShip);
void killShip(ship * kShip);
~shipStack();
};
#endif
And then I compile and get a bunch of errors like
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\gl\GL.H(1136): error C2086: ''int APIENTRY'' : redefinition
I''m obviously including the OpenGL headers in the wrong way...somehow...but how?