diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index 6be0406..f020d95 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -373,7 +373,8 @@ function module.build_square_room(map, room) end if CURRENT_LEVEL > 2 and random(10) == 1 then - set_modifier(map, "WINDY"); + directions = { "LEFT", "RIGHT", "UP", "DOWN" } + set_modifier(map, "WINDY", directions[random(#directions)]); end end diff --git a/src/map_lua.c b/src/map_lua.c index 713b015..47928f4 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -92,15 +92,26 @@ SDL_Renderer* luaL_checksdlrenderer(lua_State *L) static int l_map_set_current_room_modifier(lua_State *L) { - const char *modifier; + const char *modifier, *direction; Map *map = luaL_checkmap(L, 1); modifier = luaL_checkstring(L, 2); + direction = luaL_checkstring(L, 3); + + Vector2d dir = VECTOR2D_LEFT; + if (strcmp(direction, "LEFT") == 0) + dir = VECTOR2D_LEFT; + else if (strcmp(direction, "RIGHT") == 0) + dir = VECTOR2D_RIGHT; + else if (strcmp(direction, "UP") == 0) + dir = VECTOR2D_UP; + else if (strcmp(direction, "DOWN") == 0) + dir = VECTOR2D_DOWN; if (strcmp(modifier, "WINDY") == 0) { Room *room = map->rooms[map->currentRoom.x][map->currentRoom.y]; room->modifier.type = RMOD_TYPE_WINDY; - room->modifier.data.wind.direction = VECTOR2D_LEFT; + room->modifier.data.wind.direction = dir; } else { luaL_error(L, "Unknown room modifier: %s", modifier); return 1; diff --git a/src/vector2d.c b/src/vector2d.c index 9063577..7b711a3 100644 --- a/src/vector2d.c +++ b/src/vector2d.c @@ -9,5 +9,6 @@ vector2d_equals(Vector2d v1, Vector2d v2) bool vector2d_is_opposite(Vector2d v1, Vector2d v2) { - return (v1.x > 0 && v2.x < 0) ^ (v1.y > 0 && v2.y < 0); + return ((v1.x > 0 && v2.x < 0) ^ (v1.y > 0 && v2.y < 0)) + || ((v1.x < 0 && v2.x > 0) ^ (v1.y < 0 && v2.y > 0)); }