src/proto2/Graphics.cc
changeset 86 ed31ece6f340
parent 60 26571fd9a8d1
child 87 fa9512ace722
equal deleted inserted replaced
85:351cb6b69c04 86:ed31ece6f340
     1 
     1 
     2 #include "Graphics.hh"
     2 #include "Graphics.hh"
       
     3 #include "Physics.hh"
       
     4 #include "GameState.hh"
     3 
     5 
     4 Graphics::Graphics (Engine &engine, GameState &state) :
     6 Graphics::Graphics (Engine &engine, GameState &state) :
     5     engine(engine), 
     7     engine(engine), 
     6     state(state), 
     8     state(state), 
     7     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
     9     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
     8     win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
    10     win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
     9     keyboard(win.get_ic()->get_keyboard()) {
    11     keyboard(win.get_ic()->get_keyboard()) {
    10     
    12 
       
    13     Vector tmp;
       
    14     CL_Color color;
       
    15     CL_PixelBuffer terr;
       
    16     for (tmp.x = 0; tmp.x < MAP_WIDTH; tmp.x++) {
       
    17         for (tmp.y = 0; tmp.y < MAP_HEIGHT; tmp.y++) {
       
    18             if (state.getType(tmp) == EMPTY) {
       
    19                 color = CL_Color::white;
       
    20             } else if (state.getType(tmp) == DIRT) {
       
    21                 color = CL_Color::brown;
       
    22             } else if (state.getType(tmp) == ROCK) {
       
    23                 color = CL_Color::grey;
       
    24             } else {
       
    25                 // Fale
       
    26             }
       
    27             terr.draw_pixel(tmp.x, tmp.y, color);
       
    28         }
       
    29     }
       
    30     terrain.set_pixeldata(terr);
       
    31 
    11     // connect timer signal
    32     // connect timer signal
    12     slots.connect(update_timer.sig_timer(), this, &Graphics::on_update);
    33     slots.connect(update_timer.sig_timer(), this, &Graphics::on_update);
    13 
    34 
    14     // enable
    35     // enable
    15     update_timer.enable();
    36     update_timer.enable();
    55     gc->clear(CL_Color::white);
    76     gc->clear(CL_Color::white);
    56 
    77 
    57     const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH;
    78     const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH;
    58     const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
    79     const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
    59 
    80 
       
    81     // draw terrain
       
    82     terrain.draw(0,0, gc);
       
    83 
    60     // draw players
    84     // draw players
    61     for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) {
    85     for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) {
    62         Player *p = *it;
    86         Player *p = *it;
    63         
    87         
    64         // draw square
    88         // draw square