I am pretty fresh in Lua and Love, would like to ask you guys how to make a piece of code simplier. I've been ctrl+C ctrl+V 'ing a lot. Would love to make this thing more loopy... There are no bugs though. Just a lump. ugly stuff.
so here it is.
Code: Select all
function love.load()
queen = {'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25'}
queen[1] = {mode,x,y}
queen[1][1]=3
queen[1][2]=720
queen[1][3]=80
queen[2] = {mode,x,y}
queen[2][1]=3
queen[2][2]=800
queen[2][3]=80
queen[3] = {mode,x,y}
queen[3][1]=3
queen[3][2]=880
queen[3][3]=80
queen[4] = {mode,x,y}
queen[4][1]=3
queen[4][2]=960
queen[4][3]=80
queen[5] = {mode,x,y}
queen[5][1]=3
queen[5][2]=1040
queen[5][3]=80
queen[6] = {mode,x,y}
queen[6][1]=3
queen[6][2]=720
queen[6][3]=160
queen[7] = {mode,x,y}
queen[7][1]=3
queen[7][2]=800
queen[7][3]=160
queen[8] = {mode,x,y}
queen[8][1]=3
queen[8][2]=880
queen[8][3]=160
queen[9] = {mode,x,y}
queen[9][1]=3
queen[9][2]=960
queen[9][3]=160
queen[10] = {mode,x,y}
queen[10][1]=3
queen[10][2]=1040
queen[10][3]=160
queen[11] = {mode,x,y}
queen[11][1]=3
queen[11][2]=720
queen[11][3]=240
queen[12] = {mode,x,y}
queen[12][1]=3
queen[12][2]=800
queen[12][3]=240
queen[13] = {mode,x,y}
queen[13][1]=3
queen[13][2]=880
queen[13][3]=240
queen[14] = {mode,x,y}
queen[14][1]=3
queen[14][2]=960
queen[14][3]=240
queen[15] = {mode,x,y}
queen[15][1]=3
queen[15][2]=1040
queen[15][3]=240
queen[16] = {mode,x,y}
queen[16][1]=3
queen[16][2]=720
queen[16][3]=320
queen[17] = {mode,x,y}
queen[17][1]=3
queen[17][2]=800
queen[17][3]=320
queen[18] = {mode,x,y}
queen[18][1]=3
queen[18][2]=880
queen[18][3]=320
queen[19] = {mode,x,y}
queen[19][1]=3
queen[19][2]=960
queen[19][3]=320
queen[20] = {mode,x,y}
queen[20][1]=3
queen[20][2]=1040
queen[20][3]=320
queen[21] = {mode,x,y}
queen[21][1]=3
queen[21][2]=720
queen[21][3]=400
queen[22] = {mode,x,y}
queen[22][1]=3
queen[22][2]=800
queen[22][3]=400
queen[23] = {mode,x,y}
queen[23][1]=3
queen[23][2]=880
queen[23][3]=400
queen[24] = {mode,x,y}
queen[24][1]=3
queen[24][2]=960
queen[24][3]=400
queen[25] = {mode,x,y}
queen[25][1]=3
queen[25][2]=1040
queen[25][3]=400
end
function love.update(dt)
queen[1][3]=queen[1][3]+queenMoveSpeed *dt
queen[2][3]=queen[2][3]+queenMoveSpeed *dt
queen[3][3]=queen[3][3]+queenMoveSpeed *dt
queen[4][3]=queen[4][3]+queenMoveSpeed *dt
queen[5][3]=queen[5][3]+queenMoveSpeed *dt
queen[6][3]=queen[6][3]+queenMoveSpeed *dt
queen[7][3]=queen[7][3]+queenMoveSpeed *dt
queen[8][3]=queen[8][3]+queenMoveSpeed *dt
queen[9][3]=queen[9][3]+queenMoveSpeed *dt
queen[10][3]=queen[10][3]+queenMoveSpeed *dt
queen[11][3]=queen[11][3]+queenMoveSpeed *dt
queen[12][3]=queen[12][3]+queenMoveSpeed *dt
queen[13][3]=queen[13][3]+queenMoveSpeed *dt
queen[14][3]=queen[14][3]+queenMoveSpeed *dt
queen[15][3]=queen[15][3]+queenMoveSpeed *dt
queen[16][3]=queen[16][3]+queenMoveSpeed *dt
queen[17][3]=queen[17][3]+queenMoveSpeed *dt
queen[18][3]=queen[18][3]+queenMoveSpeed *dt
queen[19][3]=queen[19][3]+queenMoveSpeed *dt
queen[20][3]=queen[20][3]+queenMoveSpeed *dt
queen[21][3]=queen[21][3]+queenMoveSpeed *dt
queen[22][3]=queen[22][3]+queenMoveSpeed *dt
queen[23][3]=queen[23][3]+queenMoveSpeed *dt
queen[24][3]=queen[24][3]+queenMoveSpeed *dt
queen[25][3]=queen[25][3]+queenMoveSpeed *dt
queen[1][2]=queen[1][2]-queenMoveSpeed *dt
queen[2][2]=queen[2][2]-queenMoveSpeed *dt
queen[3][2]=queen[3][2]-queenMoveSpeed *dt
queen[4][2]=queen[4][2]-queenMoveSpeed *dt
queen[5][2]=queen[5][2]-queenMoveSpeed *dt
queen[6][2]=queen[6][2]-queenMoveSpeed *dt
queen[7][2]=queen[7][2]-queenMoveSpeed *dt
queen[8][2]=queen[8][2]-queenMoveSpeed *dt
queen[9][2]=queen[9][2]-queenMoveSpeed *dt
queen[10][2]=queen[10][2]-queenMoveSpeed *dt
queen[11][2]=queen[11][2]-queenMoveSpeed *dt
queen[12][2]=queen[12][2]-queenMoveSpeed *dt
queen[13][2]=queen[13][2]-queenMoveSpeed *dt
queen[14][2]=queen[14][2]-queenMoveSpeed *dt
queen[15][2]=queen[15][2]-queenMoveSpeed *dt
queen[16][2]=queen[16][2]-queenMoveSpeed *dt
queen[17][2]=queen[17][2]-queenMoveSpeed *dt
queen[18][2]=queen[18][2]-queenMoveSpeed *dt
queen[19][2]=queen[19][2]-queenMoveSpeed *dt
queen[20][2]=queen[20][2]-queenMoveSpeed *dt
queen[21][2]=queen[21][2]-queenMoveSpeed *dt
queen[22][2]=queen[22][2]-queenMoveSpeed *dt
queen[23][2]=queen[23][2]-queenMoveSpeed *dt
queen[24][2]=queen[24][2]-queenMoveSpeed *dt
queen[25][2]=queen[25][2]-queenMoveSpeed *dt
end
function love.draw()
--1
if queen[1][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[1][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[1][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[1][2], queen[1][3], 80, 80 )
--2
if queen[2][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[2][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[2][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[2][2], queen[2][3], 80, 80 )
--3
if queen[3][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[3][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[3][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[3][2], queen[3][3], 80, 80 )
--4
if queen[4][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[4][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[4][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[4][2], queen[4][3], 80, 80 )
--5
if queen[5][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[5][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[5][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[5][2], queen[5][3], 80, 80 )
--6
if queen[6][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[6][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[6][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[6][2], queen[6][3], 80, 80 )
--7
if queen[7][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[7][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[7][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[7][2], queen[7][3], 80, 80 )
--8
if queen[8][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[8][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[8][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[8][2], queen[8][3], 80, 80 )
--9
if queen[9][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[9][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[9][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[9][2], queen[9][3], 80, 80 )
--10
if queen[10][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[10][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[10][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[10][2], queen[10][3], 80, 80 )
--11
if queen[11][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[11][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[11][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[11][2], queen[11][3], 80, 80 )
--12
if queen[12][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[12][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[12][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[12][2], queen[12][3], 80, 80 )
--13
if queen[13][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[13][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[13][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[13][2], queen[13][3], 80, 80 )
--14
if queen[14][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[14][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[14][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[14][2], queen[14][3], 80, 80 )
--15
if queen[15][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[15][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[15][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[15][2], queen[15][3], 80, 80 )
--16
if queen[16][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[16][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[16][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[16][2], queen[16][3], 80, 80 )
--17
if queen[17][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[17][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[17][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[17][2], queen[17][3], 80, 80 )
--18
if queen[18][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[18][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[18][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[18][2], queen[18][3], 80, 80 )
--19
if queen[19][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[19][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[19][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[19][2], queen[19][3], 80, 80 )
--20
if queen[20][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[20][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[20][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[20][2], queen[20][3], 80, 80 )
--21
if queen[21][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[21][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[21][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[21][2], queen[21][3], 80, 80 )
--22
if queen[22][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[22][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[22][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[22][2], queen[22][3], 80, 80 )
--23
if queen[23][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[23][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[23][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[23][2], queen[23][3], 80, 80 )
--24
if queen[24][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[24][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[24][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[24][2], queen[24][3], 80, 80 )
--25
if queen[25][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[25][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[25][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[25][2], queen[25][3], 80, 80 )
end
smt like
Code: Select all
for i=1,25 then
--i
if queen[i][1]==1 then
love.graphics.setColor( 255,0,0, 255 )
end
if queen[i][1]==2 then
love.graphics.setColor(0,255,0,255)
end
if queen[i][1]==3 then
love.graphics.setColor(0,0,255,255)
end
love.graphics.rectangle( 'fill', queen[i][2], queen[i][3], 80, 80 )
end