Skip to content

Commit 63509e7

Browse files
committed
allow changing cursor size with arrow up and down
1 parent 36f6e78 commit 63509e7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

main.jl

+26-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ windowWidth = 640
1717
windowHeight = 480
1818
leftPressed = false
1919
prevPosition = nothing;
20+
cursorSize = 0
2021

2122
# TODO figure out how I want to handle resizing and map size in general
2223

@@ -86,13 +87,26 @@ function updateClickedPixel(prevPosition)
8687
function setPixel(point)
8788
x = point[1]
8889
y = point[2]
90+
if x < 0 || x >= windowWidth || y < 0 || y >= windowHeight
91+
return
92+
end
8993
board[y+1][x+1] = newVoxel(selectedBlock)
9094
if (selectedBlock == SAND)
9195
moveableMap[[y + 1, x + 1]] = SAND
9296
end
9397
end
9498

95-
applyBetween([prevPosition.x, prevPosition.y], [mousePos.x, mousePos.y], setPixel)
99+
function drawAt(point)
100+
starts = point .- cursorSize
101+
ends = point .+ cursorSize
102+
for i in starts[1]:ends[1]
103+
for j in starts[2]:ends[2]
104+
setPixel([i, j])
105+
end
106+
end
107+
end
108+
109+
applyBetween([prevPosition.x, prevPosition.y], [mousePos.x, mousePos.y], drawAt)
96110

97111
global prevPosition = mousePos
98112
end
@@ -120,6 +134,17 @@ function handleKeys(event::sfEvent)
120134
if (event.key.code == sfKeyNum2)
121135
global selectedBlock = STONE
122136
end
137+
if (event.key.code == sfKeyNum3)
138+
global selectedBlock = AIR
139+
end
140+
if (event.key.code == sfKeyUp)
141+
global cursorSize += 1
142+
println("cursorSize:", cursorSize)
143+
end
144+
if (event.key.code == sfKeyDown)
145+
global cursorSize -= 1
146+
println("cursorSize:", cursorSize)
147+
end
123148
# event_ref.x.type == sfKeyNum3 &&
124149
end
125150

0 commit comments

Comments
 (0)