ajout d'un terrain infini et la possibilité de planter n'importe où
This commit is contained in:
@@ -4,6 +4,6 @@ class_name TruckLadder
|
||||
const TRUCK_SCENE_PATH = "res://stages/terrain/truck/truck.tscn"
|
||||
|
||||
func interact(p : Player):
|
||||
p.planet.save()
|
||||
get_tree().change_scene_to_file(TRUCK_SCENE_PATH)
|
||||
return true
|
||||
p.planet.save()
|
||||
get_tree().change_scene_to_file(TRUCK_SCENE_PATH)
|
||||
return true
|
||||
|
||||
@@ -2,7 +2,7 @@ extends PlantEffect
|
||||
class_name DecontaminateTerrainEffect
|
||||
|
||||
func get_decontamination_radius():
|
||||
return 50 + 50 * level
|
||||
return (1 + level)
|
||||
|
||||
func get_effect_name() -> String:
|
||||
return tr("DECONTAMINATE")
|
||||
@@ -12,9 +12,9 @@ func get_effect_description() -> String:
|
||||
return ret
|
||||
|
||||
func effect(plant):
|
||||
var radius = get_decontamination_radius()
|
||||
|
||||
plant.planet.garden.impact_contamination(
|
||||
var tiles := Math.get_tiles_in_circle(
|
||||
plant.global_position,
|
||||
radius
|
||||
)
|
||||
get_decontamination_radius() * Planet.TILE_SIZE + Planet.TILE_SIZE/2.
|
||||
)
|
||||
|
||||
plant.planet.decontamination_layer.place_decontaminations(tiles, true)
|
||||
|
||||
41
entities/player/inventory/scripts/items/pickaxe.gd
Normal file
41
entities/player/inventory/scripts/items/pickaxe.gd
Normal 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
|
||||
1
entities/player/inventory/scripts/items/pickaxe.gd.uid
Normal file
1
entities/player/inventory/scripts/items/pickaxe.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ctucfh72pxut8
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
@@ -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 :
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="121.41377mm"
|
||||
height="49.165478mm"
|
||||
viewBox="0 0 121.41377 49.165478"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#ffffff"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="1"
|
||||
inkscape:deskcolor="#505050"
|
||||
inkscape:document-units="mm" />
|
||||
<defs
|
||||
id="defs1" />
|
||||
<g
|
||||
inkscape:label="Calque 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-77.923929,-55.520125)">
|
||||
<path
|
||||
id="path1"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke-width:0.264583;stroke-linecap:square"
|
||||
d="M 141.47612,55.520125 A 35.11824,35.11824 0 0 0 107.53969,81.850818 26.422297,26.422297 0 0 0 104.01691,81.607939 26.422297,26.422297 0 0 0 77.923926,104.6856 H 199.239 a 28.094591,28.094591 0 0 0 0.0987,-1.00304 28.094591,28.094591 0 0 0 -26.09504,-28.015344 35.11824,35.11824 0 0 0 -31.76654,-20.147091 z" />
|
||||
<path
|
||||
id="path2"
|
||||
style="fill:#c9c9c9;fill-opacity:1;stroke-width:0.264583;stroke-linecap:square"
|
||||
d="M 149.00176,77.594747 A 22.241554,22.241554 0 0 0 127.96997,92.741626 22.241554,22.241554 0 0 0 117.22799,89.969702 22.241554,22.241554 0 0 0 96.380164,104.6856 h 95.746606 a 22.241554,22.241554 0 0 0 -21.05091,-15.385108 22.241554,22.241554 0 0 0 -2.3983,0.171566 22.241554,22.241554 0 0 0 -19.6758,-11.877311 z" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.7 KiB |
@@ -1,37 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bu26h0iqutnky"
|
||||
path="res://.godot/imported/underground_loot.svg-94513f7cc11df7cda1992e530bcff786.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/underground_loot/assets/sprites/underground_loot.svg"
|
||||
dest_files=["res://.godot/imported/underground_loot.svg-94513f7cc11df7cda1992e530bcff786.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
@@ -1,39 +0,0 @@
|
||||
extends InspectableEntity
|
||||
class_name UndergroundLoot
|
||||
|
||||
const AREA_WIDTH = 20
|
||||
const LOOTED_ITEM_RANDOM_RANGE = 50
|
||||
|
||||
@export var item_number : int = 1
|
||||
|
||||
func pointer_text() -> String:
|
||||
return tr("BURIED_SEEDS")
|
||||
|
||||
func generate_collision_shape() -> CollisionShape2D:
|
||||
var collision = CollisionShape2D.new()
|
||||
var shape = CircleShape2D.new()
|
||||
shape.radius = AREA_WIDTH
|
||||
|
||||
collision.shape = shape
|
||||
add_child(collision)
|
||||
|
||||
return collision
|
||||
|
||||
func generate_loot() -> Array[Item]:
|
||||
var seeds : Array[Item] = []
|
||||
if len(GameInfo.game_data.unlocked_plant_types):
|
||||
seeds.append(
|
||||
Seed.new(
|
||||
GameInfo.game_data.unlocked_plant_types.pick_random()
|
||||
)
|
||||
)
|
||||
return seeds
|
||||
|
||||
|
||||
func dig():
|
||||
for item in generate_loot():
|
||||
planet.drop_item(item, global_position, LOOTED_ITEM_RANDOM_RANGE)
|
||||
queue_free()
|
||||
|
||||
func save() -> UndergroundLootData:
|
||||
return UndergroundLootData.new(self)
|
||||
@@ -1 +0,0 @@
|
||||
uid://dfd2hh12155lo
|
||||
@@ -1,15 +0,0 @@
|
||||
extends EntityData
|
||||
class_name UndergroundLootData
|
||||
|
||||
const SCENE = preload("res://entities/underground_loot/underground_loot.tscn")
|
||||
|
||||
@export var item_number : int
|
||||
|
||||
func _init(e : UndergroundLoot):
|
||||
position = e.global_position
|
||||
item_number = e.item_number
|
||||
|
||||
func load() -> Entity:
|
||||
var loot : UndergroundLoot = (SCENE.instantiate() as UndergroundLoot)
|
||||
loot.item_number = item_number
|
||||
return loot
|
||||
@@ -1 +0,0 @@
|
||||
uid://68plwch6h4f7
|
||||
@@ -1,21 +0,0 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dxjud7bti0na0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dfd2hh12155lo" path="res://entities/underground_loot/scripts/underground_loot.gd" id="1_knus5"]
|
||||
[ext_resource type="Texture2D" uid="uid://bu26h0iqutnky" path="res://entities/underground_loot/assets/sprites/underground_loot.svg" id="2_jfggo"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_knus5"]
|
||||
radius = 20.09975
|
||||
|
||||
[node name="UndergroundLootSprites" type="Area2D"]
|
||||
script = ExtResource("1_knus5")
|
||||
default_info_title = "BURIED_SEEDS"
|
||||
default_info_desc = "BURIED_SEEDS_DESC_TEXT"
|
||||
metadata/_custom_type_script = "uid://d3bk52402ylvl"
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
modulate = Color(0.286275, 0.219608, 0.313726, 1)
|
||||
scale = Vector2(0.0806452, 0.0806452)
|
||||
texture = ExtResource("2_jfggo")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_knus5")
|
||||
Reference in New Issue
Block a user