From 2f493c24e3771bca9b9ee717cb3d7c18c406678f Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 11 May 2024 15:34:37 +0200 Subject: map work --- src/asset_defs.c | 1 + src/editor.c | 23 ++++++++++++++++++++++- src/map.c | 16 ++++++++++++++++ src/objects.c | 2 ++ src/pathfinding.c | 1 + src/players.c | 1 + 6 files changed, 43 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/asset_defs.c b/src/asset_defs.c index cccbc7b..14fb149 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -52,6 +52,7 @@ void load_assets() { img_metal_wall2 = assets_load_image_from_file("data/imgs/objects/metal_wall2.png"); img_chair_up = assets_load_image_from_file("data/imgs/objects/chair_up.png"); img_zombie_spawner = assets_load_image_from_file("data/imgs/objects/zombie_spawner.png"); + img_lamp_east = assets_load_image_from_file("data/imgs/objects/lamp_east.png"); // Players img_gunner_black_run = assets_load_image_from_file("data/imgs/players/Black/Gunner_Black_Run.png"); diff --git a/src/editor.c b/src/editor.c index 79a5503..f65d966 100644 --- a/src/editor.c +++ b/src/editor.c @@ -116,7 +116,7 @@ void update_editor(platform_window* window) _next_camera_pos.x = -(window->width / 2) + camera_x; _next_camera_pos.y = -(window->height / 2) + camera_y; - vec2 pos = screen_pos_to_world_pos(window, _global_mouse.x + window->width/2, _global_mouse.y + window->height/2); + vec2 pos = screen_pos_to_world_pos(window, _global_mouse.x, _global_mouse.y); switch (edit_state) { case EDITING_TILES: update_tile_editor(window); break; @@ -126,9 +126,30 @@ void update_editor(platform_window* window) if (keyboard_is_key_down(KEY_LEFT_CONTROL) && keyboard_is_key_pressed(KEY_S)) { + #if 0 + map_data2* tmp = malloc(sizeof(map_data2)); + tmp->width = map_to_load.width; + tmp->height = map_to_load.height; + memcpy(tmp->heightmap, map_to_load.heightmap, sizeof(map_to_load.heightmap)); + memcpy(tmp->tiles, map_to_load.tiles, sizeof(map_to_load.tiles)); + memcpy(tmp->light_emitters, map_to_load.light_emitters, sizeof(map_to_load.light_emitters)); + + for (int i = 0; i < MAX_OBJECTS; i++) { + object o = map_to_load.objects[i]; + tmp->objects[i].active = o.active; + tmp->objects[i].position = o.position; + tmp->objects[i].size = o.size; + tmp->objects[i].type = o.type; + tmp->objects[i].collision = 1; + } + platform_write_file_content("../data/maps/map1.dat", "wb", (u8*)tmp, sizeof(map_data2)); + platform_write_file_content("data/maps/map1.dat", "wb", (u8*)tmp, sizeof(map_data2)); + log_info("Saved map"); + #else platform_write_file_content("../data/maps/map1.dat", "wb", (u8*)&map_to_load, sizeof(map_to_load)); platform_write_file_content("data/maps/map1.dat", "wb", (u8*)&map_to_load, sizeof(map_to_load)); log_info("Saved map"); + #endif } } diff --git a/src/map.c b/src/map.c index e0454aa..fdf8c4b 100644 --- a/src/map.c +++ b/src/map.c @@ -169,6 +169,7 @@ void load_mapdata_into_world() { int highest_point_topright = get_height_of_tile_tr(h, x, y); int highest_point_bottomright = get_height_of_tile_br(h, x, y); int highest_point_bottomleft = get_height_of_tile_bl(h, x, y); + loaded_map.heightmap[y][x] = (tile){.height = h, .type = map_to_load.tiles[y][x], highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright}; loaded_map.lightmap[y][x] = (light_data){0.0f,0.0f,0.0f,0.0f}; } @@ -435,6 +436,21 @@ static void draw_backdrop(platform_window* window) renderer->render_image(img_mars_surface, x*info.tile_width, y*info.tile_width, info.tile_width, info.tile_height); } } + + // south of spaceship + for (int y = 48; y <= 70; y++) + { + if (y < tilemap_render_min_y) continue; + if (y > tilemap_render_max_y) continue; + + for (int x = -40; x <= MAP_SIZE_X + 40; x++) + { + if (x < tilemap_render_min_x) continue; + if (x > tilemap_render_max_x) continue; + + renderer->render_image(img_mars_surface, x*info.tile_width, y*info.tile_width, info.tile_width, info.tile_height); + } + } } static float offset = 0.0f; diff --git a/src/objects.c b/src/objects.c index 7782ff5..eed8e8b 100644 --- a/src/objects.c +++ b/src/objects.c @@ -112,6 +112,8 @@ image* get_image_from_objecttype(object_type tile) { return img_space_window_h; case OBJECT_ZOMBIE_SPAWNER: return img_zombie_spawner; + case OBJECT_LAMP_EAST: + return img_lamp_east; default: return 0; } diff --git a/src/pathfinding.c b/src/pathfinding.c index 939adbe..05acad7 100644 --- a/src/pathfinding.c +++ b/src/pathfinding.c @@ -10,6 +10,7 @@ bool can_walk_at(float x, float y) for (int i = 0; i < MAX_OBJECTS; i++) { object o = loaded_map.objects[i]; if (!o.active) continue; + if (!o.collision) continue; if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return false; } return true; diff --git a/src/players.c b/src/players.c index 82a2815..5ad954f 100644 --- a/src/players.c +++ b/src/players.c @@ -218,6 +218,7 @@ object check_if_player_collided_with_object(player p) { for (int i = 0; i < MAX_OBJECTS; i++) { object o = loaded_map.objects[i]; if (!o.active) continue; + if (!o.collision) continue; if (check_if_player_collided_with_box(p, get_box_of_square((vec3f){o.position.x, o.position.y, o.position.z}, o.size))) { return o; -- cgit v1.2.3-70-g09d2