升级SCR模块,整理大量坐标系变换代码

This commit is contained in:
MrZ626
2021-05-30 02:23:08 +08:00
parent 51d2f43229
commit 9e61505205
20 changed files with 131 additions and 156 deletions

View File

@@ -1,7 +1,6 @@
--Blackhole
local gc=love.graphics
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_translate,gc_scale=gc.translate,gc.scale
local gc_clear,gc_replaceTransform=gc.clear,gc.replaceTransform
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_draw,gc_circle=gc.draw,gc.circle
@@ -43,9 +42,7 @@ function back.update()
end
function back.draw()
gc_clear(.1,.1,.1)
gc_push('transform')
gc_origin()
gc_translate(SCR.cx,SCR.cy)
gc_replaceTransform(SCR.xOy_m)
--Squares
gc_setColor(1,1,1,.2)
@@ -55,7 +52,6 @@ function back.draw()
end
--Blackhole
gc_scale(SCR.rad/1600)
gc_setColor(.07,.07,.07)
gc_circle('fill',0,0,157)
gc_setLineWidth(6)
@@ -63,8 +59,6 @@ function back.draw()
gc_setColor(.07,.07,.07,1-i*.0666)
gc_circle('line',0,0,160+6*i)
end
gc_scale(1600/SCR.rad)
gc_pop()
end
function back.discard()
squares=nil

View File

@@ -1,6 +1,6 @@
--Large falling tetrominoes
local gc=love.graphics
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_clear=gc.clear
local gc_setColor,gc_draw=gc.setColor,gc.draw
local rnd=math.random
@@ -36,8 +36,6 @@ function back.update()
end
function back.draw()
gc_clear(.1,.1,.1)
gc_push('transform')
gc_origin()
gc_setColor(1,1,1,.2)
for i=1,#mino do
local M=mino[i]
@@ -50,7 +48,6 @@ function back.draw()
end
end
end
gc_pop()
end
function back.discard()
mino=nil

View File

@@ -41,15 +41,12 @@ function back.update()
end
function back.draw()
gc.clear(.1,.1,.1)
gc.push('transform')
gc.origin()
for i=1,#mino do
local C=mino[i]
local c=C.color
gc.setColor(c[1],c[2],c[3],.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
function back.discard()
mino=nil

View File

@@ -1,7 +1,7 @@
--Space but tetrominoes
local gc=love.graphics
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_translate,gc_setColor,gc_draw=gc.translate,gc.setColor,gc.draw
local gc_clear,gc_translate=gc.clear,gc.translate
local gc_setColor,gc_draw=gc.setColor,gc.draw
local sin,cos=math.sin,math.cos
local rnd=math.random
@@ -36,14 +36,12 @@ function back.update()
rem(mino,i)
else
M.rotate=M.rotate+M.vr
M.v=M.v*(1+M.d/SCR.rad*.05)
M.v=M.v*(1+M.d/rad*.05)
end
end
end
function back.draw()
gc_clear(.1,.1,.1)
gc_push('transform')
gc_origin()
gc_translate(SCR.cx,SCR.cy)
for i=1,#mino do
local M=mino[i]
@@ -51,7 +49,7 @@ function back.draw()
gc_setColor(c[1],c[2],c[3],.2)
gc_draw(M.block,M.d*cos(M.ang),M.d*sin(M.ang),M.rotate,(18*M.d/SCR.rad)^1.6,nil,M.block:getWidth()/2,M.block:getHeight()/2)
end
gc_pop()
gc_translate(-SCR.cx,-SCR.cy)
end
function back.discard()
mino=nil

View File

@@ -1,6 +1,6 @@
--Flying cubes
local gc=love.graphics
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_clear=gc.clear
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_rectangle=gc.rectangle
@@ -65,8 +65,6 @@ function back.update(dt)
end
function back.draw()
gc_clear(.1,.1,.1)
gc_push('transform')
gc_origin()
gc_setLineWidth(6)
for i=1,#squares do
local S=squares[i]
@@ -76,7 +74,6 @@ function back.draw()
gc_setColor(c[1],c[2],c[3],.3)
gc_rectangle('fill',S.x,S.y,S.size,S.size)
end
gc_pop()
end
function back.discard()
squares=nil

View File

@@ -1,6 +1,6 @@
--UUZ's fan
local gc=love.graphics
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_clear,gc_origin,gc_replaceTransform=gc.clear,gc.origin,gc.replaceTransform
local gc_translate=gc.translate
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_line,gc_polygon=gc.line,gc.polygon
@@ -44,11 +44,11 @@ function back.update()
end
end
function back.draw()
gc_push('transform')
gc.replaceTransform(SCR.xOy)
gc_translate(640,360+20*sin(t*.02))
gc_clear(.1,.1,.1)
gc_replaceTransform(SCR.xOy_m)
gc_translate(0,20*sin(t*.02))
gc_setLineWidth(320)
gc_setColor(.9,.6,.9,.1)
gc_arc('line','open',0,420,500,-.8*3.1416,-.2*3.1416)
@@ -72,7 +72,6 @@ function back.draw()
local P=petal[i]
gc_ellipse('fill',P.x,P.y,P.rx,P.ry)
end
gc_pop()
end
function back.discard()
petal=nil

View File

@@ -1,6 +1,6 @@
--Firework
local gc=love.graphics
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_clear=gc.clear
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_line,gc_circle=gc.line,gc.circle
@@ -79,8 +79,6 @@ function back.update(dt)
end
function back.draw()
gc_clear(.1,.1,.1)
gc_push('transform')
gc_origin()
for i=1,#firework do
local F=firework[i]
gc_setColor(F.color)
@@ -93,7 +91,6 @@ function back.draw()
gc_setColor(c[1],c[2],c[3],P.t*.4)
gc_line(P.x,P.y,P.x-P.vx*4,P.y-P.vy*4)
end
gc_pop()
end
function back.discard()
firework=nil

View File

@@ -38,14 +38,11 @@ function back.update(dt)
end
function back.draw()
gc.clear(.1,.1,.1)
gc.push('transform')
gc.origin()
gc.setColor(1,1,1,.2)
local img=IMG.lanterns
for i=1,#lanterns do
local L=lanterns[i]
mDraw(img[int(L.phase*6)+1],L.x,L.y,nil,L.size)
end
gc.pop()
end
return back

View File

@@ -1,7 +1,6 @@
--Black-White grid
local gc=love.graphics
local gc_push,gc_pop,gc_clear=gc.push,gc.pop,gc.clear
local gc_scale=gc.scale
local gc_clear,gc_scale=gc.clear,gc.scale
local gc_setColor=gc.setColor
local gc_rectangle=gc.rectangle
@@ -19,16 +18,14 @@ function back.update(dt)
end
function back.draw()
gc_clear(.1,.1,.1)
gc_push('transform')
local k=SCR.k
gc_scale(k)
local Y=ceil(SCR.h/80/k)
for x=1,ceil(SCR.w/80/k)do
for y=1,Y do
gc_setColor(1,1,1,sin(x+matrixT[x][y]*t)*.04+.04)
gc_rectangle('fill',80*x,80*y,-80,-80)
end
local k=SCR.k
gc_scale(k)
local Y=ceil(SCR.h/80/k)
for x=1,ceil(SCR.w/80/k)do
for y=1,Y do
gc_setColor(1,1,1,sin(x+matrixT[x][y]*t)*.04+.04)
gc_rectangle('fill',80*x,80*y,-80,-80)
end
gc_pop()
end
end
return back

View File

@@ -39,14 +39,11 @@ function back.update()
end
function back.draw()
gc.clear(.1,.1,.1)
gc.push('transform')
gc.setColor(.7,.7,.7)
gc.origin()
for i=1,#snow do
local P=snow[i]
ellipse('fill',P.x,P.y,P.rx,P.ry)
end
gc.pop()
end
function back.discard()
snow=nil