int main(void) { char ** board = newBoard(); // print top row of numbers PickPiece(board); // return contents; displayBoard(board); }
void InitWell() { if (well != 0) { delete well; well = 0; } well = new Well(10, 14, 0.0, 0.0, 0.0); MakePieces(); nextPiece = PickRandomPiece(); PickPiece(); std::vector<float> grid; well->MakeGrid(grid); GenerateArrayBuffer(grid, vbo_grid); GenerateBuffers(*cp, vbo_cube, ibo_cube_elements); GenerateBuffers(*well, vbo_fixed, ibo_fixed); glutPostRedisplay(); glutTimerFunc(100, timerCallBack, 0); isGameOver = false; }
void timerCallBack(int value) { int incX = 0; switch (specialKey) { case GLUT_KEY_LEFT: incX = -1; if (well->CanMove(*cp, incX, 0)) { cp->Move(incX, 0, true); } break; case GLUT_KEY_RIGHT: incX = 1; if (well->CanMove(*cp, incX, 0)) { cp->Move(incX, 0, true); } break; } specialKey = -1; bool isDrop = false; switch (key) { case SPACEBAR: well->Drop(*cp); isDrop = true; break; case ROTATE_LEFT: if (well->CanRotateLeft(*cp)) { cp->RotateLeft(); GenerateBuffers(*cp, vbo_cube, ibo_cube_elements); } break; case ROTATE_RIGHT: if (well->CanRotateRight(*cp)) { cp->RotateRight(); GenerateBuffers(*cp, vbo_cube, ibo_cube_elements); } break; } key = -1; if (cp->MustMove()) { if (well->CanMove(*cp)) { cp->Move(0, 1); } else { if (isDrop || moveDelay > 10) { moveDelay = 0; isDrop = false; wellEmpty = false; well->Add(*cp); GenerateBuffers(*well, vbo_fixed, ibo_fixed); PickPiece(); if (well->CanAdd(*cp)) { GenerateBuffers(*cp, vbo_cube, ibo_cube_elements); } else { isGameOver = true; glwriter->Write("GAME OVER!", 10, -0.3, 0.0); } } else { moveDelay++; } } } else { cp->Increment(false, !isPause, false); } if (!isGameOver) { translate = glm::translate(glm::mat4(1.0f), glm::vec3(cp->getX(), cp->getY(), cp->getZ())); glutTimerFunc(100, timerCallBack, 0); } glutPostRedisplay(); }