0 votes

Hello,

I'm using OpenSimplexNoise to replace tiles with Node2Ds. Problem is, i want the amount of a specific tile to be predefined. This has caused my code to sort of 'print' from tope to bottom left to right like a printer instead of like a simplex noise map.

my main scene is setup:

Node2D
- TileMap

with an autoload for the tile amounts.

extends TileMap

var HexTile = preload("res://Field/BlankHex.tscn")
var OSN

func _ready():
    randomize()
    OSN = OpenSimplexNoise.new()
    OSN.seed = randi()

    OSN.octaves = 3
    OSN.period = 10
    OSN.lacunarity = 1.5
    OSN.persistence = 15

    var HexID = get_used_cells_by_id(0)
    setup(HexID)

func setup(rndArr):
    var tilePos
    for i in range(0, rndArr.size()):
        chooseHex(OSN.get_noise_2d(rndArr[i].x, rndArr[i].y))
        var newHexTile = HexTile.instance()
        tilePos = map_to_world(rndArr[i])
        newHexTile.set_position(tilePos)
        set_cell(rndArr[i].x, rndArr[i].y, -1)
        self.add_child(newHexTile)

func chooseHex(noise_sample):
    if noise_sample < -0.5 and PlayerData.Ore > 0:
        print("Ore")
        HexTile = preload("res://Field/OreHex.tscn")
        PlayerData.useOreHex()
    elif noise_sample < 0.3 and PlayerData.Timber > 0:
        print("Timber")
        HexTile = preload("res://Field/TimberHex.tscn")
        PlayerData.useTimberHex()
    elif noise_sample < 0.0 and PlayerData.Food > 0:
        print("Food")
        HexTile = preload("res://Field/FoodHex.tscn")
        PlayerData.useFoodHex()
    elif noise_sample < 0.3 and PlayerData.LiveStock > 0:
        print("LiveStock")
        HexTile = preload("res://Field/LivestockHex.tscn")
        PlayerData.useLiveStockHex()
    elif noise_sample < 0.5 and PlayerData.Sand > 0:
        print("Sand")
        HexTile = preload("res://Field/SandHex.tscn")
        PlayerData.useSandHex()
    else:
        print("Blank")
        HexTile = preload("res://Field/BlankHex.tscn")

heres the autoload:

extends Node

onready var Food = 50
onready var LiveStock = 50
onready var Timber = 50
onready var Ore = 50
onready var Sand = 50

func useFoodHex():
    Food -= 1

func useLiveStockHex():
    LiveStock -= 1

func useTimberHex():
    Timber -= 1

func useOreHex():
    Ore -= 1

func useSandHex():
    Sand -= 1
Godot version Godot 3.4.2
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.