Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --get cells you're between
- local top = math.floor(y)
- local bottom = (top + 1)
- local left = math.floor(x)
- local right = (left + 1)
- --get codes
- local c_top_left = get_world_tile_code_raw(left, top)
- local c_top_right = get_world_tile_code_raw(right, top)
- local c_bottom_left = get_world_tile_code_raw(left, bottom)
- local c_bottom_right = get_world_tile_code_raw(right, bottom)
- if(c_top_left == c_top_right == c_bottom_left == c_bottom_right) then
- --shortcut before heavy operations it's applied often enough, that it's worth of additional if.
- return terrain_codes[c_top_left]
- end
- --calc weights
- local sqrt2 = math.sqrt(2)
- local w_top_left = 1 - math.sqrt((top - y)*(top - y) + (left - x)*(left - x)) / sqrt2
- local w_top_right = 1 - math.sqrt((top - y)*(top - y) + (right - x)*(right - x)) / sqrt2
- local w_bottom_left = 1 - math.sqrt((bottom - y)*(bottom - y) + (left - x)*(left - x)) / sqrt2
- local w_bottom_right = 1 - math.sqrt((bottom - y)*(bottom - y) + (right - x)*(right - x)) / sqrt2
- w_top_left = w_top_left * w_top_left + math.random() / math.max(scale / 2, 10)
- w_top_right = w_top_right * w_top_right + math.random() / math.max(scale / 2, 10)
- w_bottom_left = w_bottom_left * w_bottom_left + math.random() / math.max(scale / 2, 10)
- w_bottom_right = w_bottom_right * w_bottom_right + math.random() / math.max(scale / 2, 10)
- --calculate total weights for codes
- local totals = {}
- add_to_total(totals, w_top_left, c_top_left)
- add_to_total(totals, w_top_right, c_top_right)
- add_to_total(totals, w_bottom_left, c_bottom_left)
- add_to_total(totals, w_bottom_right, c_bottom_right)
Advertisement
Add Comment
Please, Sign In to add comment