Item switching
This commit is contained in:
parent
ee41748ab5
commit
bf481c5eea
|
|
@ -335,11 +335,13 @@ attack_secondary_2={
|
|||
switch_primary_item_1={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":4,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":72,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
switch_secondary_item_1={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":5,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":74,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
switch_primary_item_2={
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ extends Movement_StateReceiver
|
|||
|
||||
var parent_request_state_change :FuncRef
|
||||
|
||||
var player_number: int = 1
|
||||
|
||||
func _ready():
|
||||
var state_ref :State
|
||||
var state_name :String
|
||||
|
|
@ -16,8 +18,8 @@ func _ready():
|
|||
# It works but node order really mattered.
|
||||
# State machine needed to be processed first probably for ready function.
|
||||
# good to know!
|
||||
player_number = parent.player_number
|
||||
|
||||
var player_number: int = 1
|
||||
|
||||
func get_movement_direction() -> float:
|
||||
#return Input.get_axis('move_left', 'move_right')
|
||||
|
|
@ -72,7 +74,7 @@ func wants_dash() -> bool:
|
|||
|
||||
var _wants_roll :bool
|
||||
func wants_roll() -> bool:
|
||||
if Input.is_action_just_pressed("dash_" + str(player_number)) and Input.is_action_pressed("ui_up"):
|
||||
if Input.is_action_just_pressed("dash_" + str(player_number)) and Input.is_action_pressed("move_up_" + str(player_number)):
|
||||
_wants_roll = true
|
||||
return true
|
||||
else:
|
||||
|
|
@ -81,7 +83,7 @@ func wants_roll() -> bool:
|
|||
|
||||
var _wants_climb :bool
|
||||
func wants_climb() -> bool:
|
||||
if Input.is_action_pressed("ui_up"):
|
||||
if Input.is_action_pressed("move_up_" + str(player_number)):
|
||||
_wants_climb = true
|
||||
return true
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ func _ready():
|
|||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
PlayerInfo.player_position = global_position.round()
|
||||
match movement_state_machine.current_state.name:
|
||||
"idle":
|
||||
if Input.is_action_just_released("switch_primary_item_" + str(player_number)):
|
||||
var _selected_item = player_inventory.switch_primary()
|
||||
if _selected_item:
|
||||
print("Switched Primary item to: ", _selected_item.name)
|
||||
|
||||
func hit_Receiver(damage):
|
||||
$Hurtbox_Component.set_hurtbox(false)
|
||||
|
|
@ -69,10 +75,17 @@ var state_to_item_map :Dictionary = {
|
|||
|
||||
##TODO: We need to find a way to 'use' the item.
|
||||
func primary_item() -> String:
|
||||
if player_inventory.primary_selection.consumable == false:
|
||||
if state_to_item_map.has(player_inventory.primary_selection.name):
|
||||
# if player_inventory.primary_selection.consumable == false:
|
||||
# if state_to_item_map.has(player_inventory.primary_selection.name):
|
||||
# player_inventory.remove_from_inventory(player_inventory.primary_selection)
|
||||
# return state_to_item_map[player_inventory.primary_selection.name]
|
||||
|
||||
if player_inventory.primary_selection != null: # Have to make sure we even have a second
|
||||
var _item_name :String = player_inventory.primary_selection.name
|
||||
if state_to_item_map.has(_item_name):
|
||||
player_inventory.remove_from_inventory(player_inventory.primary_selection)
|
||||
return state_to_item_map[player_inventory.primary_selection.name]
|
||||
return state_to_item_map[_item_name]
|
||||
|
||||
return ''
|
||||
|
||||
func secondary_item() -> String:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,35 @@ func select_primary(_item :Item) -> void:
|
|||
if _items.has(_item):
|
||||
primary_selection = _item
|
||||
|
||||
func switch_primary() -> Item:
|
||||
## Don't switch unless there is another item
|
||||
if primary_selection != null and _items.size() > 1:
|
||||
var found_item :bool = false
|
||||
var itemarr = _items.keys()
|
||||
for i in itemarr:
|
||||
## Item found in last iteration, grab the next one.
|
||||
if found_item:
|
||||
if i == secondary_selection:
|
||||
break
|
||||
primary_selection = i
|
||||
return i
|
||||
if i == primary_selection:
|
||||
found_item = true
|
||||
## Item found but was the last in the list, grab the first one.
|
||||
if found_item and itemarr[0] != primary_selection:
|
||||
if itemarr[0] != secondary_selection:
|
||||
primary_selection = itemarr[0]
|
||||
return itemarr[0]
|
||||
## Swap primary and secondary
|
||||
if secondary_selection != null:
|
||||
var i = secondary_selection
|
||||
if primary_selection != null:
|
||||
secondary_selection = primary_selection
|
||||
primary_selection = i
|
||||
return i
|
||||
## Nothing changed
|
||||
return null
|
||||
|
||||
func select_secondary(_item :Item) -> void:
|
||||
if _items.has(_item):
|
||||
secondary_selection = _item
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user