void Game::movePiece(std::pair<int,int>& move) { // Move in board if(board.getBoard()[move.second] != 0) lasteat = 0; else lasteat++; board.movePiece(move.first, move.second); int index = board.updateState(move.second, 0); // Returns index if update needed if (index != -1) { // If stateword 0-63-> means pawn has reached enemy backline. Pawn is promotee changePiece(index); board.updateState(move.second, 0); } if((board.getState() >> 6) == 0x01) //01000000 passant made by white { } if((board.getState() >> 6) == 0x02) //10000000 passant made by black { } if((board.getState() >> 6) == 0x03) //11000000 castling { if((move.second%8)>4) //castling to right { } else // castling to left { } } }
int playGame() { int tempx = current.getPosX(); //Temp variables for position int tempy = current.getPosY(); if (keyboard_counter > 0 && keypressed()) //Keyboard Delay { if (key[KEY_LEFT]) //Move to the left { if (noCollision(current, tempx - 1, tempy)) //Checks collisions with the left movement { tempx--; //If there is not collision move the piece current.setPosX(tempx); } } if (key[KEY_RIGHT]) { if (noCollision(current, tempx + 1, tempy)) { tempx++; current.setPosX(tempx); } } if (key[KEY_DOWN]) { if (noCollision(current, tempx, tempy + 1)) { tempy++; current.setPosY(tempy); } } if (key[KEY_UP]) //Rotate the piece to the right { /*Create a temp piece for the request rotation*/ cPiece temp; temp.type = current.type; temp.rotation = rotateBlock(1, current.rotation); cleanPiece(temp); changePiece(temp, temp.type, temp.rotation); temp.setPosX(current.getPosX()); temp.setPosY(current.getPosY()); if (noCollision(temp, temp.getPosX(), temp.getPosY())) //Checks collision for the temp piece { //If there is not collision, the real falling(current) piece rotates to the right current.rotation = rotateBlock(1, current.rotation); cleanPiece(current); changePiece(current, current.type, current.rotation); } } if (key[KEY_T]) //Up the volume of the music { volume[0]+= 5; if (volume[0] > 255){ volume[0] = 255;} options[4].d2 = volume[0]; adjust_sample(sound[0], volume[0], 128, 1000, TRUE); adjust_sample(sound[1], volume[0], 128, 1000, TRUE); } if (key[KEY_G]) //Down the volume of the music { volume[0]-= 5; if (volume[0] < 0){ volume[0] = 0;} options[4].d2 = volume[0]; adjust_sample(sound[0], volume[0], 128, 1000, TRUE); adjust_sample(sound[1], volume[0], 128, 1000, TRUE); } if (key[KEY_Y]) //Up the volume of the sound effects { volume[1]+= 5; if (volume[1] > 255){ volume[1] = 255;} options[6].d2 = volume[1]; adjust_sample(sound[2], volume[1], 128, 1000, TRUE); adjust_sample(sound[3], volume[1], 128, 1000, TRUE); } if (key[KEY_H]) //Down the volume of the sound effects { volume[1]-= 5; if (volume[1] < 0){ volume[1] = 0;} options[6].d2 = volume[1]; adjust_sample(sound[2], volume[1], 128, 1000, TRUE); adjust_sample(sound[3], volume[1], 128, 1000, TRUE); } keyboard_counter--; } fpscount++; if (ticks > speed) { tempx = current.getPosX(); tempy = current.getPosY(); if (noCollision(current, tempx, tempy + 1)) //Checks collision for the falling { tempy++; current.setPosY(tempy); } else { play_sample(sound[2], volume[1], 128, 1000, FALSE); putBlock(current, tempx, tempy); //Put block on the board possibleRows(); //Check if a row is fill if (gameOver()) //Checks if the game is over { quitgame = 1; } else createBlock(current, next); //If the game it's not over create new pieces } ticks = 0; } return quitgame; }