From a894aa2018430bc92b54080b7eba37305d757fc6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 15 Apr 2024 06:07:49 +0200 Subject: [PATCH] Add `Imp` sprite and make it eat `Sheep` --- behaviours/eat_target.gd | 2 -- behaviours/eat_target.tscn | 5 +++-- behaviours/eater.tscn | 7 +++++-- behaviours/hunt_target.tscn | 1 - behaviours/hunter.tscn | 4 ++-- entities/imp.gd | 19 ++++++------------- entities/imp.tscn | 31 ++++++++++++++++++------------- entities/imp_left.png | 3 +++ entities/imp_left.png.import | 34 ++++++++++++++++++++++++++++++++++ entities/imp_right.png | 3 +++ entities/imp_right.png.import | 34 ++++++++++++++++++++++++++++++++++ 11 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 entities/imp_left.png create mode 100644 entities/imp_left.png.import create mode 100644 entities/imp_right.png create mode 100644 entities/imp_right.png.import diff --git a/behaviours/eat_target.gd b/behaviours/eat_target.gd index d873940..3ffd6d2 100644 --- a/behaviours/eat_target.gd +++ b/behaviours/eat_target.gd @@ -30,10 +30,8 @@ func _on_target_selected(body: Node2D) -> void: func _on_target_abandoned(_body: Node2D) -> void: move_towards.target = null - func _on_eater_eaten(edible): eaten.emit(edible) - func _on_move_towards_target_move(movement): move.emit(movement) diff --git a/behaviours/eat_target.tscn b/behaviours/eat_target.tscn index ee94530..53ab7a7 100644 --- a/behaviours/eat_target.tscn +++ b/behaviours/eat_target.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://dfitiajuuvdko"] +[gd_scene load_steps=5 format=3 uid="uid://b7bdlh5akhi8s"] [ext_resource type="Script" path="res://behaviours/eat_target.gd" id="1_tlnlt"] [ext_resource type="PackedScene" uid="uid://dxmodn8mbvw0i" path="res://behaviours/hunt_target.tscn" id="2_c8wdv"] @@ -9,10 +9,11 @@ script = ExtResource("1_tlnlt") [node name="HuntTarget" parent="." instance=ExtResource("2_c8wdv")] -tag = &"" +scale = Vector2(16, 16) give_up_secs = 5.0 [node name="Eater" parent="." instance=ExtResource("3_ir2yh")] +scale = Vector2(2.5, 2.5) [node name="MoveTowardsTarget" parent="." instance=ExtResource("4_1qc2q")] diff --git a/behaviours/eater.tscn b/behaviours/eater.tscn index ce57e4a..042a7c2 100644 --- a/behaviours/eater.tscn +++ b/behaviours/eater.tscn @@ -3,14 +3,17 @@ [ext_resource type="Script" path="res://behaviours/eater.gd" id="1_urx5y"] [sub_resource type="CircleShape2D" id="CircleShape2D_61hv0"] -radius = 16.0 +radius = 8.0 [node name="Eater" type="Area2D"] +collision_layer = 0 +collision_mask = 8 +monitorable = false script = ExtResource("1_urx5y") [node name="Shape" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_61hv0") -debug_color = Color(0.47451, 0, 0.027451, 0.678431) +debug_color = Color(1, 0, 0.027451, 0) [connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="eaten" from="." to="." method="_on_eaten"] diff --git a/behaviours/hunt_target.tscn b/behaviours/hunt_target.tscn index e9e33e2..6d191d1 100644 --- a/behaviours/hunt_target.tscn +++ b/behaviours/hunt_target.tscn @@ -5,7 +5,6 @@ [node name="HuntTarget" type="Node2D"] script = ExtResource("1_1ex7u") -tag = null give_up_secs = null [node name="Hunter" parent="." instance=ExtResource("2_vjdtc")] diff --git a/behaviours/hunter.tscn b/behaviours/hunter.tscn index 42fcfc7..cb0a0ee 100644 --- a/behaviours/hunter.tscn +++ b/behaviours/hunter.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://behaviours/hunter.gd" id="1_3bmd5"] [sub_resource type="CircleShape2D" id="CircleShape2D_kxb8e"] -radius = 100.0 +radius = 8.0 [node name="Hunter" type="Node2D"] script = ExtResource("1_3bmd5") @@ -15,7 +15,7 @@ monitorable = false [node name="Shape" type="CollisionShape2D" parent="DetectionArea"] shape = SubResource("CircleShape2D_kxb8e") -debug_color = Color(1, 0, 0, 0.419608) +debug_color = Color(1, 0, 0, 0.0705882) [connection signal="tracked" from="." to="." method="_on_tracked"] [connection signal="untracked" from="." to="." method="_on_untracked"] diff --git a/entities/imp.gd b/entities/imp.gd index 52c63e4..bbbd025 100644 --- a/entities/imp.gd +++ b/entities/imp.gd @@ -4,29 +4,22 @@ class_name Imp @export var skull_chance: float = 0.2 @onready var skull_spawner: Spawner = $"SkullSpawner" +@onready var sprite: SpriteLeftRight = $"Sprite" @onready var draggable: Draggable = $"Draggable" -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta: float) -> void: - pass - - -func _on_eat_target_eaten(_target: Edible): +func _on_eat_target_eaten(target: Edible): + target.queue_free() if Random.rng.randf() < skull_chance: skull_spawner.spawn() func _on_draggable_move(movement:Vector2): if draggable.being_dragged: - print("move", movement) move_and_collide(movement) + sprite.handle_move(movement) func _on_move(movement:Vector2): if not draggable.being_dragged: - print("move", movement) - move_and_collide(movement) \ No newline at end of file + move_and_collide(movement) + sprite.handle_move(movement) diff --git a/entities/imp.tscn b/entities/imp.tscn index 9193784..6ec0350 100644 --- a/entities/imp.tscn +++ b/entities/imp.tscn @@ -1,30 +1,34 @@ -[gd_scene load_steps=8 format=3 uid="uid://4d3ksr3171x4"] +[gd_scene load_steps=10 format=3 uid="uid://4d3ksr3171x4"] [ext_resource type="Script" path="res://entities/imp.gd" id="1_dixpc"] +[ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="2_eqcdi"] [ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="3_4528r"] -[ext_resource type="PackedScene" uid="uid://dfitiajuuvdko" path="res://behaviours/eat_target.tscn" id="3_iybf3"] -[ext_resource type="PackedScene" uid="uid://cyrg770fsetyu" path="res://behaviours/spawner.tscn" id="4_d8lgm"] +[ext_resource type="PackedScene" uid="uid://b7bdlh5akhi8s" path="res://behaviours/eat_target.tscn" id="3_iybf3"] +[ext_resource type="Texture2D" uid="uid://crhwsob76ieya" path="res://entities/imp_left.png" id="3_qda0k"] +[ext_resource type="Texture2D" uid="uid://bubehid53q8h1" path="res://entities/imp_right.png" id="4_0sckn"] +[ext_resource type="PackedScene" path="res://behaviours/spawner.tscn" id="4_d8lgm"] [ext_resource type="PackedScene" uid="uid://uoxwjpmgg27a" path="res://entities/gold.tscn" id="5_yrfoq"] -[sub_resource type="CircleShape2D" id="CircleShape2D_c5tcn"] -radius = 16.0 - -[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_08frh"] +[sub_resource type="CircleShape2D" id="CircleShape2D_ide4n"] +radius = 8.0 [node name="Imp" type="CharacterBody2D"] collision_layer = 8 collision_mask = 14 script = ExtResource("1_dixpc") -[node name="Shape" type="CollisionShape2D" parent="."] -shape = SubResource("CircleShape2D_c5tcn") +[node name="Sprite" parent="." instance=ExtResource("2_eqcdi")] +scale = Vector2(2, 2) +texture = ExtResource("3_qda0k") +left_texture = ExtResource("3_qda0k") +right_texture = ExtResource("4_0sckn") -[node name="Sprite" type="Sprite2D" parent="."] -scale = Vector2(32, 32) -texture = SubResource("PlaceholderTexture2D_08frh") +[node name="Shape" type="CollisionShape2D" parent="."] +scale = Vector2(4, 4) +shape = SubResource("CircleShape2D_ide4n") [node name="Draggable" parent="." instance=ExtResource("3_4528r")] -scale = Vector2(2, 2) +scale = Vector2(4, 4) [node name="DragSound" type="AudioStreamPlayer2D" parent="Draggable"] scale = Vector2(0.5, 0.5) @@ -33,6 +37,7 @@ scale = Vector2(0.5, 0.5) scale = Vector2(0.5, 0.5) [node name="EatTarget" parent="." instance=ExtResource("3_iybf3")] +scale = Vector2(2, 2) tag = &"Sheep" [node name="SkullSpawner" parent="." instance=ExtResource("4_d8lgm")] diff --git a/entities/imp_left.png b/entities/imp_left.png new file mode 100644 index 0000000..621d4fa --- /dev/null +++ b/entities/imp_left.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7dfcf56434a18004abf18ec8ea78a04625e046454ea0ac1577b1a4b2c89b42e8 +size 549 diff --git a/entities/imp_left.png.import b/entities/imp_left.png.import new file mode 100644 index 0000000..fcb86e5 --- /dev/null +++ b/entities/imp_left.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://crhwsob76ieya" +path="res://.godot/imported/imp_left.png-08c29cf2ea70a06668881e6734bc6acb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/imp_left.png" +dest_files=["res://.godot/imported/imp_left.png-08c29cf2ea70a06668881e6734bc6acb.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/entities/imp_right.png b/entities/imp_right.png new file mode 100644 index 0000000..a0fea88 --- /dev/null +++ b/entities/imp_right.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6dbe77e6dc816a416216dc8220fb3368855ee6ad0c6099ff91109f40a80cb585 +size 577 diff --git a/entities/imp_right.png.import b/entities/imp_right.png.import new file mode 100644 index 0000000..65ccba1 --- /dev/null +++ b/entities/imp_right.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bubehid53q8h1" +path="res://.godot/imported/imp_right.png-5420c8b334729ea80ccdda0be5b78434.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/imp_right.png" +dest_files=["res://.godot/imported/imp_right.png-5420c8b334729ea80ccdda0be5b78434.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1