Skip to content

A falling sand game made in C using the minilibX as the API

License

Notifications You must be signed in to change notification settings

gecarval/Falling-Sand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REPOSITORY STATS

GitHub code size in bytes Code language count GitHub top language GitHub last commit

Cellular Automaton

A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model of computation studied in automata theory. Cellular automata are also called cellular spaces, tessellation automata, homogeneous structures, cellular structures, tessellation structures, and iterative arrays. Cellular automata have found application in various areas, including physics, theoretical biology and microstructure modeling.

-On Wikipedia.

The cellular automaton is a simulation that got populazired throught Conway's game of life where it consists of regular grids of cells or a matrix where it has a finite amount of states and each cell as a defined amount of rules based on it's neighbors relative to the cell's position and with such simple rules complex and emergent behaviors could occur.

Conway's Game of Life

The Game of Life, also known as Conway's Game of Life or simply Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. It is Turing complete and can simulate a universal constructor or any other Turing machine.

-On Wikipedia.

The game of life has simple rule sets descrived:

  • If a cell neighbourhood has less than two live cells, all cells die;
  • If the alive cell has two or three live neighbours, the cells remain;
  • If the cell neighbourhood has more than three cells, the singular cell dies;
  • If a dead cell has exactly three alive cells in the neighbourhood, it becomes a live.

Falling Sand Game

A falling-sand game is a genre of video game and a sub-genre of sandbox games which typically utilize a two-dimensional particle or cellular automaton based game engine to simulate various materials interacting in a sandbox environment. In falling-sand games, the user can interact with (e.g. place and remove) particles on a canvas which can interact with other particles in various ways, which can lead to complex emergent behaviour. As sandbox games, they generally have an emphasis on free-form gameplay, relaxed rules, and minimal goals.

-On Wikipedia.

The falling sand game is a type os cellular automaton where as the game of life each set of cell as a defined behavior when in contact with diferent cells.

Behavior

The main objective of this simulation is to recreate the behaviors of different material types within a grid-based environment. A simple action, like setting fire to water, can trigger cascading effects across large quantities of materials. These interactions create a dynamic and engaging experience, where players observe emergent physical phenomena, such as evaporation, flow, and chemical reactions.

Sand

In this game, sand behaves like a loose granular material. When the cell below a sand particle is empty, the particle "falls" by swapping places. If the space below is occupied, the sand checks neighboring cells to move diagonally, mimicking gravitational behavior.

image

Water

Water behaves similarly to sand in its falling motion, but when it hits the ground, it attempts to flow left or right. The water particles randomly move into empty horizontal spaces, simulating fluidity.

image

Chemical Reactions and Physics

Other complex interactions include:

  • Chemical reactions such as soap bubbles and acid reactions.
  • Heat-based interactions like water evaporating or lava being extinguished.
  • Inertia and momentum, where water flows to fill available space in a container, and gases spread or liquids cascade based on physical properties.

Footage

There are diverse footage took from the simulation, feel free to get a look into it:

sand

Note

In the sand, there is even the behavior of inercia and collision.

  • Soap and acid reactions:

soap

acid ract

  • Lava, fire, and water interactions:

fire and lava

oil burn

gas and wood

  • Sand in motion, reacting to inertia and collisions:

cinetics

  • Water physics, with inertia and momentum-based behavior as water fills available space:

water physics

Installation

The project uses the MiniLibX using the X11 Window system in the Linux Operating System, after the instalation of all dependencies you should do as required:

  • Clone the repository;
git clone https://github.com/gecarval/Falling-Sand.git
  • Move to the folder;
cd Falling-Sand
  • Compile the project;
make
  • execute the program.
./render

Controls

BUTTON ACTION
Q Empty
W Sand
E WetSand
R Stone
T GunPowder
Y Soap
U Wood
I Iron
O Rust
P Glass
A Water
S Lava
D Oil
F Acid
G Fly
Z Fire
X Oxygen
C Hidrogen
V Propane
B Steam
N Missil
, decrease brush size
. increase brush size
LMB activate brush
RMB deactivate brush
Esc Exit
[ increase speed
] decrease speed
1 on/off 3Dcube
2 on/off falling sand
Space clear screen

Releases

No releases published

Packages

No packages published