share/hedgewars/Data/Scripts/Utils.lua
author belphegorr <szabibibi@gmail.com>
Fri, 10 Aug 2012 04:26:58 +0300
changeset 7448 d0521a3a4358
parent 4873 98dbb9b985e5
child 13215 bc95df84395f
permissions -rw-r--r--
Solved "floating repositionings" in every mission Fixed bug where gear message wouldn't be reset after animations Mission 5: fixed bug where control would be messed up when animation interrupted the turn of a hedgehog that was using multi-shot weapons Replaced graves with circles for marking enemy positions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4873
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     1
-- Library for miscellaneous utilitiy functions
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     2
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     3
-- Check if a gear is inside a box
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     4
function gearIsInBox(gear, x, y, w, h)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     5
    gx, gy = GetGearPosition(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     6
    if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     7
        return true
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     8
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
     9
    return false
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    10
end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    11
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    12
-- Check if a gear is inside a circle
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    13
function gearIsInCircle(gear, x, y, r, useRadius)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    14
    gx, gy = GetGearPosition(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    15
    if useRadius then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    16
        r = r + GetGearRadius(gear)
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    17
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    18
    if r ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    19
        return true
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    20
    end
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    21
    return false
98dbb9b985e5 add a new lua library with misc tools and removed redundant tracker functions
Henek
parents:
diff changeset
    22
end