[Solved] Drawing sprites on the fly from array information?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
_pinia
Prole
Posts: 2
Joined: Fri Jul 07, 2017 6:27 am
Contact:

[Solved] Drawing sprites on the fly from array information?

Post by _pinia »

Morning everyone!

Fast explanation here, I've trying to port my 2D minimap code from C# to Lua.

It should look like this
Image

But instead, is showing like this :
Image

What I'm doing? I have a 2D Array that stores the map data, and with a loop, I scan the arrea arround the character position and with that, show it on screen. Code below :

Code: Select all

function DrawScreenMiniMap()
		mapY = playerY - 3;
        mapX = playerX - 3;
        mapVisualX = 56;
        mapVisualY = 93;

        for i=1,7 do

        	for j=1,7 do
        		--[[We put player icon on MiniMap]]--
        		if ((mapY == playerY) and (mapX == playerX)) then
        			if (facingDirection == "n") then
        				love.graphics.draw(smN, mapVisualX, mapVisualY)
        			elseif (facingDirection == "s") then
        				love.graphics.draw(smS, mapVisualX, mapVisualY)
        			elseif (facingDirection == "w") then
        				love.graphics.draw(smW, mapVisualX, mapVisualY)
        			elseif (facingDirection == "e") then
        				love.graphics.draw(smE, mapVisualX, mapVisualY)
        			end
        		elseif (mapY >= 1 and mapY <= #testMap and mapX >= 1 and mapX <= #testMap[1]) then
        			if (testMap[mapY][mapX]==0) then
        				love.graphics.draw(smFl, mapVisualX, mapVisualY)
        			elseif (testMap[mapY][mapX]==1) then
        				love.graphics.draw(smWl, mapVisualX, mapVisualY) 
        		else 
        			love.graphics.draw(smNothing, mapVisualX, mapVisualY)
        		end
        		mapX=mapX+1;
                mapVisualX = mapVisualX + 7;

        	end
        	
        	mapY = mapY+1;
            mapX = playerX - 3;
            mapVisualX = 56;
            mapVisualY = mapVisualY + 7;
        end
    end
end
But It isn't working the same way as I was doing it when I was working with MonoGame. Any idea on what I'm doing wrong (and why is my map only going downwards instead of doing a square map)?

Thanks in advance.
Last edited by _pinia on Sat Jul 08, 2017 9:28 am, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Drawing sprites on the fly from array information?

Post by Nixola »

You are resetting mapVisualX to 56 at the end of every iteration of the outer for loop, I think that's the issue. Not related, but you should probably fix your indentation (either use spaces or tabs; don't mix it up), and if you could upload a functional .love file, that'd help more in debugging. Help us help you ;)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
_pinia
Prole
Posts: 2
Joined: Fri Jul 07, 2017 6:27 am
Contact:

[Solved]Re: Drawing sprites on the fly from array information?

Post by _pinia »

Thanks for the answer and sorry for not uploading the .love file, for the next time I now what to do.
And, you were right, and all the errors I had (aside of this) was due to Sublime Text not formating correctly the program (I'm used to use "{}" in C# for almost everything, and using "then" and "end" it isn't as visual to me as it is "{}".

Final code for anyone interested.

Code: Select all

function DrawScreenMiniMap()
		mapY = playerY - 3;
        mapX = playerX - 3;
        mapVisualX = 56;
        mapVisualY = 93;

        for i=1,7 do

        	for j=1,7 do
        		--[[We put player icon on MiniMap]]--
        		
        		if (mapY >= 1 and mapY <= #testMap and mapX >= 1 and mapX <= #testMap[1]) then
                    if ((mapY == playerY) and (mapX == playerX)) then
                        if (facingDirection == "n") then
                        love.graphics.draw(smN, mapVisualX, mapVisualY)
                        elseif (facingDirection == "s") then
                        love.graphics.draw(smS, mapVisualX, mapVisualY)
                        elseif (facingDirection == "w") then
                        love.graphics.draw(smW, mapVisualX, mapVisualY)
                        elseif (facingDirection == "e") then
                        love.graphics.draw(smE, mapVisualX, mapVisualY)
                        end
        			elseif (testMap[mapY][mapX]==0) then
        				love.graphics.draw(smFl, mapVisualX, mapVisualY)
        			elseif (testMap[mapY][mapX]==1) then
        				love.graphics.draw(smWl, mapVisualX, mapVisualY) 
                    end
        		else 
        			love.graphics.draw(smNothing, mapVisualX, mapVisualY)
        		end
        		mapX=mapX+1;
                mapVisualX = mapVisualX + 7;

        	    
        	
        	
                end
            mapY = mapY+1;
            mapX = playerX - 3;
            mapVisualX = 56;
            mapVisualY = mapVisualY + 7;
        end
end
Image
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests