A level editor for my unnamed-platformer project. https://gitea.planet-casio.com/KikooDX/unnamed-platformer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
up-editor/mouse.lua

33 lines
1.0 KiB

function update_mouse()
mouse_x, mouse_y = love.mouse.getX(), love.mouse.getY() --mouse position
mouse_x = math.floor(mouse_x / scale)
mouse_y = math.floor(mouse_y / scale)
clip_mouse_x = mouse_x - mouse_x % 16
clip_mouse_y = mouse_y - mouse_y % 16
--edition mode
mouse_mode = 0
if love.mouse.isDown(1) then
mouse_mode = 1
elseif love.mouse.isDown(2) then
mouse_mode = -1
end
if mouse_mode == 0 then buffer_x, buffer_y = 0, 0 end
--add to layer if
if mouse_mode == 1 and (clip_mouse_x ~= buffer_x or clip_mouse_y ~= buffer_y) then
set_tile(tiles_char[selected_tile])
buffer_x = clip_mouse_x
buffer_y = clip_mouse_y
end
--delete of layer if
if mouse_mode == -1 and (clip_mouse_x ~= buffer_x or clip_mouse_y ~= buffer_y) then
set_tile('.')
buffer_x = clip_mouse_x
buffer_y = clip_mouse_y
end
end
function set_tile(char)
pos = clip_mouse_x / 16 + 1 + clip_mouse_y / 16 * 26
selected_screen = selected_screen:sub(1, pos - 1)..char..
selected_screen:sub(pos + 1, -1)
end