ajout d'un terrain infini et la possibilité de planter n'importe où

This commit is contained in:
2025-11-30 16:53:07 +01:00
parent 72ffa0b222
commit 8917a02a7b
63 changed files with 2847 additions and 1190 deletions

View File

@@ -0,0 +1,41 @@
extends Item
class_name Pickaxe
const USE_INTERVAL = 0.15
func get_item_name() -> String:
return tr("PICKAXE")
func get_description() -> String:
return tr("PICKAXE_DESC_TEXT")
func get_icon() -> Texture2D:
return preload("res://common/icons/pick.svg")
func get_energy_used() -> int:
return 1
func get_usage_zone_radius() -> int:
return 50
func use_text() -> String:
return tr("DIG")
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
if zone and zone.area:
var bodies = zone.area.get_overlapping_bodies()
for body in bodies :
if body is RockLayer:
return true
return false
func use(_player : Player, zone : Player.ActionZone) -> bool:
var bodies = zone.area.get_overlapping_bodies()
var rock_layer_id = bodies.find_custom(func (b) : return b is RockLayer)
if rock_layer_id != -1:
var rock_layer : RockLayer = bodies[rock_layer_id]
return rock_layer.dig_rocks(zone.get_tiles())
return false

View File

@@ -0,0 +1 @@
uid://ctucfh72pxut8

View File

@@ -11,192 +11,191 @@ const SCORE_ICON = preload("res://common/icons/growth.svg")
@export var plant_mutations: Array[PlantMutation]
func get_item_name() -> String:
return tr("%s_SEED") % plant_type.name
return tr("%s_SEED") % plant_type.name
func get_description() -> String:
return tr("PLANT_%s_MUST_BE_USED_IN_DECONTAMINATED_ZONE") % plant_type.name
return tr("PLANT_%s_MUST_BE_USED_IN_DECONTAMINATED_ZONE") % plant_type.name
func get_icon() -> Texture2D:
return plant_type.seed_texture
return plant_type.seed_texture
func get_energy_used() -> int:
return 1
return 1
func get_usage_zone_radius() -> int:
return 35
return 35
func get_usage_object_affected(i : InspectableEntity) -> bool:
return i is Plant
return i is Plant
func _init(
_plant_type : PlantType = null,
_parent_mutation : Array[PlantMutation] = []
_plant_type : PlantType = null,
_parent_mutation : Array[PlantMutation] = []
):
plant_type = _plant_type
plant_mutations = Seed.mutate(_parent_mutation)
plant_type = _plant_type
plant_mutations = Seed.mutate(_parent_mutation)
func use_text() -> String:
return tr("PLANT_%s") % plant_type.name
return tr("PLANT_%s") % plant_type.name
func is_one_time_use():
return true
return true
func can_use(player : Player, zone : Player.ActionZone) -> bool:
if (
player.planet == null
or not player.planet.garden.is_in_garden(zone.get_global_position())
):
return false
if (
player.planet == null
):
return false
var is_there_a_plant_here = false
for area in zone.get_affected_areas():
if area is Plant:
is_there_a_plant_here = true
var is_there_contamination_in_zone = false
for point in zone.get_points_in_zone():
if player.planet.garden.is_there_contamination(point):
is_there_contamination_in_zone = true
var is_there_a_plant_here = false
for area in zone.get_affected_areas():
if area is Plant:
is_there_a_plant_here = true
var is_there_contamination_in_zone = false
for tile in zone.get_tiles():
if not player.planet.decontamination_layer.is_decontamined(tile):
is_there_contamination_in_zone = true
return not is_there_a_plant_here and not is_there_contamination_in_zone
return not is_there_a_plant_here and not is_there_contamination_in_zone
func use(player : Player, zone : Player.ActionZone) -> bool:
if player.planet == null:
return false
if player.planet == null:
return false
AudioManager.play_sfx("Dig")
return player.planet.plant(
plant_type,
zone.get_global_position(),
plant_mutations
)
AudioManager.play_sfx("Dig")
return player.planet.plant(
plant_type,
zone.get_global_position(),
plant_mutations
)
func card_info() -> CardInfo:
var info = CardInfo.new(
get_item_name()
)
info.texture = icon
info.type_icon = TYPE_ICON
var info = CardInfo.new(
get_item_name()
)
info.texture = icon
info.type_icon = TYPE_ICON
info.stats.append(
CardStatInfo.new(
tr("COST_%d_ENERGY") % energy_usage,
ENERGY_ICON
)
)
info.stats.append(
CardStatInfo.new(
tr("COST_%d_ENERGY") % energy_usage,
ENERGY_ICON
)
)
if is_one_time_use():
info.stats.append(
CardStatInfo.new(
tr("ONE_TIME_USE"),
ONE_TIME_ICON
)
)
if is_one_time_use():
info.stats.append(
CardStatInfo.new(
tr("ONE_TIME_USE"),
ONE_TIME_ICON
)
)
var effect_section = CardSectionInfo.new(
tr("EFFECT"),
get_description()
)
effect_section.title_icon = ACTION_ICON
var effect_section = CardSectionInfo.new(
tr("EFFECT"),
get_description()
)
effect_section.title_icon = ACTION_ICON
if energy_usage > 0:
effect_section.title_icon = ENERGY_ICON
info.sections.append(effect_section)
if energy_usage > 0:
effect_section.title_icon = ENERGY_ICON
info.sections.append(effect_section)
if len(plant_mutations) != 0:
var rarest : int = plant_mutations.map(
func(m : PlantMutation) : return m.get_rarity()
).max()
info.bg_color = PlantMutation.get_rarity_color(rarest)
for m in plant_mutations:
info.sections.append(m.card_section())
return info
if len(plant_mutations) != 0:
var rarest : int = plant_mutations.map(
func(m : PlantMutation) : return m.get_rarity()
).max()
info.bg_color = PlantMutation.get_rarity_color(rarest)
for m in plant_mutations:
info.sections.append(m.card_section())
return info
func get_particles() -> Array[Particles.Parameters]:
var param : Array[Particles.Parameters] = []
var param : Array[Particles.Parameters] = []
for m in plant_mutations:
param.append(
Particles.Parameters.new(
m.get_icon(),
PlantMutation.get_rarity_color(m.get_rarity())
)
)
for m in plant_mutations:
param.append(
Particles.Parameters.new(
m.get_icon(),
PlantMutation.get_rarity_color(m.get_rarity())
)
)
return param
return param
static func mutate(parent_mutation : Array[PlantMutation] = []) -> Array[PlantMutation]:
if randf() > MUTATION_PROBABILITY:
return parent_mutation
if randf() > MUTATION_PROBABILITY:
return parent_mutation
var possible_mutations : Array[MutationPossibility] = [
AddMutation.new()
]
var possible_mutations : Array[MutationPossibility] = [
AddMutation.new()
]
if (
len(parent_mutation) >= 2
):
possible_mutations = [
UpgradeMutation.new(),
RemoveMutation.new(),
]
elif len(parent_mutation) > 0:
possible_mutations = [
AddMutation.new(),
UpgradeMutation.new(),
RemoveMutation.new(),
]
var chosen_mutation = possible_mutations.pick_random()
if (
len(parent_mutation) >= 2
):
possible_mutations = [
UpgradeMutation.new(),
RemoveMutation.new(),
]
elif len(parent_mutation) > 0:
possible_mutations = [
AddMutation.new(),
UpgradeMutation.new(),
RemoveMutation.new(),
]
var chosen_mutation = possible_mutations.pick_random()
return chosen_mutation.mutate(parent_mutation)
return chosen_mutation.mutate(parent_mutation)
class MutationPossibility:
func mutate(_parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
return []
func mutate(_parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
return []
class DontMutate extends MutationPossibility:
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
return parent_mutation
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
return parent_mutation
class AddMutation extends MutationPossibility:
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
var new_mutations = parent_mutation.duplicate_deep()
var mut = PlantMutation.random_mutation(parent_mutation)
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
var new_mutations = parent_mutation.duplicate_deep()
var mut = PlantMutation.random_mutation(parent_mutation)
if mut:
var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): return m.get_mutation_name() == mut.get_mutation_name())
if existing_mut_id >= 0:
new_mutations[existing_mut_id].level += 1
else :
new_mutations.append(mut)
if mut:
var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): return m.get_mutation_name() == mut.get_mutation_name())
if existing_mut_id >= 0:
new_mutations[existing_mut_id].level += 1
else :
new_mutations.append(mut)
return new_mutations
return new_mutations
class UpgradeMutation extends MutationPossibility:
func mutate(
parent_mutation : Array[PlantMutation] = []
) -> Array[PlantMutation]:
var new_mutations = parent_mutation.duplicate_deep()
func mutate(
parent_mutation : Array[PlantMutation] = []
) -> Array[PlantMutation]:
var new_mutations = parent_mutation.duplicate_deep()
new_mutations.pick_random().level += 1
new_mutations.pick_random().level += 1
return new_mutations
return new_mutations
class RemoveMutation extends MutationPossibility:
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
var new_mutations :Array[PlantMutation] = parent_mutation.duplicate_deep()
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
var new_mutations :Array[PlantMutation] = parent_mutation.duplicate_deep()
var mut_to_remove = new_mutations.pick_random()
if mut_to_remove.level > 1:
mut_to_remove.level -= 1
else:
new_mutations.remove_at(new_mutations.find(mut_to_remove))
var mut_to_remove = new_mutations.pick_random()
if mut_to_remove.level > 1:
mut_to_remove.level -= 1
else:
new_mutations.remove_at(new_mutations.find(mut_to_remove))
return new_mutations
return new_mutations

View File

@@ -4,41 +4,45 @@ class_name Shovel
const SHOVEL_ZONE_RADIUS = 50
func get_item_name() -> String:
return tr("SHOVEL")
return tr("SHOVEL")
func get_description() -> String:
return tr("SHOVEL_DESC_TEXT")
return tr("SHOVEL_DESC_TEXT")
func get_icon() -> Texture2D:
return preload("res://common/icons/shovel.svg")
return preload("res://common/icons/shovel.svg")
func get_usage_zone_radius() -> int:
return SHOVEL_ZONE_RADIUS
return SHOVEL_ZONE_RADIUS
func get_usage_object_affected(i : InspectableEntity) -> bool:
return i is Plant or i is UndergroundLoot
return i is Plant
func use_text() -> String:
return tr("DIG")
return tr("DIG")
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
var areas = zone.get_affected_areas()
for area in areas :
if area is Plant or area is UndergroundLoot:
return true
return false
var areas = zone.get_affected_areas()
var bodies = zone.area.get_overlapping_bodies()
for body in bodies :
if body is RockLayer:
return true
for area in areas :
if area is Plant:
return true
return false
func use(player : Player, zone : Player.ActionZone) -> bool:
for area in zone.get_affected_areas():
if area and area is Plant:
harvest(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
if area and area is UndergroundLoot:
dig(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
return true
for area in zone.get_affected_areas():
if area and area is Plant:
harvest(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
var bodies = zone.area.get_overlapping_bodies()
var rock_layer_id = bodies.find_custom(func (b) : return b is RockLayer)
if rock_layer_id != -1:
var rock_layer : RockLayer = bodies[rock_layer_id]
func dig(u: UndergroundLoot, player: Player):
AudioManager.play_sfx("Dig")
u.dig()
rock_layer.dig_rocks(zone.get_tiles())
return true

View File

@@ -10,320 +10,324 @@ signal upgraded
var terrain : Terrain
var planet : Planet :
get(): return terrain if terrain is Planet else null
get(): return terrain if terrain is Planet else null
@export var speed = 350
var data : PlayerData
var last_action_area_movement_timer : float = 100.
var controlling_player : bool = true :
set(v):
controlling_player = v
velocity = Vector2.ZERO
set(v):
controlling_player = v
velocity = Vector2.ZERO
var instruction : Instruction = null
@onready var preview_zone : ActionZone = setup_action_zone(Vector2.ZERO, null)
@onready var action_zone : ActionZone = setup_action_zone(Vector2.ZERO, null)
@onready var preview_zone : ActionZone = await setup_action_zone(Vector2.ZERO, null)
@onready var action_zone : ActionZone = await setup_action_zone(Vector2.ZERO, null)
func _ready():
data = GameInfo.game_data.player_data
data.inventory.updated.connect(_on_inventory_updated)
player_updated.emit(self)
Pointer.player = self
data = GameInfo.game_data.player_data
data.inventory.updated.connect(_on_inventory_updated)
player_updated.emit(self)
Pointer.player = self
setup_preview_zone(data.inventory.get_item())
func _input(_event) -> void:
if Input.is_action_pressed("change_item_left"):
data.inventory.change_current_item(1)
if Input.is_action_pressed("change_item_right"):
data.inventory.change_current_item(-1)
for i in range(1, 10):
if Input.is_action_pressed("item_" + str(i)):
data.inventory.set_current_item(i - 1)
if Input.is_action_pressed("change_item_left"):
data.inventory.change_current_item(1)
if Input.is_action_pressed("change_item_right"):
data.inventory.change_current_item(-1)
for i in range(1, 10):
if Input.is_action_pressed("item_" + str(i)):
data.inventory.set_current_item(i - 1)
# Méthode déclenchée par la classe planet
func _start_pass_day():
controlling_player = false
instruction = null
controlling_player = false
instruction = null
# Méthode déclenchée par la classe planet
func _pass_day():
full_recharge()
full_recharge()
# Méthode déclenchée par la classe planet
func _end_pass_day():
controlling_player = true
controlling_player = true
func _process(delta):
last_action_area_movement_timer += delta
if controlling_player:
calculate_direction()
last_action_area_movement_timer += delta
if controlling_player:
calculate_direction()
if (
last_action_area_movement_timer >= ACTION_AREA_UPDATE_TIME
and instruction and instruction.can_be_done(self)
):
instruction.do(self)
instruction = null
move_preview_zone(get_global_mouse_position())
else:
velocity = Vector2.ZERO
move_and_slide()
if (
last_action_area_movement_timer >= ACTION_AREA_UPDATE_TIME
and instruction and instruction.can_be_done(self)
):
instruction.do(self)
instruction = null
move_preview_zone(get_global_mouse_position())
else:
velocity = Vector2.ZERO
move_and_slide()
func _on_inventory_updated(_inventory: Inventory):
setup_preview_zone(data.inventory.get_item())
var item : Item = data.inventory.get_item()
if item:
var item_texture = item.icon
%ItemSprite.texture = item_texture
%ItemSprite.scale = Vector2(
1./(item_texture.get_width()/HOLDING_ITEM_SPRITE_SIZE),
1./(item_texture.get_height()/HOLDING_ITEM_SPRITE_SIZE)
)
%HideEyes.visible = item != null
%ItemSprite.visible = item != null
emit_signal("player_updated", self)
setup_preview_zone(data.inventory.get_item())
var item : Item = data.inventory.get_item()
if item:
var item_texture = item.icon
%ItemSprite.texture = item_texture
%ItemSprite.scale = Vector2(
1./(item_texture.get_width()/HOLDING_ITEM_SPRITE_SIZE),
1./(item_texture.get_height()/HOLDING_ITEM_SPRITE_SIZE)
)
%HideEyes.visible = item != null
%ItemSprite.visible = item != null
emit_signal("player_updated", self)
func calculate_direction():
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if input_direction.length() != 0:
instruction = null
if input_direction.length() != 0:
instruction = null
if instruction and instruction.position.distance_to(global_position) > (MAX_REACH - 1.):
input_direction = self.global_position.direction_to(instruction.position)
if (
instruction
and (
instruction.position.distance_to(global_position) > (MAX_REACH - 1.)
or instruction is MoveInstruction
)
):
input_direction = self.global_position.direction_to(instruction.position)
velocity = input_direction * speed
if input_direction.x:
flip_character(input_direction.x > 0)
velocity = input_direction * speed
if input_direction.x:
flip_character(input_direction.x > 0)
func flip_character(face_right = true):
$Sprite.flip_h = not face_right
%ItemSprite.position.x = abs(%ItemSprite.position.x) * (1 if face_right else -1)
%HideEyes.position.x = abs(%ItemSprite.position.x) * (1 if face_right else -1)
$Sprite.flip_h = not face_right
%ItemSprite.position.x = abs(%ItemSprite.position.x) * (1 if face_right else -1)
%HideEyes.position.x = abs(%ItemSprite.position.x) * (1 if face_right else -1)
func can_interact(interactable : Interactable):
return interactable.can_interact(self)
return interactable.can_interact(self)
func try_interact(interactable : Interactable):
if interactable:
instruction = InteractableInstruction.new(
interactable
)
if interactable:
instruction = InteractableInstruction.new(
interactable
)
func try_move(move_to : Vector2):
instruction = MoveInstruction.new(move_to)
instruction = MoveInstruction.new(move_to)
func pick_item(item : Item) -> Item:
AudioManager.play_sfx("PickUp")
if data.inventory.is_full():
drop_item()
AudioManager.play_sfx("PickUp")
if data.inventory.is_full():
drop_item()
var available_slot_ind = data.inventory.get_best_available_slot_ind()
if (
available_slot_ind == data.inventory.current_item_ind
&& data.inventory.items[available_slot_ind] != null
):
var current_item : Item = data.inventory.get_item()
data.inventory.set_item(item, available_slot_ind)
return current_item
else :
if data.inventory.set_item(item, available_slot_ind):
data.inventory.set_current_item(available_slot_ind);
return null
var available_slot_ind = data.inventory.get_best_available_slot_ind()
if (
available_slot_ind == data.inventory.current_item_ind
&& data.inventory.items[available_slot_ind] != null
):
var current_item : Item = data.inventory.get_item()
data.inventory.set_item(item, available_slot_ind)
return current_item
else :
if data.inventory.set_item(item, available_slot_ind):
data.inventory.set_current_item(available_slot_ind);
return null
func drop_item():
var item_to_drop = data.inventory.pop_item()
if item_to_drop:
terrain.drop_item(item_to_drop, global_position)
AudioManager.play_sfx("Drop")
var item_to_drop = data.inventory.pop_item()
if item_to_drop:
terrain.drop_item(item_to_drop, global_position)
AudioManager.play_sfx("Drop")
func delete_item(item: Item):
data.inventory.remove_item(item)
data.inventory.remove_item(item)
func try_use_item(item : Item, use_position : Vector2):
setup_action_zone(use_position, item)
instruction = ItemActionInstruction.new(
use_position,
item
)
await setup_action_zone(use_position, item)
instruction = ItemActionInstruction.new(
use_position,
item
)
func preview_could_use_item(item : Item) -> bool:
return could_use_item_on_zone(item, preview_zone)
return could_use_item_on_zone(item, preview_zone)
func could_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
return (
data.inventory.has_item(item)
and item.can_use(self, zone)
)
return (
data.inventory.has_item(item)
and item.can_use(self, zone)
)
func can_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
return (
could_use_item_on_zone(item, zone)
and has_energy_to_use_item(item)
)
return (
could_use_item_on_zone(item, zone)
and has_energy_to_use_item(item)
)
func has_energy_to_use_item(item : Item):
return (data.energy - item.energy_usage) >= 0
return (data.energy - item.energy_usage) >= 0
func use_item(item : Item):
if can_use_item_on_zone(item, action_zone):
var is_item_used = await item.use(self, action_zone)
if is_item_used:
data.energy -= item.energy_usage
if item.is_one_time_use():
data.inventory.remove_item(item)
if can_use_item_on_zone(item, action_zone):
var is_item_used = await item.use(self, action_zone)
if is_item_used:
data.energy -= item.energy_usage
if item.is_one_time_use():
data.inventory.remove_item(item)
func upgrade_max_energy(amount = 1):
data.max_energy += amount
upgraded.emit()
player_updated.emit(self)
data.max_energy += amount
upgraded.emit()
player_updated.emit(self)
func upgrade_inventory_size(amount = 1):
data.inventory.size += 1
upgraded.emit()
player_updated.emit(self)
data.inventory.size += amount
upgraded.emit()
player_updated.emit(self)
func recharge(amount : int = data.max_energy):
data.energy += + amount
upgraded.emit()
data.energy += + amount
upgraded.emit()
func full_recharge():
data.energy = max(data.energy, data.max_energy)
data.energy = max(data.energy, data.max_energy)
func generate_action_zone(item : Item) -> ActionZone:
var zone = ActionZone.new(item)
var zone = ActionZone.new(item)
if zone.area:
get_parent().add_child(zone.area)
if not get_parent().is_node_ready():
await get_parent().ready
get_parent().add_child(zone.area)
return zone
return zone
func setup_preview_zone(item : Item) -> ActionZone:
if preview_zone and preview_zone.item == item:
return preview_zone
elif preview_zone:
preview_zone.destroy()
if item:
preview_zone = generate_action_zone(item)
else:
preview_zone = null
return preview_zone
func setup_preview_zone(item : Item):
if preview_zone and preview_zone.item == item:
return preview_zone
elif preview_zone:
preview_zone.destroy()
if item:
preview_zone = await generate_action_zone(item)
else:
preview_zone = null
func setup_action_zone(zone_position : Vector2, item: Item) -> ActionZone:
if action_zone:
action_zone.destroy()
action_zone = generate_action_zone(item)
action_zone.move_to_position(zone_position)
last_action_area_movement_timer = 0.
return action_zone
if action_zone:
action_zone.destroy()
action_zone = await generate_action_zone(item)
action_zone.move_to_position(zone_position)
last_action_area_movement_timer = 0.
return action_zone
func move_preview_zone(zone_position : Vector2):
if preview_zone:
preview_zone.move_to_position(zone_position)
if preview_zone:
preview_zone.move_to_position(zone_position)
class Instruction:
var position : Vector2
var position : Vector2
func _init(_pos : Vector2):
position = _pos
func _init(_pos : Vector2):
position = _pos
func can_be_done(player : Player):
return player.global_position.distance_to(position) < player.MAX_REACH
func can_be_done(player : Player):
return player.global_position.distance_to(position) < player.MAX_REACH
func do(_player : Player):
pass
func do(_player : Player):
pass
class MoveInstruction extends Instruction:
pass
func can_be_done(player : Player):
return player.global_position.distance_to(position) < 10.
class ItemActionInstruction extends Instruction:
var item = Item
var item = Item
func _init(_pos : Vector2, _item : Item):
position = _pos
item = _item
func can_be_done(player : Player):
return (
player.global_position.distance_to(position) < player.MAX_REACH
)
func do(player : Player):
player.use_item(item)
func _init(_pos : Vector2, _item : Item):
position = _pos
item = _item
func can_be_done(player : Player):
return (
player.global_position.distance_to(position) < player.MAX_REACH
)
func do(player : Player):
player.use_item(item)
class InteractableInstruction extends Instruction:
var interactable = Interactable
var interactable = Interactable
func _init(_interactable : Interactable):
interactable = _interactable
position = interactable.global_position
func can_be_done(player : Player):
return player.global_position.distance_to(position) < player.MAX_REACH
func do(player : Player):
interactable.interact(player)
func _init(_interactable : Interactable):
interactable = _interactable
position = interactable.global_position
func can_be_done(player : Player):
return player.global_position.distance_to(position) < player.MAX_REACH
func do(player : Player):
interactable.interact(player)
class ActionZone:
var item : Item = null
var area : Area2D
var affected_areas : Array[InspectableEntity]= []
var item : Item = null
var area : Area2D
var affected_areas : Array[InspectableEntity]= []
func _init(_i : Item):
item = _i
if item and item.get_usage_zone_radius() > 0:
area = Area2D.new()
var collision_shape = CollisionShape2D.new()
var circle_shape = CircleShape2D.new()
func _init(_i : Item):
item = _i
if item and item.get_usage_zone_radius() > 0:
area = Area2D.new()
var collision_shape = CollisionShape2D.new()
var circle_shape = CircleShape2D.new()
circle_shape.radius = item.get_usage_zone_radius()
collision_shape.shape = circle_shape
area.add_child(collision_shape)
circle_shape.radius = item.get_usage_zone_radius()
collision_shape.shape = circle_shape
area.add_child(collision_shape)
func clear_preview_on_affected_area():
for a in affected_areas:
if a:
a.affect_preview(false)
func clear_preview_on_affected_area():
for a in affected_areas:
if a:
a.affect_preview(false)
func update_preview_on_affected_area():
var detected_areas = get_affected_areas()
clear_preview_on_affected_area()
var new_affected_areas : Array[InspectableEntity] = []
for a in detected_areas:
if a is InspectableEntity and item.get_usage_object_affected(a):
a.affect_preview(true)
new_affected_areas.append(a)
affected_areas = new_affected_areas
func update_preview_on_affected_area():
var detected_areas = get_affected_areas()
clear_preview_on_affected_area()
var new_affected_areas : Array[InspectableEntity] = []
for a in detected_areas:
if a is InspectableEntity and item.get_usage_object_affected(a):
a.affect_preview(true)
new_affected_areas.append(a)
affected_areas = new_affected_areas
func get_affected_areas() -> Array[Area2D]:
var empty_array : Array[Area2D] = []
return empty_array if area == null else area.get_overlapping_areas()
func get_affected_areas() -> Array[Area2D]:
var empty_array : Array[Area2D] = []
return empty_array if area == null else area.get_overlapping_areas()
func destroy():
clear_preview_on_affected_area()
if area:
area.queue_free()
func get_global_position() -> Vector2:
return Vector2.ZERO if area == null else area.global_position
func destroy():
clear_preview_on_affected_area()
if area:
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:
update_preview_on_affected_area()
area.global_position = pos
func move_to_position(pos : Vector2):
if area:
update_preview_on_affected_area()
area.global_position = pos
func get_points_in_zone(point_factor = 10) -> Array[Vector2]:
var points : Array[Vector2] = []
var radius = item.get_usage_zone_radius()
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
func get_tiles() -> Array[Vector2i]:
return Math.get_tiles_in_circle(
get_global_position(),
item.get_usage_zone_radius()
)

View File

@@ -3,7 +3,7 @@ class_name PlayerData
signal updated(player_data : PlayerData)
const DEFAULT_MAX_ENERGY = 2
const DEFAULT_MAX_ENERGY = 3
const DEFAULT_INVENTORY_SIZE = 3
@export var max_energy : int = DEFAULT_MAX_ENERGY :