@@ -17,6 +17,7 @@ leftPressed = false
17
17
# TODO figure out how I want to handle resizing and map size in general
18
18
19
19
board = [[newVoxel (AIR) for i in 0 : windowWidth- 1 ] for j in 0 : windowHeight- 1 ]
20
+ moveableMap = Dict ()
20
21
21
22
function getBoardColors (board)
22
23
flatBoard = collect (Iterators. flatten (board))
@@ -70,7 +71,22 @@ function updateClickedPixel()
70
71
71
72
# set boards voxel to new color
72
73
board[mousePos. y+ 1 ][mousePos. x+ 1 ] = newVoxel (SAND)
74
+ moveableMap[[mousePos. y + 1 , mousePos. x + 1 ]] = SAND
75
+ end
73
76
77
+ function physicsTick (board)
78
+ # iterate over moveableMap and move particles down if air below them
79
+ for (i, j) in keys (moveableMap)
80
+ if i < windowHeight
81
+ down1 = board[i+ 1 ][j]
82
+ if down1. type == AIR
83
+ board[i+ 1 ][j] = board[i][j]
84
+ board[i][j] = down1
85
+ moveableMap[[i + 1 , j]] = moveableMap[[i, j]]
86
+ delete! (moveableMap, [i, j])
87
+ end
88
+ end
89
+ end
74
90
end
75
91
76
92
function mouseHandler (event:: sfEvent )
@@ -90,6 +106,7 @@ function mouseHandler(event::sfEvent)
90
106
end
91
107
end
92
108
109
+ lastPhysicsTick = 0.0
93
110
while Bool (sfRenderWindow_isOpen (window))
94
111
95
112
currentTime = sfTime_asSeconds (sfClock_getElapsedTime (clock))
@@ -134,14 +151,22 @@ while Bool(sfRenderWindow_isOpen(window))
134
151
# draw the sprite
135
152
# newBoardSprite = updateBoard()
136
153
137
- # update board
154
+ # make pysics happen
155
+
156
+ if (currentTime - lastPhysicsTick > 0.01 )
157
+ global lastPhysicsTick = currentTime
158
+ physicsTick (board)
159
+ end
160
+
161
+ # draw board
138
162
updateImageBuffer ()
139
163
texture = sfTexture_createFromImage (imageBuffer, C_NULL )
140
164
@assert texture != C_NULL
141
165
142
166
sfSprite_setTexture (sprite, texture, sfTrue)
143
167
sfRenderWindow_drawSprite (window, sprite, C_NULL )
144
168
169
+
145
170
sfRenderWindow_drawText (window, text, C_NULL )
146
171
# update the window
147
172
sfRenderWindow_display (window)
0 commit comments