- Joined
- Mar 29, 2016
- Messages
- 688
Bound Coordinates v1.01
This simple snippet helps you implement map boundary with convenience when setting units' coordinates. It helps in other cases as well.
Script
This simple snippet helps you implement map boundary with convenience when setting units' coordinates. It helps in other cases as well.
Script
JASS:
library BoundCoordinates /*v1.01
*/requires WorldBounds/*
- https://github.com/nestharus/JASS/blob/master/jass/Systems/WorldBounds/script.j
*///! novjass
_________________
| |
| WRITTEN BY: AGD |
|_________________|
|=====|
| API |
|=====|
function SafeSetX takes unit u, real x returns boolean/*
- Sets the x-coordinate of a unit while implementing map bounds
- Returns true if the taken <x> value is already within the map bounds
and returns false if not
*/function SafeSetY takes unit u, real y returns boolean/*
- Sets the y-coordinate of a unit while implementing map bounds
- Returns true if the taken <y> value is already within the map bounds
and returns false if not
*/function SafeSetXY takes unit u, real x, real y returns boolean/*
- Sets the x-coordinate and y-coordinate of a unit while implementing map bounds
- Returns true if both taken coordinates are already within the map bounds
and returns false if not
*/function BoundX takes real x returns real/*
- Returns the bounded value of x: if x is outside the map coordinates,
x is set to x of the map boundary
*/function BoundY takes real y returns real/*
- Returns the bounded value of y: if y is outside the map coordinates,
y is set to y of the map boundary
*///! endnovjass
function SafeSetX takes unit u, real x returns boolean
local boolean check = true
if x < WorldBounds.minX then
set x = I2R(WorldBounds.minX)
set check = false
elseif x > WorldBounds.maxX then
set x = I2R(WorldBounds.maxX)
set check = false
endif
call SetUnitX(u, x)
return check
endfunction
function SafeSetY takes unit u, real y returns boolean
local boolean check = true
if y < WorldBounds.minY then
set y = I2R(WorldBounds.minY)
set check = false
elseif y > WorldBounds.maxY then
set y = I2R(WorldBounds.maxY)
set check = false
endif
call SetUnitY(u, y)
return check
endfunction
function SafeSetXY takes unit u, real x, real y returns boolean
return SafeSetX(u, x) and SafeSetY(u, y)
endfunction
function BoundX takes real x returns real
if x < WorldBounds.minX then
return I2R(WorldBounds.minX)
elseif x > WorldBounds.maxX then
return I2R(WorldBounds.maxX)
endif
return x
endfunction
function BoundY takes real y returns real
if y < WorldBounds.minY then
return I2R(WorldBounds.minY)
elseif y > WorldBounds.maxY then
return I2R(WorldBounds.maxY)
endif
return y
endfunction
endlibrary
Last edited: