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()) { |
|
12 |
|
13 Vector tmp; |
|
14 CL_Color color; |
|
15 CL_PixelBuffer terr(MAP_WIDTH, MAP_HEIGHT, 3*MAP_WIDTH, CL_PixelFormat::rgb888); |
10 |
16 |
|
17 |
|
18 for (tmp.x = 0; tmp.x < MAP_WIDTH; tmp.x++) { |
|
19 for (tmp.y = 0; tmp.y < MAP_HEIGHT; tmp.y++) { |
|
20 if (state.getType(tmp) == EMPTY) { |
|
21 color = CL_Color(80, 35, 0); |
|
22 } else if (state.getType(tmp) == DIRT) { |
|
23 color = CL_Color(144, 82, 23); |
|
24 } else if (state.getType(tmp) == ROCK) { |
|
25 color = CL_Color(132, 136, 135); |
|
26 } else { |
|
27 // Fale |
|
28 } |
|
29 terr.draw_pixel(tmp.x, tmp.y, color); |
|
30 } |
|
31 } |
|
32 terrain = CL_Surface(terr); |
|
33 |
|
34 Engine::log(DEBUG, "Graphics") << "Taalla ollaan."; |
|
35 |
11 // connect timer signal |
36 // connect timer signal |
12 slots.connect(update_timer.sig_timer(), this, &Graphics::on_update); |
37 slots.connect(update_timer.sig_timer(), this, &Graphics::on_update); |
13 |
38 |
14 // enable |
39 // enable |
15 update_timer.enable(); |
40 update_timer.enable(); |
55 gc->clear(CL_Color::white); |
80 gc->clear(CL_Color::white); |
56 |
81 |
57 const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH; |
82 const float factorX = GRAPHICS_RESOLUTION_WIDTH / MAP_WIDTH; |
58 const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT; |
83 const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT; |
59 |
84 |
|
85 // draw terrain |
|
86 terrain.draw(0,0, gc); |
|
87 |
60 // draw players |
88 // draw players |
61 for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) { |
89 for (std::list<Player*>::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) { |
62 Player *p = *it; |
90 Player *p = *it; |
63 |
91 |
64 // draw square |
92 // draw square |