Add direction to windy rooms in lua

This commit is contained in:
Linus_Probert 2018-03-16 10:04:43 +01:00
parent 2393608682
commit 42fd246185
3 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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));
}