Displaying (or Drawing) Coordinates
Posted: Thu Dec 14, 2023 4:40 pm
Hello, I am new to LOVE's Lua scripting. I do have some knowledge of scripting with C#, and to be honest, translating that knowledge to Lua is not that hard. But, I am having some trouble trying to display, or draw, x and y coordinates for my player's position or however big the window size is. I attempted to make a new variable and call that variable to a draw line, but that obviously didn't work. Could I get some help, please? Thank you!
Here is the code for reference, this is also the only code I have scripted in my learning experience (Be warned - very, very messy):
function love.load() --practically "void Start()"
player = { --table that sets the players values/variable
x = 0,
y= 0,
speed = 75,
}
cords = {
x = 100,
y = 100,
coordinates
}
end
function love.update(dt) --practically "void Update(dt = deltaTime)"
--player movement
if love.keyboard.isDown("d") then
player.x = player.x + 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("d") then
player.x = player.x + 4
end
-----------------------------------------------------------------------------------------
if love.keyboard.isDown("a") then
player.x = player.x - 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("a") then
player.x = player.x - 4
end
-----------------------------------------------------------------------------------------
if love.keyboard.isDown("w") then
player.y = player.y - 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("w") then
player.y = player.y - 4
end
-----------------------------------------------------------------------------------------
if love.keyboard.isDown("s") then
player.y = player.y + 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("s") then
player.y = player.y + 4
end
-----------------------------------------------------------------------------------------
if player.x < 0 then
player.x = 0
end
end
function love.draw() --practically the "unity editor"
love.graphics.rectangle("fill", player.x, player.y, 50, 50)
love.graphics.newText(cords.coordinates)
end
Here is the code for reference, this is also the only code I have scripted in my learning experience (Be warned - very, very messy):
function love.load() --practically "void Start()"
player = { --table that sets the players values/variable
x = 0,
y= 0,
speed = 75,
}
cords = {
x = 100,
y = 100,
coordinates
}
end
function love.update(dt) --practically "void Update(dt = deltaTime)"
--player movement
if love.keyboard.isDown("d") then
player.x = player.x + 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("d") then
player.x = player.x + 4
end
-----------------------------------------------------------------------------------------
if love.keyboard.isDown("a") then
player.x = player.x - 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("a") then
player.x = player.x - 4
end
-----------------------------------------------------------------------------------------
if love.keyboard.isDown("w") then
player.y = player.y - 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("w") then
player.y = player.y - 4
end
-----------------------------------------------------------------------------------------
if love.keyboard.isDown("s") then
player.y = player.y + 3
end
if love.keyboard.isDown("lshift") and love.keyboard.isDown("s") then
player.y = player.y + 4
end
-----------------------------------------------------------------------------------------
if player.x < 0 then
player.x = 0
end
end
function love.draw() --practically the "unity editor"
love.graphics.rectangle("fill", player.x, player.y, 50, 50)
love.graphics.newText(cords.coordinates)
end