We now have a scene we can twirl around and we can see the rays being cast in the left side.
This commit is contained in:
parent
b30ac77049
commit
35f6fcc01d
1 changed files with 29 additions and 5 deletions
|
@ -59,16 +59,16 @@ void draw_rect(Fenster &window, Point pos, Point size, uint32_t color) {
|
|||
}
|
||||
}
|
||||
|
||||
void draw_map_rect(Fenster &window, int x, int y, uint8_t color) {
|
||||
void draw_map_rect(Fenster &window, int x, int y, uint32_t color) {
|
||||
draw_rect(window,
|
||||
{size_t(x * TILE_SIZE), size_t(y * TILE_SIZE)},
|
||||
{size_t(TILE_SIZE-1), size_t(TILE_SIZE-1)},
|
||||
gray_color(color));
|
||||
color);
|
||||
}
|
||||
|
||||
void draw_map(Fenster &window, Matrix &map) {
|
||||
uint8_t light_grey = 191;
|
||||
uint8_t dark_grey = 65;
|
||||
uint32_t light_grey = gray_color(191);
|
||||
uint32_t dark_grey = gray_color(65);
|
||||
|
||||
for(size_t y = 0; y < matrix::height(map); y++) {
|
||||
for(size_t x = 0; x < matrix::width(map); x++) {
|
||||
|
@ -78,7 +78,31 @@ void draw_map(Fenster &window, Matrix &map) {
|
|||
}
|
||||
|
||||
void draw_line(Fenster &window, Point start, Point end) {
|
||||
int x = int(start.x);
|
||||
int y = int(start.y);
|
||||
int x1 = int(end.x);
|
||||
int y1 = int(end.y);
|
||||
int dx = std::abs(x1 - x);
|
||||
int sx = x < x1 ? 1 : -1;
|
||||
int dy = std::abs(y1 - y) * -1;
|
||||
int sy = y < y1 ? 1 : -1;
|
||||
int error = dx + dy;
|
||||
|
||||
while(x != x1 || y != y1) {
|
||||
int e2 = 2 * error;
|
||||
|
||||
if(e2 >= dy) {
|
||||
error = error + dy;
|
||||
x = x + sx;
|
||||
}
|
||||
|
||||
if(e2 <= dx) {
|
||||
error = error + dx;
|
||||
y = y + sy;
|
||||
}
|
||||
|
||||
window.px(x, y) = rgba_color(200, 20, 20, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void clear(Fenster &window) {
|
||||
|
@ -90,7 +114,7 @@ void clear(Fenster &window) {
|
|||
}
|
||||
|
||||
void draw_map_rays(Fenster &window, int col, int row, Point target) {
|
||||
draw_map_rect(window, col, row, 100);
|
||||
draw_map_rect(window, col, row, rgba_color(100, 20, 20, 255));
|
||||
draw_line(window, {size_t(player_x), size_t(player_y)}, target);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue