~colbyhub/pocket_dust

ac5b47990233af20f684fff7a9a6f2565664ee61 — colbyhub 5 months ago 1c15670
Remove redundant movement calls
1 files changed, 3 insertions(+), 12 deletions(-)

M src/main.c
M src/main.c => src/main.c +3 -12
@@ 173,7 173,6 @@ particle_t* update_lava(uint8_t x, uint8_t y) {
  }

  if (get_particle_updated(particle) == false && y < CANVAS_HEIGHT) {
    
    // Ignite the sand
    if (get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_SAND_ID) {
      if ((rand() % 100) < 70) {


@@ 246,7 245,6 @@ particle_t* update_lava(uint8_t x, uint8_t y) {
    if (get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_AIR_ID && y < CANVAS_HEIGHT - 1) {
      if ((rand() % 100) > 50) {
        new_position.y = y + 1;
        move_particle(x, y, new_position.x, new_position.y);
      }
      // If there is air on both sides, randomly choose a direction to move
    } else if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID && 


@@ 260,18 258,16 @@ particle_t* update_lava(uint8_t x, uint8_t y) {
          new_position.x = x + 1;
        }
      }
      move_particle(x, y, new_position.x, new_position.y);
    } else if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID) {
      if ((rand() % 100) > 50) {
        new_position.x = x - 1;
      }
      move_particle(x, y, new_position.x, new_position.y);
    } else if (get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID && x < CANVAS_WIDTH - 1) {
      if ((rand() % 100) > 50) {
        new_position.x = x + 1;
      }
      move_particle(x, y, new_position.x, new_position.y);
    }
    move_particle(x, y, new_position.x, new_position.y);
  }

  particle_t *particle_at_new_position = get_particle(new_position.x, new_position.y);


@@ 336,18 332,15 @@ particle_t* update_fire(uint8_t x, uint8_t y) {

    if (get_particle_material_id(get_particle(x, y - 1)) == MATERIAL_AIR_ID) {
      new_position.y = y - 1;
      move_particle(x, y, new_position.x, new_position.y);
    } 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) {
      new_position.x = rand() % 100 < 50 ? x - 1 : x + 1;
      move_particle(x, y, new_position.x, new_position.y);
    } else if (get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID) {
      new_position.x = x - 1;
      move_particle(x, y, new_position.x, new_position.y);
    } else if (get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID) {
      new_position.x = x + 1;
      move_particle(x, y, new_position.x, new_position.y);
    }
    move_particle(x, y, new_position.x, new_position.y);
  }

  particle_t *particle_at_new_position = get_particle(new_position.x, new_position.y);


@@ 434,18 427,16 @@ particle_t* update_sand(uint8_t x, uint8_t y) {
    if (get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_AIR_ID || 
        get_particle_material_id(get_particle(x, y + 1)) == MATERIAL_WATER_ID) {
      new_position.y = y + 1;
      move_particle(x, y, new_position.x, new_position.y);
    } else if (get_particle_material_id(get_particle(x - 1, y + 1)) == MATERIAL_AIR_ID &&
        get_particle_material_id(get_particle(x - 1, y)) == MATERIAL_AIR_ID) {
      new_position.x = x - 1;
      new_position.y = y + 1;
      move_particle(x, y, new_position.x, new_position.y);
    } else if (get_particle_material_id(get_particle(x + 1, y + 1)) == MATERIAL_AIR_ID && 
        get_particle_material_id(get_particle(x + 1, y)) == MATERIAL_AIR_ID) {
      new_position.x = x + 1;
      new_position.y = y + 1;
      move_particle(x, y, new_position.x, new_position.y);
    }
    move_particle(x, y, new_position.x, new_position.y);
  }

  particle_t *particle_at_new_position = get_particle(new_position.x, new_position.y);