Status
Not open for further replies.

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
I have a grid as follow (pseudo):

@map_width = 100@grid = {}def set_tile(x, y, value)  @grid[y * @map_width + x] = valueend...def set_tile(50, 50, true)But because a tile is nothing but a coordinate (not a class) I can not use the typical recursive algorithm to flood fill tiles to true.

Code:
def flood_fill4(x, y)  # erm... yeah... what to put here...end...flood_fill4(50, 50)
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,879
First Language
English
I don't understand what problem you are having.


You have a grid, you have the dimensions, you have a starting coordinate where the fill begins...
 
Last edited by a moderator:

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
I can't use recursion without creating a new custom object for every tile that I check. Because I have a grid of bools and not a grid with classes.

Update:

Oh wait... I can just use a 2nd method... I'm so silly... I solved it.

For whoever is interested, here is my (unoptimized) solution:

Code:
    def flood_fill4_recursive(x, y, width, matching_hash, new_hash, ignore_condition=false)      location_key = y * width + x      return if ($game_map.region_data[location_key] != matching_hash) && !ignore_condition      $game_map.region_data[location_key] = new_hash.clone            flood_fill4_recursive(x + 1, y, width, matching_hash, new_hash) if (x + 1) < width      flood_fill4_recursive(x - 1, y, width, matching_hash, new_hash) if x > 0      flood_fill4_recursive(x, y + 1, width, matching_hash, new_hash) if (y + 1) < $game_map.height      flood_fill4_recursive(x, y - 1, width, matching_hash, new_hash) if y > 0    end
 
Last edited by a moderator:
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Working in the IT industry:
- "How long does it take?".
- "It takes 1 month".
- "What if we add more people to the project?".
- "It would take 2 months".
Doing RPG Maker News for 16th September 2021

Stream is live! I am currently doing pixel art and will be practicing shading! Feel free to drop by!
wow, Surface Tension is really one MF of an FPS level huh
So, I got let go from my current job because my skill set didn't align with the department's goals anymore. I have some hope, because I am currently in contact with a manager from a different department, and they are desperate for more employees. We'll see what happens... :kaoswt:

Forum statistics

Threads
115,121
Messages
1,087,375
Members
149,607
Latest member
iamicon
Top