#include #include #include #include "wall.h" extern struct Texture wall_texture; static inline bool tile_is_collidable(int tile) { int non_collidable[] = {65, 122}; for (size_t i = 0; i < sizeof(non_collidable) / sizeof(non_collidable[0]); i++) if (non_collidable[i] == tile) return false; return true; } void add_wall(float xpos, float ypos, int tile) { int tile_x = tile % 18; int tile_y = tile / 18; struct entity wall = { .type = Wall_Entity, .flags = (ENTITY_ACTIVE | ENTITY_VISIBLE), .texture = wall_texture, .sprite_source_rect = (Rectangle) { .x = tile_x * 129, .y = tile_y * 129, .width = 128, .height = 128 }, .sprite_dest_rect = (Rectangle) { .x = -BLOCK_WIDTH / 2, .y = -BLOCK_HEIGHT / 2, .width = BLOCK_WIDTH, .height = BLOCK_HEIGHT }, .position = { .x = xpos, .y = ypos }, .velocity = (Vector2) {0}, .collider = (Rectangle) { .x = -BLOCK_WIDTH / 2, .y = -BLOCK_HEIGHT / 2, .width = BLOCK_WIDTH, .height = BLOCK_HEIGHT }, }; if (tile_is_collidable(tile)) wall.flags |= ENTITY_COLLISION_ACTIVE; add_entity(&wall); }