string get_footstep_sound(int current_x, int base_end, int grass_end) { // Check if in water first (overrides all other terrain) if (is_position_in_water(current_x)) { return "sounds/terrain/shallow_water.ogg"; } // Firepit uses hard stone sound if (get_firepit_at(current_x) != null) { return "sounds/terrain/hard_stone.ogg"; } if (current_x <= base_end) { // Base area return "sounds/terrain/wood.ogg"; } else if (current_x <= grass_end) { // Grass area return "sounds/terrain/grass.ogg"; } else if (current_x <= GRAVEL_END) { // Gravel area return "sounds/terrain/gravel.ogg"; } else if (expanded_area_start != -1 && current_x >= expanded_area_start && current_x <= expanded_area_end) { // Expanded area - check terrain type int index = current_x - expanded_area_start; if (index >= 0 && index < expanded_terrain_types.length()) { string terrain = expanded_terrain_types[index]; if (terrain == "stone") { return "sounds/terrain/stone.ogg"; } else if (terrain == "grass") { return "sounds/terrain/grass.ogg"; } else if (terrain == "snow") { return "sounds/terrain/snow.ogg"; } } } // Default to gravel return "sounds/terrain/gravel.ogg"; } void play_footstep(int current_x, int base_end, int grass_end) { string sound_file = get_footstep_sound(current_x, base_end, grass_end); if(file_exists(sound_file)) { p.play_stationary(sound_file, false); } } int play_1d_with_volume_step(string sound_file, int listener_x, int sound_x, bool looping, float volume_step) { int slot = p.play_1d(sound_file, listener_x, sound_x, looping); if (slot != -1) { p.update_sound_positioning_values(slot, -1.0, volume_step, true); } return slot; } void play_positional_footstep(int listener_x, int step_x, int base_end, int grass_end, int max_distance, float volume_step) { int distance = step_x - listener_x; if (distance < 0) { distance = -distance; } if (distance > max_distance) { return; } string sound_file = get_footstep_sound(step_x, base_end, grass_end); if(file_exists(sound_file)) { play_1d_with_volume_step(sound_file, listener_x, step_x, false, volume_step); } } void play_land_sound(int current_x, int base_end, int grass_end) { // Reusing the same logic to play the terrain sound on landing string sound_file = get_footstep_sound(current_x, base_end, grass_end); if(file_exists(sound_file)) { p.play_stationary(sound_file, false); } }