From 94e51d300964adb966950913a661c5b992114203 Mon Sep 17 00:00:00 2001 From: fram3d Date: Wed, 3 Jul 2024 14:41:24 +0200 Subject: [PATCH] fix spawning --- src/NPCs/bigooze.gd | 12 ++++++++---- src/NPCs/femalegoblin.gd | 29 ++++++++++++++++++++--------- src/NPCs/malegoblin.gd | 14 ++++++++++++++ src/NPCs/ooze.gd | 15 +++++++++------ src/NPCs/smallooze.gd | 9 +++++++-- src/NPCs/smallooze.tscn | 1 - src/World.tscn | 2 +- src/spawn.gd | 17 ++++++++++------- 8 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/NPCs/bigooze.gd b/src/NPCs/bigooze.gd index 9c27131..dca1fbe 100644 --- a/src/NPCs/bigooze.gd +++ b/src/NPCs/bigooze.gd @@ -1,5 +1,8 @@ extends KinematicBody2D +onready var rootnode = get_node("/root/World") +onready var tilesmap = $"/root/World/tilemap" + const MOVEMENT_VECTORS = [ Vector2.UP, Vector2.RIGHT, @@ -8,6 +11,9 @@ const MOVEMENT_VECTORS = [ ] func _physics_process(_delta): + if position != null: + if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0: + queue_free() var movement = MOVEMENT_VECTORS[randi() % 4] move_and_collide(movement * 2) @@ -20,8 +26,8 @@ func _on_death_finished(): var instance2 = ooze.instance() instance1.position = position instance2.position = find_free_position(position) - get_parent().add_child(instance1) - get_parent().add_child(instance2) + rootnode.add_child(instance1) + rootnode.add_child(instance2) queue_free() func _on_Hitbox_area_entered(_area): @@ -34,8 +40,6 @@ func _on_Hitbox_area_entered(_area): pass func find_free_position(start, skip = 0): - var tilesmap = $"../TileMap" - var direction = randi() % 4 var pos = start + MOVEMENT_VECTORS[direction]*11 for _i in range(0, skip + 1): diff --git a/src/NPCs/femalegoblin.gd b/src/NPCs/femalegoblin.gd index 67dd63e..f81f665 100644 --- a/src/NPCs/femalegoblin.gd +++ b/src/NPCs/femalegoblin.gd @@ -1,6 +1,10 @@ extends KinematicBody2D onready var pregnancy = 0 +onready var age = 0 + +onready var tilesmap = $"/root/World/tilemap" +onready var rootnode = get_node("/root/World") const MOVEMENT_VECTORS = [ Vector2.UP, @@ -10,18 +14,27 @@ const MOVEMENT_VECTORS = [ ] func _physics_process(_delta): - if pregnancy == 20: + if position != null: + if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0: + queue_free() + + if age > 5000: + queue_free() + else: + age = age + 1 + + if pregnancy == 100: + pregnancy = 0 var female = load("res://NPCs/femalegoblin.tscn") var male = load("res://NPCs/malegoblin.tscn") var femalechild = female.instance() var malechild = male.instance() femalechild.position = find_free_position(position) - femalechild.pregnancy = 200 malechild.position = find_free_position(position, 1) - get_parent().add_child(femalechild) - get_parent().add_child(malechild) + rootnode.add_child(femalechild) + rootnode.add_child(malechild) if pregnancy > 0: - pregnancy = pregnancy - 1 + pregnancy = pregnancy + 1 var movement = MOVEMENT_VECTORS[randi() % 4] move_and_collide(movement * 2) @@ -32,12 +45,10 @@ func _on_death_finished(): queue_free() func _on_Romance_area_entered(area): - if area.is_in_group("malegoblin") and pregnancy == 0: - pregnancy = 100 + if area.is_in_group("malegoblin") and pregnancy == 0 and age > 2500: + pregnancy = 1 func find_free_position(start, skip = 0): - var tilesmap = $"../TileMap" - var direction = randi() % 4 var pos = start + MOVEMENT_VECTORS[direction]*11 for _i in range(0, skip): diff --git a/src/NPCs/malegoblin.gd b/src/NPCs/malegoblin.gd index 4f749bf..dedfbea 100644 --- a/src/NPCs/malegoblin.gd +++ b/src/NPCs/malegoblin.gd @@ -1,5 +1,9 @@ extends KinematicBody2D +onready var age = 0 + +onready var tilesmap = $"/root/World/tilemap" + const MOVEMENT_VECTORS = [ Vector2.UP, Vector2.RIGHT, @@ -8,6 +12,16 @@ const MOVEMENT_VECTORS = [ ] func _physics_process(_delta): + if position != null: + if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0: + queue_free() + if age > 2500: + $"Romance".add_to_group("malegoblin") + if age > 5000: + queue_free() + else: + age = age + 1 + var movement = MOVEMENT_VECTORS[randi() % 4] move_and_collide(movement * 2) diff --git a/src/NPCs/ooze.gd b/src/NPCs/ooze.gd index 79dbfcf..9d37cb9 100644 --- a/src/NPCs/ooze.gd +++ b/src/NPCs/ooze.gd @@ -1,6 +1,8 @@ extends KinematicBody2D -onready var immunity = 500 +onready var immunity = 50 +onready var tilesmap = $"/root/World/tilemap" +onready var rootnode = get_node("/root/World") const MOVEMENT_VECTORS = [ Vector2.UP, @@ -10,6 +12,9 @@ const MOVEMENT_VECTORS = [ ] func _physics_process(_delta): + if position != null: + if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0: + queue_free() if immunity > 0: immunity = immunity - 1 var movement = MOVEMENT_VECTORS[randi() % 4] @@ -25,8 +30,8 @@ func _on_death_finished(): var instance2 = smallooze.instance() instance1.position = position instance2.position = find_free_position(position) - get_parent().add_child(instance1) - get_parent().add_child(instance2) + rootnode.add_child(instance1) + rootnode.add_child(instance2) queue_free() func _on_Hitbox_area_entered(_area): @@ -34,12 +39,10 @@ func _on_Hitbox_area_entered(_area): var bigooze = load("res://NPCs/big_ooze.tscn") var instance = bigooze.instance() instance.position = position - get_parent().add_child(instance) + rootnode.add_child(instance) queue_free() func find_free_position(start, skip = 0): - var tilesmap = $"../TileMap" - var direction = randi() % 4 var pos = start + MOVEMENT_VECTORS[direction]*11 for _i in range(0, skip): diff --git a/src/NPCs/smallooze.gd b/src/NPCs/smallooze.gd index 55040ec..6a340ab 100644 --- a/src/NPCs/smallooze.gd +++ b/src/NPCs/smallooze.gd @@ -1,6 +1,8 @@ extends KinematicBody2D -onready var immunity = 5 +onready var immunity = 50 +onready var tilesmap = $"/root/World/tilemap" +onready var rootnode = get_node("/root/World") const MOVEMENT_VECTORS = [ Vector2.UP, @@ -10,6 +12,9 @@ const MOVEMENT_VECTORS = [ ] func _physics_process(_delta): + if position != null: + if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0: + queue_free() if immunity > 0: immunity = immunity - 1 var movement = MOVEMENT_VECTORS[randi() % 4] @@ -27,6 +32,6 @@ func _on_Hitbox_area_entered(_area): var ooze = load("res://NPCs/ooze.tscn") var instance = ooze.instance() instance.position = position - get_parent().add_child(instance) + rootnode.add_child(instance) queue_free() diff --git a/src/NPCs/smallooze.tscn b/src/NPCs/smallooze.tscn index ce6d026..64b4d93 100644 --- a/src/NPCs/smallooze.tscn +++ b/src/NPCs/smallooze.tscn @@ -51,7 +51,6 @@ stream = ExtResource( 3 ) ]] position = Vector2( -0.0787458, 0.0787449 ) shape = SubResource( 3 ) -script = ExtResource( 2 ) [connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"] [connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"] [connection signal="finished" from="Hurtbox/death" to="." method="_on_death_finished"] diff --git a/src/World.tscn b/src/World.tscn index ddd0f70..0332f0e 100644 --- a/src/World.tscn +++ b/src/World.tscn @@ -226,7 +226,7 @@ max_zoom = 8.0 [node name="Tween" type="Tween" parent="Camera2D"] -[node name="TileMap" type="TileMap" parent="."] +[node name="tilemap" type="TileMap" parent="."] tile_set = SubResource( 16 ) cell_size = Vector2( 8, 8 ) cell_quadrant_size = 8 diff --git a/src/spawn.gd b/src/spawn.gd index c9b93d0..f2cef91 100644 --- a/src/spawn.gd +++ b/src/spawn.gd @@ -1,6 +1,8 @@ extends Timer -onready var tilesmap = $"../TileMap" +onready var tilesmap = $"/root/World/tilemap" +onready var rootnode = get_node("/root/World") + onready var dirttiles = tilesmap.get_used_cells_by_id(0) onready var tilesize = tilesmap.tile_set.autotile_get_size(0) @@ -27,28 +29,29 @@ func _on_Timer_timeout(): var mossscene = load("res://NPCs/moss.tscn") var mossinstance = mossscene.instance() mossinstance.position = mossspawner * tilesize + (tilesize / 2) - get_parent().add_child(mossinstance) + rootnode.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) + rootnode.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) + rootnode.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) + rootnode.add_child(oozeinstance) func find_coast(): - var coast = [] + var coastline = [] for dirt in dirttiles: for direction in MOVEMENT_VECTORS: if dirt + direction in watertiles: - coast.append(dirt) + coastline.append(dirt) break - return coast + return coastline