更好地使用scr变量,debug用print独立,鼠标触发圆形波纹

This commit is contained in:
MrZ_26
2020-08-05 00:58:23 +08:00
parent 31f5875fe2
commit d7136d0f1c
8 changed files with 101 additions and 63 deletions

View File

@@ -1,31 +1,47 @@
local gc=love.graphics
local setColor=gc.setColor
local setWidth=gc.setLineWidth
local rect=gc.rectangle
local ins,rem=table.insert,table.remove
local fx={}
local FXupdate={}
function FXupdate.ripple(S,dt)
S.t=S.t+dt*S.rate
return S.t>=1
end
function FXupdate.rectRipple(S,dt)
S.t=S.t+dt*S.rate
return S.t>=1
end
function FXupdate.shade(S,dt)
S.t=S.t+dt*S.rate
return S.t>=1
end
local FXdraw={}
function FXdraw.ripple(S)
setWidth(2)
local t=S.t
setColor(1,1,1,1-t)
gc.circle("line",S.x,S.y,t*(2-t)*S.r)
end
function FXdraw.rectRipple(S)
setWidth(6)
setColor(1,1,1,1-S.t)
local r=(10*S.t)^1.2
rect("line",S[1]-r,S[2]-r,S[3]+2*r,S[4]+2*r)
gc.rectangle("line",S.x-r,S.y-r,S.w+2*r,S.h+2*r)
end
function FXdraw.shade(S)
setColor(S[1],S[2],S[3],1-S.t)
rect("fill",S[4],S[5],S[6],S[7],2)
setColor(S.r,S.g,S.b,1-S.t)
gc.rectangle("fill",S.x,S.y,S.w,S.h,2)
end
local sysFX={}
function sysFX.update(dt)
for i=#fx,1,-1 do
local S=fx[i]
S.t=S.t+dt*S.rate
if S.t>=1 then
for i=i,#fx do
fx[i]=fx[i+1]
end
if fx[i]:update(dt) then
rem(fx,i)
end
end
end
@@ -34,9 +50,33 @@ function sysFX.draw()
fx[i]:draw()
end
end
--0=ripple,x,y,w,h
--1=shade,r,g,b,x,y,w,h
function sysFX.new(type,duration,...)
fx[#fx+1]={draw=FXdraw[type],t=0,rate=1/duration,...}
function sysFX.newRipple(duration,x,y,r)
fx[#fx+1]={
update=FXupdate.ripple,
draw=FXdraw.ripple,
t=0,
rate=1/duration,
x=x,y=y,r=r,
}
end
function sysFX.newRectRipple(duration,x,y,w,h)
fx[#fx+1]={
update=FXupdate.rectRipple,
draw=FXdraw.rectRipple,
t=0,
rate=1/duration,
x=x,y=y,w=w,h=h,
}
end
function sysFX.newShade(duration,r,g,b,x,y,w,h)
fx[#fx+1]={
update=FXupdate.shade,
draw=FXdraw.shade,
t=0,
rate=1/duration,
r=r,g=g,b=b,
x=x,y=y,w=w,h=h,
}
end
return sysFX