Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Somar |
Before I start just want to let you know that I am very new to Godot and programming in general, and that I do not know every concept of programming, and math is not really my forte. But I am very keen to learning new things. Sorry for any English mistakes and thanks in advance.
I have this drawing of what I am trying to achieve:
This is a map with 30x30 tiles, each tile being 8x8 pixels. The objective of my code is to:
- Select three random locations having the regions as modifiers for the chance of the seed being located there. The red region would be the rarest, the yellow the uncommon and the green would have a higher chance of spawning a seed.
- Each seed would define its own region and spawn other two to three seeds that would again create their own areas.
- In step three all the map would be filled with tiles. The regions created in steps one and two would highly increase the chance of spawning water tiles, while the remaining area out of the regions would be populated with grass tiles.
The result without the tiles being something like this:
The code I am currently using is very repetitive and not very editable. And makes it necessary to make if statements
for every corner of every region created this way. Becoming very, very repetitive and not very editable (I’ve not been able to make variations of regions size and quantity of secondary nodes).
This is a snippet of what I am currently using:
func _getChance(cellX, cellY):
if cellX >= 21 and cellX <= mapSize-21 and cellY >= 21 and cellY <= mapSize-21:
chance = 2
elif cellX >= 5 and cellX <= mapSize-5 and cellY >= 5 and cellY <= mapSize-5:
chance = 11
else:
chance = 28
This only creates the three original regions. I would have to repeat it 17 times! to achieve something like the second image. How can I automatize this?