diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2019-02-12 21:25:06 -0200 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2019-02-12 21:25:06 -0200 |
commit | 3fcdf3a76dc9c96b35dda1cab8786c5210024876 (patch) | |
tree | 79c07b3fd169efc46fa8b06b4b670f8bb5628f48 | |
parent | 1d8014b6cbb3bf4cb640b6fb5f9c9fbb6031d7f5 (diff) |
Experimental mouse support
-rw-r--r-- | main.lua | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/main.lua b/main.lua index dbc63b5..31922d8 100644 --- a/main.lua +++ b/main.lua @@ -118,6 +118,43 @@ function setback(pos, highlight) end end +local in_mouse = false + +function love.mousepressed(x, y, button, istouch, presses) + if button == 1 then + if visual_start then + for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do + setback(i, false) + end + visual_start = false + else + setback(cp, false) + end + local x, y = math.floor(x / 36), math.floor(y / 36) + if x > 15 or y > 15 then return end + cp = y * 16 + x + 1 + setback(cp, true) + backimage:replacePixels(backimagedata) + in_mouse = true + end +end + +function love.mousereleased(x, y, button, istouch, presses) + in_mouse = false +end + +function love.mousemoved(x, y, dx, dy, istouch) + if in_mouse then + if visual_start then + local x, y = math.floor(x / 36), math.floor(y / 36) + if x > 15 or y > 15 then return end + cp = y * 16 + x + 1 + else + visual_start = cp + end + end +end + function love.update(dt) local function ktup(key, func) if kt[key] then @@ -284,14 +321,14 @@ function love.update(dt) image:replacePixels(imagedata) end local function visual() - visual_start = not visual_start and cp - if not visual_start then - for i=1,255 do + if visual_start then + for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do setback(i, false) end setback(cp, true) backimage:replacePixels(backimagedata) end + visual_start = not visual_start and cp end ktup('k', imgup) ktup('up', imgup) |