diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-05-01 09:41:02 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-05-01 09:41:02 +0200 |
commit | d192b1546ab39180cdc28d2621c117539e3d26d6 (patch) | |
tree | bfe040b5fa56aab1cf1161aab4883ba6ca3510df /Scenes/Entities | |
parent | 81cc6f1d22677dd4a60aa9377c91b291bf10e523 (diff) |
update
Diffstat (limited to 'Scenes/Entities')
-rw-r--r-- | Scenes/Entities/Enemies/Components/Collision.gd | 4 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Components/Health.gd | 4 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Flower.gd | 22 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Flower.tscn | 126 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Flowers.gd | 82 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Flowers.tscn | 29 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Tree.gd | 2 | ||||
-rw-r--r-- | Scenes/Entities/Objects/Sign.tscn | 2 |
8 files changed, 269 insertions, 2 deletions
diff --git a/Scenes/Entities/Enemies/Components/Collision.gd b/Scenes/Entities/Enemies/Components/Collision.gd index 2dfba2a..6e25402 100644 --- a/Scenes/Entities/Enemies/Components/Collision.gd +++ b/Scenes/Entities/Enemies/Components/Collision.gd @@ -14,9 +14,11 @@ signal collided @export_node_path("Component_Health") var component_health_path: NodePath var component_health: Component_Health +var collision_area: Area2D + func init(): - var collision_area = Utilities.Collision.Area.new(entity, collision_shape) + collision_area = Utilities.Collision.Area.new(entity, collision_shape) collision_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, true) collision_area.connect("collided", func(area): emit_signal("collided", area)) entity.add_child(collision_area) diff --git a/Scenes/Entities/Enemies/Components/Health.gd b/Scenes/Entities/Enemies/Components/Health.gd index f5e231e..d6b7361 100644 --- a/Scenes/Entities/Enemies/Components/Health.gd +++ b/Scenes/Entities/Enemies/Components/Health.gd @@ -3,6 +3,8 @@ extends Node class_name Component_Health +signal died + @export_node_path("CharacterBody2D") var entityPath: NodePath @onready var entity: CharacterBody2D = get_node(entityPath) @@ -20,6 +22,8 @@ func take_damage(): func death(): + emit_signal("died") + entity.set_physics_process(false) sprite.play("death") diff --git a/Scenes/Entities/Enemies/Flower.gd b/Scenes/Entities/Enemies/Flower.gd new file mode 100644 index 0000000..3e50e80 --- /dev/null +++ b/Scenes/Entities/Enemies/Flower.gd @@ -0,0 +1,22 @@ +extends CharacterBody2D + + +var angle: float = 0 + + +func _ready(): + $Body/Bottom.play("default") + + add_to_group("enemies") + $Collision.init() + $Collision.collision_area.set_collision_layer_value(Utilities.Collision.Layer.ENEMY, true) + $Health.died.connect(func(): + $Body.remove_child($Body/Top) + ) + + +func shrink(): + $Body/Top.play_backwards("default") + +func expand(): + $Body/Top.play("default") diff --git a/Scenes/Entities/Enemies/Flower.tscn b/Scenes/Entities/Enemies/Flower.tscn new file mode 100644 index 0000000..71f61e9 --- /dev/null +++ b/Scenes/Entities/Enemies/Flower.tscn @@ -0,0 +1,126 @@ +[gd_scene load_steps=22 format=3 uid="uid://dvxwc0lvwh0pi"] + +[ext_resource type="Script" path="res://Scenes/Entities/Enemies/Flower.gd" id="1_0uei7"] +[ext_resource type="Texture2D" uid="uid://db43umele3i0n" path="res://Assets/Enemies/Flower_death.png" id="2_j1q7v"] +[ext_resource type="Texture2D" uid="uid://cpl4n4jmgiwrv" path="res://Assets/Enemies/Enemy_death_01_01.png" id="3_wopor"] +[ext_resource type="Texture2D" uid="uid://d2gk5amafhctu" path="res://Assets/Enemies/Enemy_death_01_02.png" id="4_i6ewr"] +[ext_resource type="Texture2D" uid="uid://dqwxq3g3aph4i" path="res://Assets/Enemies/Enemy_death_01_03.png" id="5_3shgr"] +[ext_resource type="Texture2D" uid="uid://uoj5222vlq8q" path="res://Assets/Enemies/Enemy_death_01_04.png" id="6_pw71b"] +[ext_resource type="Texture2D" uid="uid://cxx2vv1ohiw07" path="res://Assets/Enemies/Enemy_death_01_05.png" id="7_wypb7"] +[ext_resource type="Texture2D" uid="uid://bgyp0iqatf2o0" path="res://Assets/Enemies/Flower_body_02.png" id="8_d8hoi"] +[ext_resource type="Texture2D" uid="uid://c31y7nll8ld3m" path="res://Assets/Enemies/Flower_body_01.png" id="9_v1055"] +[ext_resource type="Texture2D" uid="uid://cujhdc04p5cbp" path="res://Assets/Enemies/Flower_head_2_01.png" id="10_netfh"] +[ext_resource type="Texture2D" uid="uid://dvyhfd6mdokmk" path="res://Assets/Enemies/Flower_head_2_02.png" id="11_ygolp"] +[ext_resource type="Texture2D" uid="uid://3fldnmw8r5su" path="res://Assets/Enemies/Flower_head_2_03.png" id="12_xe8f4"] +[ext_resource type="Texture2D" uid="uid://djm5688x6wwfy" path="res://Assets/Enemies/Flower_head_2_04.png" id="13_yduun"] +[ext_resource type="Texture2D" uid="uid://bix8yc8hfgiom" path="res://Assets/Enemies/Flower_head_2_05.png" id="14_l0rh6"] +[ext_resource type="Texture2D" uid="uid://dq67dc5chscm5" path="res://Assets/Enemies/Flower_head_2_06.png" id="15_5rbtl"] +[ext_resource type="Texture2D" uid="uid://blhxiqe538btd" path="res://Assets/Enemies/Flower_head_2_07.png" id="16_12lar"] +[ext_resource type="PackedScene" uid="uid://ce3vv2pod6auc" path="res://Scenes/Entities/Enemies/Components/Collision.tscn" id="17_ie8xg"] +[ext_resource type="PackedScene" uid="uid://b3i372vgdbxk" path="res://Scenes/Entities/Enemies/Components/Health.tscn" id="18_j2oh0"] + +[sub_resource type="SpriteFrames" id="SpriteFrames_fjxcc"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("2_j1q7v") +}], +"loop": false, +"name": &"death", +"speed": 1.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_wopor") +}, { +"duration": 1.0, +"texture": ExtResource("4_i6ewr") +}, { +"duration": 1.0, +"texture": ExtResource("5_3shgr") +}, { +"duration": 1.0, +"texture": ExtResource("6_pw71b") +}, { +"duration": 1.0, +"texture": ExtResource("7_wypb7") +}], +"loop": false, +"name": &"death_post", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("8_d8hoi") +}, { +"duration": 1.0, +"texture": ExtResource("9_v1055") +}], +"loop": true, +"name": &"default", +"speed": 3.0 +}] + +[sub_resource type="SpriteFrames" id="SpriteFrames_sokwy"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("10_netfh") +}, { +"duration": 1.0, +"texture": ExtResource("11_ygolp") +}, { +"duration": 1.0, +"texture": ExtResource("12_xe8f4") +}, { +"duration": 1.0, +"texture": ExtResource("13_yduun") +}, { +"duration": 1.0, +"texture": ExtResource("14_l0rh6") +}, { +"duration": 1.0, +"texture": ExtResource("15_5rbtl") +}, { +"duration": 1.0, +"texture": ExtResource("16_12lar") +}], +"loop": false, +"name": &"default", +"speed": 6.0 +}] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_tq41g"] +radius = 6.0 +height = 22.0 + +[node name="Flower" type="CharacterBody2D"] +collision_layer = 0 +collision_mask = 184 +script = ExtResource("1_0uei7") + +[node name="Body" type="Node2D" parent="."] +metadata/_edit_group_ = true + +[node name="Bottom" type="AnimatedSprite2D" parent="Body"] +texture_filter = 1 +sprite_frames = SubResource("SpriteFrames_fjxcc") + +[node name="Top" type="AnimatedSprite2D" parent="Body"] +texture_filter = 1 +position = Vector2(0, -8) +sprite_frames = SubResource("SpriteFrames_sokwy") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(0, -6) +shape = SubResource("CapsuleShape2D_tq41g") + +[node name="Collision" parent="." instance=ExtResource("17_ie8xg")] +entityPath = NodePath("..") +collision_shape_path = NodePath("../CollisionShape2D") +component_health_path = NodePath("../Health") + +[node name="Health" parent="." instance=ExtResource("18_j2oh0")] +entityPath = NodePath("..") +spritePath = NodePath("../Body/Bottom") +health = 1 diff --git a/Scenes/Entities/Enemies/Flowers.gd b/Scenes/Entities/Enemies/Flowers.gd new file mode 100644 index 0000000..09e6085 --- /dev/null +++ b/Scenes/Entities/Enemies/Flowers.gd @@ -0,0 +1,82 @@ +extends CharacterBody2D + + +@export var speed: int = 5 +@export var min_radius: int = 5 +@export var max_radius: int = 25 +@export var mode_duration: float = 4.0 + +var follows_player: bool = false +@onready var radius: float = float(min_radius) + +enum MovementMode { + EXPAND, + SHRINK, +} +var movement_mode: MovementMode = MovementMode.SHRINK + +var flowers: Array = [] + + +func _ready(): + $Timer.wait_time = mode_duration + + var FlowerScene = preload("res://Scenes/Entities/Enemies/Flower.tscn") + + for number in range(3): + var flower = FlowerScene.instantiate() + flower.angle = deg_to_rad(120 * number) + + # if last flower is removed, remove self + flower.get_node("Health").died.connect(func(): + flowers.remove_at(flowers.find(flower)) + if flowers.is_empty(): + queue_free() + ) + + get_parent().add_child(flower) + flowers.push_front(flower) + + +func _physics_process(delta): + if follows_player: + var player_direction = position.direction_to(Global.player.position) + velocity = player_direction * float(speed) * delta + move_and_collide(velocity) + + if movement_mode == MovementMode.SHRINK and radius > min_radius: + radius = max( + min_radius, + radius - ((max_radius - min_radius) / mode_duration) * delta + ) + elif movement_mode == MovementMode.EXPAND and radius < max_radius: + radius = min( + max_radius, + radius + ((max_radius - min_radius) / mode_duration) * delta + ) + + for flower in flowers: + flower.move_and_collide(velocity) + flower.position = position + Vector2(cos(flower.angle) * radius, sin(flower.angle) * radius) + flower.angle += float(speed) * delta + + +func _on_detection_area_body_entered(body): + if body is Player: + follows_player = true + + +func _on_detection_area_body_exited(body): + if body is Player: + follows_player = false + + +func _on_timer_timeout(): + if movement_mode == MovementMode.SHRINK: + movement_mode = MovementMode.EXPAND + for flower in flowers: + flower.expand() + elif movement_mode == MovementMode.EXPAND: + movement_mode = MovementMode.SHRINK + for flower in flowers: + flower.shrink() diff --git a/Scenes/Entities/Enemies/Flowers.tscn b/Scenes/Entities/Enemies/Flowers.tscn new file mode 100644 index 0000000..91c54d4 --- /dev/null +++ b/Scenes/Entities/Enemies/Flowers.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=4 format=3 uid="uid://cplelcvju50xj"] + +[ext_resource type="Script" path="res://Scenes/Entities/Enemies/Flowers.gd" id="1_a4wuh"] +[ext_resource type="Texture2D" uid="uid://bbo73owb43h0e" path="res://icon.svg" id="2_womd7"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_2a0s2"] +radius = 64.0 + +[node name="Flowers" type="CharacterBody2D"] +motion_mode = 1 +script = ExtResource("1_a4wuh") + +[node name="DetectionArea" type="Area2D" parent="."] +collision_layer = 64 +collision_mask = 2 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionArea"] +shape = SubResource("CircleShape2D_2a0s2") + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.0625, 0.0625) +texture = ExtResource("2_womd7") + +[node name="Timer" type="Timer" parent="."] +autostart = true + +[connection signal="body_entered" from="DetectionArea" to="." method="_on_detection_area_body_entered"] +[connection signal="body_exited" from="DetectionArea" to="." method="_on_detection_area_body_exited"] +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/Scenes/Entities/Enemies/Tree.gd b/Scenes/Entities/Enemies/Tree.gd index 7c87a18..db78788 100644 --- a/Scenes/Entities/Enemies/Tree.gd +++ b/Scenes/Entities/Enemies/Tree.gd @@ -16,7 +16,7 @@ func _physics_process(delta): get_node("Movement").physics_process(delta) -func _on_detection_body_entered(body): +func _on_detection_body_entered(_body): $AnimatedSprite2D.play("spawn") await $AnimatedSprite2D.animation_finished set_physics_process(true) diff --git a/Scenes/Entities/Objects/Sign.tscn b/Scenes/Entities/Objects/Sign.tscn index 847b768..a4cd832 100644 --- a/Scenes/Entities/Objects/Sign.tscn +++ b/Scenes/Entities/Objects/Sign.tscn @@ -7,6 +7,8 @@ size = Vector2(14, 17) [node name="Sign" type="StaticBody2D"] +y_sort_enabled = true +texture_filter = 1 collision_layer = 8 collision_mask = 6 script = ExtResource("1_gowid") |