kingkingyyk3
Visitor (Welcome to the Jungle, Baby!)
- Reaction score
- 216
Jump
JASS:
//////////////////////////////////////////////////////////////////////////////////////////////
// _______ _ _ _________ ____
// |__ __| | | | | | _ _ | | __ | by
// | | | | | | | | | | | | | ~__| kingking
// _| | | |__| | | | | | | | | |
// |___| |______| |_| |_| |_| |_| v1.01
//
//
// What is Jump?
// This library makes jumping more natural. =D
//
// ==How to use== o.o?
// call Jump_Start(whichunit,speed)
//
// Extra :
// TriggerRegisterUnitLanded(whichtrigger)
// GetLandedUnit() -> landed unit
//
// Requires :
// T32
// Event
// Jass helper 0.9.K.0 or newer
// Jump Ability(Get from Object editor)
// Fly Trick(Get from Object editor)
//
// Impletement note :
// Ensure the rawcodes in library are correct.
// "Data - Spell List" in Jump Ability must includes Fly Trick.
//////////////////////////////////////////////////////////////////////////////////////////////
JASS:
library Jump initializer Init requires T32, Event
globals
//Configurable.
private constant integer JUMP_ABILITY = 039;A001039;
private constant integer FLY_TRICK = 039;Arav039;// 'Amrf' does same
public constant real GRAVITIONAL_ACCELERATION = 30.
endglobals
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Restricted Area~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
globals
private unit Landed_Unit = null
private integer UnitLandedEvent
private constant real PeriodicGA = GRAVITIONAL_ACCELERATION / T32_FPS
endglobals
private struct Jump
unit targ
real speed
real height
integer status
integer ticks
integer add
private method periodic takes nothing returns boolean
if .speed > 0. and .status == 1 then
set .ticks = .ticks + 1
set .speed = .speed - PeriodicGA
set .height = .height + .speed
call SetUnitFlyHeight(.targ,.height,0.)
if .speed < .0 then
set .status = 2
set .speed = .001
endif
endif
if .speed > 0. and .status == 2 and .ticks > 0 then
set .ticks = .ticks - 1
set .speed = .speed + PeriodicGA
set .height = .height - this.speed
call SetUnitFlyHeight(.targ,.height,0.)
endif
if .ticks > 0 then
return false
endif
call .destroy()
return true
endmethod
private method onDestroy takes nothing returns nothing
if .add == 1 then
call UnitRemoveAbility(.targ,JUMP_ABILITY)
endif
set .ticks = 0
set .speed = 0.
set .height = 0.
set .status = 0
set Landed_Unit = .targ
call FireEvent(UnitLandedEvent)
endmethod
implement T32
endstruct
public function Start takes unit whichunit, real speed returns nothing
local Jump d = Jump.create()
set d.targ = whichunit
set d.speed = speed / T32_FPS
set d.status = 1 //1 -> up, 2->down
set d.height = GetUnitDefaultFlyHeight(d.targ)
if UnitAddAbility(d.targ,JUMP_ABILITY) then
set d.add = 1
else
set d.add = 2
endif
call d.startPeriodic()
endfunction
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Trigger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function GetLandedUnit takes nothing returns unit
return Landed_Unit
endfunction
function TriggerRegisterUnitLanded takes trigger whichtrigger returns EventReg
return TriggerRegisterEvent(whichtrigger,UnitLandedEvent)
endfunction
private function Init takes nothing returns nothing
local integer i = 0
loop
exitwhen i > 15
call SetPlayerAbilityAvailable(Player(i),JUMP_ABILITY,false)
set i = i + 1
endloop
set UnitLandedEvent = CreateEvent()
endfunction
endlibrary