-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.lua
64 lines (63 loc) · 2.13 KB
/
mouse.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 % grid_spacing
clip_mouse_y = mouse_y - mouse_y % grid_spacing
--edition mode
mouse_mode = 0
if (clip_mouse_x >= bounds.min_x) and (clip_mouse_x <= bounds.max_x) and
(clip_mouse_y >= bounds.min_y) and (clip_mouse_y <= bounds.max_y) then
if love.mouse.isDown(1) then
mouse_mode = 1
elseif love.mouse.isDown(2) then
mouse_mode = -1
end
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
add_to_layer(layer_selected)
if sfx then s_place:stop() s_place:play() end
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
rem_of_layer(layer_selected)
buffer_x = clip_mouse_x
buffer_y = clip_mouse_y
end
end
function love.mousepressed(x, y, button)
x = math.floor(x / scale)
y = math.floor(y / scale)
--slots
do
local bound_x = 8
local bound_y = 16
if x >= bound_x and y >= bound_y and
x <= bound_x + 76 and y <= bound_y + 252 then
local x = x - bound_x
local y = y - bound_y
select_slot(math.floor(x / 26) + 1 + math.floor(y / 82) * 3)
if sfx then s_scroll:play() end
end
end
--layers
if x >= GAME_WIDTH - 96 and y <= GAME_WIDTH and
y >= 16 and y <= #layers * 18 + 14 then
layer_clicked = #layers - math.floor((y - 2) / 18) + 1
if x >= GAME_WIDTH - 39 then
option = math.floor((-(x - GAME_WIDTH) - 3) / 12)
if option == 0 then layer_move_up(layer_clicked)
elseif option == 1 then layer_move_down(layer_clicked)
elseif option == 2 then
layer_change_visibility(layer_clicked)
end
else layer_selected = layer_clicked end
elseif x >= GAME_WIDTH - 15 and y >= #layers * 16 + 4 and
x <= GAME_WIDTH - 3 and y >= #layers * 16 + 16 then
layer_new()
end
end