- Joined
- Oct 29, 2007
- Messages
- 1,184
I've been starting to understand more and more jass lately and so I wanted to make my own function. : < How's the performance? Any ways to make it better?
This function is for arrowkey movement.
This function is for arrowkey movement.
JASS:
unction MoveUnit takes integer i returns nothing
local integer j = 0
set udg_move_speed[i] = 0
set udg_move_direction[i] = GetUnitFacing(udg_Player[i])
if (udg_detect_up[i] == 1) then
set udg_move_speed[i] = 4
if (udg_detect_left[i] == 1) then
set udg_move_direction[i] = udg_move_direction[i] + 8
elseif (udg_detect_right[i] == 1) then
set udg_move_direction[i] = udg_move_direction[i] - 8
endif
elseif (udg_detect_down[i] == 1) then
set udg_move_speed[i] = -4
if (udg_detect_left[i] == 1) then
set udg_move_direction[i] = udg_move_direction[i] - 8
elseif (udg_detect_right[i] == 1) then
set udg_move_direction[i] = udg_move_direction[i] + 8
endif
elseif ((udg_detect_left[i] == 1) and (udg_detect_up[i] == 0) and (udg_detect_down[i] == 0)) then
if (udg_turn_speed[i] < 12) then
set udg_turn_speed[i] = udg_turn_speed[i] + 0.1
endif
set udg_move_direction[i] = udg_move_direction[i] + 8 + udg_turn_speed[i]
elseif ((udg_detect_right[i] == 1) and (udg_detect_up[i] == 0) and (udg_detect_down[i] == 0)) then
if (udg_turn_speed[i] > -12) then
set udg_turn_speed[i] = udg_turn_speed[i] - 0.1
endif
set udg_move_direction[i] = udg_move_direction[i] - 8 + udg_turn_speed[i]
endif
set udg_tmp_loc = GetUnitLoc(udg_Player[i])
set udg_tmp_loc2 = PolarProjectionBJ(udg_tmp_loc, udg_move_speed[i], udg_move_direction[i])
set udg_bool_path = IsTerrainPathingType(GetLocationX(udg_tmp_loc2), GetLocationY(udg_tmp_loc2), TERRAIN_PATHING_WALKABLE)
if (udg_bool_path == true) then
call SetUnitPositionLocFacingBJ(udg_Player[i], udg_tmp_loc2, udg_move_direction[i])
call RemoveLocation(udg_tmp_loc2)
elseif (udg_bool_path == false) then
call RemoveLocation(udg_tmp_loc2)
set j = 1
loop
set udg_tmp_loc2 = PolarProjectionBJ(udg_tmp_loc, (udg_move_speed[i] / 2), udg_move_direction[i] + ( 9 * j ))
set udg_bool_path = IsTerrainPathingType(GetLocationX(udg_tmp_loc2), GetLocationY(udg_tmp_loc2), TERRAIN_PATHING_WALKABLE)
if (udg_bool_path == true) then
call SetUnitPositionLocFacingBJ(udg_Player[i], udg_tmp_loc2, udg_move_direction[i])
call RemoveLocation(udg_tmp_loc2)
exitwhen true
elseif (udg_bool_path == false) then
call RemoveLocation(udg_tmp_loc2)
set udg_tmp_loc2 = PolarProjectionBJ(udg_tmp_loc, (udg_move_speed[i] / 2), udg_move_direction[i] - ( 9 * j ))
set udg_bool_path = IsTerrainPathingType(GetLocationX(udg_tmp_loc2), GetLocationY(udg_tmp_loc2), TERRAIN_PATHING_WALKABLE)
if (udg_bool_path == true) then
call SetUnitPositionLocFacingBJ(udg_Player[i], udg_tmp_loc2, udg_move_direction[i])
call RemoveLocation(udg_tmp_loc2)
exitwhen true
elseif (udg_bool_path == false) then
call RemoveLocation(udg_tmp_loc2)
endif
endif
set j = j + 1
if (j == 20) then
exitwhen true
endif
endloop
call RemoveLocation(udg_tmp_loc)
endif
endfunction
Last edited: