inventaire de 3 items #52
This commit is contained in:
parent
42edc97401
commit
88bfa71bd8
@ -4,7 +4,27 @@ class_name Inventory
|
||||
signal inventory_changed(inventory: Inventory)
|
||||
|
||||
@export var items: Array[Item] = []
|
||||
@export var max_items: int = 1
|
||||
@export var max_items: int = 3
|
||||
|
||||
var current_item_ind: int = 0
|
||||
|
||||
func set_current_item(new_ind: int):
|
||||
if new_ind >= length():
|
||||
return
|
||||
|
||||
if new_ind != current_item_ind:
|
||||
current_item_ind = new_ind
|
||||
emit_signal("inventory_changed", self)
|
||||
|
||||
func change_current_item(ind_mod: int):
|
||||
if length() == 0:
|
||||
current_item_ind = 0
|
||||
return
|
||||
var new_ind : int = current_item_ind + ind_mod
|
||||
new_ind = new_ind % length()
|
||||
if new_ind < 0:
|
||||
new_ind += length()
|
||||
set_current_item(new_ind)
|
||||
|
||||
func add_item(item: Item):
|
||||
if items.size() < max_items:
|
||||
@ -28,10 +48,10 @@ func add_items(items_to_add: Array[Item], fillup: bool = false):
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
|
||||
func lenght() -> int:
|
||||
func length() -> int:
|
||||
return len(items)
|
||||
|
||||
func set_item(item : Item, ind: int = 0) -> bool:
|
||||
func set_item(item: Item, ind: int = 0) -> bool:
|
||||
if ind >= max_items:
|
||||
return false
|
||||
while len(items) <= ind:
|
||||
@ -40,26 +60,41 @@ func set_item(item : Item, ind: int = 0) -> bool:
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
|
||||
func get_item(ind: int = 0) -> Item:
|
||||
func get_item(ind: int = current_item_ind) -> Item:
|
||||
if len(items) <= ind:
|
||||
return null;
|
||||
return null
|
||||
return items[ind]
|
||||
|
||||
func has_item(item : Item) -> bool:
|
||||
func has_item(item: Item) -> bool:
|
||||
return item in items
|
||||
|
||||
func remove_item(item : Item):
|
||||
func remove_item(item: Item):
|
||||
items.erase(item)
|
||||
emit_signal("inventory_changed", self)
|
||||
|
||||
func pop_item(ind: int = 0) -> Item:
|
||||
func remove_item_at(ind: int = current_item_ind):
|
||||
if len(items) <= ind:
|
||||
return
|
||||
items.remove_at(ind)
|
||||
if current_item_ind >= length():
|
||||
change_current_item(-1)
|
||||
emit_signal("inventory_changed", self)
|
||||
|
||||
func remove_current_item():
|
||||
remove_item_at()
|
||||
|
||||
func pop_item(ind: int = current_item_ind) -> Item:
|
||||
if length() == 0:
|
||||
return
|
||||
|
||||
var item_removed: Item = items.pop_at(ind)
|
||||
if current_item_ind >= length():
|
||||
change_current_item(-1)
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_removed
|
||||
|
||||
func swap_items(item_to_add: Item, ind_to_get: int = 0) -> Item:
|
||||
func swap_items(item_to_add: Item, ind_to_get: int = current_item_ind) -> Item:
|
||||
var item_to_get := items[ind_to_get]
|
||||
items[ind_to_get] = item_to_add
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_to_get
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bcj812ox8xv2t"]
|
||||
[gd_scene load_steps=8 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="Texture2D" uid="uid://bo3o2qf3i20ke" path="res://common/icons/scuba-diving-tank.svg" id="2_ng3e4"]
|
||||
@ -30,6 +30,18 @@ tracks/1/keys = {
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath(".:scale")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ng201"]
|
||||
resource_name = "default"
|
||||
@ -60,10 +72,27 @@ tracks/1/keys = {
|
||||
"values": [Vector2(0, 0), Vector2(0, -8), Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ng3e4"]
|
||||
resource_name = "pickup"
|
||||
length = 0.3
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:scale")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.3),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1, 1), Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_ng3e4"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_wing4"),
|
||||
&"default": SubResource("Animation_ng201")
|
||||
&"default": SubResource("Animation_ng201"),
|
||||
&"pickup": SubResource("Animation_ng3e4")
|
||||
}
|
||||
|
||||
[node name="ItemObjectSprite" type="Node2D"]
|
||||
@ -80,6 +109,7 @@ scale = Vector2(0.875, 0.875)
|
||||
texture = ExtResource("2_ng201")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_ng3e4")
|
||||
}
|
||||
|
||||
@ -43,9 +43,7 @@ func inspector_info() -> Inspector.Info:
|
||||
)
|
||||
|
||||
func interact(player : Player) -> bool:
|
||||
var swapped_item = player.inventory.get_item()
|
||||
|
||||
player.get_item(item)
|
||||
var swapped_item = player.pick_item(item)
|
||||
|
||||
if swapped_item:
|
||||
item = swapped_item
|
||||
@ -63,6 +61,7 @@ func pickup_animation(player : Player):
|
||||
func():
|
||||
queue_free()
|
||||
)
|
||||
object_sprite.pickup_animation()
|
||||
|
||||
func generate_sprite() -> ItemObjectSprite:
|
||||
var spriteNode = SPRITE_SCENE.instantiate() as ItemObjectSprite
|
||||
|
||||
@ -10,3 +10,6 @@ func apply_texture_to_sprite(texture, item_sprite_size = 50.):
|
||||
1./(texture.get_width()/item_sprite_size),
|
||||
1./(texture.get_height()/item_sprite_size)
|
||||
)
|
||||
|
||||
func pickup_animation():
|
||||
%AnimationPlayer.play("pickup")
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
[gd_resource type="Resource" script_class="MachineType" load_steps=3 format=3 uid="uid://cv2tf0tydqj5v"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bkwh1ntvgkkrt" path="res://entities/interactables/machines/compost/compost.tscn" id="1_8ajib"]
|
||||
[ext_resource type="Script" uid="uid://bhncww816fjsb" path="res://entities/interactables/machines/scripts/machine_info.gd" id="1_vktn1"]
|
||||
[ext_resource type="Script" path="res://entities/interactables/machines/scripts/machine_info.gd" id="1_vktn1"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_vktn1")
|
||||
|
||||
@ -30,7 +30,7 @@ func interact(p : Player) -> bool:
|
||||
return false
|
||||
|
||||
p.play_sfx("harvest")
|
||||
p.delete_item(p.inventory.get_item())
|
||||
p.inventory.remove_current_item()
|
||||
containing_seed += 1
|
||||
if containing_seed >= get_seed_needed():
|
||||
$AnimationPlayer.play("empty")
|
||||
|
||||
@ -4,7 +4,7 @@ class_name Interactable
|
||||
var available : bool = true
|
||||
|
||||
func can_interact(_p : Player) -> bool:
|
||||
return true
|
||||
return available
|
||||
|
||||
func interaction_cost(_p : Player) -> int:
|
||||
return 0
|
||||
|
||||
@ -34,6 +34,15 @@ func _ready():
|
||||
inventory.inventory_changed.connect(_on_inventory_updated)
|
||||
Pointer.player = self
|
||||
|
||||
func _input(_event) -> void:
|
||||
if Input.is_action_pressed("change_item_left"):
|
||||
inventory.change_current_item(1)
|
||||
if Input.is_action_pressed("change_item_right"):
|
||||
inventory.change_current_item(-1)
|
||||
for i in range(1, 10):
|
||||
if Input.is_action_pressed("item_" + str(i)):
|
||||
inventory.set_current_item(i - 1)
|
||||
|
||||
# Méthode déclenchée par la classe planet
|
||||
func _start_pass_day():
|
||||
controlling_player = false
|
||||
@ -67,16 +76,17 @@ func _process(_delta):
|
||||
move_and_slide()
|
||||
|
||||
func _on_inventory_updated(_inventory: Inventory):
|
||||
if inventory.get_item():
|
||||
setup_preview_zone(inventory.get_item().usage_zone_radius)
|
||||
var item_texture = inventory.get_item().icon
|
||||
var item : Item = inventory.get_item()
|
||||
if item:
|
||||
setup_preview_zone(item.usage_zone_radius)
|
||||
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 = inventory.get_item() != null
|
||||
%ItemSprite.visible = inventory.get_item() != null
|
||||
%HideEyes.visible = item != null
|
||||
%ItemSprite.visible = item != null
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
|
||||
@ -112,9 +122,18 @@ func try_interact(interactable : Interactable):
|
||||
func try_move(move_to : Vector2):
|
||||
instruction = MoveInstruction.new(move_to)
|
||||
|
||||
func get_item(item : Item):
|
||||
inventory.set_item(item)
|
||||
func pick_item(item : Item) -> Item:
|
||||
var itemAdded = inventory.add_item(item)
|
||||
var currentItem : Item = inventory.get_item()
|
||||
var itemSwapped : bool = false
|
||||
if itemAdded:
|
||||
inventory.set_current_item(inventory.length() - 1)
|
||||
else:
|
||||
itemSwapped = inventory.set_item(item, inventory.current_item_ind)
|
||||
play_sfx("pick")
|
||||
if !itemSwapped:
|
||||
currentItem = null
|
||||
return currentItem
|
||||
|
||||
func drop_item():
|
||||
var item_to_drop = inventory.pop_item()
|
||||
@ -148,7 +167,7 @@ func use_item(item : Item):
|
||||
if is_item_used:
|
||||
energy -= item.energy_usage
|
||||
if item.is_one_time_use():
|
||||
delete_item(item)
|
||||
inventory.remove_current_item()
|
||||
|
||||
func upgrade_max_energy(amount = 1):
|
||||
max_energy += amount
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=28 format=3 uid="uid://12nak7amd1uq"]
|
||||
[gd_scene load_steps=30 format=3 uid="uid://12nak7amd1uq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cqao7n800qy40" path="res://gui/game/scripts/game_gui.gd" id="1_udau0"]
|
||||
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="2_nq5i2"]
|
||||
@ -7,7 +7,9 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="4_k4juk"]
|
||||
[ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/title_label_settings.tres" id="4_ujg5r"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3lff5fui1k0c" path="res://gui/game/inspector/inspector.tscn" id="6_dr1y2"]
|
||||
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/icons/shovel.svg" id="8_h6540"]
|
||||
[ext_resource type="Texture2D" uid="uid://b5cuxgisrsfgt" path="res://common/icons/player-pause.svg" id="9_2wykm"]
|
||||
[ext_resource type="Texture2D" uid="uid://bupl1y0cfj21q" path="res://entities/plants/assets/sprites/chardi/mature.png" id="9_id0t5"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_id0t5"]
|
||||
interpolation_mode = 1
|
||||
@ -375,6 +377,33 @@ focus_mode = 0
|
||||
mouse_filter = 1
|
||||
icon = ExtResource("9_2wykm")
|
||||
|
||||
[node name="Inventory" type="HBoxContainer" parent="MarginContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 8
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="MarginContainer/Inventory"]
|
||||
modulate = Color(1, 0, 1, 1)
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("8_h6540")
|
||||
expand_mode = 3
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="MarginContainer/Inventory"]
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("4_k4juk")
|
||||
expand_mode = 3
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="MarginContainer/Inventory"]
|
||||
modulate = Color(1, 0.37254903, 0.101960786, 1)
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("9_id0t5")
|
||||
expand_mode = 3
|
||||
|
||||
[node name="PassDayFade" type="ColorRect" parent="."]
|
||||
physics_interpolation_mode = 0
|
||||
layout_mode = 1
|
||||
|
||||
@ -10,6 +10,24 @@ func _on_player_updated(player:Player):
|
||||
%EnergyCount.text = str(player.energy) + "/" + str(player.max_energy)
|
||||
%EnergyInfo.modulate = Color.WHITE if player.energy > 0 else Color.RED
|
||||
|
||||
for i in player.inventory.max_items:
|
||||
var item : Item = player.inventory.get_item(i)
|
||||
if item:
|
||||
if %Inventory.get_child_count() <= i:
|
||||
var texture_rect = TextureRect.new()
|
||||
texture_rect.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
|
||||
%Inventory.add_child(texture_rect)
|
||||
%Inventory.get_child(i).texture = item.icon
|
||||
%Inventory.get_child(i).visible = true
|
||||
if i == player.inventory.current_item_ind:
|
||||
%Inventory.get_child(i).modulate = Color.WHITE
|
||||
else:
|
||||
%Inventory.get_child(i).modulate = Color.DARK_GRAY
|
||||
else:
|
||||
if %Inventory.get_child_count() > i:
|
||||
%Inventory.get_child(i).visible = false
|
||||
|
||||
|
||||
update_no_energy_left_info(player.energy)
|
||||
|
||||
func _on_planet_updated(planet:Planet):
|
||||
|
||||
@ -69,6 +69,61 @@ move={
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(231, 25),"global_position":Vector2(240, 73),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
change_item_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
change_item_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_1={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":38,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_2={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":233,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_3={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":34,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_4={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":39,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_5={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":53,"key_label":0,"unicode":40,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_6={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":54,"key_label":0,"unicode":45,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_7={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":55,"key_label":0,"unicode":232,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_8={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":56,"key_label":0,"unicode":95,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
item_9={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":57,"key_label":0,"unicode":231,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
[ext_resource type="Script" uid="uid://c54457tbocdwk" path="res://gui/menu/scripts/menu.gd" id="1_bf3um"]
|
||||
[ext_resource type="Texture2D" uid="uid://bnrjnvceprxfn" path="res://stages/terrain/planet/assets/textures/sol_gamejam_normal.png" id="2_huihk"]
|
||||
[ext_resource type="Texture2D" uid="uid://dcn4cq53h1qiy" path="res://stages/terrain/planet/resources/textures/sol_gamejam_fleurs_transp.png" id="3_tw3kd"]
|
||||
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="4_gd4vy"]
|
||||
[ext_resource type="Theme" uid="uid://ldxkd6wn5qu1" path="res://gui/ressources/default_theme.tres" id="4_gd4vy"]
|
||||
[ext_resource type="Texture2D" uid="uid://nx4wxpr6mk8l" path="res://gui/menu/assets/texture/SeedingPlanetsLogo.png" id="5_qw60f"]
|
||||
[ext_resource type="Texture2D" uid="uid://03ijmo6xlytu" path="res://gui/menu/assets/texture/abre1glow.png" id="6_eji0w"]
|
||||
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="7_qwhpj"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user