fix spawning

This commit is contained in:
fram3d 2024-07-03 14:41:24 +02:00
parent dbfff61052
commit 94e51d3009
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
8 changed files with 69 additions and 30 deletions

View File

@ -1,5 +1,8 @@
extends KinematicBody2D extends KinematicBody2D
onready var rootnode = get_node("/root/World")
onready var tilesmap = $"/root/World/tilemap"
const MOVEMENT_VECTORS = [ const MOVEMENT_VECTORS = [
Vector2.UP, Vector2.UP,
Vector2.RIGHT, Vector2.RIGHT,
@ -8,6 +11,9 @@ const MOVEMENT_VECTORS = [
] ]
func _physics_process(_delta): 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] var movement = MOVEMENT_VECTORS[randi() % 4]
move_and_collide(movement * 2) move_and_collide(movement * 2)
@ -20,8 +26,8 @@ func _on_death_finished():
var instance2 = ooze.instance() var instance2 = ooze.instance()
instance1.position = position instance1.position = position
instance2.position = find_free_position(position) instance2.position = find_free_position(position)
get_parent().add_child(instance1) rootnode.add_child(instance1)
get_parent().add_child(instance2) rootnode.add_child(instance2)
queue_free() queue_free()
func _on_Hitbox_area_entered(_area): func _on_Hitbox_area_entered(_area):
@ -34,8 +40,6 @@ func _on_Hitbox_area_entered(_area):
pass pass
func find_free_position(start, skip = 0): func find_free_position(start, skip = 0):
var tilesmap = $"../TileMap"
var direction = randi() % 4 var direction = randi() % 4
var pos = start + MOVEMENT_VECTORS[direction]*11 var pos = start + MOVEMENT_VECTORS[direction]*11
for _i in range(0, skip + 1): for _i in range(0, skip + 1):

View File

@ -1,6 +1,10 @@
extends KinematicBody2D extends KinematicBody2D
onready var pregnancy = 0 onready var pregnancy = 0
onready var age = 0
onready var tilesmap = $"/root/World/tilemap"
onready var rootnode = get_node("/root/World")
const MOVEMENT_VECTORS = [ const MOVEMENT_VECTORS = [
Vector2.UP, Vector2.UP,
@ -10,18 +14,27 @@ const MOVEMENT_VECTORS = [
] ]
func _physics_process(_delta): 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 female = load("res://NPCs/femalegoblin.tscn")
var male = load("res://NPCs/malegoblin.tscn") var male = load("res://NPCs/malegoblin.tscn")
var femalechild = female.instance() var femalechild = female.instance()
var malechild = male.instance() var malechild = male.instance()
femalechild.position = find_free_position(position) femalechild.position = find_free_position(position)
femalechild.pregnancy = 200
malechild.position = find_free_position(position, 1) malechild.position = find_free_position(position, 1)
get_parent().add_child(femalechild) rootnode.add_child(femalechild)
get_parent().add_child(malechild) rootnode.add_child(malechild)
if pregnancy > 0: if pregnancy > 0:
pregnancy = pregnancy - 1 pregnancy = pregnancy + 1
var movement = MOVEMENT_VECTORS[randi() % 4] var movement = MOVEMENT_VECTORS[randi() % 4]
move_and_collide(movement * 2) move_and_collide(movement * 2)
@ -32,12 +45,10 @@ func _on_death_finished():
queue_free() queue_free()
func _on_Romance_area_entered(area): func _on_Romance_area_entered(area):
if area.is_in_group("malegoblin") and pregnancy == 0: if area.is_in_group("malegoblin") and pregnancy == 0 and age > 2500:
pregnancy = 100 pregnancy = 1
func find_free_position(start, skip = 0): func find_free_position(start, skip = 0):
var tilesmap = $"../TileMap"
var direction = randi() % 4 var direction = randi() % 4
var pos = start + MOVEMENT_VECTORS[direction]*11 var pos = start + MOVEMENT_VECTORS[direction]*11
for _i in range(0, skip): for _i in range(0, skip):

View File

@ -1,5 +1,9 @@
extends KinematicBody2D extends KinematicBody2D
onready var age = 0
onready var tilesmap = $"/root/World/tilemap"
const MOVEMENT_VECTORS = [ const MOVEMENT_VECTORS = [
Vector2.UP, Vector2.UP,
Vector2.RIGHT, Vector2.RIGHT,
@ -8,6 +12,16 @@ const MOVEMENT_VECTORS = [
] ]
func _physics_process(_delta): 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] var movement = MOVEMENT_VECTORS[randi() % 4]
move_and_collide(movement * 2) move_and_collide(movement * 2)

View File

@ -1,6 +1,8 @@
extends KinematicBody2D 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 = [ const MOVEMENT_VECTORS = [
Vector2.UP, Vector2.UP,
@ -10,6 +12,9 @@ const MOVEMENT_VECTORS = [
] ]
func _physics_process(_delta): func _physics_process(_delta):
if position != null:
if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0:
queue_free()
if immunity > 0: if immunity > 0:
immunity = immunity - 1 immunity = immunity - 1
var movement = MOVEMENT_VECTORS[randi() % 4] var movement = MOVEMENT_VECTORS[randi() % 4]
@ -25,8 +30,8 @@ func _on_death_finished():
var instance2 = smallooze.instance() var instance2 = smallooze.instance()
instance1.position = position instance1.position = position
instance2.position = find_free_position(position) instance2.position = find_free_position(position)
get_parent().add_child(instance1) rootnode.add_child(instance1)
get_parent().add_child(instance2) rootnode.add_child(instance2)
queue_free() queue_free()
func _on_Hitbox_area_entered(_area): 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 bigooze = load("res://NPCs/big_ooze.tscn")
var instance = bigooze.instance() var instance = bigooze.instance()
instance.position = position instance.position = position
get_parent().add_child(instance) rootnode.add_child(instance)
queue_free() queue_free()
func find_free_position(start, skip = 0): func find_free_position(start, skip = 0):
var tilesmap = $"../TileMap"
var direction = randi() % 4 var direction = randi() % 4
var pos = start + MOVEMENT_VECTORS[direction]*11 var pos = start + MOVEMENT_VECTORS[direction]*11
for _i in range(0, skip): for _i in range(0, skip):

View File

@ -1,6 +1,8 @@
extends KinematicBody2D 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 = [ const MOVEMENT_VECTORS = [
Vector2.UP, Vector2.UP,
@ -10,6 +12,9 @@ const MOVEMENT_VECTORS = [
] ]
func _physics_process(_delta): func _physics_process(_delta):
if position != null:
if tilesmap.get_cellv(tilesmap.world_to_map(position)) != 0:
queue_free()
if immunity > 0: if immunity > 0:
immunity = immunity - 1 immunity = immunity - 1
var movement = MOVEMENT_VECTORS[randi() % 4] var movement = MOVEMENT_VECTORS[randi() % 4]
@ -27,6 +32,6 @@ func _on_Hitbox_area_entered(_area):
var ooze = load("res://NPCs/ooze.tscn") var ooze = load("res://NPCs/ooze.tscn")
var instance = ooze.instance() var instance = ooze.instance()
instance.position = position instance.position = position
get_parent().add_child(instance) rootnode.add_child(instance)
queue_free() queue_free()

View File

@ -51,7 +51,6 @@ stream = ExtResource( 3 )
]] ]]
position = Vector2( -0.0787458, 0.0787449 ) position = Vector2( -0.0787458, 0.0787449 )
shape = SubResource( 3 ) shape = SubResource( 3 )
script = ExtResource( 2 )
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"] [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="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
[connection signal="finished" from="Hurtbox/death" to="." method="_on_death_finished"] [connection signal="finished" from="Hurtbox/death" to="." method="_on_death_finished"]

View File

@ -226,7 +226,7 @@ max_zoom = 8.0
[node name="Tween" type="Tween" parent="Camera2D"] [node name="Tween" type="Tween" parent="Camera2D"]
[node name="TileMap" type="TileMap" parent="."] [node name="tilemap" type="TileMap" parent="."]
tile_set = SubResource( 16 ) tile_set = SubResource( 16 )
cell_size = Vector2( 8, 8 ) cell_size = Vector2( 8, 8 )
cell_quadrant_size = 8 cell_quadrant_size = 8

View File

@ -1,6 +1,8 @@
extends Timer 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 dirttiles = tilesmap.get_used_cells_by_id(0)
onready var tilesize = tilesmap.tile_set.autotile_get_size(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 mossscene = load("res://NPCs/moss.tscn")
var mossinstance = mossscene.instance() var mossinstance = mossscene.instance()
mossinstance.position = mossspawner * tilesize + (tilesize / 2) mossinstance.position = mossspawner * tilesize + (tilesize / 2)
get_parent().add_child(mossinstance) rootnode.add_child(mossinstance)
if random in range(0, 25): if random in range(0, 25):
var femalegoblinscene = load("res://NPCs/femalegoblin.tscn") var femalegoblinscene = load("res://NPCs/femalegoblin.tscn")
var femalegoblininstance = femalegoblinscene.instance() var femalegoblininstance = femalegoblinscene.instance()
femalegoblininstance.position = spawner * tilesize + (tilesize / 2) femalegoblininstance.position = spawner * tilesize + (tilesize / 2)
get_parent().add_child(femalegoblininstance) rootnode.add_child(femalegoblininstance)
if random in range(25, 50): if random in range(25, 50):
var malegoblinscene = load("res://NPCs/malegoblin.tscn") var malegoblinscene = load("res://NPCs/malegoblin.tscn")
var malegoblininstance = malegoblinscene.instance() var malegoblininstance = malegoblinscene.instance()
malegoblininstance.position = spawner * tilesize + (tilesize / 2) malegoblininstance.position = spawner * tilesize + (tilesize / 2)
get_parent().add_child(malegoblininstance) rootnode.add_child(malegoblininstance)
if random in range(50,75): if random in range(50,75):
var oozescene = load("res://NPCs/ooze.tscn") var oozescene = load("res://NPCs/ooze.tscn")
var oozeinstance = oozescene.instance() var oozeinstance = oozescene.instance()
oozeinstance.position = spawner * tilesize + (tilesize / 2) oozeinstance.position = spawner * tilesize + (tilesize / 2)
rootnode.add_child(oozeinstance)
func find_coast(): func find_coast():
var coast = [] var coastline = []
for dirt in dirttiles: for dirt in dirttiles:
for direction in MOVEMENT_VECTORS: for direction in MOVEMENT_VECTORS:
if dirt + direction in watertiles: if dirt + direction in watertiles:
coast.append(dirt) coastline.append(dirt)
break break
return coast return coastline