share/hedgewars/Data/Scripts/Utils.lua
changeset 14252 74bf2d906097
parent 13665 5664650befcd
child 14496 2113296b7a29
equal deleted inserted replaced
14251:8edbdd3a1fe7 14252:74bf2d906097
     1 -- Library for miscellaneous utilitiy functions and global helper variables
     1 -- Library for miscellaneous utilitiy functions and global helper variables
     2 
     2 
     3 --[[ FUNCTIONS ]]
     3 --[[ FUNCTIONS ]]
     4 -- Check if a gear is inside a box
     4 -- Check if a gear is inside a box
     5 function gearIsInBox(gear, x, y, w, h)
     5 function gearIsInBox(gear, x, y, w, h)
     6     gx, gy = GetGearPosition(gear)
     6     local gx, gy = GetGearPosition(gear)
     7     if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
     7     if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
     8         return true
     8         return true
     9     end
     9     end
    10     return false
    10     return false
    11 end
    11 end
    12 
    12 
    13 -- Check if a gear is inside a circle
    13 -- Check if a gear is inside a circle
    14 function gearIsInCircle(gear, x, y, r, useRadius)
    14 function gearIsInCircle(gear, x, y, r, useRadius)
    15     gx, gy = GetGearPosition(gear)
    15     local gx, gy = GetGearPosition(gear)
    16     if useRadius then
    16     if useRadius then
    17         r = r + GetGearRadius(gear)
    17         r = r + GetGearRadius(gear)
    18     end
    18     end
    19     if r ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
    19     if r ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
    20         return true
    20         return true