Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Linux
- g++ AbsObject.cpp Camera.cpp main.cpp -o run.exe -lGL -lGLEW -lsfml-graphics -lsfml-window -lsfml-system && ./run.exe
- Windows
- g++ AbsObject.cpp Camera.cpp main.cpp -o run.exe -IC:/glew/include -LC:/glew/lib -fpermissive -IC:/sfml/include -LC:/sfml/lib -IC:/glm -lsfml-window -lsfml-graphics -lsfml-system -lglew32 -lopengl32 -lglu32 && run.exe
- Start Window
- */
- #include <iostream>
- #include <GL/glew.h>
- #include <SFML/Window.hpp>
- #include "AbsObject.h"
- #include "Camera.h"
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- bool win = false;
- bool yellow = false;
- bool blue = true;
- sf::ContextSettings settings;
- settings.depthBits = 24;
- settings.stencilBits = 8;
- settings.antialiasingLevel = 4;
- settings.majorVersion = 3;
- settings.minorVersion = 0;
- srand (time(NULL));
- sf::Window window(sf::VideoMode(3500, 2000), "Horse Play ", sf::Style::Default, settings);
- window.setPosition(sf::Vector2i(0,0));
- GLenum status = glewInit();
- if(status != GLEW_OK)
- std::cout << "ERROR" << std::endl;
- GLfloat points[] =
- {
- -0.5f, 0.5f, 0.0f,
- -0.5f,-0.5f, 0.0f,
- 0.5f,-0.5f, 0.0f,
- -0.5f, 0.5f, 0.0f,
- 0.5f,-0.5f, 0.0f,
- 0.5f, 0.5f, 0.0f,
- };
- const int BOARD_LENGTH = 3;
- const float TILE_SIZE = 0.2f;
- const float Xmover_SIZE = TILE_SIZE*0.76f;
- bool isPressed = false;
- int xPos = 0;
- int yPos = 0;
- bool black = false;
- AbsObject object[BOARD_LENGTH][BOARD_LENGTH];
- int pos[3][3]=
- {
- 0,0,0,
- 0,0,0,
- 0,0,0
- };
- AbsObject Xmover(points,sizeof(points),1,0.77,0.61);
- Xmover.getScalePtr()->x = Xmover_SIZE/2;
- Xmover.getScalePtr()->y = Xmover_SIZE/2;
- Xmover.getTranslationPtr()->y = - TILE_SIZE*5;
- Xmover.getTranslationPtr()->x = - TILE_SIZE*5;
- for(int i=0;i<BOARD_LENGTH;i++)
- {
- for(int j=0;j<BOARD_LENGTH;j++)
- {
- if(i%2==0&&j%2==0 || i%2==1&&j%2==1)
- object[i][j].init(points,sizeof(points),1,1,1);
- else
- object[i][j].init(points,sizeof(points),1,1,1);
- object[i][j].getScalePtr()->x = TILE_SIZE/1.6f;
- object[i][j].getScalePtr()->y = TILE_SIZE/1.6f;
- object[i][j].getTranslationPtr()->y = i*TILE_SIZE - TILE_SIZE*5;
- object[i][j].getTranslationPtr()->x = j*TILE_SIZE - TILE_SIZE*5;
- }
- }
- bool trigger = false;
- Camera camera(70,800.0f/600.0f,0.01f,100.0f,0,0,3);
- camera.updateCamera();
- //makes sure the program runs at 60 FPS
- const float TIME_PER_FRAME = 1.0f/60*1000;
- sf::Clock clock;
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- {
- window.close();
- }else if (event.type == sf::Event::Resized)
- {
- glViewport(0, 0, event.size.width, event.size.height);
- }//end else if
- }//end while
- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
- if(!isPressed && yPos+1 < BOARD_LENGTH)
- {
- std::cout << "UP" << std::endl;
- Xmover.getTranslationPtr()->y += TILE_SIZE;
- yPos++;
- std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
- isPressed = true;
- }
- }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- {
- if(!isPressed && yPos-1 >= 0)
- {
- std::cout << "DOWN" << std::endl;
- Xmover.getTranslationPtr()->y -= TILE_SIZE;
- yPos--;
- std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
- isPressed = true;
- }
- }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- {
- if(!isPressed && xPos-1 >= 0)
- {
- std::cout << "LEFT" << std::endl;
- Xmover.getTranslationPtr()->x -= TILE_SIZE;
- xPos--;
- std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
- isPressed = true;
- }
- }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- {
- if(!isPressed && xPos+1 < BOARD_LENGTH)
- {
- std::cout << "RIGHT" << std::endl;
- Xmover.getTranslationPtr()->x += TILE_SIZE;
- xPos++;
- std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
- isPressed = true;
- }
- }
- // else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
- // {
- // object[yPos][xPos].init(points,sizeof(points),1,1,0);
- // object[yPos][xPos].getScalePtr()->x = TILE_SIZE/1.6f;
- // object[yPos][xPos].getScalePtr()->y = TILE_SIZE/1.6f;
- // object[yPos][xPos].getTranslationPtr()->y = yPos*TILE_SIZE - TILE_SIZE*5;
- // object[yPos][xPos].getTranslationPtr()->x = xPos*TILE_SIZE - TILE_SIZE*5;
- // }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
- {
- if(!isPressed)
- {
- if(pos[yPos][xPos]==0)
- {
- std::cout<<"press"<<std::endl;
- if(blue)
- {
- object[yPos][xPos].init(points,sizeof(points),0,0,1);
- object[yPos][xPos].getScalePtr()->x = TILE_SIZE/1.6f;
- object[yPos][xPos].getScalePtr()->y = TILE_SIZE/1.6f;
- object[yPos][xPos].getTranslationPtr()->y = yPos*TILE_SIZE - TILE_SIZE*5;
- object[yPos][xPos].getTranslationPtr()->x = xPos*TILE_SIZE - TILE_SIZE*5;
- pos[yPos][xPos]=1;
- blue = false;
- yellow = true;
- }
- else if(yellow)
- {
- object[yPos][xPos].init(points,sizeof(points),1,1,0);
- object[yPos][xPos].getScalePtr()->x = TILE_SIZE/1.6f;
- object[yPos][xPos].getScalePtr()->y = TILE_SIZE/1.6f;
- object[yPos][xPos].getTranslationPtr()->y = yPos*TILE_SIZE - TILE_SIZE*5;
- object[yPos][xPos].getTranslationPtr()->x = xPos*TILE_SIZE - TILE_SIZE*5;
- pos[yPos][xPos]=2;
- yellow = false;
- blue = true;
- }
- isPressed = true;
- }
- }
- }
- else
- {
- if(isPressed)
- isPressed = false;
- }
- ////horizontals
- if(pos[0][0]==1 && pos[1][0] == 1 && pos[2][0] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[0][0]==2 && pos[1][0] == 2 && pos[2][0] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[0][0]==2 && pos[0][1] == 2 && pos[0][2] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[0][0]==1 && pos[0][1] == 1 && pos[0][2] ==1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[1][0]==1 && pos[1][1] == 1 && pos[1][2] ==1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[1][0]==2 && pos[1][1] == 2 && pos[1][2] ==2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[2][0]==2 && pos[2][1] == 2 && pos[2][2] ==2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[2][0]==1 && pos[2][1] == 1 && pos[2][2] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- ////verticals
- else if(pos[0][0]==1 && pos[1][0] == 1 && pos[2][0] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[0][0]==2 && pos[1][0] == 2 && pos[2][0] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[0][1]==1 && pos[1][1] == 1 && pos[2][1] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[0][1]==2 && pos[1][1] == 2 && pos[2][1] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[0][2]==1 && pos[1][2] == 1 && pos[2][2] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[0][2]==2 && pos[1][2] == 2 && pos[2][2] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- //diagonals
- else if(pos[0][0]==1 && pos[1][1] == 1 && pos[2][2] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[0][0]==2 && pos[1][1] == 2 && pos[2][2] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- //
- else if(pos[2][0]==1 && pos[1][1] == 1 && pos[0][2] == 1)
- {
- cout << "Blue wins" << endl;
- return main();
- }
- //
- else if(pos[2][0]==2 && pos[1][1] == 2 && pos[0][2] == 2)
- {
- cout << "Yellow wins" << endl;
- return main();
- }
- ///////////////////////////////////////
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- for(int i=0;i<BOARD_LENGTH;i++)
- for(int j=0;j<BOARD_LENGTH;j++)
- object[i][j].draw(camera.getProjection());
- Xmover.draw(camera.getProjection());
- window.display();
- //regulates the frames to 60
- sf::sleep(sf::milliseconds(TIME_PER_FRAME-
- clock.getElapsedTime().asMilliseconds()));
- clock.restart();
- }//end while
- return 0;
- }//end func
- /*
- (T▽T) - proper response!
- FPS regulator now allows a specific rate of refresh. This makes
- game behaviour more understandable.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement