Esempio n. 1
0
void game(void)
{
  int16_t t,c,i;
  bool flashplayer=false;
  if (gauntlet) {
    cgtime=gtime*1193181l;
    timeout=false;
  }
  initlives();
  gamedat[0].level=startlev;
  if (nplayers==2)
    gamedat[1].level=startlev;
  alldead=false;
  ddap->gclear();
  curplayer=0;
  initlevel();
  curplayer=1;
  initlevel();
  zeroscores();
  bonusvisible=true;
  if (nplayers==2)
    flashplayer=true;
  curplayer=0;
  while (getalllives()!=0 && !escape && !timeout) {
    while (!alldead && !escape && !timeout) {
      initmbspr();

      if (playing)
        randv=playgetrand();
      else
        randv=getlrt();
#ifdef INTDRF
      fprintf(info,"%lu\n",randv);
      frame=0;
#endif
      recputrand(randv);
      if (levnotdrawn) {
        levnotdrawn=false;
        drawscreen(ddap);
        if (flashplayer) {
          flashplayer=false;
          strcpy(pldispbuf,"PLAYER ");
          if (curplayer==0)
            strcat(pldispbuf,"1");
          else
            strcat(pldispbuf,"2");
          cleartopline();
          for (t=0;t<15;t++)
            for (c=1;c<=3;c++) {
              outtext(ddap, pldispbuf,108,0,c);
              writecurscore(ddap, c);
              newframe();
              if (escape)
                return;
            }
          drawscores(ddap);
          for (i=0;i<diggers;i++)
            addscore(ddap, i,0);
        }
      }
      else
        initchars();
      outtext(ddap, "        ",108,0,3);
      initscores(ddap);
      drawlives(ddap);
      music(1);

      flushkeybuf();
      for (i=0;i<diggers;i++)
        readdirect(i);
      while (!alldead && !gamedat[curplayer].levdone && !escape && !timeout) {
        penalty=0;
        dodigger(ddap);
        domonsters(ddap);
        dobags(ddap);
        if (penalty>8)
          incmont(penalty-8);
        testpause();
        checklevdone();
      }
      erasediggers();
      musicoff();
      t=20;
      while ((getnmovingbags()!=0 || t!=0) && !escape && !timeout) {
        if (t!=0)
          t--;
        penalty=0;
        dobags(ddap);
        dodigger(ddap);
        domonsters(ddap);
        if (penalty<8)
          t=0;
      }
      soundstop();
      for (i=0;i<diggers;i++)
        killfire(i);
      erasebonus(ddap);
      cleanupbags();
      savefield();
      erasemonsters();
      recputeol();
      if (playing)
        playskipeol();
      if (escape)
        recputeog();
      if (gamedat[curplayer].levdone)
        soundlevdone();
      if (countem()==0 || gamedat[curplayer].levdone) {
#ifdef INTDRF
        fprintf(info,"%i\n",frame);
#endif
        for (i=curplayer;i<diggers+curplayer;i++)
          if (getlives(i)>0 && !digalive(i))
            declife(i);
        drawlives(ddap);
        gamedat[curplayer].level++;
        if (gamedat[curplayer].level>1000)
          gamedat[curplayer].level=1000;
        initlevel();
      }
      else
        if (alldead) {
#ifdef INTDRF
          fprintf(info,"%i\n",frame);
#endif
          for (i=curplayer;i<curplayer+diggers;i++)
            if (getlives(i)>0)
              declife(i);
          drawlives(ddap);
        }
      if ((alldead && getalllives()==0 && !gauntlet && !escape) || timeout)
        endofgame(ddap);
    }
    alldead=false;
    if (nplayers==2 && getlives(1-curplayer)!=0) {
      curplayer=1-curplayer;
      flashplayer=levnotdrawn=true;
    }
  }
#ifdef INTDRF
  fprintf(info,"-1\n%lu\n%i",getscore0(),gamedat[0].level);
#endif
}
Esempio n. 2
0
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;
}