From 1c98e550c537732276e8626c27e7180a81e11911 Mon Sep 17 00:00:00 2001 From: fram3d Date: Wed, 3 Jul 2024 02:56:08 +0200 Subject: [PATCH] fix spawning --- src/NPCs/big_ooze.tscn | 6 +-- src/NPCs/bigooze.gd | 25 ++++++++--- src/NPCs/femalegoblin.gd | 30 ++++++++------ src/NPCs/ooze.gd | 13 +++++- src/NPCs/ooze.tscn | 6 +-- src/NPCs/smallooze.gd | 1 + src/World.tscn | 90 ++++++++++++++++++++++++++++++++++++++-- src/spaw.gd | 24 ----------- src/spawn.gd | 24 +++++++++++ 9 files changed, 166 insertions(+), 53 deletions(-) delete mode 100644 src/spaw.gd create mode 100644 src/spawn.gd diff --git a/src/NPCs/big_ooze.tscn b/src/NPCs/big_ooze.tscn index 8291ee1..bf97340 100644 --- a/src/NPCs/big_ooze.tscn +++ b/src/NPCs/big_ooze.tscn @@ -5,13 +5,13 @@ [ext_resource path="res://Audio/Hits/goblinattack.ogg" type="AudioStream" id=3] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 5.89857, 6.21018 ) +extents = Vector2( 6, 6 ) [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 5.81983, 5.97394 ) +extents = Vector2( 6, 6 ) [sub_resource type="RectangleShape2D" id=3] -extents = Vector2( 5.66234, 5.58022 ) +extents = Vector2( 6, 6 ) [node name="big_ooze" type="KinematicBody2D"] script = ExtResource( 2 ) diff --git a/src/NPCs/bigooze.gd b/src/NPCs/bigooze.gd index 8eef194..9c27131 100644 --- a/src/NPCs/bigooze.gd +++ b/src/NPCs/bigooze.gd @@ -19,14 +19,27 @@ func _on_death_finished(): var instance1 = ooze.instance() var instance2 = ooze.instance() instance1.position = position - instance2.position = position + instance2.position = find_free_position(position) get_parent().add_child(instance1) get_parent().add_child(instance2) queue_free() func _on_Hitbox_area_entered(_area): - yield(get_tree().create_timer(2.0),"timeout") - var ooze = load("res://NPCs/ooze.tscn") - var instance = ooze.instance() - instance.position = position - get_parent().add_child(instance) + # NERF OOZE + #yield(get_tree().create_timer(2.0),"timeout") + #var ooze = load("res://NPCs/ooze.tscn") + #var instance = ooze.instance() + #instance.position = position + #get_parent().add_child(instance) + 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): + while tilesmap.get_cellv(tilesmap.world_to_map(pos)) != 0: + direction = (direction + 1) % 4 + pos = start + MOVEMENT_VECTORS[direction]*11 + return pos diff --git a/src/NPCs/femalegoblin.gd b/src/NPCs/femalegoblin.gd index 2e6410d..67dd63e 100644 --- a/src/NPCs/femalegoblin.gd +++ b/src/NPCs/femalegoblin.gd @@ -13,18 +13,13 @@ func _physics_process(_delta): if pregnancy == 20: var female = load("res://NPCs/femalegoblin.tscn") var male = load("res://NPCs/malegoblin.tscn") - var femalechild1 = female.instance() - var femalechild2 = female.instance() - var malechild1 = male.instance() - var malechild2 = male.instance() - femalechild1.position = position - femalechild2.position = position - malechild1.position = position - malechild2.position = position - get_parent().add_child(femalechild1) - get_parent().add_child(femalechild2) - get_parent().add_child(malechild1) - get_parent().add_child(malechild2) + 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) if pregnancy > 0: pregnancy = pregnancy - 1 var movement = MOVEMENT_VECTORS[randi() % 4] @@ -39,3 +34,14 @@ func _on_death_finished(): func _on_Romance_area_entered(area): if area.is_in_group("malegoblin") and pregnancy == 0: pregnancy = 100 + +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): + while tilesmap.get_cellv(tilesmap.world_to_map(pos)) != 0: + direction = (direction + 1) % 4 + pos = start + MOVEMENT_VECTORS[direction]*11 + return pos diff --git a/src/NPCs/ooze.gd b/src/NPCs/ooze.gd index 3d3a6e0..79dbfcf 100644 --- a/src/NPCs/ooze.gd +++ b/src/NPCs/ooze.gd @@ -24,7 +24,7 @@ func _on_death_finished(): var instance1 = smallooze.instance() var instance2 = smallooze.instance() instance1.position = position - instance2.position = position + instance2.position = find_free_position(position) get_parent().add_child(instance1) get_parent().add_child(instance2) queue_free() @@ -36,3 +36,14 @@ func _on_Hitbox_area_entered(_area): instance.position = position get_parent().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): + while tilesmap.get_cellv(tilesmap.world_to_map(pos)) != 0: + direction = (direction + 1) % 4 + pos = start + MOVEMENT_VECTORS[direction]*11 + return pos diff --git a/src/NPCs/ooze.tscn b/src/NPCs/ooze.tscn index 2e169a0..de63871 100644 --- a/src/NPCs/ooze.tscn +++ b/src/NPCs/ooze.tscn @@ -5,13 +5,13 @@ [ext_resource path="res://Audio/Hits/goblinattack.ogg" type="AudioStream" id=3] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 4.7174, 4.63528 ) +extents = Vector2( 5, 5 ) [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 4.79614, 4.55653 ) +extents = Vector2( 5, 5 ) [sub_resource type="RectangleShape2D" id=3] -extents = Vector2( 4.7174, 4.55653 ) +extents = Vector2( 5, 5 ) [node name="ooze" type="KinematicBody2D"] script = ExtResource( 2 ) diff --git a/src/NPCs/smallooze.gd b/src/NPCs/smallooze.gd index 73672be..55040ec 100644 --- a/src/NPCs/smallooze.gd +++ b/src/NPCs/smallooze.gd @@ -29,3 +29,4 @@ func _on_Hitbox_area_entered(_area): instance.position = position get_parent().add_child(instance) queue_free() + diff --git a/src/World.tscn b/src/World.tscn index d73f280..6d2f637 100644 --- a/src/World.tscn +++ b/src/World.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=2] +[gd_scene load_steps=27 format=2] [ext_resource path="res://Tilesets/stone.png" type="Texture" id=1] [ext_resource path="res://Tilesets/dirt.png" type="Texture" id=2] @@ -9,7 +9,7 @@ [ext_resource path="res://Audio/Background/cave.ogg" type="AudioStream" id=7] [ext_resource path="res://camera.gd" type="Script" id=8] [ext_resource path="res://NPCs/big_ooze.tscn" type="PackedScene" id=9] -[ext_resource path="res://spaw.gd" type="Script" id=10] +[ext_resource path="res://spawn.gd" type="Script" id=10] [sub_resource type="ConvexPolygonShape2D" id=1] points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) @@ -29,6 +29,33 @@ 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=8] +points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) + +[sub_resource type="ConvexPolygonShape2D" id=9] +points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) + +[sub_resource type="ConvexPolygonShape2D" id=10] +points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) + +[sub_resource type="ConvexPolygonShape2D" id=11] +points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) + +[sub_resource type="ConvexPolygonShape2D" id=12] +points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) + +[sub_resource type="ConvexPolygonShape2D" id=13] +points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) + +[sub_resource type="ConvexPolygonShape2D" id=14] +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] 0/name = "dirt.png 0" 0/texture = ExtResource( 2 ) @@ -132,9 +159,64 @@ 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_one_way = false -2/shape_one_way_margin = 0.0 -2/shapes = [ ] +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_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_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_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_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_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_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_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_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_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) +} ] 2/z_index = 0 [node name="World" type="Node2D"] diff --git a/src/spaw.gd b/src/spaw.gd deleted file mode 100644 index 5b7d72a..0000000 --- a/src/spaw.gd +++ /dev/null @@ -1,24 +0,0 @@ -extends Timer - -#onready var mapwidth = get("display/window/size/width") -#onready var mapheight = get("display/window/size/height") - -onready var mapwidth = 80 -onready var mapheight = 64 - -func _on_Timer_timeout(): - var width = randi() % mapwidth - var height = randi() % mapheight - - var random = randi() % 100 - - var scene = load("res://NPCs/moss.tscn") - if random in range(0, 10): - scene = load("res://NPCs/femalegoblin.tscn") - if random in range(10, 20): - scene = load("res://NPCs/malegoblin.tscn") - if random in range(20, 40): - scene = load("res://NPCs/ooze.tscn") - var instance = scene.instance() - instance.position = Vector2(width, height) - get_parent().add_child(instance) diff --git a/src/spawn.gd b/src/spawn.gd new file mode 100644 index 0000000..c7e0fd1 --- /dev/null +++ b/src/spawn.gd @@ -0,0 +1,24 @@ +extends Timer + +onready var tilesmap = $"../TileMap" +onready var tiles = 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() ] + + 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)