• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] MapBounds

JASS:
/*
*=================================================================================*
*   Map Bounds 1.2                                                                *                                                          
*   By Adiktuz                                                                    *
*                                                                                 *
*                                                                                 *
*   This is a short snippet that provides some useful functions utilizing         *
*   the WorldBounds library created by Nestharus                                  * 
*                                                                                 *
*                                                                                 *  
*   Credits:                                                                      *
*       Nestharus for the WorldBounds library                                     *
*       Magtheridon96 for suggestions                                             *
*                                                                                 * 
*   Functions:                                                                    *
*                                                                                 *  
*       -> MapContainsX(real x) returns boolean                                    *
*       -> MapContainsY(real y) returns boolean                                    *
*       -> GetBoundedX(real x) returns real                                       *
*       -> GetBoundedY(real y) returns real                                       *
*                                                                                 *
*                                                                                 *
*   The MapContainsX/Y functions return if the given x/y value is inside the map   *
*                                                                                 *
*   The GetBoundedX/Y  checks if the given value is within the map. If it's       *
*       within the map, it will return the value given and if Not                 *
*       it will return the value of the border that it will exceed                *
*                                                                                 *
*=================================================================================*
*/

library MapBounds requires WorldBounds

    function MapContainsX takes real x returns boolean
        return x < WorldBounds.maxX and x > WorldBounds.minX
    endfunction
    
    function MapContainsY takes real y returns boolean
        return y < WorldBounds.maxY and y > WorldBounds.minY
    endfunction
    
    function GetBoundedX takes real x returns real
        if x > WorldBounds.maxX then
            return I2R(WorldBounds.maxX)
        elseif x < WorldBounds.minX then
            return I2R(WorldBounds.minX)
        endif
        return x
    endfunction
    
    function GetBoundedY takes real y returns real
        if y > WorldBounds.maxY then
            return I2R(WorldBounds.maxY)
        elseif y < WorldBounds.minY then
            return I2R(WorldBounds.minY)
        endif
        return y
    endfunction
    
endlibrary

Well, its a simple snippet of functions for WorldBounds...

I hope you find it useful even if its really simple...
 
Last edited by a moderator:
Top