summaryrefslogtreecommitdiff
path: root/src/objects.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/objects.c')
-rw-r--r--src/objects.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/objects.c b/src/objects.c
index c8a150c..3969000 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -31,13 +31,25 @@ void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) {
object get_object_at_tile(float x, float y) {
for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = objects[i];
+ object o = loaded_map.objects[i];
if (!o.active) 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 o;
}
return (object){0};
}
+image* get_image_from_objecttype(object_type tile) {
+ switch (tile)
+ {
+ case OBJECT_COBBLESTONEWALL1:
+ return img_obj_wall1;
+ case OBJECT_PLANTBOX1:
+ return img_obj_plants;
+ default:
+ return 0;
+ }
+}
+
void draw_objects_at_row(platform_window* window, int row) {
map_info info = get_map_info(window);
@@ -48,8 +60,12 @@ void draw_objects_at_row(platform_window* window, int row) {
if (!o.active) continue;
box box = get_box_of_object(window, o);
- renderer->render_image(o.image, box.tl_u.x, box.tl_u.y,
- box.br_d.x - box.tl_d.x, box.br_d.y - box.tr_u.y);
+
+ image* img = get_image_from_objecttype(o.type);
+ if (img) {
+ renderer->render_image(img, box.tl_u.x, box.tl_u.y,
+ box.br_d.x - box.tl_d.x, box.br_d.y - box.tr_u.y);
+ }
/*
render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgb(200,200,0));
render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,200,0));
@@ -58,47 +74,32 @@ void draw_objects_at_row(platform_window* window, int row) {
}
}
-void create_box(float x, float y, float h, image* img) {
- for (int i = 0; i < MAX_OBJECTS; i++) {
- object o = objects[i];
- if (o.active) continue;
-
- objects[i].active = true;
- objects[i].position = (vec2f){x, y};
- objects[i].h = h;
- objects[i].size = (vec3f){1,1,2};
- objects[i].image = img;
- break;
- }
-}
-
void create_objects() {
+ /*
// rechts naar links op map.
-
-
for (int i = MAP_SIZE_X-1; i >= 0; i--) {
- create_box(i, 0, 0, img_obj_wall1);
- create_box(i, MAP_SIZE_Y-1, 0, img_obj_wall1);
+ create_box(i, 0, 0, OBJECT_COBBLESTONEWALL1);
+ create_box(i, MAP_SIZE_Y-1, 0, OBJECT_COBBLESTONEWALL1);
}
for (int i = MAP_SIZE_Y-1; i >= 0; i--) {
- create_box(0, i, 0, img_obj_wall1);
- create_box(MAP_SIZE_X-1, i, 0, img_obj_wall1);
+ create_box(0, i, 0, OBJECT_COBBLESTONEWALL1);
+ create_box(MAP_SIZE_X-1, i, 0, OBJECT_COBBLESTONEWALL1);
}
- create_box(16, 8, 0, img_obj_plants);
- create_box(14, 8, 0, img_obj_plants);
- create_box(11, 8, 0, img_obj_plants);
- create_box(10, 8, 0, img_obj_plants);
+ create_box(16, 8, 0, OBJECT_PLANTBOX1);
+ create_box(14, 8, 0, OBJECT_PLANTBOX1);
+ create_box(11, 8, 0, OBJECT_PLANTBOX1);
+ create_box(10, 8, 0, OBJECT_PLANTBOX1);
- create_box(15, 10, 0, img_obj_plants);
- create_box(14, 10, 0, img_obj_plants);
- create_box(13, 10, 0, img_obj_plants);
- create_box(11, 10, 0, img_obj_plants);
+ create_box(15, 10, 0, OBJECT_PLANTBOX1);
+ create_box(14, 10, 0, OBJECT_PLANTBOX1);
+ create_box(13, 10, 0, OBJECT_PLANTBOX1);
+ create_box(11, 10, 0, OBJECT_PLANTBOX1);
create_spawner((vec2){15, 5});
create_spawner((vec2){3, 8});
create_spawner((vec2){11, 18});
-
+ */
create_wallitem((vec3f){14, 1, 0}, WALLITEM_GUN, (wall_item_data){.gun = GUN_NOVA});
} \ No newline at end of file