Const cSLEEPTIME
= 5 'iterations until cell goes to sleep
Const cNUMOFMATERIALS
= 15 ' one more than # of actual materials Const matFOAM
= 4 'floats on liquids Const matWATERSOURCE
= 12
Const reactFOAM
= 4 'floats on liquids Const reactACIDWATER
= 10 Const reactWATERSOURCE
= 12
'Dim reaction_matrix(cNUMOFMATERIALS, cNUMOFMATERIALS, 8) As Integer
Dim World
(SIZE_X
, SIZE_Y
) As tMATERIAL
Dim material_prop
(20) As tMATERIAL
Call material_init
(material_prop
())
Call render_menu
(material_prop
(), mouse
) Call handle_kepress
(World
(), material_prop
()) Call handle_mouse
(World
(), mouse
, material_prop
())
Sub render_menu
(mat_prop
() As tMATERIAL
, mouse
As tMOUSE
) Line (0, 0)-(SIZE_X
* SCALE
- 1, SIZE_Y
* SCALE
- 1), _RGB(50, 67, 127), B
For i
= 0 To cNUMOFMATERIALS
Line (102 * 8, i
* 16 + 143)-(116 * 8, i
* 16 + 158), , B
Print "Use Mousewheel to" Print "Left Mouse Button" Print "to Deposit material" fpsLast = fps
fps = 0
Sub handle_kepress
(world
() As tMATERIAL
, mat_prop
() As tMATERIAL
)
Call clear_world
(world
(), mat_prop
()) Call save_world
(world
(), "CellAuto.ca") Call load_world
(world
(), "CellAuto.ca")
Print #1, world
(i
, j
).material
Print #1, world
(i
, j
).behavior
Print #1, world
(i
, j
).flammable
Print #1, world
(i
, j
).sleeptime
Print #1, world
(i
, j
).update_ticks
Print #1, world
(i
, j
).update
Print #1, world
(i
, j
).lifetime
Input #1, world
(i
, j
).material
Input #1, world
(i
, j
).behavior
Input #1, world
(i
, j
).flammable
Input #1, world
(i
, j
).sleeptime
Input #1, world
(i
, j
).update_ticks
Input #1, world
(i
, j
).update
Input #1, world
(i
, j
).lifetime
Sub clear_world
(world
() As tMATERIAL
, mat_prop
() As tMATERIAL
) world(i, j) = mat_prop(matNOTHING)
Sub run_sim
(world
() As tMATERIAL
, mat_prop
() As tMATERIAL
) Dim process_direction_x
, process_direction_y
, active_flag
As Integer
process_direction_y
= 1 - Int((Rnd > .5) * 2) start_y = 1: finish_y = SIZE_Y - 1
If process_direction_y
< 0 Then
For j
= start_y
To finish_y
Step process_direction_y
start_x = 1: finish_x = SIZE_X - 1
process_direction_x
= 1 - Int((Rnd > .5) * 2)
If process_direction_x
< 0 Then
For i
= start_x
To finish_x
Step process_direction_x
If world
(i
, j
).update
= 0 Then ' update tick are used to slow certain materials down If world
(i
, j
).sleeptime
> 0 Then ' make sure cell is still active and not sleeping UP = j - 1
DOWN = j + 1
LEFT = i - 1
RIGHT = i + 1
' reaction behavior
If world
(LEFT
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(i
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(RIGHT
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(LEFT
, j
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(RIGHT
, j
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(LEFT
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(i
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(RIGHT
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matACIDWATER
).material
, i
, j
)
If world
(LEFT
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, LEFT
, UP
) If world
(i
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, UP
) If world
(RIGHT
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, RIGHT
, UP
) If world
(LEFT
, j
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, LEFT
, j
) If world
(RIGHT
, j
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, RIGHT
, j
) If world
(LEFT
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, LEFT
, DOWN
) If world
(i
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, DOWN
) If world
(RIGHT
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matRESIDUE
).material
, RIGHT
, DOWN
)
If world
(LEFT
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, LEFT
, UP
) If world
(i
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, UP
) If world
(RIGHT
, UP
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, RIGHT
, UP
) If world
(LEFT
, j
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, LEFT
, j
) If world
(RIGHT
, j
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, RIGHT
, j
) If world
(LEFT
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, LEFT
, DOWN
) If world
(i
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, DOWN
) If world
(RIGHT
, DOWN
).material
= matACID
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, RIGHT
, DOWN
) active_flag = 0
If world
(LEFT
, UP
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(i
, UP
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(RIGHT
, UP
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(LEFT
, j
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(RIGHT
, j
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(LEFT
, DOWN
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(i
, DOWN
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
)
If world
(RIGHT
, DOWN
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, j
) If world
(i
, DOWN
).material
= matSOLID
Or world
(i
, DOWN
).material
= matFOAM
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matASH
).material
, i
, j
) active_flag = 1
Call set_mat
(world
(), mat_prop
(), mat_prop
(matFIRE
).material
, i
, DOWN
) If world
(i
, UP
).material
= reactWOOD
Or world
(i
, UP
).material
= reactFOAM
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactFIRE
).material
, i
, UP
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactASH
).material
, i
, j
) active_flag = 1
If world
(LEFT
, j
).material
= matSOLID
Or world
(LEFT
, j
).material
= matFOAM
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matASH
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matFIRE
).material
, LEFT
, j
) active_flag = 1
If world
(RIGHT
, j
).material
= matSOLID
Or world
(RIGHT
, j
).material
= matFOAM
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matGAS
).material
, i
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(matASH
).material
, i
, j
)
Call set_mat
(world
(), mat_prop
(), mat_prop
(matFIRE
).material
, RIGHT
, j
) active_flag = 1
world(i, j).lifetime = world(i, j).lifetime - 1
If world
(i
, j
).lifetime
< 1 Then Call set_mat
(world
(), mat_prop
(), mat_prop
(matNOTHING
).material
, i
, j
) world(i, j).sleeptime = 50
world(i, j).update = 0
If world
(LEFT
, DOWN
).material
= matACID
Or world
(LEFT
, DOWN
).material
= reactWATER
Then
Call set_mat
(world
(), mat_prop
(), mat_prop
(reactACIDWATER
).material
, LEFT
, DOWN
) If world
(i
, DOWN
).material
= matACID
Or world
(i
, DOWN
).material
= reactWATER
Then
Call set_mat
(world
(), mat_prop
(), mat_prop
(reactACIDWATER
).material
, i
, DOWN
) If world
(RIGHT
, DOWN
).material
= matACID
Or world
(RIGHT
, DOWN
).material
= reactWATER
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactACIDWATER
).material
, RIGHT
, DOWN
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, LEFT
, UP
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, UP
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, RIGHT
, UP
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, LEFT
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, RIGHT
, j
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, LEFT
, DOWN
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, i
, DOWN
) Call set_mat
(world
(), mat_prop
(), mat_prop
(reactAIR
).material
, RIGHT
, DOWN
) If world
(LEFT
, UP
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, LEFT
, UP
) If world
(i
, UP
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, i
, UP
) If world
(RIGHT
, UP
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, RIGHT
, UP
) If world
(LEFT
, j
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, LEFT
, j
) If world
(RIGHT
, j
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, RIGHT
, j
) If world
(LEFT
, DOWN
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, LEFT
, DOWN
) If world
(i
, DOWN
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, i
, DOWN
) If world
(RIGHT
, DOWN
).material
= reactNOTHING
Then Call set_mat
(world
(), mat_prop
(), mat_prop
(reactWATER
).material
, RIGHT
, DOWN
)
'movement behavior below
'Check DOWN
If world
(i
, DOWN
).behavior
= matNOTHING
Or world
(i
, DOWN
).behavior
= matLIQUID
Or world
(i
, DOWN
).behavior
= matGAS
Or world
(i
, DOWN
).material
= reactOIL
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, DOWN
) 'Check LEFT DOWN
If world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matLIQUID
Or world
(LEFT
, DOWN
).behavior
= matGAS
Or world
(LEFT
, DOWN
).material
= reactOIL
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) 'Check RIGHT DOWN
If world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matLIQUID
Or world
(RIGHT
, DOWN
).behavior
= matGAS
Or world
(RIGHT
, DOWN
).material
= reactOIL
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) If world
(i
, DOWN
).behavior
= matNOTHING
Or world
(i
, DOWN
).behavior
= matFOAM
Or world
(i
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, DOWN
) ' if both left down and right down are available then RNG the direction
If (world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matFOAM
Or world
(LEFT
, DOWN
).behavior
= matGAS
) And _
(world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matFOAM
Or world
(RIGHT
, DOWN
).behavior
= matGAS
) Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) 'Check LEFT DOWN
If world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matFOAM
Or world
(LEFT
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) 'Check RIGHT DOWN
If world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matFOAM
Or world
(RIGHT
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) If (world
(LEFT
, j
).behavior
= matNOTHING
Or world
(LEFT
, j
).behavior
= matFOAM
Or world
(LEFT
, j
).behavior
= matGAS
) And _
(world
(RIGHT
, j
).behavior
= matNOTHING
Or world
(RIGHT
, j
).behavior
= matFOAM
Or world
(RIGHT
, j
).behavior
= matgas
) Then ' if both left and right are available then RNG the direction
Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
) ' Check LEFT
If world
(LEFT
, j
).behavior
= matNOTHING
Or world
(LEFT
, j
).behavior
= matFOAM
Or world
(LEFT
, j
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) 'Check RIGHT
If world
(RIGHT
, j
).behavior
= matNOTHING
Or world
(RIGHT
, j
).behavior
= matFOAM
Or world
(RIGHT
, j
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
) 'Do Nothing no movement
'Check DOWN
If world
(i
, DOWN
).behavior
= matNOTHING
Or world
(i
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, DOWN
) If (world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matGAS
) And (world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matGAS
) Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) 'Check LEFT DOWN
If world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) 'Check RIGHT DOWN
If world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) 'Check UP
If world
(i
, UP
).behavior
= matLIQUID
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, UP
) If world
(LEFT
, UP
).behavior
= matLIQUID
And world
(RIGHT
, UP
).behavior
= matLIQUID
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, UP
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, UP
) 'Check LEFT UP
If world
(LEFT
, UP
).behavior
= matLIQUID
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, UP
) 'Check RIGHT UP
If world
(RIGHT
, UP
).behavior
= matLIQUID
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, UP
) If (world
(LEFT
, j
).behavior
= matLIQUID
Or world
(LEFT
, j
).behavior
= matNOTHING
Or world
(LEFT
, j
).behavior
= matGAS
) And (world
(RIGHT
, j
).behavior
= matLIQUID
Or world
(RIGHT
, j
).behavior
= matNOTHING
Or world
(RIGHT
, j
).behavior
= matGAS
) Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
) 'Check LEFT
If world
(LEFT
, j
).behavior
= matLIQUID
Or world
(LEFT
, j
).behavior
= matNOTHING
Or world
(LEFT
, j
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) 'Check RIGHT
If world
(RIGHT
, j
).behavior
= matLIQUID
Or world
(RIGHT
, j
).behavior
= matNOTHING
Or world
(RIGHT
, j
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
)
If world
(i
, UP
).behavior
= matNOTHING
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, UP
) ' if both left up and right up are available then RNG the direction
If (world
(LEFT
, UP
).behavior
= matNOTHING
) And (world
(RIGHT
, UP
).behavior
= matNOTHING
) Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, UP
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, UP
) 'Check LEFT up
If world
(LEFT
, UP
).behavior
= matNOTHING
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, UP
) 'Check RIGHT up
If world
(RIGHT
, UP
).behavior
= matNOTHING
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, UP
) If (world
(LEFT
, j
).behavior
= matNOTHING
) And (world
(RIGHT
, j
).behavior
= matNOTHING
) Then ' if both left and right are available then RNG the direction
Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
) ' Check LEFT
If world
(LEFT
, j
).behavior
= matNOTHING
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) 'Check RIGHT
If world
(RIGHT
, j
).behavior
= matNOTHING
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
) If world
(i
, DOWN
).behavior
= matNOTHING
Or world
(i
, DOWN
).behavior
= matFOAM
Or world
(i
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, DOWN
) ' if both left down and right down are available then RNG the direction
If (world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matFOAM
Or world
(LEFT
, DOWN
).behavior
= matGAS
) and _
(world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matFOAM
Or world
(RIGHT
, DOWN
).behavior
= matGAS
) Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) 'Check LEFT DOWN
If world
(LEFT
, DOWN
).behavior
= matNOTHING
Or world
(LEFT
, DOWN
).behavior
= matFOAM
Or world
(LEFT
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, DOWN
) 'Check RIGHT DOWN
If world
(RIGHT
, DOWN
).behavior
= matNOTHING
Or world
(RIGHT
, DOWN
).behavior
= matFOAM
Or world
(RIGHT
, DOWN
).behavior
= matGAS
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, DOWN
) If world
(i
, UP
).material
= reactWATER
Then Call move_mat
(world
(), mat_prop
(), i
, j
, i
, UP
) If world
(LEFT
, UP
).material
= reactWATER
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, UP
) If world
(RIGHT
, UP
).material
= reactWATER
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, UP
) If (world
(LEFT
, j
).behavior
= matNOTHING
Or world
(LEFT
, j
).behavior
= matFOAM
Or world
(LEFT
, j
).behavior
= matGAS
Or world
(LEFT
, j
).material
= reactWATER
) And _
(world
(RIGHT
, j
).behavior
= matNOTHING
Or world
(RIGHT
, j
).behavior
= matFOAM
Or world
(RIGHT
, j
).behavior
= matGAS
Or world
(RIGHT
, j
).material
= reactWATER
) Then ' if both left and right are available then RNG the direction
Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
) ' Check LEFT
If world
(LEFT
, j
).behavior
= matNOTHING
Or world
(LEFT
, j
).behavior
= matFOAM
Or world
(LEFT
, j
).behavior
= matGAS
Or world
(LEFT
, j
).material
= reactWATER
Then Call move_mat
(world
(), mat_prop
(), i
, j
, LEFT
, j
) 'Check RIGHT
If world
(RIGHT
, j
).behavior
= matNOTHING
Or world
(RIGHT
, j
).behavior
= matFOAM
Or world
(RIGHT
, j
).behavior
= matGAS
Or world
(RIGHT
, j
).material
= reactWATER
Then Call move_mat
(world
(), mat_prop
(), i
, j
, RIGHT
, j
)
If world
(LEFT
, j
).behavior
<> matFIRE
Then 'Never put fire to sleep world(i, j).sleeptime = world(i, j).sleeptime - 1
Sub render
(world
() As tMATERIAL
) Line (i
* SCALE
, j
* SCALE
)-(i
* SCALE
+ (SCALE
- 1), j
* SCALE
+ (SCALE
- 1)), world
(i
, j
).c
, BF
If world
(i
, j
).update
> 0 Then world(i, j).update = world(i, j).update - 1 ' decrement tick count for next update
world(x, y) = mat_prop(material)
Call update_lifetime
(world
(), x
, y
, cSLEEPTIME
) ' wake up neighboring cells
SWAPMat = world(xm, ym)
world(xm, ym) = world(x, y)
world(x, y) = SWAPMat
world(x, y).update = mat_prop(world(x, y).material).update_ticks ' cell has been processed this cycle
world(xm, ym).update = mat_prop(world(xm, ym).material).update_ticks ' cell has been processed this cycle
Call update_lifetime
(world
(), x
, y
, cSLEEPTIME
) ' wake up neighboring cells Call update_lifetime
(world
(), xm
, ym
, cSLEEPTIME
) ' wake up neighboring cells
'wake up neighboring cells as they may be affected by nearby changes
If world
(i
+ x
, j
+ y
).material
> matNOTHING
Then world(x + i, y + j).sleeptime = l
Sub material_init
(ms
() As tMATERIAL
)
Data "air",0,0,0,0,0,-1,"sand",1,1,166,172,127,-1,"water",2,1,67,72,183,-1,"wood",3,1,111,72,0,-1 Data "foam",4,1,255,255,255,-1,"acid",2,4,17,216,22,-1,"residue",1,6,127,67,127,-1,"gas",7,10,128,127,127,-1 Data "fire",8,20,255,64,0,10,"ash",1,4,32,32,32,-1,"acidwater",2,10,6,83,6,-1,"drain",11,4,44,28,28,-1 Data "water source",12,1,44,28,28,-1,"stone",13,1,127,127,127,-1,"oil",14,2,20,20,20,-1 For i
= 0 To cNUMOFMATERIALS
- 1 ms(i).behavior = behavior
ms(i).material = i
ms(i).sleeptime = cSLEEPTIME
ms(i).update = update
ms(i).update_ticks = update
ms(i).lifetime = life
Sub handle_mouse
(world
() As tMATERIAL
, mouse
As tMOUSE
, mat_prop
() As tMATERIAL
) If mouse.position.x
> 1 And mouse.position.x
< SIZE_X
* SCALE
- 1 And mouse.position.y
> 1 And mouse.position.y
< SIZE_Y
* SCALE
- 1 Then Call set_mat
(world
(), mat_prop
(), mat_prop
(w
).material
, mouse.position.x
/ SCALE
+ i
, mouse.position.y
/ SCALE
+ j
)