#40 developpement de l'enclenchement des sfx
This commit is contained in:
parent
49e16d12f8
commit
5d0104d029
@ -14,5 +14,5 @@ func can_use(_player : Player) -> bool:
|
||||
func use_requirement_text() -> String:
|
||||
return ""
|
||||
|
||||
func use(_player : Player) -> bool:
|
||||
func use(_player : Player):
|
||||
return false
|
||||
@ -22,4 +22,5 @@ func can_use(player : Player) -> bool:
|
||||
func use(player : Player) -> bool:
|
||||
if not can_use(player):
|
||||
return false
|
||||
player.play_sfx("dig")
|
||||
return player.planet.plant(plant_type, player.global_position)
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
extends ToolItem
|
||||
class_name Shovel
|
||||
|
||||
const USE_INTERVAL = 0.15
|
||||
|
||||
func can_use(player : Player) -> bool:
|
||||
var areas = player.action_area.get_overlapping_areas()
|
||||
for area in areas :
|
||||
@ -12,10 +14,19 @@ func use(player : Player) -> bool:
|
||||
if not can_use(player):
|
||||
return false
|
||||
|
||||
var areas = player.action_area.get_overlapping_areas()
|
||||
dig(
|
||||
player.action_area.get_overlapping_areas(),
|
||||
player
|
||||
)
|
||||
|
||||
return true
|
||||
|
||||
func dig(areas: Array[Area2D], player: Player):
|
||||
for area in areas :
|
||||
if area is Plant:
|
||||
player.play_sfx("harvest")
|
||||
area.harvest()
|
||||
if area is UndergroundLoot:
|
||||
player.play_sfx("dig")
|
||||
area.dig()
|
||||
return true
|
||||
await player.get_tree().create_timer(USE_INTERVAL).timeout
|
||||
@ -22,6 +22,7 @@ func interact(p : Player) -> bool:
|
||||
if not can_interact(p):
|
||||
return false
|
||||
|
||||
p.play_sfx("harvest")
|
||||
p.delete_item()
|
||||
fill_value += value_per_seed
|
||||
if fill_value >= 1.:
|
||||
|
||||
@ -45,6 +45,24 @@ func _ready():
|
||||
emit_signal("player_updated", self)
|
||||
inventory.inventory_changed.connect(_on_inventory_updated)
|
||||
|
||||
# Méthode déclenchée par la classe planet
|
||||
func _pass_day():
|
||||
energy = max_energy
|
||||
|
||||
func _process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
detect_closest_interactable()
|
||||
|
||||
func _on_root_gui_day_pass_pressed():
|
||||
controlling_player = false
|
||||
|
||||
func _on_root_gui_day_pass_finished():
|
||||
controlling_player = true
|
||||
|
||||
func _on_root_gui_game_click():
|
||||
try_use_item()
|
||||
|
||||
func _on_inventory_updated(_inventory: Inventory):
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
@ -64,7 +82,7 @@ func get_input():
|
||||
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()
|
||||
play_sfx("move")
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
@ -83,27 +101,25 @@ func get_item(item : Item):
|
||||
inventory.set_item(item)
|
||||
if item is ToolItem:
|
||||
add_action_area(item.generate_action_area())
|
||||
play_sfx("pick")
|
||||
|
||||
func drop_item():
|
||||
var item_to_drop = inventory.pop_item()
|
||||
planet.drop_item(item_to_drop, global_position)
|
||||
remove_action_area()
|
||||
play_sfx("pick")
|
||||
|
||||
func delete_item():
|
||||
inventory.set_item(null)
|
||||
remove_action_area()
|
||||
|
||||
func use_item():
|
||||
var item = inventory.get_item()
|
||||
var item : Item = inventory.get_item()
|
||||
var is_item_used = item.use(self)
|
||||
if is_item_used:
|
||||
energy -= 1
|
||||
if item.is_one_time_use():
|
||||
delete_item()
|
||||
|
||||
# Méthode déclenchée par la classe planet
|
||||
func _pass_day():
|
||||
energy = max_energy
|
||||
|
||||
func detect_closest_interactable():
|
||||
var in_range_interactables : Array[Interactable] = []
|
||||
@ -134,16 +150,13 @@ func upgrade():
|
||||
energy += 1
|
||||
upgraded.emit()
|
||||
|
||||
func _process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
detect_closest_interactable()
|
||||
|
||||
func _on_root_gui_day_pass_pressed():
|
||||
controlling_player = false
|
||||
|
||||
func _on_root_gui_day_pass_finished():
|
||||
controlling_player = true
|
||||
|
||||
func _on_root_gui_game_click():
|
||||
try_use_item()
|
||||
func play_sfx(sound : String):
|
||||
match sound:
|
||||
"dig":
|
||||
$Audio/AudioStreamPlayer_dig.play()
|
||||
"harvest":
|
||||
$Audio/AudioStreamPlayer_harvest.play()
|
||||
"pick":
|
||||
$Audio/AudioStreamPlayer_pick_up.play()
|
||||
"move":
|
||||
$Audio/AudioStreamPlayer_movement.play()
|
||||
|
||||
@ -23,4 +23,3 @@ func stop_inspect_entity(entity : InspectableEntity):
|
||||
if inspected_entity == entity:
|
||||
%InspectorText.visible = false
|
||||
inspected_entity = null
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user