summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-05-11 15:34:37 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-05-11 15:34:37 +0200
commit2f493c24e3771bca9b9ee717cb3d7c18c406678f (patch)
tree9613b0ee6e1adf495e1171b399d818b7111565de
parent2f9e8a6033075f68bbed46a66d22712a84b8f678 (diff)
map work
-rw-r--r--.vscode/settings.json5
-rw-r--r--data/imgs/objects/lamp_east.pngbin0 -> 3760 bytes
-rw-r--r--data/maps/map1.datbin8344008 -> 8384008 bytes
-rw-r--r--data/psd/lamp_east.psdbin0 -> 26254 bytes
-rw-r--r--include/asset_defs.h1
-rw-r--r--include/map.h10
-rw-r--r--include/objects.h28
-rw-r--r--src/asset_defs.c1
-rw-r--r--src/editor.c23
-rw-r--r--src/map.c16
-rw-r--r--src/objects.c2
-rw-r--r--src/pathfinding.c1
-rw-r--r--src/players.c1
13 files changed, 78 insertions, 10 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 30eb399..e9e1d02 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,5 +1,8 @@
{
"files.associations": {
- "project_base.h": "c"
+ "project_base.h": "c",
+ "initializer_list": "c",
+ "type_traits": "c",
+ "xutility": "c"
}
} \ No newline at end of file
diff --git a/data/imgs/objects/lamp_east.png b/data/imgs/objects/lamp_east.png
new file mode 100644
index 0000000..ba04cbf
--- /dev/null
+++ b/data/imgs/objects/lamp_east.png
Binary files differ
diff --git a/data/maps/map1.dat b/data/maps/map1.dat
index 963babd..f0db3c0 100644
--- a/data/maps/map1.dat
+++ b/data/maps/map1.dat
Binary files differ
diff --git a/data/psd/lamp_east.psd b/data/psd/lamp_east.psd
new file mode 100644
index 0000000..22e1e0d
--- /dev/null
+++ b/data/psd/lamp_east.psd
Binary files differ
diff --git a/include/asset_defs.h b/include/asset_defs.h
index fc770cb..fa04472 100644
--- a/include/asset_defs.h
+++ b/include/asset_defs.h
@@ -44,6 +44,7 @@ image* img_metal_wall;
image* img_metal_wall2;
image* img_chair_up;
image* img_zombie_spawner;
+image* img_lamp_east;
// Throwables
image* img_grenade;
diff --git a/include/map.h b/include/map.h
index 3980c8a..8b57d84 100644
--- a/include/map.h
+++ b/include/map.h
@@ -51,6 +51,16 @@ typedef struct t_map_data { // Data written to disk.
light_emitter light_emitters[MAX_LIGHT_EMITTERS];
} map_data;
+/* used for migerations.
+typedef struct t_map_data2 { // Data written to disk.
+ int width;
+ int height;
+ int heightmap[MAP_SIZE_Y][MAP_SIZE_X];
+ tile_type tiles[MAP_SIZE_Y][MAP_SIZE_X];
+ object2 objects[MAX_OBJECTS];
+ light_emitter light_emitters[MAX_LIGHT_EMITTERS];
+} map_data2;*/
+
typedef struct t_light_data {
float tl;
float tr;
diff --git a/include/objects.h b/include/objects.h
index da1459e..6369224 100644
--- a/include/objects.h
+++ b/include/objects.h
@@ -29,6 +29,7 @@ typedef enum t_object_type {
OBJECT_CHAIR_UP = 6,
OBJECT_SPACE_WINDOW_H = 7,
OBJECT_ZOMBIE_SPAWNER = 8, // Substitute.
+ OBJECT_LAMP_EAST = 9,
OBJECT_END,
} object_type;
@@ -38,8 +39,18 @@ typedef struct t_object {
vec3f position;
vec3f size;
object_type type;
+ bool collision;
} object;
+/*
+typedef struct t_object2 {
+ bool active;
+ vec3f position;
+ vec3f size;
+ object_type type;
+ bool collision;
+} object2;*/
+
typedef struct t_box {
vec2f tl_d;
vec2f tr_d;
@@ -54,14 +65,15 @@ typedef struct t_box {
// @NEWOBJECT
object object_dict[OBJECT_END] = {
- {0,(vec3f){0, 0, 0},{1,3,0.5f},OBJECT_SPACE_CONTROL_PANEL},
- {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_SPACE_WINDOW},
- {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_METAL_WALL},
- {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_METAL_WALL2},
- {0,(vec3f){0, 0, 0},{3,1,0.5f},OBJECT_SPACE_CONTROL_PANEL2},
- {0,(vec3f){0, 0, 0},{1,1,0.5f},OBJECT_CHAIR_UP},
- {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_SPACE_WINDOW_H},
- {0,(vec3f){0, 0, 0},{1,1,0.5},OBJECT_ZOMBIE_SPAWNER},
+ {0,(vec3f){0, 0, 0},{1,3,0.5f},OBJECT_SPACE_CONTROL_PANEL, 1},
+ {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_SPACE_WINDOW, 1},
+ {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_METAL_WALL, 1},
+ {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_METAL_WALL2, 1},
+ {0,(vec3f){0, 0, 0},{3,1,0.5f},OBJECT_SPACE_CONTROL_PANEL2, 1},
+ {0,(vec3f){0, 0, 0},{1,1,0.5f},OBJECT_CHAIR_UP, 1},
+ {0,(vec3f){0, 0, 0},{1,1,1},OBJECT_SPACE_WINDOW_H, 1},
+ {0,(vec3f){0, 0, 0},{1,1,0.5},OBJECT_ZOMBIE_SPAWNER, 1},
+ {0,(vec3f){0, 0, 0},{1,1,0},OBJECT_LAMP_EAST, 0},
};
object get_object_at_tile(float x, float y);
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;