#13 suite du developpement d'inventaire avec le rajout des ItemObjects, description sur le GUI, items d'exemple et corrections mineures
This commit was merged in pull request #35.
This commit is contained in:
@@ -13,16 +13,16 @@ radius = 40.0
|
||||
script = ExtResource("1_abrql")
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
position = Vector2(2, -20)
|
||||
position = Vector2(2, -55)
|
||||
scale = Vector2(0.084375, 0.084375)
|
||||
texture = ExtResource("1_symyc")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-2, 15)
|
||||
position = Vector2(-2, -20)
|
||||
shape = SubResource("CircleShape2D_sglur")
|
||||
|
||||
[node name="InteractArea2D" type="Area2D" parent="."]
|
||||
position = Vector2(0, 21)
|
||||
position = Vector2(0, -14)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractArea2D"]
|
||||
shape = SubResource("CircleShape2D_abrql")
|
||||
|
||||
@@ -3,14 +3,26 @@ class_name Player
|
||||
|
||||
signal player_updated(player: Player)
|
||||
|
||||
var controlling_player : bool = true
|
||||
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
|
||||
|
||||
var controlling_player : bool = true :
|
||||
set(v):
|
||||
controlling_player = v
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
var closest_interactable : Interactable = null :
|
||||
set(v):
|
||||
var old = closest_interactable
|
||||
closest_interactable = v
|
||||
if old != closest_interactable:
|
||||
player_updated.emit(self)
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
@@ -29,6 +41,11 @@ func get_input():
|
||||
|
||||
if Input.is_action_just_pressed("action") and energy > 0:
|
||||
action()
|
||||
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:
|
||||
var item_to_drop = inventory.pop_item()
|
||||
planet.drop_item(item_to_drop, global_position)
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
@@ -46,9 +63,26 @@ func action():
|
||||
func pass_day():
|
||||
energy = max_energy
|
||||
|
||||
func _physics_process(_delta):
|
||||
func detect_closest_interactable():
|
||||
var in_range_interactables : Array[Interactable] = []
|
||||
for area in $InteractArea2D.get_overlapping_areas():
|
||||
if area is Interactable and area.available:
|
||||
in_range_interactables.append(area)
|
||||
|
||||
in_range_interactables.sort_custom(
|
||||
func(a : Node2D, b : Node2D) :
|
||||
return a.global_position.distance_to(global_position) > b.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
if len(in_range_interactables) > 0:
|
||||
closest_interactable = in_range_interactables[0]
|
||||
else :
|
||||
closest_interactable = null
|
||||
|
||||
func _process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
detect_closest_interactable()
|
||||
|
||||
func _on_root_gui_day_pass_pressed():
|
||||
controlling_player = false
|
||||
|
||||
Reference in New Issue
Block a user