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) { |