godot-particles/Materials/sand.gd

26 lines
757 B
GDScript

class_name Sand
extends GameMaterial
func _init() -> void:
name = "Sand"
color = Color.GOLD
density = 0.2
func update(grid: GameGrid, y, x) -> void:
var this = grid.get_material_at_position(y, x)
# Water should fall if element below has less density
if grid.get_bottom_of(y, x).density < this.density:
grid.swap_with(y, x, grid.BOTTOM)
Game.material_changed()
return
if grid.get_bottom_left_of(y, x).density < this.density and grid.get_left_of(y, x).density < this.density:
grid.swap_with(y, x, grid.BOTTOM_LEFT)
Game.material_changed()
return
if grid.get_bottom_right_of(y, x).density < this.density and grid.get_right_of(y, x).density < this.density:
grid.swap_with(y, x, grid.BOTTOM_RIGHT)
Game.material_changed()
return