Punching and shooting a mushroom. Major inentory usage progress but lots to cleanup.

This commit is contained in:
Dustin 2025-04-07 22:57:51 -07:00
parent fc5898ce7a
commit 2e30a20389
7 changed files with 119 additions and 17 deletions

View File

@ -10,6 +10,7 @@ export var debug_state_machine: bool = false
signal state_changed(old_state_name, new_state)
signal modifiers_updated(modifier_type, modifier_eventid)
var current_state: State
var state_modifiers: Array
onready var merged_animation_state_modifiers :StateModifierAnimatedActor = StateModifierAnimatedActor.new()
@ -96,6 +97,15 @@ 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 get_state_reference(state_name: String) -> State:
print ("what you want? ", state_name)
if states_index.has(state_name):

View File

@ -1,5 +1,7 @@
extends Movement_StateReceiver
var parent_request_state_change :FuncRef
func _ready():
var state_ref :State
var state_name :String
@ -7,7 +9,7 @@ func _ready():
state_ref = get_node(callable_state_machine).get_state_reference(state_name)
#TODO Should probably assert here or something.
state_ref.connect("state_entered", self, "_on_state_entered_" + state_name)
parent_request_state_change = funcref(get_node(callable_state_machine), 'check_parent_before_state_change')
# Lets see if this nutty thing works
# var state_ref :State = get_node(callable_state_machine).get_state_reference('idle')
# state_ref.connect("state_entered", self, "_on_state_entered_idle")
@ -41,13 +43,13 @@ func wants_crouch() -> bool:
_wants_crouch = false
return false
var _wants_shoot :bool
func wants_shoot() -> bool:
var _wants_attack_primary :bool
func wants_attack_primary() -> bool:
if Input.is_action_just_pressed("attack_" + str(player_number)):
_wants_shoot = true
_wants_attack_primary = true
return true
else:
_wants_shoot = false
_wants_attack_primary = false
return false
var _wants_attack_secondary :bool
@ -105,7 +107,7 @@ func process_physics_input(delta):
get_movement_direction()
wants_jump()
wants_crouch()
wants_shoot()
wants_attack_primary()
wants_attack_secondary()
wants_dash()
wants_roll()
@ -132,15 +134,32 @@ func _state_process_physics_idle():
if _wants_roll == true:
request_state_change.call_func('roll')
if _wants_shoot == true:
request_state_change.call_func('attack_shoot')
if _wants_attack_primary == true:
#request_state_change.call_func('attack_shoot')
attack_primary()
if _wants_attack_secondary == true:
request_state_change.call_func('attack_sword')
#parent_request_state_change.call_func('attack_sword')
attack_secondary()
if $"../LadderDetector".is_colliding() and _wants_climb == true:
request_state_change.call_func('climb')
func attack_primary():
##Another thing I wish I could avoid the funcref or string call
if get_parent().has_method("primary_item"):
var _item_state_name :String = get_parent().primary_item()
if _item_state_name != '':
request_state_change.call_func(_item_state_name)
func attack_secondary():
if get_parent().has_method("secondary_item"):
var _item_state_name :String = get_parent().secondary_item()
if _item_state_name != '':
request_state_change.call_func(_item_state_name)
func _state_process_physics_attack_shoot():
if current_state.animation_finished == true:
request_state_change.call_func('idle')
@ -149,6 +168,13 @@ func _state_process_physics_attack_shoot():
#return fall_state
request_state_change.call_func('fall')
func _state_process_physics_attack_punch():
if current_state.animation_finished == true:
request_state_change.call_func('idle')
if !parent.is_on_floor():
#return fall_state
request_state_change.call_func('fall')
func _state_process_physics_attack_sword():
if current_state.animation_finished == true:

View File

@ -59,3 +59,38 @@ func touch_the_thing(the_thing: Interactable) -> bool:
player_inventory.select_secondary(the_thing.item)
the_thing.trigger_interaction()
return true
var state_to_item_map :Dictionary = {
"sword": "attack_sword" ,
"gun": "attack_shoot",
"punch" : "attack_punch",
"mushroom" : "attack_shoot"
}
##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):
player_inventory.remove_from_inventory(player_inventory.primary_selection)
return state_to_item_map[player_inventory.primary_selection.name]
return ''
func secondary_item() -> String:
if player_inventory.secondary_selection != null: # Have to make sure we even have a second
var _item_name :String = player_inventory.secondary_selection.name
if state_to_item_map.has(_item_name):
player_inventory.remove_from_inventory(player_inventory.secondary_selection)
return state_to_item_map[_item_name]
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

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=33 format=2]
[gd_scene load_steps=34 format=2]
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
@ -26,6 +26,7 @@
[ext_resource path="res://lib/classes/sound_effect_state_frame.gd" type="Script" id=24]
[ext_resource path="res://assets_tmp/SE/tap.wav" type="AudioStream" id=25]
[ext_resource path="res://assets_tmp/SE/land.wav" type="AudioStream" id=26]
[ext_resource path="res://src/actors/players/playerE/states/attack_punch.tres" type="Resource" id=27]
[sub_resource type="Resource" id=3]
resource_local_to_scene = true
@ -78,7 +79,7 @@ player_number = 1
[node name="Movement_StateMachine" parent="." index="0"]
starting_state_name = "idle"
states = [ ExtResource( 4 ), ExtResource( 9 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 12 ), ExtResource( 11 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), SubResource( 3 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 22 ), ExtResource( 23 ) ]
states = [ ExtResource( 4 ), ExtResource( 9 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 12 ), ExtResource( 11 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), SubResource( 3 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 27 ) ]
[node name="AnimatedSprite_StateReceiver" parent="." index="1"]
frames = ExtResource( 2 )

View File

@ -0,0 +1,17 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
resource_name = "attack_punch"
script = ExtResource( 1 )
debug_state = false
timeout_seconds = 0.0
name = "attack_punch"
horizontal_speed = 1.36422e-12
horizontal_acceleration = 0.0
horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0
animation_sequence = [ "attack-punch" ]

View File

@ -39,12 +39,21 @@ func add_to_inventory(_item :Item) -> int:
func remove_from_inventory (_item :Item) -> int:
if _items.has(_item):
if _item.consumable:
## Reduce inventory for item
_items[_item] -= 1
if _items[_item] == 0:
_items.erase(_item)
if _items[_item] == 0: ## Item count 0, no inentory
if primary_selection == _item:
primary_selection = null
if secondary_selection == _item:
secondary_selection = null
_items.erase(_item) ## Remove it
return 0
else:
return _items[_item]
return _items[_item] ## Return item count
else:
## Non consumables don't get cleared out.
return 1
else:
return 0

View File

@ -16,6 +16,10 @@ func _ready():
func _process(delta):
if (PlayerInfo.player_inventory.primary_selection):
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon
else:
primary_item.texture = null
if (PlayerInfo.player_inventory.secondary_selection):
secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
else:
secondary_item.texture = null