blackhole背景中方块会公转,整理代码

This commit is contained in:
MrZ626
2021-04-29 14:28:07 +08:00
parent 19a3181ffb
commit bb30a8e9d1
3 changed files with 20 additions and 32 deletions

View File

@@ -1,5 +1,6 @@
--Blackhole
local gc=love.graphics
local sin,cos=math.sin,math.cos
local rnd=math.random
local ins,rem=table.insert,table.remove
local back={}
@@ -13,36 +14,23 @@ end
function back.update()
t=t-1
if t==0 then
local size=SCR.rad*(2+rnd()*3)/100
local S={
x=(SCR.w-size)*rnd()-SCR.w/2,
y=(SCR.h-size)*rnd()-SCR.h/2,
ang=6.2832*rnd(),
d=SCR.rad*1.05/2,
rotate=6.2832*rnd(),
va=.05-rnd()*.1,
size=size,
texture=rnd(16),
size=SCR.rad*(2+rnd()*3)/100,
texture=SKIN.curText[rnd(16)],
}
if rnd()<.5 then
S.x=rnd()<.5 and
-SCR.w/2-S.size or
SCR.w/2
else
S.y=rnd()<.5 and
-SCR.h/2-S.size or
SCR.h/2
end
ins(squares,S)
t=rnd(6,16)
t=rnd(6,12)
end
for i=#squares,1,-1 do
local S=squares[i]
local ang=math.atan2(S.y,S.x)
local d=(S.x^2+S.y^2)^.5
d=d-SCR.rad/(d+60)
if d>0 then
S.x=d*math.cos(ang)
S.y=d*math.sin(ang)
S.ang=S.ang+S.va
S.d=S.d-SCR.rad/(S.d+60)
if S.d>0 then
S.ang=S.ang+.008
S.rotate=S.rotate+S.va
else
rem(squares,i)
end
@@ -58,11 +46,11 @@ function back.draw()
gc.setColor(.5,.5,.5)
for i=1,#squares do
local S=squares[i]
gc.draw(SKIN.curText[S.texture],S.x,S.y,S.ang,S.size*.026,nil,15,15)
gc.draw(S.texture,S.d*cos(S.ang),S.d*sin(S.ang),S.rotate,S.size*.026,nil,15,15)
end
--Blackhole
gc.scale(SCR.rad/1260)
gc.scale(SCR.rad/1600)
gc.setColor(0,0,0)
gc.circle("fill",0,0,157)
gc.setLineWidth(6)
@@ -70,7 +58,7 @@ function back.draw()
gc.setColor(0,0,0,1-i*.0666)
gc.circle("line",0,0,160+6*i)
end
gc.scale(1260/SCR.rad)
gc.scale(1600/SCR.rad)
gc.pop()
end
function back.discard()

View File

@@ -1,4 +1,4 @@
--Block rain
--Large falling tetrominoes
local gc=love.graphics
local rnd=math.random
local ins,rem=table.insert,table.remove
@@ -17,12 +17,12 @@ function back.update()
local B=BLOCKS[r][rnd(0,3)]
local k=(1+rnd()*2)*SCR.rad/1000
ins(mino,{
block=B,
texture=SKIN.curText[SETTING.skin[r]],
k=k,
x=(SCR.w)*rnd()-15*#B[1],
y=0,
k=k,
vy=k*2,
block=B,
texture=SKIN.curText[SETTING.skin[r]],
})
end
for i=#mino,1,-1 do

View File

@@ -21,7 +21,7 @@ function back.update()
x=SCR.w*rnd(),
y=SCR.h*-.05,
k=SCR.rad/100,
a=rnd()*6.2832,
ang=rnd()*6.2832,
vy=.5+rnd()*.4,
vx=rnd()*.4-.2,
va=rnd()*.04-.02,
@@ -34,7 +34,7 @@ function back.update()
rem(mino,i)
else
P.x=P.x+P.vx
P.a=P.a+P.va
P.ang=P.ang+P.va
P.vx=P.vx-.01+rnd()*.02
end
end
@@ -47,7 +47,7 @@ function back.draw()
local C=mino[i]
local c=C.color
gc.setColor(c[1],c[2],c[3],.5)
gc.draw(C.block,C.x,C.y,C.a,C.k,C.k,C.block:getWidth()/2,C.block:getHeight()/2)
gc.draw(C.block,C.x,C.y,C.ang,C.k,C.k,C.block:getWidth()/2,C.block:getHeight()/2)
end
gc.pop()
end