Skip to content

Commit

Permalink
move code to create trees from TileMap in TreesLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
theludovyc committed Nov 26, 2024
1 parent 67c1e85 commit b9c7a24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
16 changes: 16 additions & 0 deletions Script/World/TreesLayer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends TileMapLayer

@onready var tileMap := get_parent()

func create_trees():
var noise := FastNoiseLite.new()
noise.frequency = 0.3

for i in range(tileMap.minimap.size()):
if tileMap.minimap[i] == MyTileMap.Minimap_Cell_Type.Ground:
var pos = tileMap.minimap_get_pos(i)

if noise.get_noise_2dv(pos) > 0.1:
set_cell(pos, 1, Vector2(0, 1))

tileMap.minimap[i] = MyTileMap.Minimap_Cell_Type.Tree
4 changes: 3 additions & 1 deletion theLudovyc/Game2D.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://bbbuj3ne5rupv"]
[gd_scene load_steps=17 format=3 uid="uid://bbbuj3ne5rupv"]

[ext_resource type="Script" path="res://theLudovyc/Game2D.gd" id="1_i3wk0"]
[ext_resource type="Script" path="res://theLudovyc/EventBus.gd" id="2_jbfdl"]
Expand All @@ -15,6 +15,7 @@
[ext_resource type="TileSet" uid="uid://dprvpcto8mhgv" path="res://theLudovyc/tile_set_trees.tres" id="12_25naw"]
[ext_resource type="Script" path="res://Script/World/GroundLayer.gd" id="12_dmqkb"]
[ext_resource type="PackedScene" uid="uid://cdwvtbtwmrqbn" path="res://Scene/RGT/PauseMenu.tscn" id="13_xikc4"]
[ext_resource type="Script" path="res://Script/World/TreesLayer.gd" id="14_wtd65"]

[node name="Game2D" type="Node"]
script = ExtResource("1_i3wk0")
Expand Down Expand Up @@ -67,6 +68,7 @@ script = ExtResource("12_dmqkb")
z_index = 2
y_sort_enabled = true
tile_set = ExtResource("12_25naw")
script = ExtResource("14_wtd65")

[node name="Entities" type="Node2D" parent="ZSorter"]
unique_name_in_owner = true
Expand Down
13 changes: 1 addition & 12 deletions theLudovyc/TileMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,7 @@ func create_island(map_file:String) -> int:
json.data["ground_tiles"]
)

# spawn trees
var noise := FastNoiseLite.new()
noise.frequency = 0.3

for i in range(minimap.size()):
if minimap[i] == Minimap_Cell_Type.Ground:
var pos = minimap_get_pos(i)

if noise.get_noise_2dv(pos) > 0.1:
trees_layer.set_cell(pos, 1, Vector2(0, 1))

minimap[i] = Minimap_Cell_Type.Tree
trees_layer.create_trees()

return OK

Expand Down

0 comments on commit b9c7a24

Please sign in to comment.