~colbyhub/pocket_dust

1c1567012cb31ad335233f8909598b098cfb0148 — colbyhub 3 months ago ed505c1
Add better water

Lots of effort went into figuring out how to make more realistic water.
Look at the other "strange-water" branches for examples of lightening
and other strange effects.

Fixes: https://todo.sr.ht/~colbyhub/pocket_dust-issues/23
1 files changed, 34 insertions(+), 15 deletions(-)

M src/main.c
M src/main.c => src/main.c +34 -15
@@ 361,25 361,44 @@ particle_t* update_water(uint8_t x, uint8_t y) {
  set_particle_color(particle, 2);

  if (get_particle_updated(particle) == false && y < CANVAS_HEIGHT) {
    if (get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_AIR_ID && y < CANVAS_HEIGHT - 1) {
    if (get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_AIR_ID &&
        get_particle_material_id(get_particle(x - 1, y + 1)) != MATERIAL_WATER_ID &&
        get_particle_material_id(get_particle(x + 1, y - 1)) != MATERIAL_WATER_ID && 
          y < CANVAS_HEIGHT - 1
          ) {
      new_position.y = y + 1;
    } 

    if (get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_WATER_ID){
      // If there is air on both sides, randomly choose a direction to move
      if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID && 
          get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID ) {
        if ((rand() % 100) > 50) {
          new_position.x = x - 1;
        } else if (x < CANVAS_WIDTH - 1) {
          new_position.x = x + 1;
        }
      } else if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID &&
          get_particle_material_id(get_particle(x + 1, y)) != MATERIAL_AIR_ID) {
    } else if (get_particle_material_id(get_particle(x - 1, y + 1)) == MATERIAL_AIR_ID && 
        get_particle_material_id(get_particle(x + 1, y + 1)) == MATERIAL_AIR_ID &&
        y < CANVAS_HEIGHT - 1
        ) {
      // set_particle_color(particle, 1);
      if ((rand() % 100) > 50) {
        new_position.x = x - 1;
      } else if (x < CANVAS_WIDTH - 1) {
        new_position.x = x + 1;
      }
      new_position.y = y + 1;
    } else if (get_particle_material_id(get_particle(x - 1, y + 1)) == MATERIAL_AIR_ID
      && y < CANVAS_HEIGHT - 1
       ) {
      new_position.x = x - 1;
      new_position.y = y + 1;
    } else if (get_particle_material_id(get_particle(x + 1, y + 1)) == MATERIAL_AIR_ID
        && y < CANVAS_HEIGHT - 1
        ) {
      new_position.x = x + 1;
      new_position.y = y + 1;
    } else if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID && 
        get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID) {
      if ((rand() % 100) > 50) {
        new_position.x = x - 1;
      } else if (get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID && x < CANVAS_WIDTH - 1) {
      } else if (x < CANVAS_WIDTH - 1) {
        new_position.x = x + 1;
      }
    } else if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID) {
      new_position.x = x - 1;
    } else if (get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID && x < CANVAS_WIDTH - 1) {
      new_position.x = x + 1;
    }
    move_particle(x, y, new_position.x, new_position.y);