make moss spawn next to water

This commit is contained in:
fram3d 2024-07-03 03:17:33 +02:00
parent 1c98e550c5
commit 61a33c05c0
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
2 changed files with 57 additions and 31 deletions

View File

@ -29,6 +29,9 @@ points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="ConvexPolygonShape2D" id=6]
points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="ConvexPolygonShape2D" id=7]
points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="ConvexPolygonShape2D" id=8]
points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
@ -53,10 +56,7 @@ points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="ConvexPolygonShape2D" id=15]
points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="ConvexPolygonShape2D" id=16]
points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="TileSet" id=7]
[sub_resource type="TileSet" id=16]
0/name = "dirt.png 0"
0/texture = ExtResource( 2 )
0/tex_offset = Vector2( 0, 0 )
@ -159,62 +159,62 @@ points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
2/navigation_offset = Vector2( 0, 0 )
2/shape_offset = Vector2( 0, 0 )
2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
2/shape = SubResource( 8 )
2/shape = SubResource( 7 )
2/shape_one_way = false
2/shape_one_way_margin = 1.0
2/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 8 ),
"shape": SubResource( 7 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 1, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 9 ),
"shape": SubResource( 8 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 2, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 10 ),
"shape": SubResource( 9 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 0, 1 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 11 ),
"shape": SubResource( 10 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 1, 1 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 12 ),
"shape": SubResource( 11 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 2, 1 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 13 ),
"shape": SubResource( 12 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 0, 2 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 14 ),
"shape": SubResource( 13 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 1, 2 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 15 ),
"shape": SubResource( 14 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 2, 2 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 16 ),
"shape": SubResource( 15 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
2/z_index = 0
@ -229,7 +229,7 @@ script = ExtResource( 8 )
[node name="Tween" type="Tween" parent="Camera2D"]
[node name="TileMap" type="TileMap" parent="."]
tile_set = SubResource( 7 )
tile_set = SubResource( 16 )
cell_size = Vector2( 8, 8 )
cell_quadrant_size = 8
cell_custom_transform = Transform2D( 8, 0, 0, 8, 0, 0 )

View File

@ -1,24 +1,50 @@
extends Timer
onready var tilesmap = $"../TileMap"
onready var tiles = tilesmap.get_used_cells_by_id(0)
onready var dirttiles = tilesmap.get_used_cells_by_id(0)
onready var tilesize = tilesmap.tile_set.autotile_get_size(0)
func _on_Timer_timeout():
var spawner = tiles[ randi() % tiles.size() ]
onready var watertiles = tilesmap.get_used_cells_by_id(2)
onready var coast = find_coast()
const MOVEMENT_VECTORS = [
Vector2.UP,
Vector2.RIGHT,
Vector2.DOWN,
Vector2.LEFT
]
func _on_Timer_timeout():
var spawner = dirttiles[ randi() % dirttiles.size() ]
var mossspawner = coast[ randi() % coast.size() ]
var random = randi() % 100
var scene = load("res://NPCs/moss.tscn")
if random in range(0, 20):
scene = load("res://NPCs/femalegoblin.tscn")
scene = load("res://NPCs/malegoblin.tscn")
var instance = scene.instance()
instance.position = spawner * tilesize + (tilesize / 2)
get_parent().add_child(instance)
if random in range(20,30):
scene = load("res://NPCs/ooze.tscn")
var instance = scene.instance()
instance.position = spawner * tilesize + (tilesize / 2)
get_parent().add_child(instance)
var mossscene = load("res://NPCs/moss.tscn")
var mossinstance = mossscene.instance()
mossinstance.position = mossspawner * tilesize + (tilesize / 2)
get_parent().add_child(mossinstance)
if random in range(0, 25):
var femalegoblinscene = load("res://NPCs/femalegoblin.tscn")
var femalegoblininstance = femalegoblinscene.instance()
femalegoblininstance.position = spawner * tilesize + (tilesize / 2)
get_parent().add_child(femalegoblininstance)
if random in range(25, 50):
var malegoblinscene = load("res://NPCs/malegoblin.tscn")
var malegoblininstance = malegoblinscene.instance()
malegoblininstance.position = spawner * tilesize + (tilesize / 2)
get_parent().add_child(malegoblininstance)
if random in range(50,75):
var oozescene = load("res://NPCs/ooze.tscn")
var oozeinstance = oozescene.instance()
oozeinstance.position = spawner * tilesize + (tilesize / 2)
func find_coast():
var coast = []
for dirt in dirttiles:
for direction in MOVEMENT_VECTORS:
if dirt + direction in watertiles:
coast.append(dirt)
break
return coast