@@ -6,8 +6,6 @@ signal player_updated(player: Player)
|
||||
var planet : Planet # mis à jour par la classe Planet
|
||||
@export var speed = 400
|
||||
|
||||
@export var testPlantType : PlantType
|
||||
|
||||
@onready var inventory : Inventory = Inventory.new()
|
||||
|
||||
var max_energy : int = 10
|
||||
@@ -23,6 +21,12 @@ var closest_interactable : Interactable = null :
|
||||
closest_interactable = v
|
||||
if old != closest_interactable:
|
||||
player_updated.emit(self)
|
||||
var can_use_item : bool = false :
|
||||
set(v):
|
||||
var old = can_use_item
|
||||
can_use_item = v
|
||||
if old != can_use_item:
|
||||
player_updated.emit(self)
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
@@ -40,8 +44,9 @@ func get_input():
|
||||
var old_velocity=velocity
|
||||
calculate_direction()
|
||||
|
||||
if Input.is_action_just_pressed("action") and energy > 0:
|
||||
action()
|
||||
can_use_item = inventory.lenght() != 0 and inventory.get_item().can_use(self)
|
||||
if Input.is_action_just_pressed("action"):
|
||||
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:
|
||||
@@ -56,12 +61,17 @@ func calculate_direction():
|
||||
if input_direction.x:
|
||||
$Sprite.flip_h = (input_direction.x < 0)
|
||||
|
||||
func action():
|
||||
if planet:
|
||||
planet.plant(
|
||||
testPlantType,
|
||||
global_position
|
||||
)
|
||||
func try_use_item():
|
||||
if energy > 0 and can_use_item:
|
||||
use_item()
|
||||
|
||||
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()
|
||||
|
||||
func pass_day():
|
||||
energy = max_energy
|
||||
@@ -94,4 +104,4 @@ func _on_root_gui_day_pass_finished():
|
||||
controlling_player = true
|
||||
|
||||
func _on_root_gui_game_click():
|
||||
action()
|
||||
try_use_item()
|
||||
|
||||
Reference in New Issue
Block a user