#I'm not even sure how to summarize this one

1 messages · Page 1 of 1 (latest)

viral shadow
#

Node object:

class Node:
    def __init__(self, location_x, location_y, terrain_type, battle_map):
        self.location_x = location_x
        self.location_y = location_y
        self.terrain_type = terrain_type
        self.battle_map = battle_map

Battle map object

class BattleMap:
    def __init__(self, width, height):
        self.width = width
        self.height = height

        self.nodes = np.zeros((width, height), dtype=object)
        self.combatants = {"Charmander": (15, 15)}

        self.initialize_nodes()

    def initialize_nodes(self):
        for x in range(self.width):
            for y in range(self.height):
                self.nodes[x, y] = Node(x, y, "default", self)

    def get_node(self, x, y):
        return self.nodes[x, y]

Creating the battle _map and canvas

b_map = BattleMap(30, 30)

canvas = Image.new("RGBA", ((b_map.width * 16) + 1, (b_map.height * 16) + 1), (0, 0, 0, 255))

.

#

The code in question

for x in range(b_map.width):
    for y in range(b_map.height):
        node = b_map.get_node(x, y)
        directions = [(1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1)]
        roll = random.randint(1, 40)
        if roll <= 38:
            node.terrain_type = "grass"
        if roll == 39:
            node.terrain_type = "rocky"
            for direction in directions:
                new_x = node.location_x + direction[0]
                new_y = node.location_y + direction[1]
                if 0 <= new_x < b_map.width and 0 <= new_y < b_map.height:
                    try_node = b_map.get_node(new_x, new_y)
                    try_node.terrain_type = "rocky"
        if roll == 40:
            node.terrain_type = "water"
            for direction in directions:
                new_x = node.location_x + direction[0]
                new_y = node.location_y + direction[1]
                if 0 <= new_x < b_map.width and 0 <= new_y < b_map.height:
                    try_node = b_map.get_node(new_x, new_y)
                    try_node.terrain_type = "water"

Also the rest, I don't think this is where the issue is coming from, but including it anyway

for x in range(b_map.width):
    for y in range(b_map.height):
        node = b_map.get_node(x, y)
        if node.terrain_type == "grass":
            colour = (144, 238, 144, 255)
        if node.terrain_type == "rocky":
            colour = (165, 42, 42, 255)
        if node.terrain_type == "water":
            colour = (0, 0, 255, 255)
        block = Image.new("RGBA", (15, 15), colour)
        canvas.paste(block, ((x * 16) + 1, (y * 16) + 1), block)

canvas.show()
#

output looks like this

#

Always that same shape

viral shadow
#

Wait

#

I think I realized what it is

#

They are getting turned into rock/water

#

But then it continues to that nodes roll and 38 times out of 40 it gets reassigned back to grass

#

I feel stupid for not noticing that, and am going to immediately delete all evidence of ever having been stuck on this