src/proto2/Graphics.cc
changeset 138 cc326b64ae20
parent 125 8e15c7db2333
child 153 73402d5b778e
equal deleted inserted replaced
137:8736fdd12197 138:cc326b64ae20
     9     state(state), 
     9     state(state), 
    10     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
    10     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
    11     win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
    11     win(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
    12     keyboard(win.get_ic()->get_keyboard()) {
    12     keyboard(win.get_ic()->get_keyboard()) {
    13 
    13 
    14     Vector tmp;
       
    15     CL_Color color;
       
    16     CL_PixelBuffer terr(MAP_WIDTH, MAP_HEIGHT, 4*MAP_WIDTH, CL_PixelFormat::rgba8888);
       
    17     
       
    18     
       
    19     for (tmp.x = 0; tmp.x < MAP_WIDTH; tmp.x++) {
       
    20         for (tmp.y = 0; tmp.y < MAP_HEIGHT; tmp.y++) {
       
    21             if (state.getType(tmp) == EMPTY) {
       
    22                 color = CL_Color(86, 41, 0);
       
    23             } else if (state.getType(tmp) == DIRT) {
       
    24                 color = CL_Color(144, 82, 23);
       
    25             } else if (state.getType(tmp) == ROCK) {
       
    26                 color = CL_Color(132, 136, 135);
       
    27             } else {
       
    28                 // Fale
       
    29             }
       
    30             terr.draw_pixel(tmp.x, tmp.y, color);
       
    31      	}
       
    32     }
       
    33     terrain = CL_Surface(terr);
       
    34  
       
    35     // connect timer signal
    14     // connect timer signal
    36     slots.connect(update_timer.sig_timer(), this, &Graphics::on_update);
    15     slots.connect(update_timer.sig_timer(), this, &Graphics::on_update);
    37 
    16 
    38     // enable
    17     // enable
    39     update_timer.enable();
    18     update_timer.enable();
    89 
    68 
    90     const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH;
    69     const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH;
    91     const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
    70     const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
    92 
    71 
    93     // draw terrain
    72     // draw terrain
    94     terrain.draw(0,0, gc);
    73     state.drawTerrain(gc);
    95 
    74     //terrain.draw(gc);
       
    75     /*
    96     // Demonstrates digging, but is very slow
    76     // Demonstrates digging, but is very slow
    97 /*    Vector tmp(0, 0);
    77     Vector tmp(0, 0);
    98     CL_Color color;
    78     CL_Color color;
    99     CL_PixelBuffer pix(1, 1, 4, CL_PixelFormat::rgba8888);
    79     CL_PixelBuffer pix(1, 1, 4, CL_PixelFormat::rgba8888);
   100     CL_Surface surf(pix);
    80     CL_Surface surf(pix);
   101     for (tmp.x = 380; tmp.x < 430; tmp.x++) {
    81     for (tmp.x = 0; tmp.x < MAP_WIDTH; tmp.x++) {
   102         for (tmp.y = 560; tmp.y < 600; tmp.y++) {
    82         for (tmp.y = 0; tmp.y < MAP_HEIGHT; tmp.y++) {
   103             if (state.getType(tmp) == EMPTY) {
    83             if (state.getType(tmp) == EMPTY) {
   104                 color = CL_Color(86, 41, 0);
    84                 color = CL_Color(86, 41, 0);
   105             } else if (state.getType(tmp) == DIRT) {
    85             } else if (state.getType(tmp) == DIRT) {
   106                 color = CL_Color(144, 82, 23);
    86                 color = CL_Color(144, 82, 23);
   107             } else if (state.getType(tmp) == ROCK) {
    87             } else if (state.getType(tmp) == ROCK) {
   110                 // Fale
    90                 // Fale
   111             }
    91             }
   112             surf.set_color(color);
    92             surf.set_color(color);
   113             surf.draw(tmp.x, tmp.y, gc);
    93             surf.draw(tmp.x, tmp.y, gc);
   114         }
    94         }
   115     }*/
    95         }*/
   116   
    96   
   117     // draw players
    97     // draw players
   118     for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) {
    98     for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) {
   119         Player *p = *it;
    99         Player *p = *it;
   120         
   100