@@ -17,6 +17,7 @@ windowWidth = 640
17
17
windowHeight = 480
18
18
leftPressed = false
19
19
prevPosition = nothing ;
20
+ cursorSize = 0
20
21
21
22
# TODO figure out how I want to handle resizing and map size in general
22
23
@@ -86,13 +87,26 @@ function updateClickedPixel(prevPosition)
86
87
function setPixel (point)
87
88
x = point[1 ]
88
89
y = point[2 ]
90
+ if x < 0 || x >= windowWidth || y < 0 || y >= windowHeight
91
+ return
92
+ end
89
93
board[y+ 1 ][x+ 1 ] = newVoxel (selectedBlock)
90
94
if (selectedBlock == SAND)
91
95
moveableMap[[y + 1 , x + 1 ]] = SAND
92
96
end
93
97
end
94
98
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)
96
110
97
111
global prevPosition = mousePos
98
112
end
@@ -120,6 +134,17 @@ function handleKeys(event::sfEvent)
120
134
if (event. key. code == sfKeyNum2)
121
135
global selectedBlock = STONE
122
136
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
123
148
# event_ref.x.type == sfKeyNum3 &&
124
149
end
125
150
0 commit comments