pmc/main.cc
changeset 45 7197576fedcf
parent 42 83b8151b966d
child 46 4b9e1ac40246
equal deleted inserted replaced
44:bb6586b1c547 45:7197576fedcf
    13 #ifndef STEP
    13 #ifndef STEP
    14 #define STEP 1
    14 #define STEP 1
    15 #endif
    15 #endif
    16 
    16 
    17 #define MAX 3
    17 #define MAX 3
       
    18 
       
    19 using namespace algebra;
    18 
    20 
    19 int main (int argc, char **argv)
    21 int main (int argc, char **argv)
    20 {
    22 {
    21     Surface *surface;
    23     Surface *surface;
    22     SDL_Event event;
    24     SDL_Event event;
    43     d[0] = new Rectangle (surface, p1, p2, p3, p4);
    45     d[0] = new Rectangle (surface, p1, p2, p3, p4);
    44     d[1] = new Cube (surface);
    46     d[1] = new Cube (surface);
    45     d[2] = new Cube (surface, p1, p2, p3, p4, height);
    47     d[2] = new Cube (surface, p1, p2, p3, p4, height);
    46 
    48 
    47     bool running = true;
    49     bool running = true;
    48     int x, y;
    50     int i, x, y;
    49 
    51 
    50     x = y = 0;
    52     x = y = 0;
    51 
    53 
    52     d[1]->move (Vector (25, 25));
    54     d[1]->move (Vector (25, 25));
    53     d[2]->move (Vector (290, 0));
    55     d[2]->move (Vector (290, 0));
    58         if (event.type == SDL_QUIT)
    60         if (event.type == SDL_QUIT)
    59             running = false;
    61             running = false;
    60 
    62 
    61         if (event.type == SDL_KEYDOWN) {
    63         if (event.type == SDL_KEYDOWN) {
    62             surface->setColor (Surface::BLACK);
    64             surface->setColor (Surface::BLACK);
    63             for (int i = 0; i < MAX; i++)
    65             for (i = 0; i < MAX; i++)
    64                 d[i]->show ();
    66                 d[i]->show ();
    65             surface->setColor (Surface::RED);
    67             surface->setColor (Surface::RED);
    66 
    68 
    67             switch (event.key.keysym.sym) {
    69             switch (event.key.keysym.sym) {
    68             case SDLK_ESCAPE:
    70             case SDLK_ESCAPE:
    69                 running = false;
    71                 running = false;
    70                 break;
    72                 break;
    71 
    73 
    72             case SDLK_UP:
    74             case SDLK_UP:
    73                 for (int i = 0; i < MAX; i++)
    75                 for (i = 0; i < MAX; i++)
    74                     d[i]->move ((Vector (x, y - STEP)));
    76                     d[i]->move ((Vector (x, y - STEP)));
    75                 break;
    77                 break;
    76 
    78 
    77             case SDLK_DOWN:
    79             case SDLK_DOWN:
    78                 for (int i = 0; i < MAX; i++)
    80                 for (i = 0; i < MAX; i++)
    79                     d[i]->move ((Vector (x, y + STEP)));
    81                     d[i]->move ((Vector (x, y + STEP)));
    80                 break;
    82                 break;
    81 
    83 
    82             case SDLK_LEFT:
    84             case SDLK_LEFT:
    83                 for (int i = 0; i < MAX; i++)
    85                 for (i = 0; i < MAX; i++)
    84                     d[i]->move ((Vector (x - STEP, y)));
    86                     d[i]->move ((Vector (x - STEP, y)));
    85                 break;
    87                 break;
    86 
    88 
    87             case SDLK_RIGHT:
    89             case SDLK_RIGHT:
    88                 for (int i = 0; i < MAX; i++)
    90                 for (i = 0; i < MAX; i++)
    89                     d[i]->move ((Vector (x + STEP, y)));
    91                     d[i]->move ((Vector (x + STEP, y)));
    90                 break;
    92                 break;
    91             default:
    93             default:
    92                 break;
    94                 break;
    93             }
    95             }
    94 
    96 
    95             for (int i = 0; i < MAX; i++) {
    97             for (i = 0; i < MAX; i++) {
    96                 d[i]->show ();
    98                 d[i]->show ();
    97             }
    99             }
    98 
   100 
    99             surface->flip ();
   101             surface->flip ();
   100         }
   102         }
   101     }
   103     }
   102 
   104 
   103     for (int i = 0; i < MAX; i++)
   105     for (i = 0; i < MAX; i++)
   104         delete d[i];
   106         delete d[i];
   105 
   107 
   106     delete surface;
   108     delete surface;
   107 
   109 
   108     return EXIT_SUCCESS;
   110     return EXIT_SUCCESS;