#37 ajout d'item outils ainsi que de visualisation de leur zone d'effet (avec la classe ActionArea
This commit is contained in:
@@ -31,6 +31,7 @@ var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
emit_signal("player_updated", self)
|
||||
var action_area : ActionArea = null
|
||||
|
||||
func _ready():
|
||||
emit_signal("player_updated", self)
|
||||
@@ -44,14 +45,15 @@ func get_input():
|
||||
var old_velocity=velocity
|
||||
calculate_direction()
|
||||
|
||||
can_use_item = inventory.lenght() != 0 and inventory.get_item().can_use(self)
|
||||
can_use_item = inventory.get_item() and inventory.get_item().can_use(self)
|
||||
if action_area:
|
||||
action_area.activated = can_use_item
|
||||
if Input.is_action_just_pressed("action"):
|
||||
use_item()
|
||||
try_use_item()
|
||||
if Input.is_action_just_pressed("interact") and closest_interactable:
|
||||
closest_interactable.interact(self)
|
||||
if Input.is_action_just_pressed("drop") and inventory.lenght() > 0:
|
||||
var item_to_drop = inventory.pop_item()
|
||||
planet.drop_item(item_to_drop, global_position)
|
||||
if Input.is_action_just_pressed("drop") and inventory.get_item():
|
||||
drop_item()
|
||||
if old_velocity.length()==0 and velocity.length()!=0:
|
||||
$Audio/AudioStreamPlayer_movement.play()
|
||||
|
||||
@@ -65,13 +67,29 @@ func try_use_item():
|
||||
if energy > 0 and can_use_item:
|
||||
use_item()
|
||||
|
||||
func get_item(item : Item):
|
||||
remove_action_area()
|
||||
inventory.set_item(item)
|
||||
if item is ToolItem:
|
||||
add_action_area(item.generate_action_area())
|
||||
|
||||
func drop_item():
|
||||
var item_to_drop = inventory.pop_item()
|
||||
planet.drop_item(item_to_drop, global_position)
|
||||
remove_action_area()
|
||||
|
||||
func delete_item():
|
||||
inventory.set_item(null)
|
||||
remove_action_area()
|
||||
|
||||
func use_item():
|
||||
var item = inventory.get_item()
|
||||
var is_item_used = item.use(self)
|
||||
if is_item_used:
|
||||
energy -= 1
|
||||
if item.is_one_time_use():
|
||||
inventory.pop_item()
|
||||
delete_item()
|
||||
|
||||
|
||||
func pass_day():
|
||||
energy = max_energy
|
||||
@@ -92,6 +110,14 @@ func detect_closest_interactable():
|
||||
else :
|
||||
closest_interactable = null
|
||||
|
||||
func add_action_area(area : ActionArea):
|
||||
action_area = area
|
||||
add_child(action_area)
|
||||
|
||||
func remove_action_area():
|
||||
if (action_area):
|
||||
remove_child(action_area)
|
||||
|
||||
func _process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
|
||||
Reference in New Issue
Block a user