- Joined
- Jun 21, 2012
- Messages
- 431
JASS:
library MotionBlur uses TimerUtils, UnitIndexer
/***********************************************************************************
* MotionBlur
* __________
* v1.0.0.0
* by Thelordmarshall
*
* This code allow to add motion blur for a unit and destroy
* by calling .destroy() method. Useful for dash spells.
*
* API:
* ____
*
* struct MotionBlur extends array
* - method add takes integer typeId, string animation, real animSpeed, integer blurLvl, integer blurSpeed, boolean getDummy returns nothing
* - Add motion blur for unit.
* - method destroy takes nothing returns nothing
* - Add motion blur for unit.
* - method addSimple takes integer blurLvl, integer blurSpeed, boolean removeUnit returns nothing
* - This method add timer transparency for a unit. You not need call
* destroy method on finish.
*
* Copyright © 2014.
************************************************************************************/
//Configuration.
globals
private constant player DUMMY_OWNER = Player(PLAYER_NEUTRAL_PASSIVE)
endglobals
//EndConfig.
struct MotionBlur extends array
private static constant real PERIOD = .03125
private static unit mt_blurDummy
private unit source
private unit blur
private string animation
private real animSpeed
private integer typeId
private integer blurLvl
private integer blurSpeed
private boolean getDummy
private boolean destroyBlur
private boolean removeUnit
implement UnitIndexStruct
private static method blurLoop takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
set .blurLvl = .blurLvl-.blurSpeed
call SetUnitVertexColor(.blur,255,255,255,.blurLvl)
if .blurLvl <= 0 then
if .removeUnit then
call RemoveUnit(.blur)
else
call SetUnitVertexColor(.blur,255,255,255,255)
endif
set .blur = null
call ReleaseTimer(t)
endif
set t = null
endmethod
private method getBlurDummy takes integer id, real x, real y, real a returns unit
set mt_blurDummy = CreateUnit(DUMMY_OWNER,id,0.,0.,a)
call UnitAddAbility(mt_blurDummy,'Aloc')
call UnitAddAbility(mt_blurDummy,'Aeth')
call UnitAddAbility(mt_blurDummy,'Avul')
call SetUnitPathing(mt_blurDummy,false)
call SetUnitPosition(mt_blurDummy,x,y)
call SetUnitColor(mt_blurDummy,GetPlayerColor(GetOwningPlayer(.source)))
return mt_blurDummy
endmethod
private static method onLoop takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
local real x = GetUnitX(.source)
local real y = GetUnitY(.source)
local real a = GetUnitFacing(.source)
local thistype newId
local unit blur
if .getDummy then
set blur = .getBlurDummy(.typeId,x,y,a)
else
set blur = CreateUnit(GetOwningPlayer(.source),.typeId,x,y,a)
endif
call SetUnitTimeScale(blur,.animSpeed*.01)
call SetUnitAnimation(blur,.animation)
set newId = GetUnitId(blur)
set newId.blur = blur
set newId.blurLvl = .blurLvl
set newId.blurSpeed = .blurSpeed
set newId.removeUnit = true
call TimerStart(NewTimerEx(newId),PERIOD,true,function thistype.blurLoop)
if .destroyBlur then
set .source = null
call ReleaseTimer(t)
endif
set blur = null
set t = null
endmethod
method add takes integer typeId, string animation, real animSpeed, integer blurLvl, integer blurSpeed, boolean getDummy returns nothing
set .source = .unit
set .typeId = typeId
set .animation = animation
set .animSpeed = animSpeed
set .blurLvl = blurLvl
set .blurSpeed = blurSpeed
set .getDummy = getDummy
set .destroyBlur = false
call TimerStart(NewTimerEx(this),PERIOD,true,function thistype.onLoop)
endmethod
method addSimple takes integer blurLvl, integer blurSpeed, boolean removeUnit returns nothing
set .blur = .unit
set .blurLvl = blurLvl
set .blurSpeed = blurSpeed
set .removeUnit = removeUnit
call TimerStart(NewTimerEx(this),PERIOD,true,function thistype.blurLoop)
endmethod
method destroy takes nothing returns nothing
set .destroyBlur = true
endmethod
endstruct
endlibrary