Tractor beam
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
[gd_scene load_steps=8 format=3 uid="uid://bcj812ox8xv2t"]
|
[gd_scene format=3 uid="uid://bcj812ox8xv2t"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://reliyx2pg7kf" path="res://entities/interactables/item_object/script/item_object_sprite.gd" id="1_wing4"]
|
[ext_resource type="Script" uid="uid://reliyx2pg7kf" path="res://entities/interactables/item_object/script/item_object_sprite.gd" id="1_wing4"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bo3o2qf3i20ke" path="res://common/icons/scuba-diving-tank.svg" id="2_ng3e4"]
|
[ext_resource type="Texture2D" uid="uid://bo3o2qf3i20ke" path="res://common/icons/scuba-diving-tank.svg" id="2_ng3e4"]
|
||||||
[ext_resource type="Texture2D" uid="uid://c1eiu5ag7lcp8" path="res://entities/interactables/item_object/assets/sprites/shadow.svg" id="2_ng201"]
|
[ext_resource type="Texture2D" uid="uid://c1eiu5ag7lcp8" path="res://entities/interactables/item_object/assets/sprites/shadow.svg" id="2_ng201"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dompaj451gklw" path="res://entities/player/assets/sprites/movement_particles.png" id="4_ng3e4"]
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_wing4"]
|
[sub_resource type="Animation" id="Animation_wing4"]
|
||||||
length = 0.001
|
length = 0.001
|
||||||
@@ -95,22 +96,46 @@ _data = {
|
|||||||
&"pickup": SubResource("Animation_ng3e4")
|
&"pickup": SubResource("Animation_ng3e4")
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="ItemObjectSprite" type="Node2D"]
|
[sub_resource type="Curve" id="Curve_b6vos"]
|
||||||
|
_data = [Vector2(0, 0.29213488), 0.0, 0.0, 0, 0, Vector2(0.3, 1), 0.0, 0.0, 0, 0, Vector2(0.63809526, 0.46067423), 0.0, 0.0, 0, 0, Vector2(0.9904762, 0.3820225), 0.0, 0.0, 0, 0]
|
||||||
|
point_count = 4
|
||||||
|
|
||||||
|
[sub_resource type="Gradient" id="Gradient_14kbc"]
|
||||||
|
offsets = PackedFloat32Array(0, 0.77729255, 1)
|
||||||
|
colors = PackedColorArray(0.5803922, 0.7058824, 0.8862745, 1, 0.5785, 0.70829165, 0.89, 1, 0.5785, 0.70829165, 0.89, 0)
|
||||||
|
|
||||||
|
[node name="ItemObjectSprite" type="Node2D" unique_id=69332129]
|
||||||
script = ExtResource("1_wing4")
|
script = ExtResource("1_wing4")
|
||||||
|
|
||||||
[node name="Icon" type="Sprite2D" parent="."]
|
[node name="Icon" type="Sprite2D" parent="." unique_id=2070904988]
|
||||||
texture = ExtResource("2_ng3e4")
|
texture = ExtResource("2_ng3e4")
|
||||||
|
|
||||||
[node name="Shadow" type="Sprite2D" parent="."]
|
[node name="Shadow" type="Sprite2D" parent="." unique_id=1621814025]
|
||||||
modulate = Color(1, 1, 1, 0.227451)
|
modulate = Color(1, 1, 1, 0.227451)
|
||||||
z_index = -1
|
z_index = -1
|
||||||
position = Vector2(0, 23)
|
position = Vector2(0, 23)
|
||||||
scale = Vector2(0.875, 0.875)
|
scale = Vector2(0.875, 0.875)
|
||||||
texture = ExtResource("2_ng201")
|
texture = ExtResource("2_ng201")
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1385834581]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
libraries = {
|
libraries/ = SubResource("AnimationLibrary_ng3e4")
|
||||||
&"": SubResource("AnimationLibrary_ng3e4")
|
autoplay = &"default"
|
||||||
}
|
|
||||||
autoplay = "default"
|
[node name="TractorBeam" type="CPUParticles2D" parent="." unique_id=382704689]
|
||||||
|
z_index = -1
|
||||||
|
position = Vector2(83, 0)
|
||||||
|
scale = Vector2(0.7, 0.7)
|
||||||
|
emitting = false
|
||||||
|
amount = 5
|
||||||
|
texture = ExtResource("4_ng3e4")
|
||||||
|
lifetime = 1.25
|
||||||
|
local_coords = true
|
||||||
|
particle_flag_align_y = true
|
||||||
|
direction = Vector2(-1, 0)
|
||||||
|
spread = 0.0
|
||||||
|
gravity = Vector2(0, 0)
|
||||||
|
initial_velocity_min = 100.0
|
||||||
|
initial_velocity_max = 100.0
|
||||||
|
scale_amount_curve = SubResource("Curve_b6vos")
|
||||||
|
color_ramp = SubResource("Gradient_14kbc")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ extends Node2D
|
|||||||
class_name ItemObjectSprite
|
class_name ItemObjectSprite
|
||||||
|
|
||||||
@onready var icon_sprite = $Icon
|
@onready var icon_sprite = $Icon
|
||||||
|
@onready var tractor_beam: CPUParticles2D = $TractorBeam
|
||||||
|
|
||||||
const PARTICLES_SCENE : PackedScene = preload("res://common/vfx/particles/effect_particles.tscn")
|
const PARTICLES_SCENE : PackedScene = preload("res://common/vfx/particles/effect_particles.tscn")
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ func _init(size : int = 1):
|
|||||||
seeds_size = size
|
seeds_size = size
|
||||||
|
|
||||||
func current_is_tool() -> bool:
|
func current_is_tool() -> bool:
|
||||||
return current_item_ind < len(tools)
|
return ind_is_tool(current_item_ind)
|
||||||
|
|
||||||
|
func ind_is_tool(ind:int)->bool:
|
||||||
|
return ind < len(tools)
|
||||||
|
|
||||||
func set_current_item(new_ind: int):
|
func set_current_item(new_ind: int):
|
||||||
if new_ind < 0:
|
if new_ind < 0:
|
||||||
@@ -75,7 +78,7 @@ func update_seeds_size(size = seeds_size):
|
|||||||
|
|
||||||
func add_item_at(item: Item, item_ind: int) -> bool:
|
func add_item_at(item: Item, item_ind: int) -> bool:
|
||||||
if item.type == Item.ItemType.CONSUMABLE_ITEM:
|
if item.type == Item.ItemType.CONSUMABLE_ITEM:
|
||||||
return add_seed_at(item, item_ind - tools.size())
|
return add_seed_at(item, item_ind - len(tools))
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
@@ -89,7 +92,7 @@ func add_seed_at(s: Item, seed_ind: int) -> bool:
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
func get_all_items_size() -> int:
|
func get_all_items_size() -> int:
|
||||||
return tools.size() + seeds.size()
|
return len(tools) + len(seeds)
|
||||||
|
|
||||||
func get_all_items() -> Array[Item]:
|
func get_all_items() -> Array[Item]:
|
||||||
return tools + seeds
|
return tools + seeds
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ func is_action_need_press_time() -> bool:
|
|||||||
func get_action_press_time() -> float:
|
func get_action_press_time() -> float:
|
||||||
return DEFAULT_PRESS_TIME
|
return DEFAULT_PRESS_TIME
|
||||||
|
|
||||||
|
func get_action_is_hold() -> bool:
|
||||||
|
return false
|
||||||
|
|
||||||
func get_usage_object_affected(_i : Area2D) -> bool:
|
func get_usage_object_affected(_i : Area2D) -> bool:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|||||||
49
entities/player/inventory/scripts/items/tractor_beam.gd
Normal file
49
entities/player/inventory/scripts/items/tractor_beam.gd
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
extends Item
|
||||||
|
class_name TractorBeam
|
||||||
|
|
||||||
|
const USE_INTERVAL = 0.15
|
||||||
|
|
||||||
|
func get_item_name() -> String:
|
||||||
|
return tr("TRACTOR_BEAM")
|
||||||
|
|
||||||
|
func get_description() -> String:
|
||||||
|
return tr("TRACTOR_BEAM_DESC_TEXT")
|
||||||
|
|
||||||
|
func get_icon() -> Texture2D:
|
||||||
|
# return preload("res://common/icons/tractor_beam.svg")
|
||||||
|
return preload("res://common/icons/alert-triangle.svg")
|
||||||
|
|
||||||
|
func get_item_type() -> ItemType:
|
||||||
|
return Item.ItemType.TOOL_ITEM
|
||||||
|
|
||||||
|
func get_energy_used() -> int:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
func get_usage_zone_radius() -> int:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
func is_usage_need_proximity() -> bool:
|
||||||
|
return false
|
||||||
|
|
||||||
|
func get_action_is_hold() -> bool:
|
||||||
|
return true
|
||||||
|
|
||||||
|
func use_text() -> String:
|
||||||
|
return tr("MOVE")
|
||||||
|
|
||||||
|
func can_use(_player: Player, _zone: Player.ActionZone) -> bool:
|
||||||
|
return Pointer.inspected != null
|
||||||
|
|
||||||
|
func use(_player: Player, _zone: Player.ActionZone) -> bool:
|
||||||
|
if Pointer.dragging_inspected:
|
||||||
|
Pointer.stop_dragging()
|
||||||
|
if !Pointer.dragging_inspected:
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
return false
|
||||||
|
else:
|
||||||
|
Pointer.start_dragging()
|
||||||
|
if Pointer.dragging_inspected:
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
return false
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://drs03fydfofxx
|
||||||
@@ -55,6 +55,7 @@ func appear(with_falling_animation = true):
|
|||||||
%AnimationPlayer.play("float")
|
%AnimationPlayer.play("float")
|
||||||
|
|
||||||
func _input(_event) -> void:
|
func _input(_event) -> void:
|
||||||
|
if not Pointer.dragging_inspected:
|
||||||
if Input.is_action_pressed("change_item_left"):
|
if Input.is_action_pressed("change_item_left"):
|
||||||
data.inventory.change_current_item(1)
|
data.inventory.change_current_item(1)
|
||||||
if Input.is_action_pressed("change_item_right"):
|
if Input.is_action_pressed("change_item_right"):
|
||||||
|
|||||||
@@ -85,8 +85,15 @@ func _process(delta):
|
|||||||
cursor = current_selected_item.get_pointer()
|
cursor = current_selected_item.get_pointer()
|
||||||
Input.set_custom_mouse_cursor(cursor)
|
Input.set_custom_mouse_cursor(cursor)
|
||||||
|
|
||||||
if player and dragging_inspected:
|
if player:
|
||||||
|
if dragging_inspected:
|
||||||
inspected.global_position = player.get_global_mouse_position()
|
inspected.global_position = player.get_global_mouse_position()
|
||||||
|
if inspected is ItemObject:
|
||||||
|
var global_dir: Vector2 = (inspected.global_position - player.global_position).normalized()
|
||||||
|
inspected.object_sprite.tractor_beam.position = 30 * global_dir
|
||||||
|
inspected.object_sprite.tractor_beam.rotation = Vector2.RIGHT.angle_to(global_dir)
|
||||||
|
if not inspected.object_sprite.tractor_beam.emitting:
|
||||||
|
inspected.object_sprite.tractor_beam.emitting = true
|
||||||
|
|
||||||
func process_player_actions(delta: float):
|
func process_player_actions(delta: float):
|
||||||
can_interact = (
|
can_interact = (
|
||||||
@@ -147,42 +154,11 @@ func process_player_actions(delta: float):
|
|||||||
%ActionProgressPlayer.playing = false
|
%ActionProgressPlayer.playing = false
|
||||||
%ActionProgressBar.value = 0.
|
%ActionProgressBar.value = 0.
|
||||||
|
|
||||||
if (
|
if Input.is_action_just_pressed("action"):
|
||||||
inspected and
|
|
||||||
(inspected is ItemObject
|
|
||||||
or (inspected is InventoryGuiItemMouseDetector
|
|
||||||
and GameInfo.game_data.player_data.inventory.get_item(inspected.index)
|
|
||||||
and press_time > PRESS_TIME_DRAG))
|
|
||||||
):
|
|
||||||
if Input.is_action_pressed("action"):
|
|
||||||
all_inspected.clear()
|
|
||||||
all_inspected.append(inspected)
|
|
||||||
dragging_inspected = true
|
|
||||||
can_interact = false
|
|
||||||
if inspected is ItemObject:
|
|
||||||
inspected.mouse_over = false
|
|
||||||
elif inspected is InventoryGuiItemMouseDetector:
|
|
||||||
var item_to_drop: Item = GameInfo.game_data.player_data.inventory.pop_item(inspected.index)
|
|
||||||
if item_to_drop and item_to_drop.type != Item.ItemType.TOOL_ITEM:
|
|
||||||
var dropped_item_object := player.terrain.drop_item(item_to_drop, player.get_global_mouse_position())
|
|
||||||
inspected = dropped_item_object
|
|
||||||
all_inspected.clear()
|
|
||||||
all_inspected.append(inspected)
|
|
||||||
player.region.save()
|
|
||||||
else:
|
|
||||||
dragging_inspected = false
|
|
||||||
else:
|
|
||||||
dragging_inspected = false
|
|
||||||
if inspected is ItemObject and inspected_inventory_slot is InventoryGuiItemMouseDetector:
|
|
||||||
# GameInfo.game_data.player_data.inventory.add_seed(inspected.item)
|
|
||||||
if GameInfo.game_data.player_data.inventory.add_item_at(inspected.item, inspected_inventory_slot.index):
|
|
||||||
all_inspected.clear()
|
|
||||||
inspected.queue_free()
|
|
||||||
inspected = null
|
|
||||||
|
|
||||||
if Input.is_action_just_released("action") and press_time < PRESS_TIME_DRAG:
|
|
||||||
if inspected is InventoryGuiItemMouseDetector:
|
if inspected is InventoryGuiItemMouseDetector:
|
||||||
GameInfo.game_data.player_data.inventory.set_current_item(inspected.index)
|
GameInfo.game_data.player_data.inventory.set_current_item(inspected.index)
|
||||||
|
elif can_use_item and not current_selected_item.is_action_need_press_time() and current_selected_item.get_action_is_hold():
|
||||||
|
player.try_use_item(current_selected_item, player.get_global_mouse_position())
|
||||||
elif can_interact:
|
elif can_interact:
|
||||||
var interactable = inspected as Interactable
|
var interactable = inspected as Interactable
|
||||||
player.try_interact(interactable)
|
player.try_interact(interactable)
|
||||||
@@ -192,6 +168,16 @@ func process_player_actions(delta: float):
|
|||||||
player.get_global_mouse_position()
|
player.get_global_mouse_position()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
Input.is_action_just_released("action")
|
||||||
|
and can_use_item
|
||||||
|
and current_selected_item.get_action_is_hold()
|
||||||
|
):
|
||||||
|
if dragging_inspected:
|
||||||
|
player.try_use_item(current_selected_item, player.get_global_mouse_position())
|
||||||
|
else:
|
||||||
|
player.instruction = null
|
||||||
|
|
||||||
func inspect(node: Node):
|
func inspect(node: Node):
|
||||||
if (
|
if (
|
||||||
not node in all_inspected
|
not node in all_inspected
|
||||||
@@ -237,7 +223,6 @@ func update_inspector(current_inspected):
|
|||||||
if current_inspected:
|
if current_inspected:
|
||||||
if inspected != current_inspected:
|
if inspected != current_inspected:
|
||||||
if inspected and inspected.has_method("inspect"):
|
if inspected and inspected.has_method("inspect"):
|
||||||
print("Stop inspect")
|
|
||||||
inspected.inspect(false)
|
inspected.inspect(false)
|
||||||
inspected = current_inspected
|
inspected = current_inspected
|
||||||
if inspected.has_method("card_info"):
|
if inspected.has_method("card_info"):
|
||||||
@@ -252,12 +237,7 @@ func update_inspector(current_inspected):
|
|||||||
inspected = null
|
inspected = null
|
||||||
|
|
||||||
if player and not action_disabled and (get_tree() and not get_tree().paused):
|
if player and not action_disabled and (get_tree() and not get_tree().paused):
|
||||||
if can_interact and inspected and inspected is Interactable:
|
if dragging_inspected:
|
||||||
%Action.visible = true
|
|
||||||
%ActionText.text = inspected.interact_text()
|
|
||||||
%Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
|
||||||
%ActionEnergyImage.visible = inspected.interaction_cost(player) != 0
|
|
||||||
elif dragging_inspected:
|
|
||||||
%Action.visible = true
|
%Action.visible = true
|
||||||
if inspected is ItemObject:
|
if inspected is ItemObject:
|
||||||
%ActionText.text = inspected.item.name
|
%ActionText.text = inspected.item.name
|
||||||
@@ -267,6 +247,15 @@ func update_inspector(current_inspected):
|
|||||||
%ActionText.text = item.name
|
%ActionText.text = item.name
|
||||||
else:
|
else:
|
||||||
%Action.visible = false
|
%Action.visible = false
|
||||||
|
elif current_selected_item and current_selected_item.use_text() != "" and current_selected_item.get_action_is_hold():
|
||||||
|
%Action.visible = true
|
||||||
|
%ActionText.text = current_selected_item.use_text()
|
||||||
|
%Action.modulate = DEFAULT_ACTION_COLOR
|
||||||
|
elif can_interact and inspected and inspected is Interactable:
|
||||||
|
%Action.visible = true
|
||||||
|
%ActionText.text = inspected.interact_text()
|
||||||
|
%Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
||||||
|
%ActionEnergyImage.visible = inspected.interaction_cost(player) != 0
|
||||||
elif current_selected_item and current_selected_item.use_text() != "":
|
elif current_selected_item and current_selected_item.use_text() != "":
|
||||||
%Action.visible = true
|
%Action.visible = true
|
||||||
%ActionText.text = current_selected_item.use_text() + (tr("NO_ENERGY_LEFT") if not have_energy_to_use_item else "")
|
%ActionText.text = current_selected_item.use_text() + (tr("NO_ENERGY_LEFT") if not have_energy_to_use_item else "")
|
||||||
@@ -280,8 +269,41 @@ func update_inspector(current_inspected):
|
|||||||
else:
|
else:
|
||||||
%Action.visible = false
|
%Action.visible = false
|
||||||
|
|
||||||
func stop_inspect(node: Node = get_current_inspected()):
|
func stop_inspect(node: Node):
|
||||||
if not dragging_inspected:
|
if not dragging_inspected:
|
||||||
all_inspected.erase(node)
|
all_inspected.erase(node)
|
||||||
if node is InventoryGuiItemMouseDetector:
|
if node is InventoryGuiItemMouseDetector:
|
||||||
inspected_inventory_slot = null
|
inspected_inventory_slot = null
|
||||||
|
|
||||||
|
func start_dragging():
|
||||||
|
if not dragging_inspected:
|
||||||
|
dragging_inspected = true
|
||||||
|
if inspected is ItemObject:
|
||||||
|
inspected.mouse_over = false
|
||||||
|
elif inspected is InventoryGuiItemMouseDetector:
|
||||||
|
var item_to_drop: Item = GameInfo.game_data.player_data.inventory.get_item(inspected.index)
|
||||||
|
if item_to_drop and item_to_drop.type != Item.ItemType.TOOL_ITEM:
|
||||||
|
GameInfo.game_data.player_data.inventory.remove_item_at(inspected.index)
|
||||||
|
var dropped_item_object := player.terrain.drop_item(item_to_drop, player.get_global_mouse_position())
|
||||||
|
inspected_inventory_slot = inspected
|
||||||
|
inspected = dropped_item_object
|
||||||
|
player.region.save()
|
||||||
|
else:
|
||||||
|
dragging_inspected = false
|
||||||
|
if dragging_inspected:
|
||||||
|
all_inspected.clear()
|
||||||
|
all_inspected.append(inspected)
|
||||||
|
can_interact = false
|
||||||
|
|
||||||
|
func stop_dragging():
|
||||||
|
if dragging_inspected:
|
||||||
|
dragging_inspected = false
|
||||||
|
if inspected is ItemObject:
|
||||||
|
inspected.object_sprite.tractor_beam.emitting = false
|
||||||
|
if (
|
||||||
|
inspected_inventory_slot is InventoryGuiItemMouseDetector
|
||||||
|
and GameInfo.game_data.player_data.inventory.add_item_at(inspected.item, inspected_inventory_slot.index)
|
||||||
|
):
|
||||||
|
all_inspected.clear()
|
||||||
|
inspected.queue_free()
|
||||||
|
inspected = null
|
||||||
|
|||||||
Reference in New Issue
Block a user