make new map tiles be empty by default and only expand map by one row/column

This commit is contained in:
Sven Balzer 2025-02-27 18:15:35 +01:00
parent 08e3dfd9d3
commit 3c02064f2b

View File

@ -240,7 +240,7 @@ void change_map_size(char direction, int amount) {
for (int y = 0; y < to_fill_height; y++) {
for (int x = 0; x < to_fill_width; x++) {
map_tiles[(y + to_fill_y_offset) * map_width + (x + to_fill_x_offset)] = 0;
map_tiles[(y + to_fill_y_offset) * map_width + (x + to_fill_x_offset)] = 1;
}
}
@ -900,9 +900,6 @@ int main(int argc, char **argv) {
if (io.WantCaptureMouse)
continue;
if (selected_tile == -1)
continue;
float mouse_x = event.button.x;
float mouse_y = event.button.y;
@ -932,37 +929,39 @@ int main(int argc, char **argv) {
if (mouse_y< 0)
tile_y = -1;
if(0 <= tile_x && tile_x < map_width &&
0 <= tile_y && tile_y < map_height)
map_tiles[tile_x + map_width * tile_y] = selected_tile;
if (selected_tile != -1) {
if(0 <= tile_x && tile_x < map_width &&
0 <= tile_y && tile_y < map_height)
map_tiles[tile_x + map_width * tile_y] = selected_tile;
}
SDL_Keymod modifiers = SDL_GetModState();
if (modifiers & SDL_KMOD_SHIFT && tile_x == -1) {
if(modifiers & SDL_KMOD_CTRL)
change_map_size('W', -1);
else
change_map_size('W', 2);
change_map_size('W', 1);
}
if (modifiers & SDL_KMOD_SHIFT && tile_x == map_width) {
if (modifiers & SDL_KMOD_CTRL)
change_map_size('E', -1);
else
change_map_size('E', 2);
change_map_size('E', 1);
}
if (modifiers & SDL_KMOD_SHIFT && tile_y == -1) {
if (modifiers & SDL_KMOD_CTRL)
change_map_size('N', -1);
else
change_map_size('N', 2);
change_map_size('N', 1);
}
if (modifiers & SDL_KMOD_SHIFT && tile_y == map_height) {
if (modifiers & SDL_KMOD_CTRL)
change_map_size('S', -1);
else
change_map_size('S', 2);
change_map_size('S', 1);
}
} break;
}