ajout du détecteur et liaison entre les scènes
This commit is contained in:
@@ -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
|
||||
|
||||
33
entities/player/inventory/scripts/items/detector.gd
Normal file
33
entities/player/inventory/scripts/items/detector.gd
Normal 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")
|
||||
1
entities/player/inventory/scripts/items/detector.gd.uid
Normal file
1
entities/player/inventory/scripts/items/detector.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cok1wowc6uqmj
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://c0sivthidxafm
|
||||
Reference in New Issue
Block a user