Block Placing
Posted: Wed Jul 16, 2014 6:08 pm
I'm working on a new project and am having slight issues with placing blocks in game. When the player clicks, the game checks what block they have in their hand. If it is "scrap_metal", it will place that block. My problem comes when we go to actually draw the block. Each time you click again, the old block is moved to the new location. This is because each time you click (after moving the mouse), you're getting a new position of the mouse (which is where the block is drawn). What I want to do is to create a value for each block's location when it is placed, so it has its own static location and thus it won't move when the player places another block. How would I go about doing this?
Code: Select all
function love.draw()
for i = 0, blocks.scrapmetal do
love.graphics.draw(smetal, tx, ty) -- Each time you click, the block moves due to the mouse moving!
end
end
function love.mousepressed()
if player.inv.tool == "scrap_metal" then
blocks.scrapmetal = blocks.scrapmetal + 1
tx = love.mouse.getX()
ty = love.mouse.getY()
end
end