From 962378fe936f76710f6ad8a70adb136d9c3c61b2 Mon Sep 17 00:00:00 2001 From: Luna Manson Date: Sat, 17 Feb 2024 16:31:03 +0100 Subject: [PATCH] Ajout du comportement des ItemContainer --- Scene/Interactibles/Crate.tscn | 2 +- Scene/Interactibles/Shelf.tscn | 13 +++++ Scene/Tes888C.tmp | 34 +++++++++++ Scene/TestScene.tscn | 4 +- Scripts/Interactibles/Crate.gd | 15 +++-- Scripts/Interactibles/InteractibleClass.gd | 2 - Scripts/Interactibles/Item.gd | 5 ++ Scripts/Interactibles/Item_Container.gd | 17 ++++++ Scripts/Interactibles/Item_Processor.gd | 8 +++ Scripts/PlayerControler.gd | 41 +++++++++++++- Scripts/Shelf.gd | 18 ++++++ Sprite/IMG_0156.PNG | Bin 0 -> 2010 bytes Sprite/IMG_0156.PNG.import | 34 +++++++++++ Tilemaps/TestScene.tres | 4 +- Tilemaps/Tiles/tile_0277.png | Bin 0 -> 238 bytes Tilemaps/Tiles/tile_0277.png.import | 34 +++++++++++ export_presets.cfg | 62 +++++++++++++++++++++ project.godot | 5 ++ 18 files changed, 285 insertions(+), 13 deletions(-) create mode 100644 Scene/Interactibles/Shelf.tscn create mode 100644 Scene/Tes888C.tmp create mode 100644 Scripts/Interactibles/Item.gd create mode 100644 Scripts/Interactibles/Item_Container.gd create mode 100644 Scripts/Interactibles/Item_Processor.gd create mode 100644 Scripts/Shelf.gd create mode 100644 Sprite/IMG_0156.PNG create mode 100644 Sprite/IMG_0156.PNG.import create mode 100644 Tilemaps/Tiles/tile_0277.png create mode 100644 Tilemaps/Tiles/tile_0277.png.import create mode 100644 export_presets.cfg diff --git a/Scene/Interactibles/Crate.tscn b/Scene/Interactibles/Crate.tscn index eb9c7a1..d656ad0 100644 --- a/Scene/Interactibles/Crate.tscn +++ b/Scene/Interactibles/Crate.tscn @@ -8,7 +8,6 @@ size = Vector2(16, 16) [node name="Crate" type="Area2D"] script = ExtResource("1_a65k5") -Interact_Type = "Crate1" [node name="Sprite2D" type="Sprite2D" parent="."] texture_filter = 1 @@ -32,3 +31,4 @@ position = Vector2(16, 0) shape = SubResource("RectangleShape2D_jjien") [connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="body_exited" from="." to="." method="_on_body_exited"] diff --git a/Scene/Interactibles/Shelf.tscn b/Scene/Interactibles/Shelf.tscn new file mode 100644 index 0000000..76d6b9d --- /dev/null +++ b/Scene/Interactibles/Shelf.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=4 format=3 uid="uid://d1oww5u6d2464"] + +[ext_resource type="PackedScene" uid="uid://nv8r4yu48mbj" path="res://Scene/Interactibles/Crate.tscn" id="1_4363q"] +[ext_resource type="Script" path="res://Scripts/Shelf.gd" id="2_5mi56"] +[ext_resource type="Texture2D" uid="uid://dfoc57ynahbbg" path="res://Tilemaps/Tiles/tile_0277.png" id="2_m2jbe"] + +[node name="Crate" instance=ExtResource("1_4363q")] +script = ExtResource("2_5mi56") +duration = 0 +duration_type = 0 + +[node name="Sprite2D" parent="." index="0"] +texture = ExtResource("2_m2jbe") diff --git a/Scene/Tes888C.tmp b/Scene/Tes888C.tmp new file mode 100644 index 0000000..b0dc8cc --- /dev/null +++ b/Scene/Tes888C.tmp @@ -0,0 +1,34 @@ +[gd_scene load_steps=4 format=3 uid="uid://bvam15obn13sp"] + +[ext_resource type="TileSet" uid="uid://btq4xft7ghfa1" path="res://Tilemaps/TestScene.tres" id="1_ppucb"] +[ext_resource type="Script" path="res://Scripts/NavigationTiles.gd" id="2_j8mqm"] +[ext_resource type="PackedScene" uid="uid://dy12im5456ufx" path="res://Scene/PlayerScene.tscn" id="3_hlgkw"] + +[node name="Node2D" type="Node2D"] + +[node name="Camera2D" type="Camera2D" parent="."] +scale = Vector2(1, 0.68) +offset = Vector2(84.925, 47.62) +zoom = Vector2(6.645, 6.645) + +[node name="NavigationMap" type="TileMap" parent="."] +texture_filter = 1 +tile_set = ExtResource("1_ppucb") +format = 2 +layer_0/name = "Background" +layer_0/tile_data = PackedInt32Array(65537, 524288, 0, 131073, 524288, 1, 196609, 524288, 1, 262145, 524288, 2, 327681, 1048576, 1610612740, 65538, 589824, 0, 131074, 589824, 1, 196610, 589824, 1, 262146, 589824, 2, 327682, 1048576, 1610612742, 65539, 589824, 0, 196611, 589824, 1, 262147, 589824, 2, 327683, 1048576, 1610612742, 65540, 589824, 0, 262148, 589824, 2, 327684, 1048576, 1610612742, 65541, 655360, 0, 131077, 655360, 1, 196613, 655360, 1, 262149, 655360, 2, 327685, 1048576, 1610612742, 65542, 1048576, 5, 131078, 1048576, 5, 196614, 1048576, 5, 262150, 1048576, 5, 327686, 1048576, 7, 0, 1048576, 4, 65536, 1048576, 5, 131072, 1048576, 5, 196608, 1048576, 5, 262144, 1048576, 5, 327680, 1048576, 7, 1, 1048576, 1610612740, 2, 1048576, 1610612742, 3, 1048576, 1610612742, 4, 1048576, 1610612742, 5, 1048576, 1610612742, 6, 1048576, 4, 131075, 589824, 1, 196612, 589824, 1, 131076, 589824, 1) +layer_1/name = "Object" +layer_1/tile_data = PackedInt32Array(131076, 3, 65536, 196610, 3, 131072) +layer_2/name = "ColisionMask" +layer_2/modulate = Color(1, 1, 1, 0) +layer_2/tile_data = PackedInt32Array(131076, 1048576, 5) +script = ExtResource("2_j8mqm") + +[node name="PlayerScene" parent="." instance=ExtResource("3_hlgkw")] +position = Vector2(24, 24) + +[connection signal="body_entered" from="NavigationMap/Crate" to="NavigationMap/Crate" method="_on_body_entered"] +[connection signal="body_exited" from="NavigationMap/Crate" to="NavigationMap/Crate" method="_on_body_exited"] +[connection signal="body_entered" from="NavigationMap/@Area2D@35587" to="NavigationMap/@Area2D@35587" method="_on_body_entered"] +[connection signal="body_exited" from="NavigationMap/@Area2D@35587" to="NavigationMap/@Area2D@35587" method="_on_body_exited"] +[connection signal="remove_interact" from="PlayerScene" to="PlayerScene" method="_on_remove_interact"] diff --git a/Scene/TestScene.tscn b/Scene/TestScene.tscn index c82abf5..6d3a6cd 100644 --- a/Scene/TestScene.tscn +++ b/Scene/TestScene.tscn @@ -18,7 +18,7 @@ format = 2 layer_0/name = "Background" layer_0/tile_data = PackedInt32Array(65537, 524288, 0, 131073, 524288, 1, 196609, 524288, 1, 262145, 524288, 2, 327681, 1048576, 1610612740, 65538, 589824, 0, 131074, 589824, 1, 196610, 589824, 1, 262146, 589824, 2, 327682, 1048576, 1610612742, 65539, 589824, 0, 196611, 589824, 1, 262147, 589824, 2, 327683, 1048576, 1610612742, 65540, 589824, 0, 262148, 589824, 2, 327684, 1048576, 1610612742, 65541, 655360, 0, 131077, 655360, 1, 196613, 655360, 1, 262149, 655360, 2, 327685, 1048576, 1610612742, 65542, 1048576, 5, 131078, 1048576, 5, 196614, 1048576, 5, 262150, 1048576, 5, 327686, 1048576, 7, 0, 1048576, 4, 65536, 1048576, 5, 131072, 1048576, 5, 196608, 1048576, 5, 262144, 1048576, 5, 327680, 1048576, 7, 1, 1048576, 1610612740, 2, 1048576, 1610612742, 3, 1048576, 1610612742, 4, 1048576, 1610612742, 5, 1048576, 1610612742, 6, 1048576, 4, 131075, 589824, 1, 196612, 589824, 1, 131076, 589824, 1) layer_1/name = "Object" -layer_1/tile_data = PackedInt32Array(131076, 3, 65536) +layer_1/tile_data = PackedInt32Array(131076, 3, 65536, 196610, 3, 131072) layer_2/name = "ColisionMask" layer_2/modulate = Color(1, 1, 1, 0) layer_2/tile_data = PackedInt32Array(131076, 1048576, 5) @@ -27,4 +27,4 @@ script = ExtResource("2_j8mqm") [node name="PlayerScene" parent="." instance=ExtResource("3_hlgkw")] position = Vector2(24, 24) -[connection signal="body_entered" from="NavigationMap/Crate" to="NavigationMap/Crate" method="_on_body_entered"] +[connection signal="remove_interact" from="PlayerScene" to="PlayerScene" method="_on_remove_interact"] diff --git a/Scripts/Interactibles/Crate.gd b/Scripts/Interactibles/Crate.gd index 747911c..b1976ce 100644 --- a/Scripts/Interactibles/Crate.gd +++ b/Scripts/Interactibles/Crate.gd @@ -1,9 +1,15 @@ -extends Interactible +extends ItemContainer # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + var firstitem = Item.new() + firstitem.name = "rouge" + firstitem.Icon = Sprite2D.new() + firstitem.Icon.set_texture(preload("res://Sprite/IMG_0156.PNG")) + firstitem.Icon.set_texture_filter(CanvasItem.TEXTURE_FILTER_NEAREST) + + items.append(firstitem) # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -12,7 +18,8 @@ func _process(delta): func _on_body_entered(body : Player): - body.can_interact.emit(Interact_Type,self) + body.can_interact.emit(self) - +func _on_body_exited(body: Player): + body.remove_interact.emit() # Replace with function body. diff --git a/Scripts/Interactibles/InteractibleClass.gd b/Scripts/Interactibles/InteractibleClass.gd index cce2075..cade0a2 100644 --- a/Scripts/Interactibles/InteractibleClass.gd +++ b/Scripts/Interactibles/InteractibleClass.gd @@ -1,6 +1,4 @@ class_name Interactible extends Area2D -@export -var Interact_Type = "none" diff --git a/Scripts/Interactibles/Item.gd b/Scripts/Interactibles/Item.gd new file mode 100644 index 0000000..06f7702 --- /dev/null +++ b/Scripts/Interactibles/Item.gd @@ -0,0 +1,5 @@ +class_name Item extends Node + +var Name : String = "none" + +var Icon : Sprite2D diff --git a/Scripts/Interactibles/Item_Container.gd b/Scripts/Interactibles/Item_Container.gd new file mode 100644 index 0000000..60a6326 --- /dev/null +++ b/Scripts/Interactibles/Item_Container.gd @@ -0,0 +1,17 @@ +class_name ItemContainer extends Interactible + + +@export +var items : Array[Item] + + +func pop_item(index: int = 0): + pass + + +func add_item(item: Item): + pass + + + + diff --git a/Scripts/Interactibles/Item_Processor.gd b/Scripts/Interactibles/Item_Processor.gd new file mode 100644 index 0000000..c1916aa --- /dev/null +++ b/Scripts/Interactibles/Item_Processor.gd @@ -0,0 +1,8 @@ +class_name ItemProcessor extends ItemContainer + + +@export_group("Processor config") +@export var duration : int = 0 +@export var duration_type : DURATION_TYPE + +enum DURATION_TYPE {Instant, AP, Turn} diff --git a/Scripts/PlayerControler.gd b/Scripts/PlayerControler.gd index b517b79..0665838 100644 --- a/Scripts/PlayerControler.gd +++ b/Scripts/PlayerControler.gd @@ -3,7 +3,16 @@ class_name Player @onready var gridcontrol: TileMap = $"../NavigationMap" +signal can_interact(object : Interactible) +signal remove_interact() + var current_path : Array[Vector2i] + +var object_near : Interactible +var can_interact_flag : bool + +var held_item : Item + # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. @@ -31,9 +40,35 @@ func _unhandled_input(event): gridcontrol.local_to_map(click_position) ).slice(1) -signal can_interact(object : String) +func _shortcut_input(event): + if event.is_action_pressed("interact") && can_interact_flag: + if object_near is ItemContainer : + if not object_near.items.is_empty() && held_item == null: + held_item = object_near.items[0] + object_near.pop_item(0) + _add_item_overhead() + else : + object_near.add_item(held_item) + remove_child(held_item) + remove_child(held_item.Icon) + held_item = null -func _on_can_interact(Interact_Type: String, object : Interactible): - prints("yippie", Interact_Type) +func _on_can_interact(object : Interactible): + can_interact_flag = true + object_near = object + + +func _on_remove_interact(): + can_interact_flag = false + object_near = null + + +func _add_item_overhead() : + add_child(held_item) + add_child(held_item.Icon) + held_item.Icon.set_scale(Vector2(0.5,0.5)) + held_item.Icon.offset = Vector2i(0,-10) + held_item.Icon.modulate = Color(1,1,1,0.4) + diff --git a/Scripts/Shelf.gd b/Scripts/Shelf.gd new file mode 100644 index 0000000..35dfe11 --- /dev/null +++ b/Scripts/Shelf.gd @@ -0,0 +1,18 @@ +extends ItemProcessor + + +# 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 _process(delta): + pass + +func _on_body_entered(body : Player): + body.can_interact.emit(self) + + +func _on_body_exited(body: Player): + body.remove_interact.emit() # Replace with function body. diff --git a/Sprite/IMG_0156.PNG b/Sprite/IMG_0156.PNG new file mode 100644 index 0000000000000000000000000000000000000000..a80b67297dc5a53111352271f71edbbe431e7a99 GIT binary patch literal 2010 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=hEVFq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