summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Enemies
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-04-14 21:49:20 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-04-14 21:49:20 +0200
commitf27937e6e9b6a7146dd09fc711d2d293ecf5abbf (patch)
treee0ddd5e6d356000e4f29af6211a736284a4972ee /Scenes/Entities/Enemies
parent96d36cee33d6321834565f0a5d412ef95c5ceffd (diff)
update
Diffstat (limited to 'Scenes/Entities/Enemies')
-rw-r--r--Scenes/Entities/Enemies/Balloon.gd43
-rw-r--r--Scenes/Entities/Enemies/Balloon.tscn123
-rw-r--r--Scenes/Entities/Enemies/Components/Collision.gd18
-rw-r--r--Scenes/Entities/Enemies/Components/Collision.tscn6
-rw-r--r--Scenes/Entities/Enemies/Components/Movement.gd56
-rw-r--r--Scenes/Entities/Enemies/Components/Movement.tscn6
6 files changed, 252 insertions, 0 deletions
diff --git a/Scenes/Entities/Enemies/Balloon.gd b/Scenes/Entities/Enemies/Balloon.gd
new file mode 100644
index 0000000..bc79f24
--- /dev/null
+++ b/Scenes/Entities/Enemies/Balloon.gd
@@ -0,0 +1,43 @@
+extends CharacterBody2D
+
+
+@export var health: int
+
+
+func _ready():
+ add_to_group("enemies")
+
+ get_node("Collision").init()
+
+ get_node("Movement").connect("direction_changed", func(current_direction):
+ var frame = $AnimatedSprite2D.frame
+ var progress = $AnimatedSprite2D.frame_progress
+ if current_direction == Vector2.UP:
+ $AnimatedSprite2D.play("up")
+ elif current_direction == Vector2.DOWN:
+ $AnimatedSprite2D.play("down")
+ elif current_direction == Vector2.LEFT:
+ $AnimatedSprite2D.play("left")
+ elif current_direction == Vector2.RIGHT:
+ $AnimatedSprite2D.play("right")
+ $AnimatedSprite2D.set_frame_and_progress(frame, progress)
+ )
+
+ get_node("Collision").connect("collided", func(area):
+ if area.is_in_group("explosions"):
+ health -= 1
+ if health <= 0:
+ set_physics_process(false)
+ remove_child(get_node("Movement"))
+
+ $AnimatedSprite2D.play("death")
+ await $AnimatedSprite2D.animation_finished
+ # todo shrink to 0
+ queue_free()
+ )
+
+
+func _physics_process(delta):
+ get_node("Movement").physics_process(delta)
+
+ # todo: animation shadow
diff --git a/Scenes/Entities/Enemies/Balloon.tscn b/Scenes/Entities/Enemies/Balloon.tscn
new file mode 100644
index 0000000..85b68c1
--- /dev/null
+++ b/Scenes/Entities/Enemies/Balloon.tscn
@@ -0,0 +1,123 @@
+[gd_scene load_steps=19 format=3 uid="uid://ccolri3egf8rk"]
+
+[ext_resource type="Script" path="res://Scenes/Entities/Enemies/Balloon.gd" id="1_8q3w8"]
+[ext_resource type="Texture2D" uid="uid://ck1sxw5vqhoa" path="res://Assets/Enemies/Balloon_death_2.png" id="2_c4j5c"]
+[ext_resource type="Texture2D" uid="uid://b1mr0hh682o5o" path="res://Assets/Enemies/Balloon_down_2_01.png" id="3_pcii7"]
+[ext_resource type="Texture2D" uid="uid://bqjxycrl7qh2s" path="res://Assets/Enemies/Balloon_down_2_02.png" id="4_3eanq"]
+[ext_resource type="Texture2D" uid="uid://ciku28v7q6a2q" path="res://Assets/Enemies/Balloon_down_2_03.png" id="5_vhsnp"]
+[ext_resource type="Texture2D" uid="uid://di8wp5yyn36uj" path="res://Assets/Enemies/Balloon_left_2_01.png" id="6_ykdih"]
+[ext_resource type="Texture2D" uid="uid://c0qju385rrnvv" path="res://Assets/Enemies/Balloon_left_2_02.png" id="7_81kws"]
+[ext_resource type="Texture2D" uid="uid://bgjm6vhpdxgbe" path="res://Assets/Enemies/Balloon_left_2_03.png" id="8_7eum3"]
+[ext_resource type="Texture2D" uid="uid://cjqjq1ppdhoxe" path="res://Assets/Enemies/Balloon_right_2_01.png" id="9_doy2d"]
+[ext_resource type="Texture2D" uid="uid://dmsxbrwqju44n" path="res://Assets/Enemies/Balloon_right_2_02.png" id="10_xyola"]
+[ext_resource type="Texture2D" uid="uid://ci21n2unmik6w" path="res://Assets/Enemies/Balloon_right_2_03.png" id="11_y5de8"]
+[ext_resource type="Texture2D" uid="uid://w7jyuri324sv" path="res://Assets/Enemies/Balloon_up_2_01.png" id="12_jhcfp"]
+[ext_resource type="Texture2D" uid="uid://dts0ofiyjlxfe" path="res://Assets/Enemies/Balloon_up_2_02.png" id="13_8valq"]
+[ext_resource type="Texture2D" uid="uid://u56kfb4hq87o" path="res://Assets/Enemies/Balloon_up_2_03.png" id="14_757al"]
+[ext_resource type="PackedScene" uid="uid://cq7yj2av01tqd" path="res://Scenes/Entities/Enemies/Components/Movement.tscn" id="15_fwetl"]
+[ext_resource type="PackedScene" uid="uid://ce3vv2pod6auc" path="res://Scenes/Entities/Enemies/Components/Collision.tscn" id="16_yau34"]
+
+[sub_resource type="SpriteFrames" id="SpriteFrames_nxaqi"]
+animations = [{
+"frames": [{
+"duration": 1.0,
+"texture": ExtResource("2_c4j5c")
+}],
+"loop": false,
+"name": &"death",
+"speed": 1.0
+}, {
+"frames": [{
+"duration": 1.0,
+"texture": ExtResource("3_pcii7")
+}, {
+"duration": 1.0,
+"texture": ExtResource("4_3eanq")
+}, {
+"duration": 1.0,
+"texture": ExtResource("3_pcii7")
+}, {
+"duration": 1.0,
+"texture": ExtResource("5_vhsnp")
+}],
+"loop": true,
+"name": &"down",
+"speed": 2.0
+}, {
+"frames": [{
+"duration": 1.0,
+"texture": ExtResource("6_ykdih")
+}, {
+"duration": 1.0,
+"texture": ExtResource("7_81kws")
+}, {
+"duration": 1.0,
+"texture": ExtResource("6_ykdih")
+}, {
+"duration": 1.0,
+"texture": ExtResource("8_7eum3")
+}],
+"loop": true,
+"name": &"left",
+"speed": 2.0
+}, {
+"frames": [{
+"duration": 1.0,
+"texture": ExtResource("9_doy2d")
+}, {
+"duration": 1.0,
+"texture": ExtResource("10_xyola")
+}, {
+"duration": 1.0,
+"texture": ExtResource("9_doy2d")
+}, {
+"duration": 1.0,
+"texture": ExtResource("11_y5de8")
+}],
+"loop": true,
+"name": &"right",
+"speed": 2.0
+}, {
+"frames": [{
+"duration": 1.0,
+"texture": ExtResource("12_jhcfp")
+}, {
+"duration": 1.0,
+"texture": ExtResource("13_8valq")
+}, {
+"duration": 1.0,
+"texture": ExtResource("12_jhcfp")
+}, {
+"duration": 1.0,
+"texture": ExtResource("14_757al")
+}],
+"loop": true,
+"name": &"up",
+"speed": 2.0
+}]
+
+[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_abul4"]
+radius = 6.0
+height = 18.0
+
+[node name="Balloon" type="CharacterBody2D"]
+collision_layer = 16
+collision_mask = 62
+script = ExtResource("1_8q3w8")
+health = 1
+
+[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
+sprite_frames = SubResource("SpriteFrames_nxaqi")
+animation = &"down"
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+shape = SubResource("CapsuleShape2D_abul4")
+
+[node name="Movement" parent="." instance=ExtResource("15_fwetl")]
+entityPath = NodePath("..")
+spritePath = NodePath("../AnimatedSprite2D")
+SPEED = 2
+
+[node name="Collision" parent="." instance=ExtResource("16_yau34")]
+entityPath = NodePath("..")
+collision_shape_path = NodePath("../CollisionShape2D")
diff --git a/Scenes/Entities/Enemies/Components/Collision.gd b/Scenes/Entities/Enemies/Components/Collision.gd
new file mode 100644
index 0000000..b2e8d9b
--- /dev/null
+++ b/Scenes/Entities/Enemies/Components/Collision.gd
@@ -0,0 +1,18 @@
+extends Node
+
+class_name Component_Collision
+
+
+signal collided
+
+@export_node_path("CharacterBody2D") var entityPath: NodePath
+@onready var entity: CharacterBody2D = get_node(entityPath)
+
+@export_node_path("CollisionShape2D") var collision_shape_path: NodePath
+@onready var collision_shape: CollisionShape2D = get_node(collision_shape_path)
+
+
+func init():
+ var collision_area = Utilities.Collision.Area.new(entity, collision_shape)
+ collision_area.connect("collided", func(area): emit_signal("collided", area))
+ entity.add_child(collision_area)
diff --git a/Scenes/Entities/Enemies/Components/Collision.tscn b/Scenes/Entities/Enemies/Components/Collision.tscn
new file mode 100644
index 0000000..d11f927
--- /dev/null
+++ b/Scenes/Entities/Enemies/Components/Collision.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://ce3vv2pod6auc"]
+
+[ext_resource type="Script" path="res://Scenes/Entities/Enemies/Components/Collision.gd" id="1_j60o5"]
+
+[node name="Collision" type="Node"]
+script = ExtResource("1_j60o5")
diff --git a/Scenes/Entities/Enemies/Components/Movement.gd b/Scenes/Entities/Enemies/Components/Movement.gd
new file mode 100644
index 0000000..0b30820
--- /dev/null
+++ b/Scenes/Entities/Enemies/Components/Movement.gd
@@ -0,0 +1,56 @@
+extends Node
+
+signal direction_changed
+
+@export_node_path("CharacterBody2D") var entityPath: NodePath
+@onready var entity: CharacterBody2D = get_node(entityPath)
+
+@export_node_path("AnimatedSprite2D") var spritePath: NodePath
+@onready var sprite: AnimatedSprite2D = get_node(spritePath)
+
+@export var SPEED: int
+
+const DIRECTIONS = [Vector2.UP, Vector2.RIGHT, Vector2.DOWN, Vector2.LEFT]
+var CURRENT_DIRECTION = Vector2.UP
+
+@onready var MovementTimer: Timer = Timer.new()
+
+
+func _ready():
+ MovementTimer.wait_time = 3.0
+ MovementTimer.autostart = true
+ MovementTimer.connect("timeout", Callable(_on_movement_timer_timeout))
+ add_child(MovementTimer)
+
+
+func physics_process(delta):
+ if CURRENT_DIRECTION == Vector2.UP:
+ entity.velocity.y -= SPEED
+ sprite.play("up")
+ elif CURRENT_DIRECTION == Vector2.DOWN:
+ entity.velocity.y += SPEED
+ sprite.play("down")
+ elif CURRENT_DIRECTION == Vector2.LEFT:
+ entity.velocity.x -= SPEED
+ sprite.play("left")
+ elif CURRENT_DIRECTION == Vector2.RIGHT:
+ entity.velocity.x += SPEED
+ sprite.play("right")
+
+ var collision = entity.move_and_collide(entity.velocity * delta)
+ entity.velocity = entity.velocity.lerp(Vector2(0, 0), 1)
+
+ return collision
+
+
+func _on_movement_timer_timeout():
+ var directions = DIRECTIONS.duplicate()
+
+ directions.remove_at(directions.find(CURRENT_DIRECTION))
+ directions.shuffle()
+
+ CURRENT_DIRECTION = directions[0]
+
+ emit_signal("direction_changed", CURRENT_DIRECTION)
+
+ MovementTimer.start()
diff --git a/Scenes/Entities/Enemies/Components/Movement.tscn b/Scenes/Entities/Enemies/Components/Movement.tscn
new file mode 100644
index 0000000..f3d5909
--- /dev/null
+++ b/Scenes/Entities/Enemies/Components/Movement.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://cq7yj2av01tqd"]
+
+[ext_resource type="Script" path="res://Scenes/Entities/Enemies/Components/Movement.gd" id="1_mtee1"]
+
+[node name="Movement" type="Node"]
+script = ExtResource("1_mtee1")