fix spawning

This commit is contained in:
fram3d 2024-07-03 02:56:08 +02:00
parent 130a538509
commit 1c98e550c5
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
9 changed files with 166 additions and 53 deletions

View File

@ -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 )

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 )

View File

@ -29,3 +29,4 @@ func _on_Hitbox_area_entered(_area):
instance.position = position
get_parent().add_child(instance)
queue_free()

View File

@ -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"]

View File

@ -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)

24
src/spawn.gd Normal file
View File

@ -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)