pmc/main.cc
changeset 4 236f8f747073
child 9 c3fecc82ade6
equal deleted inserted replaced
3:820ed7fb9314 4:236f8f747073
       
     1 /***
       
     2  *
       
     3  * $Id: main.cc,v 1.1.1.1 2008-04-28 17:33:22 mbroeker Exp $
       
     4  * $Source: /development/cpp/pmc/main.cc,v $
       
     5  *
       
     6  */
       
     7 
       
     8 #include <cube.h>
       
     9 #include <SDL/SDL.h>
       
    10 
       
    11 unsigned long color;
       
    12 SDL_Surface *screen;
       
    13 
       
    14 #ifndef STEP
       
    15 #define STEP 1
       
    16 #endif
       
    17 
       
    18 int main (int argc, char **argv)
       
    19 {
       
    20 
       
    21     unsigned long red, black;
       
    22     SDL_Event event;
       
    23 
       
    24     if (argc != 2) {
       
    25         std::cout << "USAGE: " << argv[0]
       
    26             << " height" << std::endl;
       
    27         exit (0);
       
    28     }
       
    29     int h = atoi (argv[1]);
       
    30 
       
    31     if ((h < 10) || (h >= 360))
       
    32         h = 200;
       
    33 
       
    34     Vector p1 (0, 0, 0);
       
    35     Vector p2 (0, h, 0);
       
    36     Vector p3 (h, 0, 0);
       
    37     Vector p4 (h, h, 0);
       
    38 
       
    39     SDL_Init (SDL_INIT_VIDEO);
       
    40     screen = SDL_SetVideoMode (1010, 700, 16, SDL_HWSURFACE);
       
    41     red = SDL_MapRGB (screen->format, 0xff, 0x00, 0x00);
       
    42     black = SDL_MapRGB (screen->format, 0x00, 0x00, 0x00);
       
    43 
       
    44     Cube *c = new Cube (p1, p2, p3, p4, h);
       
    45     Cube *d = new Cube (p1, p2, p3, p4, h);
       
    46 
       
    47     c->move (Vector (100, 250, 0));
       
    48     d->move (Vector (400, 250, 0));
       
    49 
       
    50     bool running = true;
       
    51     int x, y, z;
       
    52 
       
    53     x = y = z = 0;
       
    54 
       
    55     while (running) {
       
    56         SDL_PollEvent (&event);
       
    57 
       
    58         if (event.type == SDL_QUIT)
       
    59             running = false;
       
    60 
       
    61         if (event.type == SDL_KEYDOWN) {
       
    62             color = black;
       
    63             c->show ();
       
    64             d->show ();
       
    65             color = red;
       
    66 
       
    67             switch (event.key.keysym.sym) {
       
    68             case SDLK_ESCAPE:
       
    69                 running = false;
       
    70                 break;
       
    71 
       
    72             case SDLK_UP:
       
    73                 c->move ((Vector (x, y - STEP, z)));
       
    74                 d->move ((Vector (x, y - STEP, z)));
       
    75                 break;
       
    76 
       
    77             case SDLK_DOWN:
       
    78                 c->move ((Vector (x, y + STEP, z)));
       
    79                 d->move ((Vector (x, y + STEP, z)));
       
    80                 break;
       
    81 
       
    82             case SDLK_LEFT:
       
    83                 c->move ((Vector (x - STEP, y, z)));
       
    84                 d->move ((Vector (x - STEP, y, z)));
       
    85                 break;
       
    86 
       
    87             case SDLK_RIGHT:
       
    88                 c->move ((Vector (x + STEP, y, z)));
       
    89                 d->move ((Vector (x + STEP, y, z)));
       
    90                 break;
       
    91             default:
       
    92                 break;
       
    93             }
       
    94 
       
    95             c->show ();
       
    96             d->show ();
       
    97             SDL_Flip (screen);
       
    98         }
       
    99     }
       
   100 
       
   101     delete c;
       
   102     delete d;
       
   103 
       
   104     SDL_Quit ();
       
   105 
       
   106     return 0;
       
   107 }