void collision_check(square& another) { const float delta_x{x_pout() - another.x_pout()}; const float delta_y{y_pout() - another.y_pout()}; if ((abs(delta_y) >= abs(delta_x)) && (abs(delta_y) <= m_side)) { if (delta_y <= 0) { y_pin(another.y_pout() - m_side); reset_jumps(); } } if ((abs(delta_x) > abs(delta_y)) && (abs(delta_x) <= m_side)) { if (delta_x <= 0) { const float x_middle{another.x_pout() + 0.5f*delta_x}; x_pin(x_middle - m_radius); another.x_pin(x_middle + m_radius); } } }
//fires on mouse move when button is down. void mouseMove(int x, int y) { cout << "x:" << x << "||y:" << y << endl; if (leftMouseDown) { if (last_x_pos > x ) { //isMovingLeft = true; s.move(-0.1f, 0); } else if (last_x_pos < x) { s.move(0.1f, 0); } //s.move((last_x_pos - x) / 10.0f, 0); last_x_pos = x; } }
void display() { /*start boiler*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //set camera direction and position gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //draw light source glLightfv(GL_LIGHT0, GL_POSITION, light_one); /*end boiler*/ s.draw(); //yellow triangle /square /*glBegin(GL_QUADS); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, yellow); glVertex3f(-2 , 2,0); glVertex3f(2 , 2,0); glVertex3f(2 , -2,0); glVertex3f(-2 , -2,0); glEnd();*/ //red triangle //glBegin(GL_TRIANGLES); // glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan); // glVertex3f(-5,0,0); // glVertex3f(-5,-5,0); // glVertex3f(0,0,0); //glEnd(); ////green triangle // glBegin(GL_TRIANGLES); // glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); // glVertex3f(0,0,0); // glVertex3f(5,-5,0); // glVertex3f(5,0,0); //glEnd(); ////blue triangle // glBegin(GL_TRIANGLES); // glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); // glVertex3f(5,-5,0); // glVertex3f(10,-5,0); // glVertex3f(10,0,0); //glEnd(); /*start boiler*/ glFlush(); glutSwapBuffers(); /*end boiler*/ }
void display() { /*start boiler*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //set camera direction and position gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //draw light source glLightfv(GL_LIGHT0, GL_POSITION, light_one); /*end boiler*/ GLfloat increment = 0.005; if (moveCounter > 1000) { moveCounter = 0; } if (moveCounter > 660) { changeColor[1] += increment; changeColor[2] = 0; changeColor[0] = 0; } else if (moveCounter > 330) { changeColor[1] = 0; changeColor[2] += increment; changeColor[0] = 0; } else if (moveCounter > 0) { changeColor[1] = 0; changeColor[2] = 0; changeColor[0] += increment; } moveCounter++; s.setColor(changeColor); for (int i = 0; i < squareLength; i++) { allSquares[i].move(); } draw(); /*start boiler*/ glFlush(); glutSwapBuffers(); /*end boiler*/ }
bool king::can_move_to(square& location) const { bool valid_move = false; int translation_X = location.get_X() - this->location()->get_X(); int translation_Y = location.get_Y() - this->location()->get_Y(); if(abs(translation_Y) == 1 && translation_X == 0) { valid_move = true; } else if(abs(translation_X) == 1 && translation_Y == 0) { valid_move = true; } else if(abs(translation_X) == 1 && abs(translation_Y) == 1) { valid_move = true; } return valid_move; }
void keyboard(unsigned char key, int x, int y) { //user interaction here switch(key) { case 'o': s.hide(); break; case 'p': s.show(); break; case 'w': s.move(0.1, 0.1); break; case 'a': break; case 's': s.move(0, -0.1); break; case 'd': break; case 'r': changeColor[0] = 1; changeColor[1] = 0; changeColor[2] = 0; break; case 'g': changeColor[0] = 0; changeColor[1] = 1; changeColor[2] = 0; break; } //s.setColor(changeColor); glutPostRedisplay(); }
//do all rendering here, "should" only call .draw on objects void draw() { if (leftMouseDown == true) { s.setColor(red); } else { s.setColor(green); } //move object according to mouse flags (should be in mouse movement function) /*if (isMovingLeft && leftMouseDown) { s.move(-0.01f, 0); } else if (leftMouseDown) { s.move(0.01f, 0); }*/ //loop through squares array and draw for (int i = 0; i < squareLength; i++) { allSquares[i].draw(); } //draw the square s //s.draw(); //force update (only if we changed something, should have this in mouse or keyboard functions glutPostRedisplay(); }
void warp(square& another) { if ((sf::Keyboard::isKeyPressed(sf::Keyboard::S) && (m_winger == wing::left)) || (sf::Keyboard::isKeyPressed(sf::Keyboard::K) && (m_winger == wing::right))) { if (!warping) { const float x_pout_ = x_pout(); const float o_x_pout = another.x_pout(); if (o_x_pout > x_pout_) { if (o_x_pout <= m_windims.x - 2.5f*m_side) { m_posit.x = o_x_pout + 2.0f*m_side; } else if (o_x_pout >= 2.5f*m_side) { m_posit.x = o_x_pout - 2.0f*m_side; } } if (o_x_pout < x_pout_) { if (o_x_pout >= 2.5f*m_side) { m_posit.x = o_x_pout - 2.0f*m_side; } else if (o_x_pout <= m_windims.x - 2.5f*m_side) { m_posit.x = o_x_pout + 2.0f*m_side; } } warping = true; } } else if (warping) { warping = false; } }
void keyboard(unsigned char key, int x, int y) { //user interaction here switch(key) { case 'a': viewer[0] -= 0.5f; break; case 'w': viewer[1] += 0.5f; break; case 's': viewer[1] -= 0.5f; break; case 'd': viewer[0] += 0.5f; break; case 'q': viewer[2] -= 0.5f; break; case 'e': viewer[2] += 0.5f; break; case 'j': light_one[1] -= 5.0f; break; case 'k': light_one[1] += 5.0f; break; case 'i': light_one[2] -= 5.0f; break; case 'm': light_one[2] += 5.0f; break; case'1': x_pos -= 0.5; break; case'2': x_pos += 0.5; break; case 'o': s.hide(); break; case 'p': s.show(); break; case 'W': s.move(0,0.1); break; case 'S': s.move(0,-0.1); break; case 'A': s.move(0.1,0); break; case'D': s.move(-0.1,0); break; case 'r': changeColor[0]= 1; changeColor[1]= 0; changeColor[2]= 0; break; case 'g': changeColor[1]+= 0.1; } s.setColor(changeColor); glutPostRedisplay(); }
void display() { /*start boiler*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //set camera direction and position gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //draw light source glLightfv(GL_LIGHT0, GL_POSITION, light_one); /*end boiler*/ //dummy triangle //glBegin(GL_QUADS); // glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); // glVertex3f(-2,2,0); // glVertex3f(2,2,0); // glVertex3f(2,-2,0); // glVertex3f(-2,-2,0); //glEnd(); /*moveCounter++; if (moveCounter < 100) { s.move(0.1, 0.1); }*/ GLfloat increment = 0.005; if (moveCounter > 1000) { moveCounter = 0; } if (moveCounter > 660) { changeColor[1] += increment; changeColor[2] = 0; changeColor[0] = 0; } else if (moveCounter > 330) { changeColor[1] = 0; changeColor[2] += increment; changeColor[0] = 0; } else if (moveCounter > 0) { changeColor[1] = 0; changeColor[2] = 0; changeColor[0] += increment; } moveCounter++; s.setColor(changeColor); s.draw(); glutPostRedisplay(); /*start boiler*/ glFlush(); glutSwapBuffers(); /*end boiler*/ }