ajout de la possibilité d'avoir des items utilisable sans se déplacer

This commit is contained in:
2026-02-26 19:52:46 +01:00
parent 6a0e7c6ca7
commit a4662f2797
4 changed files with 31 additions and 14 deletions

View File

@@ -33,6 +33,9 @@ func get_energy_used() -> int:
func get_usage_zone_radius() -> int: func get_usage_zone_radius() -> int:
return usage_zone_radius return usage_zone_radius
func is_usage_need_proximity() -> bool:
return true
func get_usage_object_affected(_i : InspectableEntity) -> bool: func get_usage_object_affected(_i : InspectableEntity) -> bool:
return false return false

View File

@@ -19,6 +19,9 @@ func get_energy_used() -> int:
func get_usage_zone_radius() -> int: func get_usage_zone_radius() -> int:
return 0 return 0
func is_usage_need_proximity() -> bool:
return false
func can_use(_player : Player, _zone: Player.ActionZone) -> bool: func can_use(_player : Player, _zone: Player.ActionZone) -> bool:
return true return true

View File

@@ -11,7 +11,7 @@ func get_description() -> String:
return tr("SHIP_TELEPORT_DESC_TEXT") return tr("SHIP_TELEPORT_DESC_TEXT")
func get_icon() -> Texture2D: func get_icon() -> Texture2D:
return preload("res://common/icons/chevrons-up.svg") return preload("res://common/icons/rocket.svg")
func get_energy_used() -> int: func get_energy_used() -> int:
return 0 return 0
@@ -19,6 +19,9 @@ func get_energy_used() -> int:
func get_usage_zone_radius() -> int: func get_usage_zone_radius() -> int:
return 0 return 0
func is_usage_need_proximity() -> bool:
return false
func can_use(_player : Player, _zone: Player.ActionZone) -> bool: func can_use(_player : Player, _zone: Player.ActionZone) -> bool:
return true return true

View File

@@ -59,7 +59,8 @@ func _end_pass_day():
func _process(delta): func _process(delta):
last_action_area_movement_timer += delta last_action_area_movement_timer += delta
if controlling_player: if controlling_player:
calculate_direction()
var input_direction : Vector2 = calculate_direction_input_direction()
if ( if (
last_action_area_movement_timer >= ACTION_AREA_UPDATE_TIME last_action_area_movement_timer >= ACTION_AREA_UPDATE_TIME
@@ -67,6 +68,15 @@ func _process(delta):
): ):
instruction.do(self) instruction.do(self)
instruction = null instruction = null
if instruction and instruction.need_movement:
if input_direction.length() != 0:
instruction = null
input_direction = calculate_direction_instruction_direction()
velocity = input_direction * speed
turn_animate(input_direction)
move_preview_zone(get_global_mouse_position()) move_preview_zone(get_global_mouse_position())
else: else:
velocity = Vector2.ZERO velocity = Vector2.ZERO
@@ -76,12 +86,7 @@ func _on_inventory_updated(_inventory: Inventory):
setup_preview_zone(data.inventory.get_item()) setup_preview_zone(data.inventory.get_item())
emit_signal("player_updated", self) emit_signal("player_updated", self)
func calculate_direction(): func calculate_direction_instruction_direction() -> Vector2:
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if input_direction.length() != 0:
instruction = null
if ( if (
instruction instruction
and ( and (
@@ -89,11 +94,11 @@ func calculate_direction():
or instruction is MoveInstruction or instruction is MoveInstruction
) )
): ):
input_direction = self.global_position.direction_to(instruction.position) return self.global_position.direction_to(instruction.position)
return Vector2.ZERO
velocity = input_direction * speed func calculate_direction_input_direction() -> Vector2:
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
turn_animate(input_direction)
func turn_animate(input_direction): func turn_animate(input_direction):
@@ -243,6 +248,7 @@ func move_preview_zone(zone_position : Vector2):
class Instruction: class Instruction:
var position : Vector2 var position : Vector2
var need_movement : bool = true
func _init(_pos : Vector2): func _init(_pos : Vector2):
position = _pos position = _pos
@@ -259,14 +265,16 @@ class MoveInstruction extends Instruction:
class ItemActionInstruction extends Instruction: class ItemActionInstruction extends Instruction:
var item = Item var item : Item
func _init(_pos : Vector2, _item : Item): func _init(_pos : Vector2, _item : Item):
position = _pos position = _pos
item = _item item = _item
need_movement = item.is_usage_need_proximity()
func can_be_done(player : Player): func can_be_done(player : Player):
return ( return (
not item.is_usage_need_proximity() or
player.global_position.distance_to(position) < player.MAX_REACH player.global_position.distance_to(position) < player.MAX_REACH
) )
@@ -274,7 +282,7 @@ class ItemActionInstruction extends Instruction:
player.use_item(item) player.use_item(item)
class InteractableInstruction extends Instruction: class InteractableInstruction extends Instruction:
var interactable = Interactable var interactable : Interactable
func _init(_interactable : Interactable): func _init(_interactable : Interactable):
interactable = _interactable interactable = _interactable