Minggu, 23 Maret 2014

Pertemuan 04. E-Book Figure Program to draw a moving ball

#include <cstdlib>
#include <iostream>
#include <graphics.h>
#define TRUE 1

using namespace std;

int main(void)
{
    const int PAUSE=20;
    const int DELTA=5;
    const int RADIUS=30;
    const int COLOR=RED;
   
    int width,height,x,y,stepX,stepY;
    width = getmaxwidth();
    height = getmaxheight();
    initwindow(width, height,"Pong - close window to quit",0,0,TRUE);
    x = RADIUS;
    y = RADIUS;
    stepX = DELTA;
    stepY = DELTA;
   
    while (TRUE){
          clearviewport();
          setfillstyle(SOLID_FILL, COLOR);
          fillellipse(x, y, RADIUS, RADIUS);
         
          swapbuffers();
          delay(PAUSE);
         
          if(x<= RADIUS)
                 stepX = DELTA;
          else if (x>= width - RADIUS)
               stepX = -DELTA;
              
          if(y <= RADIUS)
               stepY = DELTA;
          else if (y >= height - RADIUS)
               stepY + -DELTA;
              
          x = x + stepX;
          y = y + stepY;
          }
   
    closegraph();
    system("PAUSE");
    return EXIT_SUCCESS;
}

Tidak ada komentar:

Posting Komentar