From 130a538509e7f4bb2f91ca474a84e4b14449e178 Mon Sep 17 00:00:00 2001 From: fram3d Date: Tue, 2 Jul 2024 23:32:18 +0200 Subject: [PATCH] add spawning --- src/NPCs/big_ooze.tscn | 55 +++++++++++++++++++ src/NPCs/bigooze.gd | 32 +++++++++++ src/NPCs/femalegoblin.gd | 41 ++++++++++++++ src/NPCs/femalegoblin.tscn | 66 +++++++++++++++++++++++ src/NPCs/goblin.gd | 31 ----------- src/NPCs/malegoblin.gd | 18 +++++++ src/NPCs/{goblin.tscn => malegoblin.tscn} | 24 ++++++--- src/NPCs/moss.gd | 15 +----- src/NPCs/ooze.gd | 33 +++++++----- src/NPCs/ooze.tscn | 7 +-- src/NPCs/smallooze.gd | 31 +++++++++++ src/NPCs/smallooze.tscn | 57 ++++++++++++++++++++ src/World.tscn | 34 +++++++----- src/spaw.gd | 24 +++++++++ 14 files changed, 387 insertions(+), 81 deletions(-) create mode 100644 src/NPCs/big_ooze.tscn create mode 100644 src/NPCs/bigooze.gd create mode 100644 src/NPCs/femalegoblin.gd create mode 100644 src/NPCs/femalegoblin.tscn delete mode 100644 src/NPCs/goblin.gd create mode 100644 src/NPCs/malegoblin.gd rename src/NPCs/{goblin.tscn => malegoblin.tscn} (71%) create mode 100644 src/NPCs/smallooze.gd create mode 100644 src/NPCs/smallooze.tscn create mode 100644 src/spaw.gd diff --git a/src/NPCs/big_ooze.tscn b/src/NPCs/big_ooze.tscn new file mode 100644 index 0000000..8291ee1 --- /dev/null +++ b/src/NPCs/big_ooze.tscn @@ -0,0 +1,55 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://NPCs/ooze.png" type="Texture" id=1] +[ext_resource path="res://NPCs/bigooze.gd" type="Script" id=2] +[ext_resource path="res://Audio/Hits/goblinattack.ogg" type="AudioStream" id=3] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 5.89857, 6.21018 ) + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 5.81983, 5.97394 ) + +[sub_resource type="RectangleShape2D" id=3] +extents = Vector2( 5.66234, 5.58022 ) + +[node name="big_ooze" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="ooze" type="Sprite" parent="."] +position = Vector2( 0.0170081, -0.0936285 ) +scale = Vector2( 1.41341, 1.42326 ) +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=[ +"ooze", +]] +shape = SubResource( 1 ) + +[node name="Hitbox" type="Area2D" parent="." groups=[ +"ooze", +]] +collision_layer = 8 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" groups=[ +"ooze", +]] +shape = SubResource( 2 ) + +[node name="Hurtbox" type="Area2D" parent="." groups=[ +"ooze", +]] +collision_layer = 16 +collision_mask = 32 + +[node name="death" type="AudioStreamPlayer" parent="Hurtbox"] +stream = ExtResource( 3 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox" groups=[ +"ooze", +]] +shape = SubResource( 3 ) +[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/NPCs/bigooze.gd b/src/NPCs/bigooze.gd new file mode 100644 index 0000000..8eef194 --- /dev/null +++ b/src/NPCs/bigooze.gd @@ -0,0 +1,32 @@ +extends KinematicBody2D + +const MOVEMENT_VECTORS = [ + Vector2.UP, + Vector2.RIGHT, + Vector2.DOWN, + Vector2.LEFT +] + +func _physics_process(_delta): + var movement = MOVEMENT_VECTORS[randi() % 4] + move_and_collide(movement * 2) + +func _on_Hurtbox_area_entered(_area): + $Hurtbox/death.play() + +func _on_death_finished(): + var ooze = load("res://NPCs/ooze.tscn") + var instance1 = ooze.instance() + var instance2 = ooze.instance() + instance1.position = position + instance2.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) diff --git a/src/NPCs/femalegoblin.gd b/src/NPCs/femalegoblin.gd new file mode 100644 index 0000000..2e6410d --- /dev/null +++ b/src/NPCs/femalegoblin.gd @@ -0,0 +1,41 @@ +extends KinematicBody2D + +onready var pregnancy = 0 + +const MOVEMENT_VECTORS = [ + Vector2.UP, + Vector2.RIGHT, + Vector2.DOWN, + Vector2.LEFT +] + +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) + if pregnancy > 0: + pregnancy = pregnancy - 1 + var movement = MOVEMENT_VECTORS[randi() % 4] + move_and_collide(movement * 2) + +func _on_Hurtbox_area_entered(_area): + $Hurtbox/death.play() + +func _on_death_finished(): + queue_free() + +func _on_Romance_area_entered(area): + if area.is_in_group("malegoblin") and pregnancy == 0: + pregnancy = 100 diff --git a/src/NPCs/femalegoblin.tscn b/src/NPCs/femalegoblin.tscn new file mode 100644 index 0000000..9953698 --- /dev/null +++ b/src/NPCs/femalegoblin.tscn @@ -0,0 +1,66 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://NPCs/goblin.png" type="Texture" id=1] +[ext_resource path="res://Audio/Hits/goblininjured.ogg" type="AudioStream" id=2] +[ext_resource path="res://NPCs/femalegoblin.gd" type="Script" id=3] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 3.90875, 3.7602 ) + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 4.13172, 3.98318 ) + +[sub_resource type="RectangleShape2D" id=3] +extents = Vector2( 4.0574, 3.7602 ) + +[sub_resource type="RectangleShape2D" id=4] +extents = Vector2( 4.875, 4.94941 ) + +[node name="femalegoblin" type="KinematicBody2D"] +script = ExtResource( 3 ) + +[node name="goblin" type="Sprite" parent="."] +position = Vector2( 0.380203, -0.127379 ) +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=[ +"goblin", +]] +shape = SubResource( 1 ) + +[node name="Hitbox" type="Area2D" parent="." groups=[ +"goblin", +]] +collision_layer = 32 +collision_mask = 16 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" groups=[ +"goblin", +]] +shape = SubResource( 2 ) + +[node name="Hurtbox" type="Area2D" parent="." groups=[ +"goblin", +]] +collision_layer = 64 +collision_mask = 2 + +[node name="death" type="AudioStreamPlayer" parent="Hurtbox"] +stream = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox" groups=[ +"goblin", +]] +shape = SubResource( 3 ) + +[node name="Romance" type="Area2D" parent="." groups=[ +"femalegoblin", +]] +collision_layer = 128 +collision_mask = 128 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Romance"] +shape = SubResource( 4 ) +[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="area_entered" from="Romance" to="." method="_on_Romance_area_entered"] diff --git a/src/NPCs/goblin.gd b/src/NPCs/goblin.gd deleted file mode 100644 index 66f04bf..0000000 --- a/src/NPCs/goblin.gd +++ /dev/null @@ -1,31 +0,0 @@ -extends KinematicBody2D - - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - -const MOVEMENT_VECTORS = [ - Vector2.UP, - Vector2.RIGHT, - Vector2.DOWN, - Vector2.LEFT -] - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _physics_process(_delta): - var movement = MOVEMENT_VECTORS[randi() % 4] - move_and_collide(movement * 2) - pass - -func _on_Hurtbox_area_entered(_area): - $Hurtbox/death.play() - pass # Replace with function body. - -func _on_death_finished(): - queue_free() - pass # Replace with function body. diff --git a/src/NPCs/malegoblin.gd b/src/NPCs/malegoblin.gd new file mode 100644 index 0000000..4f749bf --- /dev/null +++ b/src/NPCs/malegoblin.gd @@ -0,0 +1,18 @@ +extends KinematicBody2D + +const MOVEMENT_VECTORS = [ + Vector2.UP, + Vector2.RIGHT, + Vector2.DOWN, + Vector2.LEFT +] + +func _physics_process(_delta): + var movement = MOVEMENT_VECTORS[randi() % 4] + move_and_collide(movement * 2) + +func _on_Hurtbox_area_entered(_area): + $Hurtbox/death.play() + +func _on_death_finished(): + queue_free() diff --git a/src/NPCs/goblin.tscn b/src/NPCs/malegoblin.tscn similarity index 71% rename from src/NPCs/goblin.tscn rename to src/NPCs/malegoblin.tscn index 2983020..da2a4a0 100644 --- a/src/NPCs/goblin.tscn +++ b/src/NPCs/malegoblin.tscn @@ -1,8 +1,8 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://NPCs/goblin.png" type="Texture" id=1] -[ext_resource path="res://NPCs/goblin.gd" type="Script" id=2] -[ext_resource path="res://Audio/Hits/goblininjured.ogg" type="AudioStream" id=3] +[ext_resource path="res://Audio/Hits/goblininjured.ogg" type="AudioStream" id=2] +[ext_resource path="res://NPCs/malegoblin.gd" type="Script" id=3] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 3.90875, 3.7602 ) @@ -13,8 +13,11 @@ extents = Vector2( 4.13172, 3.98318 ) [sub_resource type="RectangleShape2D" id=3] extents = Vector2( 4.0574, 3.7602 ) -[node name="goblin" type="KinematicBody2D"] -script = ExtResource( 2 ) +[sub_resource type="RectangleShape2D" id=4] +extents = Vector2( 4.875, 4.94941 ) + +[node name="malegoblin" type="KinematicBody2D"] +script = ExtResource( 3 ) [node name="goblin" type="Sprite" parent="."] position = Vector2( 0.380203, -0.127379 ) @@ -43,11 +46,20 @@ collision_layer = 64 collision_mask = 2 [node name="death" type="AudioStreamPlayer" parent="Hurtbox"] -stream = ExtResource( 3 ) +stream = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox" groups=[ "goblin", ]] shape = SubResource( 3 ) + +[node name="Romance" type="Area2D" parent="." groups=[ +"malegoblin", +]] +collision_layer = 128 +collision_mask = 128 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Romance"] +shape = SubResource( 4 ) [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/NPCs/moss.gd b/src/NPCs/moss.gd index 34feab0..6c23417 100644 --- a/src/NPCs/moss.gd +++ b/src/NPCs/moss.gd @@ -1,20 +1,7 @@ extends Area2D - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - func _on_Hurtbox_area_entered(_area): - #if area.is_in_group("ooze"): $Hurtbox/death.play() - pass # Replace with function body. - + func _on_death_finished(): queue_free() - pass # Replace with function body. diff --git a/src/NPCs/ooze.gd b/src/NPCs/ooze.gd index 66f04bf..3d3a6e0 100644 --- a/src/NPCs/ooze.gd +++ b/src/NPCs/ooze.gd @@ -1,9 +1,6 @@ extends KinematicBody2D - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" +onready var immunity = 500 const MOVEMENT_VECTORS = [ Vector2.UP, @@ -12,20 +9,30 @@ const MOVEMENT_VECTORS = [ Vector2.LEFT ] -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -# Called every frame. 'delta' is the elapsed time since the previous frame. func _physics_process(_delta): + if immunity > 0: + immunity = immunity - 1 var movement = MOVEMENT_VECTORS[randi() % 4] move_and_collide(movement * 2) - pass func _on_Hurtbox_area_entered(_area): - $Hurtbox/death.play() - pass # Replace with function body. + if immunity == 0: + $Hurtbox/death.play() func _on_death_finished(): + var smallooze = load("res://NPCs/smallooze.tscn") + var instance1 = smallooze.instance() + var instance2 = smallooze.instance() + instance1.position = position + instance2.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 bigooze = load("res://NPCs/big_ooze.tscn") + var instance = bigooze.instance() + instance.position = position + get_parent().add_child(instance) queue_free() - pass # Replace with function body. diff --git a/src/NPCs/ooze.tscn b/src/NPCs/ooze.tscn index 66a3bd8..2e169a0 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.57893, 3.98952 ) +extents = Vector2( 4.7174, 4.63528 ) [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 4.69029, 4.54633 ) +extents = Vector2( 4.79614, 4.55653 ) [sub_resource type="RectangleShape2D" id=3] -extents = Vector2( 4.69029, 4.43497 ) +extents = Vector2( 4.7174, 4.55653 ) [node name="ooze" type="KinematicBody2D"] script = ExtResource( 2 ) @@ -49,5 +49,6 @@ stream = ExtResource( 3 ) "ooze", ]] shape = SubResource( 3 ) +[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/NPCs/smallooze.gd b/src/NPCs/smallooze.gd new file mode 100644 index 0000000..73672be --- /dev/null +++ b/src/NPCs/smallooze.gd @@ -0,0 +1,31 @@ +extends KinematicBody2D + +onready var immunity = 5 + +const MOVEMENT_VECTORS = [ + Vector2.UP, + Vector2.RIGHT, + Vector2.DOWN, + Vector2.LEFT +] + +func _physics_process(_delta): + if immunity > 0: + immunity = immunity - 1 + var movement = MOVEMENT_VECTORS[randi() % 4] + move_and_collide(movement * 2) + +func _on_Hurtbox_area_entered(_area): + if immunity == 0: + $Hurtbox/death.play() + +func _on_death_finished(): + 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) + queue_free() diff --git a/src/NPCs/smallooze.tscn b/src/NPCs/smallooze.tscn new file mode 100644 index 0000000..ce6d026 --- /dev/null +++ b/src/NPCs/smallooze.tscn @@ -0,0 +1,57 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://NPCs/ooze.png" type="Texture" id=1] +[ext_resource path="res://NPCs/smallooze.gd" type="Script" id=2] +[ext_resource path="res://Audio/Hits/goblinattack.ogg" type="AudioStream" id=3] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 2.51253, 2.43041 ) + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 2.59128, 2.50916 ) + +[sub_resource type="RectangleShape2D" id=3] +extents = Vector2( 2.51253, 2.35167 ) + +[node name="small_ooze" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="ooze" type="Sprite" parent="."] +position = Vector2( 0.135125, 0.142608 ) +scale = Vector2( 0.635804, 0.65549 ) +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=[ +"ooze", +]] +shape = SubResource( 1 ) + +[node name="Hitbox" type="Area2D" parent="." groups=[ +"ooze", +]] +collision_layer = 8 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" groups=[ +"ooze", +]] +shape = SubResource( 2 ) + +[node name="Hurtbox" type="Area2D" parent="." groups=[ +"ooze", +]] +collision_layer = 16 +collision_mask = 32 + +[node name="death" type="AudioStreamPlayer" parent="Hurtbox"] +stream = ExtResource( 3 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox" groups=[ +"ooze", +]] +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 8ac92b3..d73f280 100644 --- a/src/World.tscn +++ b/src/World.tscn @@ -1,13 +1,15 @@ -[gd_scene load_steps=16 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://Tilesets/stone.png" type="Texture" id=1] [ext_resource path="res://Tilesets/dirt.png" type="Texture" id=2] [ext_resource path="res://Tilesets/water.png" type="Texture" id=3] -[ext_resource path="res://NPCs/goblin.tscn" type="PackedScene" id=4] -[ext_resource path="res://NPCs/ooze.tscn" type="PackedScene" id=5] +[ext_resource path="res://NPCs/malegoblin.tscn" type="PackedScene" id=4] +[ext_resource path="res://NPCs/femalegoblin.tscn" type="PackedScene" id=5] [ext_resource path="res://NPCs/moss.tscn" type="PackedScene" id=6] [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] [sub_resource type="ConvexPolygonShape2D" id=1] points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) @@ -157,20 +159,24 @@ position = Vector2( -4, 4 ) stream = ExtResource( 7 ) autoplay = true -[node name="goblin" parent="." instance=ExtResource( 4 )] -position = Vector2( 28, 52 ) - [node name="moss" parent="." instance=ExtResource( 6 )] position = Vector2( 44, 44 ) -[node name="ooze" parent="." instance=ExtResource( 5 )] -position = Vector2( 28, 28 ) - -[node name="goblin2" parent="." instance=ExtResource( 4 )] -position = Vector2( 36, 36 ) - [node name="moss2" parent="." instance=ExtResource( 6 )] position = Vector2( 36, 20 ) -[node name="ooze2" parent="." instance=ExtResource( 5 )] -position = Vector2( 36, 52 ) +[node name="ooze" parent="." instance=ExtResource( 9 )] +position = Vector2( 36, 44 ) + +[node name="malegoblin" parent="." instance=ExtResource( 4 )] +position = Vector2( 12, 52 ) + +[node name="femalegoblin" parent="." instance=ExtResource( 5 )] +position = Vector2( 28, 52 ) + +[node name="Timer" type="Timer" parent="."] +process_mode = 0 +wait_time = 10.0 +autostart = true +script = ExtResource( 10 ) +[connection signal="timeout" from="Timer" to="Timer" method="_on_Timer_timeout"] diff --git a/src/spaw.gd b/src/spaw.gd new file mode 100644 index 0000000..5b7d72a --- /dev/null +++ b/src/spaw.gd @@ -0,0 +1,24 @@ +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)