Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <string>
- #include <gl\glut.h>
- unsigned char gameSpriteO[768] = {0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,255,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,255,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0,0,0};
- unsigned char gameSpriteX[768] = {255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,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0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- int window, mouseButton, mouseClickState, mouseX, mouseY, cpFirstTurn = 1, boardPos = 0, spotIsTaken = 0, whosTurnIsIt = 0, oBlockedYou = 0, timesYouWon = 0;
- GLuint gameSpriteOTextureId, gameSpriteXTextureId, gameBoardTextureId;
- int xSAndOs[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char formatBuf[512];
- void DrawTexture(int textureId, float x, float y, float width, float height) {
- glBindTexture(GL_TEXTURE_2D, textureId);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex3f(x, y + height, 0); glTexCoord2f(1, 0); glVertex3f(x + width, y + height, 0); // bottom left | bottom right
- glTexCoord2f(1, 1); glVertex3f(x + width, y, 0); glTexCoord2f(0, 1); glVertex3f(x, y, 0); // top right | top left
- glEnd();
- }
- void MakeTexture(unsigned char* textureData, int textureWidth, int textureHeight, GLuint *outTextureId) {
- glGenTextures(1, outTextureId); glBindTexture(GL_TEXTURE_2D, *outTextureId); // init texture stuff
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData); // generate texture
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // no texture blending
- }
- void Reset(char *whoWon) {
- sprintf(formatBuf, "%s - %d Times Won\n", whoWon, timesYouWon); glutSetWindowTitle(formatBuf); // Set window message
- Sleep(1000); // wait a moment
- for (int i = 0; i < 9; i++) xSAndOs[i] = 0; whosTurnIsIt = 0; // clear game board
- }
- void DrawGLScene() {
- glutReshapeWindow(640, 480); // so I dont have to do any more math
- if ((xSAndOs[0] == 1 && xSAndOs[1] == 1 && xSAndOs[2] == 1) || (xSAndOs[3] == 1 && xSAndOs[4] == 1 && xSAndOs[5] == 1) || (xSAndOs[6] == 1 && xSAndOs[7] == 1 && xSAndOs[8] == 1) || (xSAndOs[0] == 1 && xSAndOs[3] == 1 && xSAndOs[6] == 1) || (xSAndOs[1] == 1 && xSAndOs[4] == 1 && xSAndOs[7] == 1) || (xSAndOs[2] == 1 && xSAndOs[5] == 1 && xSAndOs[8] == 1) || (xSAndOs[0] == 1 && xSAndOs[4] == 1 && xSAndOs[8] == 1) || (xSAndOs[2] == 1 && xSAndOs[4] == 1 && xSAndOs[6] == 1)){
- timesYouWon++; Reset("X Won"); }
- else if ((xSAndOs[0] == 2 && xSAndOs[1] == 2 && xSAndOs[2] == 2) || (xSAndOs[3] == 2 && xSAndOs[4] == 2 && xSAndOs[5] == 2) || (xSAndOs[6] == 2 && xSAndOs[7] == 2 && xSAndOs[8] == 2) || (xSAndOs[0] == 2 && xSAndOs[3] == 2 && xSAndOs[6] == 2) || (xSAndOs[1] == 2 && xSAndOs[4] == 2 && xSAndOs[7] == 2) || (xSAndOs[2] == 2 && xSAndOs[5] == 2 && xSAndOs[8] == 2) || (xSAndOs[0] == 2 && xSAndOs[4] == 2 && xSAndOs[8] == 2) || (xSAndOs[2] == 2 && xSAndOs[4] == 2 && xSAndOs[6] == 2))
- Reset("O Won");
- else if (xSAndOs[0] != 0 && xSAndOs[1] != 0 && xSAndOs[2] != 0 && xSAndOs[3] != 0 && xSAndOs[4] != 0 && xSAndOs[5] != 0 && xSAndOs[6] != 0 && xSAndOs[7] != 0 && xSAndOs[8] != 0 )
- Reset("Draw");
- if (whosTurnIsIt == 1) { // cps turn
- oBlockedYou = 0;
- for (int i = 0; i < 9; i += 3) { // check horizontal
- if (xSAndOs[i] == 1 && xSAndOs[i + 1] == 1 && xSAndOs[i + 2] == 0) {
- oBlockedYou = 1, boardPos = i + 2; break; }
- else if (xSAndOs[i] == 1 && xSAndOs[i + 1] == 0 && xSAndOs[i + 2] == 1) {
- oBlockedYou = 1, boardPos = i + 1; break; }
- else if (xSAndOs[i] == 0 && xSAndOs[i + 1] == 1 && xSAndOs[i + 2] == 1) {
- oBlockedYou = 1, boardPos = i; break; }
- }
- for (int i = 0; i < 3; i++) { // check vertical
- if (xSAndOs[i] == 1 && xSAndOs[i + 3] == 1 && xSAndOs[i + 6] == 0) {
- oBlockedYou = 1, boardPos = i + 6; break; }
- else if (xSAndOs[i] == 1 && xSAndOs[i + 3] == 0 && xSAndOs[i + 6] == 1) {
- oBlockedYou = 1, boardPos = i + 3; break; }
- else if (xSAndOs[i] == 0 && xSAndOs[i + 3] == 1 && xSAndOs[i + 6] == 1) {
- oBlockedYou = 1, boardPos = i; break; }
- }
- if (xSAndOs[0] == 1 && xSAndOs[4] == 1 && xSAndOs[8] == 0) // check diagonal
- oBlockedYou = 1, boardPos = 8;
- else if (xSAndOs[0] == 1 && xSAndOs[4] == 0 && xSAndOs[8] == 1)
- oBlockedYou = 1, boardPos = 4;
- else if (xSAndOs[0] == 0 && xSAndOs[4] == 1 && xSAndOs[8] == 1)
- oBlockedYou = 1, boardPos = 0;
- if (xSAndOs[2] == 1 && xSAndOs[4] == 1 && xSAndOs[6] == 0)
- oBlockedYou = 1, boardPos = 6;
- else if (xSAndOs[2] == 1 && xSAndOs[4] == 0 && xSAndOs[6] == 1)
- oBlockedYou = 1, boardPos = 4;
- else if (xSAndOs[2] == 0 && xSAndOs[4] == 1 && xSAndOs[6] == 1)
- oBlockedYou = 1, boardPos = 2;
- if (!oBlockedYou)
- do {
- spotIsTaken = xSAndOs[(boardPos = (rand() % 9))] != 0;
- } while (spotIsTaken);
- xSAndOs[boardPos] = 2;
- whosTurnIsIt = !whosTurnIsIt;
- }
- else if (!whosTurnIsIt && !mouseButton && mouseClickState) // our turn
- if (xSAndOs[(mouseX / 200) + ((mouseY / 150) * 3)] == 0) {
- xSAndOs[(mouseX / 200) + ((mouseY / 150) * 3)] = (whosTurnIsIt + 1);
- whosTurnIsIt = !whosTurnIsIt;
- }
- DrawTexture(gameBoardTextureId, 0, 0, 56, 56);
- for (int y = 0; y < 3; y++)
- for (int x = 0; x < 3; x++)
- if (xSAndOs[x + (y * 3)])
- DrawTexture(xSAndOs[x + (y * 3)], ((56 / 3) * x) + (x + 1), ((56 / 3) * y) + (y + 1), 16, 16);
- glutSwapBuffers();
- mouseButton = 0, mouseClickState = 0, mouseX = 0, mouseY = 0;
- }
- void MouseEvent(int button, int state, int x, int y) { mouseButton = button, mouseClickState = state, mouseX = x, mouseY = y; }
- void main(int argc, char **argv) {
- glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA); glutInitWindowSize(640, 480); // inits
- window = glutCreateWindow("Gl Tic Tac Toe"); // window creation
- glutDisplayFunc(&DrawGLScene); glutIdleFunc(&DrawGLScene); glutMouseFunc(&MouseEvent); // glut events
- MakeTexture(gameSpriteX, 16, 16, &gameSpriteXTextureId); MakeTexture(gameSpriteO, 16, 16, &gameSpriteOTextureId); MakeTexture(gameBoard, 56, 56, &gameBoardTextureId); // make textures
- glMatrixMode(GL_PROJECTION); glOrtho(0.0f, 56, 56, 0.0f, 0.0f, 1); glMatrixMode(GL_MODELVIEW); // viewport setup
- glEnable(GL_TEXTURE_2D); srand(time(0)); // enable textures and seeding random numbers
- glutMainLoop(); // start glut main loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement