ajout des mutation et refonte de l'inspecteur
* ajout des mutations #86 * changement de l'objectif #85 * refonte de l'inspecteur #71 * changement léger de la plantation * les plantes ne donnent que des graines de leurs espèces * refonte partielle du code, refacto
This commit is contained in:
@@ -27,8 +27,8 @@ var energy : int = max_energy :
|
||||
player_updated.emit(self)
|
||||
|
||||
@onready var inventory : Inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)
|
||||
@onready var preview_zone : Area2D = null
|
||||
@onready var action_zone : Area2D = null
|
||||
@onready var preview_zone : ActionZone = null
|
||||
@onready var action_zone : ActionZone = null
|
||||
|
||||
func _ready():
|
||||
player_updated.emit(self)
|
||||
@@ -126,9 +126,9 @@ func try_move(move_to : Vector2):
|
||||
func pick_item(item : Item) -> Item:
|
||||
play_sfx("pick")
|
||||
if inventory.length() >= inventory.size:
|
||||
var currentItem : Item = inventory.get_item()
|
||||
var current_item : Item = inventory.get_item()
|
||||
inventory.set_item(item, inventory.current_item_ind)
|
||||
return currentItem
|
||||
return current_item
|
||||
else :
|
||||
inventory.add_item(item)
|
||||
return null
|
||||
@@ -153,7 +153,7 @@ func try_use_item(item : Item, use_position : Vector2):
|
||||
func preview_can_use_item(item : Item) -> bool:
|
||||
return can_use_item_on_zone(item, preview_zone)
|
||||
|
||||
func can_use_item_on_zone(item : Item, zone: Area2D) -> bool:
|
||||
func can_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
|
||||
return (
|
||||
inventory.has_item(item)
|
||||
and (energy - item.energy_usage) >= 0
|
||||
@@ -185,43 +185,29 @@ func recharge(amount : int = max_energy):
|
||||
func full_recharge():
|
||||
energy = max(energy, max_energy)
|
||||
|
||||
func generate_action_zone(radius : int = 0) -> Area2D:
|
||||
var area2D = Area2D.new()
|
||||
var collision_shape = CollisionShape2D.new()
|
||||
var circle_shape = CircleShape2D.new()
|
||||
func generate_action_zone(radius : int = 0) -> ActionZone:
|
||||
var zone = ActionZone.new(radius)
|
||||
|
||||
circle_shape.radius = radius
|
||||
collision_shape.shape = circle_shape
|
||||
area2D.add_child(collision_shape)
|
||||
get_parent().add_child(zone.area)
|
||||
|
||||
get_parent().add_child(area2D)
|
||||
return zone
|
||||
|
||||
return area2D
|
||||
|
||||
func setup_preview_zone(zone_radius : int) -> Area2D:
|
||||
func setup_preview_zone(zone_radius : int) -> ActionZone:
|
||||
if preview_zone:
|
||||
preview_zone.queue_free()
|
||||
preview_zone.destroy()
|
||||
preview_zone = generate_action_zone(zone_radius)
|
||||
return preview_zone
|
||||
|
||||
func setup_action_zone(zone_position : Vector2, zone_radius : int) -> Area2D:
|
||||
func setup_action_zone(zone_position : Vector2, zone_radius : int) -> ActionZone:
|
||||
if action_zone:
|
||||
action_zone.queue_free()
|
||||
action_zone.destroy()
|
||||
action_zone = generate_action_zone(zone_radius)
|
||||
action_zone.global_position = zone_position
|
||||
action_zone.area.global_position = zone_position
|
||||
return action_zone
|
||||
|
||||
func move_preview_zone(zone_position : Vector2):
|
||||
if preview_zone:
|
||||
preview_zone.global_position = zone_position
|
||||
|
||||
func detect_area_in_preview_zone() -> Array:
|
||||
return preview_zone.get_overlapping_areas()
|
||||
|
||||
func detect_area_in_action_zone() -> Array:
|
||||
if action_zone:
|
||||
return action_zone.get_overlapping_areas()
|
||||
return []
|
||||
preview_zone.move_to_position(zone_position)
|
||||
|
||||
func play_sfx(sound : String):
|
||||
match sound:
|
||||
@@ -277,3 +263,37 @@ class InteractableInstruction extends Instruction:
|
||||
|
||||
func do(player : Player):
|
||||
interactable.interact(player)
|
||||
|
||||
class ActionZone:
|
||||
var radius : int = 10
|
||||
var area : Area2D
|
||||
|
||||
func _init(_r : int):
|
||||
radius = _r
|
||||
area = Area2D.new()
|
||||
var collision_shape = CollisionShape2D.new()
|
||||
var circle_shape = CircleShape2D.new()
|
||||
|
||||
circle_shape.radius = radius
|
||||
collision_shape.shape = circle_shape
|
||||
area.add_child(collision_shape)
|
||||
|
||||
func destroy():
|
||||
area.queue_free()
|
||||
|
||||
func get_global_position() -> Vector2:
|
||||
return Vector2.ZERO if area == null else area.global_position
|
||||
|
||||
func move_to_position(pos : Vector2):
|
||||
if area:
|
||||
area.global_position = pos
|
||||
|
||||
func get_points_in_zone(point_factor = 10) -> Array[Vector2]:
|
||||
var points : Array[Vector2] = []
|
||||
for x in range(-radius, radius, point_factor):
|
||||
for y in range(-radius, radius, point_factor):
|
||||
if Vector2(x, y).length() <= radius:
|
||||
points.append(area.global_position + Vector2(x, y))
|
||||
|
||||
return points
|
||||
|
||||
|
||||
Reference in New Issue
Block a user