Алгоритмы, Наработки и Способности
Способ реализации:
Lua
Тип:
Наработка
Надоело запускать снаряды с линейной скоростью. Встречайте jQuery Easing Plugin на lua. Сравнить функции можно здесь.
Пример
do
local InitGlobalsOrigin = InitGlobals
function InitGlobals()
InitGlobalsOrigin()
FogEnable(false)
FogMaskEnable(false)
PanCameraToTimed(0, 0, 0)
local easing = {}
local ease = 0
for f in pairs(math.ease) do
table.insert(easing, f)
end
local TIMER_PERIOD = 0.03125 --> 1/32
local DISTANCE = 1200
local DURATION = 3
local DISTANCE_INC = DISTANCE / DURATION / (1 / TIMER_PERIOD)
CreateUnit(Player(0), FourCC('hfoo'), DISTANCE / 2, 0, 180)
local caster = CreateUnit(Player(0), FourCC('Obla'), -(DISTANCE / 2), 0, 0)
local function cast()
ClearTextMessages()
ease = ease + 1
print(easing[ease])
local xa, ya = GetUnitX(caster), GetUnitY(caster)
local angle = math.rad(GetUnitFacing(caster))
local cos, sin = math.cos(angle), math.sin(angle)
local missile = AddSpecialEffect('Abilities/Weapons/DemolisherFireMissile/DemolisherFireMissile.mdl', xa, ya)
local time = 0
local way = 0
TimerStart(CreateTimer(), TIMER_PERIOD, true, function()
way = way + DISTANCE_INC
time = time + TIMER_PERIOD
local speed = way * math.ease[easing[ease]](time / DURATION)
local xb, yb = xa + speed * cos, ya + speed * sin
if time > DURATION then
if ease < #easing then
cast()
end
DestroyEffect(missile)
return DestroyTimer(GetExpiredTimer())
end
BlzSetSpecialEffectX(missile, xb)
BlzSetSpecialEffectY(missile, yb)
BlzSetSpecialEffectYaw(missile, angle)
end)
end
TimerStart(CreateTimer(), 2, false, function()
cast()
DestroyTimer(GetExpiredTimer())
end)
end
end
Код
do
local c1 = 1.70158
local c2 = c1 * 1.525
local c3 = c1 + 1
local c4 = (2 * math.pi) / 3
local c5 = (2 * math.pi) / 4.5
local pi = math.pi
---@param x real in the range 0..1
---@return real
local function OutBounce(x)
local n1, d1 = 7.5625, 2.75
if (x < 1 / d1) then
return n1 * x * x;
elseif (x < 2 / d1) then
x = x - 1.5 / d1
return n1 * x * x + 0.75
elseif (x < 2.5 / d1) then
x = x - 2.25 / d1
return n1 * x * x + 0.9375
else
x = x - 2.625 / d1
return n1 * x * x + 0.984375
end
end
math.ease = {
---@param x real in the range 0..1
---@return real
InQuad = function(x)
return x * x
end,
---@param x real in the range 0..1
---@return real
OutQuad = function(x)
return 1 - (1 - x) * (1 - x)
end,
---@param x real in the range 0..1
---@return real
InOutQuad = function(x)
return x < 0.5 and 2 * x * x or 1 - ((-2 * x + 2) ^ 2) / 2
end,
---@param x real in the range 0..1
---@return real
InCubic = function(x)
return x * x * x
end,
---@param x real in the range 0..1
---@return real
OutCubic = function(x)
return 1 - ((1 - x) ^ 3)
end,
---@param x real in the range 0..1
---@return real
InOutCubic = function(x)
return x < 0.5 and 4 * x * x * x or 1 - ((-2 * x + 2) ^ 3) / 2
end,
---@param x real in the range 0..1
---@return real
InQuart = function(x)
return x * x * x * x
end,
---@param x real in the range 0..1
---@return real
OutQuart = function(x)
return 1 - ((1 - x) ^ 4)
end,
---@param x real in the range 0..1
---@return real
InOutQuart = function(x)
return x < 0.5 and 8 * x * x * x * x or 1 - ((-2 * x + 2) ^ 4) / 2
end,
---@param x real in the range 0..1
---@return real
InQuint = function(x)
return x * x * x * x * x
end,
---@param x real in the range 0..1
---@return real
OutQuint = function(x)
return 1 - ((1 - x) ^ 5)
end,
---@param x real in the range 0..1
---@return real
InOutQuint = function(x)
return x < 0.5 and 16 * x * x * x * x * x or 1 - ((-2 * x + 2) ^ 5) / 2
end,
---@param x real in the range 0..1
---@return real
InSine = function(x)
return 1 - math.cos(x * pi / 2)
end,
---@param x real in the range 0..1
---@return real
OutSine = function(x)
return math.sin(x * pi / 2)
end,
---@param x real in the range 0..1
---@return real
InOutSine = function(x)
return -(math.cos(pi * x) - 1) / 2
end,
---@param x real in the range 0..1
---@return real
InExpo = function(x)
return x == 0 and 0 or 2 ^ (10 * x - 10)
end,
---@param x real in the range 0..1
---@return real
OutExpo = function(x)
return x == 1 and 1 or 1 - (2 ^ (-10 * x))
end,
---@param x real in the range 0..1
---@return real
InOutExpo = function(x)
if x == 0 or x == 1 then return x end
return x < 0.5 and 2 ^ (20 * x - 10) / 2 or 2 - (2 ^ (-20 * x + 10)) / 2
end,
---@param x real in the range 0..1
---@return real
InCirc = function(x)
return 1 - math.sqrt(1 - x * x)
end,
---@param x real in the range 0..1
---@return real
OutCirc = function(x)
return math.sqrt(1 - ((x - 1) ^ 2))
end,
---@param x real in the range 0..1
---@return real
InOutCirc = function(x)
return x < 0.5 and (1 - math.sqrt(1 - ((2 * x) ^ 2))) / 2 or (math.sqrt(1 - ((-2 * x + 2) ^ 2)) + 1) / 2
end,
---@param x real in the range 0..1
---@return real
InElastic = function(x)
return x == 0 and 0 or x == 1 and 1 or -(2 ^ (10 * x - 10)) * math.sin((x * 10 - 10.75) * c4)
end,
---@param x real in the range 0..1
---@return real
OutElastic = function(x)
if x == 0 or x == 1 then return x end
return (2 ^ (-10 * x)) * math.sin((x * 10 - 0.75) * c4) + 1
end,
---@param x real in the range 0..1
---@return real
InOutElastic = function(x)
if x == 0 or x == 1 then return x end
return x < 0.5 and -((2 ^ (20 * x - 10)) * math.sin((20 * x - 11.125) * c5)) / 2 or (2 ^ (-20 * x + 10)) * math.sin((20 * x - 11.125) * c5) / 2 + 1
end,
---@param x real in the range 0..1
---@return real
InBack = function(x)
return c3 * x * x * x - c1 * x * x
end,
---@param x real in the range 0..1
---@return real
OutBack = function(x)
return 1 + c3 * ((x - 1) ^ 3) + c1 * ((x - 1) ^ 2)
end,
---@param x real in the range 0..1
---@return real
InOutBack = function(x)
return x < 0.5 and (((2 * x) ^ 2) * ((c2 + 1) * 2 * x - c2)) / 2 or (((2 * x - 2) ^ 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2
end,
---@param x real in the range 0..1
---@return real
OutBounce = function(x)
return OutBounce(x)
end,
---@param x real in the range 0..1
---@return real
InBounce = function(x)
return 1 - OutBounce(1 - x)
end,
---@param x real in the range 0..1
---@return real
InOutBounce = function(x)
return x < 0.5 and (1 - OutBounce(1 - 2 * x)) / 2 or (1 + OutBounce(2 * x - 1)) / 2
end
}
end
Видео
`
ОЖИДАНИЕ РЕКЛАМЫ...
2
NekoriDes
5 лет назад
2
NazarPunk:
Ну тут тащемта справедливо, хоть и не считаю что правильно.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.