/* *-------------------------------------------------- * Init graphics and GLUT functions *-------------------------------------------------- */ void InitGraphics(int argc, char *argv[]) { glutInitWindowPosition( 0, 0 ); /* if ( ntscSize ) glutInitWindowSize( 640, 480 ); */ /* if ( ntscSize ) glutInitWindowSize( 320, 320 ); mpeg size */ if ( ntscSize ) glutInitWindowSize( 400, 320 ); /* mpeg size */ else glutInitWindowSize( 600, 600 ); /*else glutInitWindowSize( 300, 300 );*/ glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); initWin(); InitWorldTransf(); loadSessionFile( sessionFileName ); activePrim=WORLD; /* init mouse scale and rotation speeds */ mouseRotSpeed = 1/100.0; mouseScaleSpeed = 1/50.0; mouseTransSpeed = 1/5.0; /* printf("mouse speeds: rot = %f trans = %f scale = %f\n", mouseRotSpeed, mouseTransSpeed, mouseScaleSpeed); */ /* never ending GLUT loop */ glutMainLoop(); }
//------------------------------------------------------------------------------ //! CoreXGL::CoreXGL() : _dblClickDelay( 300 ) { DBG_BLOCK( os_xgl, "CoreXGL::CoreXGL" ); addRoot( "" ); _mainPointerID = Core::createPointer().id(); // Create window. initWin(); }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); double vy = drand48(); double vx = drand48(); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); GLabel llabel = initlives(window); setLocation(llabel, 10, 590); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; pause(1000); // keep playing until game over updatellabel(window, llabel, 3); while (lives > 0 && bricks > 0) { while(bricks > 0) { GEvent mouse = getNextEvent(MOUSE_EVENT); if (mouse != NULL) { if (getEventType(mouse) == MOUSE_MOVED) { double x = getX(mouse) - getWidth(paddle) / 2; double y = getY(paddle); setLocation(paddle, x,y); } } move(ball,vx,vy); if (getX(ball) + CD >= WIDTH) { vx = -vx; } else if (getX(ball) <= 0) { vx = -vx; } else if (getY(ball) <= 0) { vy = -vy; } pause(1); GObject object = detectCollision(window, ball); if (object != NULL) { if (object == paddle) { vy = -vy; } else if (strcmp(getType(object), "GRect") == 0) { bricks--; points++; updateScoreboard(window, label, points); vy = -vy; removeGWindow(window, object); } } if (getY(ball) + CD >= HEIGHT) { lives = lives - 1; updatellabel(window, llabel, lives); setLocation(ball,(WIDTH/2) - (CD/2), (HEIGHT/2) - (CD/2)); pause (1000); if (bricks == 0) { GLabel win = initWin(window); pause(5000); break; } else { break; } } } } // wait for click before exiting removeGWindow(window, label); GLabel messege = initEnd(window); sleep(5000); waitForClick(); // game over closeGWindow(window); return 0; }