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