ajout du détecteur et liaison entre les scènes

This commit is contained in:
2026-02-20 01:00:55 +01:00
parent dc1a6686bc
commit fb8a2da4ff
42 changed files with 737 additions and 418 deletions

View File

@@ -9,7 +9,8 @@ signal clicked
@export var audio_player : AudioStreamPlayer3D
func click():
clicked.emit()
if interactable:
clicked.emit()
func _ready():
if audio_player:

View File

@@ -0,0 +1,22 @@
[gd_scene format=3 uid="uid://b8m537op75gib"]
[ext_resource type="Script" uid="uid://bmxuqj0c6h60d" path="res://entities/interactables/door/script/door.gd" id="1_8kdwv"]
[sub_resource type="Gradient" id="Gradient_8kdwv"]
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_oarg0"]
gradient = SubResource("Gradient_8kdwv")
[sub_resource type="RectangleShape2D" id="RectangleShape2D_y51rk"]
size = Vector2(64, 64)
[node name="Door" type="Area2D" unique_id=2053096538]
script = ExtResource("1_8kdwv")
metadata/_custom_type_script = "uid://dyprcd68fjstf"
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=874210487]
texture = SubResource("GradientTexture2D_oarg0")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1809395872]
shape = SubResource("RectangleShape2D_y51rk")

View File

@@ -0,0 +1,19 @@
@tool
extends Interactable
class_name Door
@export var to_scene_id = ""
func _ready():
modulate = Color.WHITE if available else Color.RED
func interact(_p : Player) -> bool:
if available and to_scene_id:
interacted.emit(_p)
SceneManager.change_to_scene_id(to_scene_id)
return available
func set_available(v : bool):
available = v
modulate = Color.WHITE if available else Color.RED

View File

@@ -0,0 +1 @@
uid://bmxuqj0c6h60d

View File

@@ -5,7 +5,7 @@ signal interacted(p: Player)
@export var default_interact_text = ""
var available : bool = true
@export var available : bool = true : set = set_available
func interact_text() -> String:
return default_interact_text
@@ -29,3 +29,6 @@ func generate_collision(area_width : float) -> CollisionShape2D:
add_child(collision)
return collision
func set_available(v : bool):
available = v

View File

@@ -9,6 +9,8 @@ signal updated(inventory: Inventory)
func _init(inventory_size: int = 1):
set_size(inventory_size)
add_item(Detector.new())
add_item(Shovel.new())
func get_n_item_slots() -> int:
return items.size() - n_tools

View File

@@ -0,0 +1,33 @@
extends Item
class_name Detector
func get_item_name() -> String:
return tr("DETECTOR")
func get_item_type() -> ItemType:
return Item.ItemType.TOOL_ITEM
func get_description() -> String:
return tr("DETECTOR_DESC_TEXT")
func get_icon() -> Texture2D:
return preload("res://common/icons/broadcast.svg")
func get_energy_used() -> int:
return 0
func get_usage_zone_radius() -> int:
return 0
func can_use(_player : Player, _zone: Player.ActionZone) -> bool:
return true
func use_text() -> String:
return tr("DETECT_USE_TEXT")
func use(player : Player, zone: Player.ActionZone):
var detector_signal := DetectorSignal.new(player.region, zone.get_global_position())
detector_signal.global_position = zone.get_global_position()
player.region.add_child(detector_signal)
AudioManager.play_sfx("Signal")

View File

@@ -0,0 +1 @@
uid://cok1wowc6uqmj

View File

@@ -12,6 +12,9 @@ func get_description() -> String:
func get_icon() -> Texture2D:
return preload("res://common/icons/fork.svg")
func get_item_type() -> ItemType:
return Item.ItemType.TOOL_ITEM
func get_energy_used() -> int:
return 1

View File

@@ -6,9 +6,6 @@ const TROWEL_ZONE_RADIUS = 50
func get_item_name() -> String:
return tr("TROWEL")
func get_item_type() -> ItemType:
return Item.ItemType.TOOL_ITEM
func get_description() -> String:
return tr("TROWEL_DESC_TEXT")

View File

@@ -0,0 +1,61 @@
@tool
extends Node2D
class_name DetectorSignal
const SIGNAL_DURATION = 1
const PARTICLES_DISTANCE = 100
const DEFAULT_ICON = preload("res://common/icons/north-star.svg")
const ENERGY_ICON = preload("res://common/icons/bolt.svg")
var started_time = 0.
var signals : Array[DetectorSignalIndividual] = []
@export_tool_button("Start", "Callable") var start = func(): started_time = 0
func _init(region : Region, pos : Vector2):
for e in region.entity_container.get_children():
if e is TruckRecharge:
print(pos)
print(e.global_position)
print(e.global_position.angle_to(pos))
signals.append(
DetectorSignalIndividual.new(
(pos - e.global_position).normalized().angle(),
ENERGY_ICON
)
)
func _draw():
if started_time < SIGNAL_DURATION:
draw_circle(
Vector2.ZERO,
started_time/SIGNAL_DURATION * PARTICLES_DISTANCE,
Color(1.,1.,1.,0.5*1-started_time/SIGNAL_DURATION),
false,
5.
)
for s in signals:
draw_texture(
s.icon,
Vector2.ZERO - DEFAULT_ICON.get_size()/2 + Vector2.LEFT.rotated(s.angle) * started_time/SIGNAL_DURATION * PARTICLES_DISTANCE,
Color(1.,1.,1.,1-started_time/SIGNAL_DURATION)
)
func _process(delta):
if started_time < SIGNAL_DURATION:
started_time += delta
queue_redraw()
else:
queue_free()
class DetectorSignalIndividual:
var angle : float
var icon : Texture
func _init(
_angle : float = 0.,
_icon : Texture = DEFAULT_ICON
):
angle = _angle
icon = _icon

View File

@@ -0,0 +1 @@
uid://c0sivthidxafm