fix: level drawing was broken

This commit is contained in:
KikooDX 2021-03-26 18:54:25 +01:00
parent 42b166b783
commit dcd4afc520
1 changed files with 23 additions and 22 deletions

View File

@ -15,28 +15,29 @@ void level_draw(struct Level level, struct Options options,
for (x = 0; x < level.width; x += 1) {
for (y = 0; y < level.height; y += 1) {
const int tile_index = x + y * level.width;
if (tile_index &&
tile_index < options.tileset_width *
options.tileset_height) {
const int tile =
level.data[x + y * level.width];
const Rectangle tile_rect = {
(int)(tile %
options.tileset_width) *
options.tile_width,
(int)(tile /
options.tileset_height) *
options.tile_height,
options.tile_width,
options.tile_height};
const Vector2 tile_pos = {
x * options.tile_width +
options.editor_draw_offset_x,
y * options.tile_height +
options.editor_draw_offset_y};
DrawTextureRec(tileset, tile_rect,
tile_pos, WHITE);
}
/* if tile index is out of bound, skip */
if (tile_index >= level.width *
level.height)
continue;
const Tile tile =
level.data[x + y * level.width];
/* if tile is not in tileset, skip */
if (!tile || tile >= options.tileset_width * options.tileset_height)
continue;
const Rectangle tile_rect = {
(int)(tile % options.tileset_width) *
options.tile_width,
(int)(tile / options.tileset_height) *
options.tile_height,
options.tile_width, options.tile_height};
const Vector2 tile_pos = {
x * options.tile_width +
options.editor_draw_offset_x,
y * options.tile_height +
options.editor_draw_offset_y};
DrawTextureRec(tileset, tile_rect, tile_pos,
WHITE);
}
}
}