diff --git a/entities/interactables/plants/assets/sprites/default_plant.png b/entities/interactables/plants/assets/sprites/default_plant.png new file mode 100644 index 0000000..1f448f0 Binary files /dev/null and b/entities/interactables/plants/assets/sprites/default_plant.png differ diff --git a/entities/interactables/plants/assets/sprites/default_plant.png.import b/entities/interactables/plants/assets/sprites/default_plant.png.import new file mode 100644 index 0000000..bc340ad --- /dev/null +++ b/entities/interactables/plants/assets/sprites/default_plant.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c6vby5r0pfni2" +path="res://.godot/imported/default_plant.png-bbc4a8928e27ae5fc30489a97257bdb9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/interactables/plants/assets/sprites/default_plant.png" +dest_files=["res://.godot/imported/default_plant.png-bbc4a8928e27ae5fc30489a97257bdb9.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/interactables/plants/assets/sprites/default_plant_glowing.png b/entities/interactables/plants/assets/sprites/default_plant_glowing.png new file mode 100644 index 0000000..574a04c Binary files /dev/null and b/entities/interactables/plants/assets/sprites/default_plant_glowing.png differ diff --git a/entities/interactables/plants/assets/sprites/default_plant_glowing.png.import b/entities/interactables/plants/assets/sprites/default_plant_glowing.png.import new file mode 100644 index 0000000..7216319 --- /dev/null +++ b/entities/interactables/plants/assets/sprites/default_plant_glowing.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b3wom2xu26g43" +path="res://.godot/imported/default_plant_glowing.png-09ba534646a860193c36fa40d5f83142.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/interactables/plants/assets/sprites/default_plant_glowing.png" +dest_files=["res://.godot/imported/default_plant_glowing.png-09ba534646a860193c36fa40d5f83142.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/interactables/plants/default_plant.tscn b/entities/interactables/plants/default_plant.tscn new file mode 100644 index 0000000..7d65b7a --- /dev/null +++ b/entities/interactables/plants/default_plant.tscn @@ -0,0 +1,40 @@ +[gd_scene load_steps=8 format=3 uid="uid://clpcqkdlj3d8e"] + +[ext_resource type="Script" uid="uid://cega715smavh3" path="res://entities/interactables/plants/scripts/plant.gd" id="1_d8u7e"] +[ext_resource type="Script" uid="uid://yutflvdgdk04" path="res://entities/interactables/scripts/interactable_action.gd" id="2_rs46h"] +[ext_resource type="Resource" uid="uid://bk0kop0m75pjy" path="res://entities/interactables/resources/actions/default_water_plant.tres" id="3_5foug"] +[ext_resource type="Texture2D" uid="uid://c6vby5r0pfni2" path="res://entities/interactables/plants/assets/sprites/default_plant.png" id="4_dq24f"] +[ext_resource type="Texture2D" uid="uid://b3wom2xu26g43" path="res://entities/interactables/plants/assets/sprites/default_plant_glowing.png" id="5_2gcie"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_cdbrd"] + +[sub_resource type="SpriteFrames" id="SpriteFrames_ocwgi"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("4_dq24f") +}], +"loop": true, +"name": &"default", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("5_2gcie") +}], +"loop": true, +"name": &"watered", +"speed": 5.0 +}] + +[node name="DefaultPlant" type="Area2D"] +script = ExtResource("1_d8u7e") +actions = Array[ExtResource("2_rs46h")]([ExtResource("3_5foug")]) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +scale = Vector2(4.01154, 4.01154) +shape = SubResource("CircleShape2D_cdbrd") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +scale = Vector2(0.160462, 0.160462) +sprite_frames = SubResource("SpriteFrames_ocwgi") diff --git a/entities/interactables/plants/scripts/plant.gd b/entities/interactables/plants/scripts/plant.gd new file mode 100644 index 0000000..b609577 --- /dev/null +++ b/entities/interactables/plants/scripts/plant.gd @@ -0,0 +1,8 @@ +extends Interactable +class_name Plant + +var watered : bool = false : set = set_watered + +func set_watered(_watered): + watered = _watered + $AnimatedSprite2D.play("watered" if watered else "default") \ No newline at end of file diff --git a/entities/interactables/plants/scripts/plant.gd.uid b/entities/interactables/plants/scripts/plant.gd.uid new file mode 100644 index 0000000..61e80cf --- /dev/null +++ b/entities/interactables/plants/scripts/plant.gd.uid @@ -0,0 +1 @@ +uid://cega715smavh3 diff --git a/entities/interactables/resources/actions/default_water_plant.tres b/entities/interactables/resources/actions/default_water_plant.tres new file mode 100644 index 0000000..d43f2b3 --- /dev/null +++ b/entities/interactables/resources/actions/default_water_plant.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="WaterPlantAction" load_steps=2 format=3 uid="uid://bk0kop0m75pjy"] + +[ext_resource type="Script" uid="uid://bb38yqsd072ws" path="res://entities/interactables/scripts/actions/water_plant.gd" id="1_ghdb0"] + +[resource] +script = ExtResource("1_ghdb0") +metadata/_custom_type_script = "uid://bb38yqsd072ws" diff --git a/entities/interactables/scripts/actions/water_plant.gd b/entities/interactables/scripts/actions/water_plant.gd new file mode 100644 index 0000000..2e9ec71 --- /dev/null +++ b/entities/interactables/scripts/actions/water_plant.gd @@ -0,0 +1,8 @@ +extends InteractableAction +class_name WaterPlantAction + +func action(_p: Player, _i : Interactable): + if _i is Plant: + _i.watered = true + else : + printerr("No plant selected or interactable is not a plant") \ No newline at end of file diff --git a/entities/interactables/scripts/actions/water_plant.gd.uid b/entities/interactables/scripts/actions/water_plant.gd.uid new file mode 100644 index 0000000..a175c78 --- /dev/null +++ b/entities/interactables/scripts/actions/water_plant.gd.uid @@ -0,0 +1 @@ +uid://bb38yqsd072ws diff --git a/entities/interactables/scripts/interactable.gd b/entities/interactables/scripts/interactable.gd new file mode 100644 index 0000000..16c0091 --- /dev/null +++ b/entities/interactables/scripts/interactable.gd @@ -0,0 +1,8 @@ +extends Area2D +class_name Interactable + +@export var actions : Array[InteractableAction] = []; + +func interact(p : Player): + for a in actions: + a.action(p, self) \ No newline at end of file diff --git a/entities/interactables/scripts/interactable.gd.uid b/entities/interactables/scripts/interactable.gd.uid new file mode 100644 index 0000000..edba652 --- /dev/null +++ b/entities/interactables/scripts/interactable.gd.uid @@ -0,0 +1 @@ +uid://dyprcd68fjstf diff --git a/entities/interactables/scripts/interactable_action.gd b/entities/interactables/scripts/interactable_action.gd new file mode 100644 index 0000000..346aa63 --- /dev/null +++ b/entities/interactables/scripts/interactable_action.gd @@ -0,0 +1,6 @@ +# Classe abstraite permettant de développer diverses actions +extends Resource +class_name InteractableAction + +func action(_p: Player, _i : Interactable): + printerr("Méthode action de la classe abstraite InteractableAction appelée") \ No newline at end of file diff --git a/entities/interactables/scripts/interactable_action.gd.uid b/entities/interactables/scripts/interactable_action.gd.uid new file mode 100644 index 0000000..7ef9a22 --- /dev/null +++ b/entities/interactables/scripts/interactable_action.gd.uid @@ -0,0 +1 @@ +uid://yutflvdgdk04 diff --git a/entities/player/player.tscn b/entities/player/player.tscn index 9dac6ee..6216e7f 100644 --- a/entities/player/player.tscn +++ b/entities/player/player.tscn @@ -1,10 +1,13 @@ -[gd_scene load_steps=4 format=3 uid="uid://bgvbgeq46wee2"] +[gd_scene load_steps=5 format=3 uid="uid://bgvbgeq46wee2"] [ext_resource type="Script" uid="uid://das7twcy5153p" path="res://entities/player/scripts/player.gd" id="1_abrql"] [ext_resource type="Texture2D" uid="uid://c7ff87jniga5m" path="res://entities/player/assets/sprites/robot.png" id="1_symyc"] [sub_resource type="CircleShape2D" id="CircleShape2D_sglur"] -radius = 38.0526 +radius = 27.0 + +[sub_resource type="CircleShape2D" id="CircleShape2D_abrql"] +radius = 40.0 [node name="Player" type="CharacterBody2D"] script = ExtResource("1_abrql") @@ -15,4 +18,11 @@ scale = Vector2(0.084375, 0.084375) texture = ExtResource("1_symyc") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-2, 15) shape = SubResource("CircleShape2D_sglur") + +[node name="InteractArea2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractArea2D"] +position = Vector2(0, 37) +shape = SubResource("CircleShape2D_abrql") diff --git a/entities/player/scripts/player.gd b/entities/player/scripts/player.gd index 822584b..916a0f2 100644 --- a/entities/player/scripts/player.gd +++ b/entities/player/scripts/player.gd @@ -4,11 +4,33 @@ class_name Player @export var speed = 400 func get_input(): + calculate_direction() + + if Input.is_action_just_pressed("interact"): + try_interact() + +func calculate_direction(): var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down") velocity = input_direction * speed if input_direction.x: $Sprite.flip_h = (input_direction.x < 0) +func try_interact(): + var interactables : Array[Interactable] + + for area2D in $InteractArea2D.get_overlapping_areas(): + if area2D is Interactable: + interactables.push_front(area2D) + + if len(interactables): + if len(interactables) > 1: + # Sort them to the closer + interactables.sort_custom( + func (el : Interactable): return el.global_position.distance_to(global_position) + ) + + interactables[0].interact(self) + func _physics_process(_delta): get_input() - move_and_slide() \ No newline at end of file + move_and_slide() diff --git a/project.godot b/project.godot index db98917..1586078 100644 --- a/project.godot +++ b/project.godot @@ -41,3 +41,8 @@ move_down={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +interact={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(222, 14),"global_position":Vector2(231, 62),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} diff --git a/root.tscn b/root.tscn index 3bc71c9..f8a1d18 100644 --- a/root.tscn +++ b/root.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://c5bruelvqbm1k"] +[gd_scene load_steps=5 format=3 uid="uid://c5bruelvqbm1k"] [ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/planet/planet.tscn" id="1_pyidc"] [ext_resource type="PackedScene" uid="uid://bgvbgeq46wee2" path="res://entities/player/player.tscn" id="2_vvh5c"] [ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="3_vvh5c"] +[ext_resource type="PackedScene" uid="uid://clpcqkdlj3d8e" path="res://entities/interactables/plants/default_plant.tscn" id="4_28aoi"] [node name="Root" type="Node2D"] @@ -13,3 +14,33 @@ [node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_vvh5c")] position = Vector2(2.22, 0) following = NodePath("../Player") + +[node name="DefaultPlant" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(195, 37) + +[node name="DefaultPlant2" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(114, -40) + +[node name="DefaultPlant3" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(-222, 138) + +[node name="DefaultPlant4" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(-186, -96) + +[node name="DefaultPlant5" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(-7, 150) + +[node name="DefaultPlant6" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(-19, -102) + +[node name="DefaultPlant7" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(-115, 50) + +[node name="DefaultPlant8" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(147, -173) + +[node name="DefaultPlant9" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(98, 90) + +[node name="DefaultPlant10" parent="." instance=ExtResource("4_28aoi")] +position = Vector2(-269, 1)