#24 et #21 ajout d'une plante générique, et d'un cycle de recharge du robot avec croissance des plantes
This commit is contained in:
@@ -3,10 +3,15 @@ class_name Player
|
||||
|
||||
signal player_stats_updated(player : Player)
|
||||
|
||||
var controlling_player : bool = true
|
||||
var planet : Planet # mis à jour par la classe Planet
|
||||
@export var speed = 400
|
||||
|
||||
var energy : int = 10 :
|
||||
@export var testPlantType : PlantType
|
||||
|
||||
var max_energy : int = 10
|
||||
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
emit_signal("player_stats_updated", self)
|
||||
@@ -15,10 +20,11 @@ func _ready():
|
||||
emit_signal("player_stats_updated", self)
|
||||
|
||||
func get_input():
|
||||
calculate_direction()
|
||||
if controlling_player:
|
||||
calculate_direction()
|
||||
|
||||
if Input.is_action_just_pressed("interact") and energy > 0:
|
||||
try_interact()
|
||||
if Input.is_action_just_pressed("action") and energy > 0:
|
||||
action()
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
@@ -26,24 +32,25 @@ func calculate_direction():
|
||||
if input_direction.x:
|
||||
$Sprite.flip_h = (input_direction.x < 0)
|
||||
|
||||
func try_interact():
|
||||
var interactables : Array[Interactable]
|
||||
|
||||
for area2D in $InteractArea2D.get_overlapping_areas():
|
||||
if area2D is Interactable:
|
||||
interactables.push_front(area2D)
|
||||
func action():
|
||||
if planet:
|
||||
planet.plant(
|
||||
testPlantType,
|
||||
global_position
|
||||
)
|
||||
|
||||
if len(interactables):
|
||||
if len(interactables) > 1:
|
||||
# Sort them to the closer
|
||||
interactables.sort_custom(
|
||||
func (el1 : Interactable, el2 : Interactable):
|
||||
return el1.global_position.distance_to(global_position) > el2.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
interactables[0].interact(self)
|
||||
energy -= 1
|
||||
func pass_day():
|
||||
energy = max_energy
|
||||
|
||||
func _physics_process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
|
||||
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():
|
||||
action()
|
||||
|
||||
Reference in New Issue
Block a user