Compare commits

...

2 Commits

14 changed files with 207 additions and 21 deletions

View File

@ -25,3 +25,4 @@ script = ExtResource( 1 )
name = "mushroom" name = "mushroom"
inventory_icon = ExtResource( 3 ) inventory_icon = ExtResource( 3 )
in_game_sprite = SubResource( 3 ) in_game_sprite = SubResource( 3 )
consumable = true

BIN
assets/items/fist.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/fist.png-706e5fdb4c3a8f903a9552e9097a3a72.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/items/fist.png"
dest_files=[ "res://.import/fist.png-706e5fdb4c3a8f903a9552e9097a3a72.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

10
assets/items/punch.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/fist.png" type="Texture" id=2]
[resource]
script = ExtResource( 1 )
name = "punch"
inventory_icon = ExtResource( 2 )
consumable = false

BIN
assets/items/sword.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/sword.png-847a038487b8fb3480b77e98fb70eb52.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/items/sword.png"
dest_files=[ "res://.import/sword.png-847a038487b8fb3480b77e98fb70eb52.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -10,6 +10,7 @@ export var debug_state_machine: bool = false
signal state_changed(old_state_name, new_state) signal state_changed(old_state_name, new_state)
signal modifiers_updated(modifier_type, modifier_eventid) signal modifiers_updated(modifier_type, modifier_eventid)
var current_state: State var current_state: State
var state_modifiers: Array var state_modifiers: Array
onready var merged_animation_state_modifiers :StateModifierAnimatedActor = StateModifierAnimatedActor.new() 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) push_warning(get_parent().name + ": Attempt to switch state to unknown: " + new_state_name)
change_state(states_index["default"]) 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: func get_state_reference(state_name: String) -> State:
print ("what you want? ", state_name) print ("what you want? ", state_name)
if states_index.has(state_name): if states_index.has(state_name):

View File

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

View File

@ -8,7 +8,7 @@ export var player_number: int = 1
onready var player_inventory :InventoryManager = InventoryManager.new() onready var player_inventory :InventoryManager = InventoryManager.new()
#var mushroom :Item = preload("res://assets/items/doodad.tres") var punch_item :Item = preload("res://assets/items/punch.tres")
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -17,8 +17,8 @@ func _ready():
# Set initial player position in world. # Set initial player position in world.
global_position = LevelInfo.player_start_position global_position = LevelInfo.player_start_position
# player_inventory.add_to_inventory(mushroom) player_inventory.add_to_inventory(punch_item)
# player_inventory.select_primary(mushroom) player_inventory.select_primary(punch_item)
@ -56,6 +56,41 @@ func touch_the_thing(the_thing: Interactable) -> bool:
the_thing.trigger_interaction() the_thing.trigger_interaction()
if the_thing is ItemPickup: if the_thing is ItemPickup:
player_inventory.add_to_inventory(the_thing.item) player_inventory.add_to_inventory(the_thing.item)
player_inventory.select_primary(the_thing.item) player_inventory.select_secondary(the_thing.item)
the_thing.trigger_interaction() the_thing.trigger_interaction()
return true 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://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2] [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://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/tap.wav" type="AudioStream" id=25]
[ext_resource path="res://assets_tmp/SE/land.wav" type="AudioStream" id=26] [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] [sub_resource type="Resource" id=3]
resource_local_to_scene = true resource_local_to_scene = true
@ -78,7 +79,7 @@ player_number = 1
[node name="Movement_StateMachine" parent="." index="0"] [node name="Movement_StateMachine" parent="." index="0"]
starting_state_name = "idle" 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"] [node name="AnimatedSprite_StateReceiver" parent="." index="1"]
frames = ExtResource( 2 ) 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: func remove_from_inventory (_item :Item) -> int:
if _items.has(_item): if _items.has(_item):
_items[_item] -= 1 if _item.consumable:
if _items[_item] == 0: ## Reduce inventory for item
_items.erase(_item) _items[_item] -= 1
return 0 if _items[_item] == 0: ## Item count 0, no inentory
else: if primary_selection == _item:
return _items[_item] primary_selection = null
if secondary_selection == _item:
secondary_selection = null
_items.erase(_item) ## Remove it
return 0
else:
return _items[_item] ## Return item count
else:
## Non consumables don't get cleared out.
return 1
else: else:
return 0 return 0

View File

@ -8,6 +8,7 @@ extends Resource
export var name :String export var name :String
export var inventory_icon :Texture export var inventory_icon :Texture
export var in_game_sprite :SpriteFrames export var in_game_sprite :SpriteFrames
export var consumable :bool = true
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():

View File

@ -16,4 +16,10 @@ func _ready():
func _process(delta): func _process(delta):
if (PlayerInfo.player_inventory.primary_selection): if (PlayerInfo.player_inventory.primary_selection):
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon 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