Compare commits

..

4 Commits

Author SHA1 Message Date
bf481c5eea Item switching 2025-04-08 22:55:57 -07:00
ee41748ab5 Add keys for p1 and p2 2025-04-08 20:59:59 -07:00
ed0ee8de71 Swordgit add .! 2025-04-08 19:13:32 -07:00
dced928e16 Comment out unused plan A for inventory 2025-04-08 18:57:09 -07:00
8 changed files with 160 additions and 33 deletions

10
assets/items/sword.tres Normal file
View File

@ -0,0 +1,10 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://src/classes/item.gd" type="Script" id=1]
[ext_resource path="res://assets/items/sword.png" type="Texture" id=2]
[resource]
script = ExtResource( 1 )
name = "sword"
inventory_icon = ExtResource( 2 )
consumable = false

View File

@ -97,14 +97,14 @@ func change_to_known_state(new_state_name: String) -> void:
push_warning(get_parent().name + ": Attempt to switch state to unknown: " + new_state_name)
change_state(states_index["default"])
func check_parent_before_state_change(new_state_name: String) -> bool:
##TODO: Make this a verifiable funcref or something
if get_parent().has_method("check_state_change"):
var _check_result = get_parent().check_state_change(new_state_name)
if _check_result:
change_to_known_state(new_state_name)
return true
return false
#func check_parent_before_state_change(new_state_name: String) -> bool:
# ##TODO: Make this a verifiable funcref or something
# if get_parent().has_method("check_state_change"):
# var _check_result = get_parent().check_state_change(new_state_name)
# if _check_result:
# change_to_known_state(new_state_name)
# return true
# return false
func get_state_reference(state_name: String) -> State:
print ("what you want? ", state_name)

View File

@ -240,17 +240,28 @@ move_left_1={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right_1={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_up_1={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"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":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
crouch_1={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
jump_1={
@ -274,26 +285,74 @@ attack_1={
attack_secondary_1={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":44,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
move_left_2={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":0,"axis_value":-1.0,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
]
}
move_right_2={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":0,"axis_value":1.0,"script":null)
]
}
move_up_2={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":-1.0,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
]
}
crouch_2={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":1.0,"script":null)
]
}
jump_2={
"deadzone": 0.5,
"events": [ 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)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}
shoot_2={
attack_2={
"deadzone": 0.5,
"events": [ ]
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":2,"pressure":0.0,"pressed":false,"script":null)
]
}
attack_secondary_2={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
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={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":4,"pressure":0.0,"pressed":false,"script":null)
]
}
switch_secondary_item_2={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":5,"pressure":0.0,"pressed":false,"script":null)
]
}
[layer_names]

View File

@ -7,17 +7,22 @@ extends Interactable
# var b = "text"
export var item :Resource
var item_sprite :AnimatedSprite
# Called when the node enters the scene tree for the first time.
func _ready():
assert( item is Item, "Proper Item resourse type not given " + self.name)
if item is Item:
item_sprite = AnimatedSprite.new()
item_sprite.frames = item.in_game_sprite
add_child(item_sprite)
item_sprite.play()
if item.in_game_sprite != null:
var anim_sprite = AnimatedSprite.new()
anim_sprite.frames = item.in_game_sprite
add_child(anim_sprite)
anim_sprite.play()
elif item.inventory_icon != null:
var sprite = Sprite.new()
sprite.texture = item.inventory_icon
add_child(sprite)
func trigger_interaction():
queue_free()

View File

@ -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:

View File

@ -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:
@ -84,13 +97,13 @@ func secondary_item() -> String:
return ''
func check_state_change(_new_state_name: String) -> bool:
match _new_state_name:
"attack_sword":
print("nope.")
return false
"attack_shoot":
return true
_: # None
return true
return true
#func check_state_change(_new_state_name: String) -> bool:
# match _new_state_name:
# "attack_sword":
# print("nope.")
# return false
# "attack_shoot":
# return true
# _: # None
# return true
# return true

View File

@ -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

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=16 format=2]
[ext_resource path="res://src/templates/level_templates/LevelTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/levels/LegacyFantasy-High_Forest/tileset.tres" type="TileSet" id=2]
@ -8,6 +8,7 @@
[ext_resource path="res://assets/UI/no_cam_tile.png" type="Texture" id=6]
[ext_resource path="res://src/Interactables/ItemPickup.tscn" type="PackedScene" id=7]
[ext_resource path="res://assets/items/doodad.tres" type="Resource" id=8]
[ext_resource path="res://assets/items/sword.tres" type="Resource" id=9]
[sub_resource type="CircleShape2D" id=1]
radius = 5.09902
@ -116,7 +117,7 @@ show_collision = true
collision_layer = 256
collision_mask = 0
format = 1
tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, 65535, 0, 0, 524287, 0, 0, 589824, 0, 0, 589838, 0, 0 )
tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, 65535, 0, 0, 16, 0, 0, 524287, 0, 0, 524304, 0, 0, 589824, 0, 0, 589838, 0, 0 )
[node name="ItemPickup" parent="." index="9" instance=ExtResource( 7 )]
position = Vector2( 203, 38 )
@ -125,3 +126,11 @@ item = ExtResource( 8 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup" index="0"]
shape = SubResource( 6 )
[node name="ItemPickup2" parent="." index="10" instance=ExtResource( 7 )]
position = Vector2( 155, 133 )
type_name = "item_pickup"
item = ExtResource( 9 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup2" index="0"]
shape = SubResource( 6 )