Compare commits

..

10 Commits

Author SHA1 Message Date
18424079b4 Stamina tweak. 2025-04-10 22:45:27 -07:00
6dfba1b5b9 Stamina callback to player to decide transition. 2025-04-10 22:39:48 -07:00
41b740be4f Stamina counter 2025-04-10 20:12:47 -07:00
2f8d233559 Camera is scene unique 2025-04-10 19:30:13 -07:00
b1005379d7 Pew Machine now a component 2025-04-10 19:27:58 -07:00
35eb5b56fa Move to folder 2025-04-10 18:27:51 -07:00
51ffebbf75 Projectile is actually a parent scene 2025-04-10 18:26:20 -07:00
d1db3ed693 rename actor within scene so I dont forget 2025-04-10 18:07:58 -07:00
41897c0dc5 rename actor scene 2025-04-10 18:05:47 -07:00
0ea8d4cd13 parent_scene org structure 2025-04-10 18:02:03 -07:00
16 changed files with 199 additions and 48 deletions

View File

@ -37,6 +37,7 @@ margin_bottom = 182.0
rect_scale = Vector2( 2, 2 )
[node name="Viewport" type="Viewport" parent="ViewportContainer"]
unique_name_in_owner = true
size = Vector2( 320, 180 )
handle_input_locally = false
render_target_update_mode = 3
@ -54,6 +55,7 @@ position = Vector2( 112, 56 )
[node name="UI_Layer" parent="ViewportContainer/Viewport" instance=ExtResource( 3 )]
[node name="CameraGuide" type="KinematicBody2D" parent="ViewportContainer/Viewport"]
unique_name_in_owner = true
position = Vector2( 160, 90 )
collision_layer = 0
collision_mask = 256
@ -65,6 +67,7 @@ shape = SubResource( 1 )
one_way_collision = true
[node name="Camera2D" type="Camera2D" parent="ViewportContainer/Viewport"]
unique_name_in_owner = true
position = Vector2( 160, 90 )
current = true
script = ExtResource( 6 )

View File

@ -0,0 +1,39 @@
class_name StaminaComponent
extends Node
export var max_stamina: int = 0
## Recovery Rate in units per second
export var recovery_rate: int = 0
onready var stamina :int = max_stamina
signal stamina_depleted()
var recovery_counter: float = 0
func _process(delta):
recovery_counter += delta
if recovery_rate != 0:
var _rate :float = 1.0/float(recovery_rate)
if recovery_counter > _rate: ## Divide by zero warning
recover(1)
recovery_counter = 0
func reduce_stamina(_amount :int):
if _amount < 0:
push_error("ERROR: Only positive numbers in stamina component functions.")
stamina -= _amount
if stamina <= 0:
emit_signal("stamina_depleted")
stamina = 0
func recover(recover_amount :int):
if recover_amount < 0:
push_error("ERROR: Only positive numbers in stamina component functions.")
return
stamina += recover_amount
if stamina > max_stamina:
stamina = max_stamina

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://lib/components/Stamina_Component.gd" type="Script" id=1]
[node name="Stamina_Component" type="Node"]
script = ExtResource( 1 )

View File

@ -1,20 +1,20 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://lib/classes/animated_sprite_state_receiver.gd" type="Script" id=1]
[ext_resource path="res://lib/classes/state_machine.gd" type="Script" id=2]
[ext_resource path="res://lib/classes/audiostreamplayer_state_receiver.gd" type="Script" id=3]
[ext_resource path="res://lib/classes/movement_state_receiver.gd" type="Script" id=5]
[ext_resource path="res://lib/classes/actor.gd" type="Script" id=8]
[ext_resource path="res://lib/classes/state_machine.gd" type="Script" id=1]
[ext_resource path="res://lib/classes/actor.gd" type="Script" id=2]
[ext_resource path="res://lib/classes/movement_state_receiver.gd" type="Script" id=3]
[ext_resource path="res://lib/classes/animated_sprite_state_receiver.gd" type="Script" id=4]
[ext_resource path="res://lib/classes/audiostreamplayer_state_receiver.gd" type="Script" id=5]
[node name="ActorTemplate" type="KinematicBody2D"]
[node name="Actor" type="KinematicBody2D"]
collision_layer = 2
script = ExtResource( 8 )
[node name="Movement_StateMachine" type="Node" parent="."]
script = ExtResource( 2 )
[node name="AnimatedSprite_StateReceiver" type="AnimatedSprite" parent="."]
[node name="Movement_StateMachine" type="Node" parent="."]
script = ExtResource( 1 )
[node name="AnimatedSprite_StateReceiver" type="AnimatedSprite" parent="."]
script = ExtResource( 4 )
__meta__ = {
"_aseprite_wizard_config_": {
"layer": "",
@ -31,9 +31,9 @@ __meta__ = {
callable_state_machine = NodePath("../Movement_StateMachine")
[node name="Movement_StateReceiver" type="Node" parent="."]
script = ExtResource( 5 )
script = ExtResource( 3 )
callable_state_machine = NodePath("../Movement_StateMachine")
[node name="AudioStreamPlayer_StateReceiver" type="AudioStreamPlayer" parent="."]
script = ExtResource( 3 )
script = ExtResource( 5 )
callable_state_machine = NodePath("../Movement_StateMachine")

View File

@ -104,6 +104,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://lib/classes/sound_effect_state_frame.gd"
}, {
"base": "Node",
"class": "StaminaComponent",
"language": "GDScript",
"path": "res://lib/components/Stamina_Component.gd"
}, {
"base": "Resource",
"class": "State",
"language": "GDScript",
@ -159,6 +164,7 @@ _global_script_class_icons={
"Movement_StateReceiver": "",
"Projectile": "",
"SE_StateFrame": "",
"StaminaComponent": "",
"State": "",
"StateAnimatedActor": "",
"StateMachine": "",

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=116 format=2]
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://lib/parent_scenes/actor.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/actors/players/playerD/movement_component.gd" type="Script" id=2]
[ext_resource path="res://src/actors/players/playerD/Player.gd" type="Script" id=3]
[ext_resource path="res://lib/components/Health_Component.tscn" type="PackedScene" id=7]

View File

@ -1,10 +1,14 @@
extends Movement_StateReceiver
var parent_request_state_change :FuncRef
var parent_use_primary_item :FuncRef
var player_number: int = 1
onready var pew_machine = $"%PewMachine"
onready var stamina_component = $"%Stamina_Component"
var state_stamina_cost :Dictionary
func _ready():
var state_ref :State
@ -14,6 +18,10 @@ func _ready():
#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')
if parent.has_method("use_primary_item"):
parent_use_primary_item = funcref(parent, "use_primary_item")
# 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")
@ -30,7 +38,7 @@ func get_movement_direction() -> float:
var _wants_jump :bool
func wants_jump() -> bool:
if Input.is_action_just_pressed("jump_" + str(player_number)):
if Input.is_action_just_pressed("jump_" + str(player_number)) and stamina_component.stamina >= state_stamina_cost["jump"]:
desired_movement_vector.y = UP
_wants_jump = true
return true
@ -77,11 +85,11 @@ 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("move_up_" + str(player_number)):
_wants_roll = true
return true
else:
_wants_roll = false
return false
if parent.enough_stamina_for("roll"):
_wants_roll = true
return true
_wants_roll = false
return false
var _wants_climb :bool
func wants_climb() -> bool:
@ -151,15 +159,20 @@ func _state_process_physics_idle():
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 get_parent().has_method("use_primary_item"):
# var _item_state_name :String = get_parent().use_primary_item()
# if _item_state_name != '':
# request_state_change.call_func(_item_state_name)
if parent_use_primary_item.is_valid():
var _item_state_name :String = parent_use_primary_item.call_func()
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 get_parent().has_method("use_secondary_item"):
var _item_state_name :String = get_parent().use_secondary_item()
if _item_state_name != '':
request_state_change.call_func(_item_state_name)

View File

@ -7,25 +7,47 @@ export var player_number: int = 1
# var b = "text"
onready var player_inventory :InventoryManager = InventoryManager.new()
onready var stamina_component = $"%Stamina_Component"
onready var health_component = $"%Health_Component"
var punch_item :Item = preload("res://assets/items/punch.tres")
const state_stamina_cost :Dictionary = {
"jump": 10,
"attack_sword":20,
"attack_punch":10,
"roll":40,
"ledge_climb":10
}
# Called when the node enters the scene tree for the first time.
func _ready():
PlayerInfo.player_health = $Health_Component.health
PlayerInfo.player_health = health_component.health
PlayerInfo.player_inventory = player_inventory
PlayerInfo.player_stamina = stamina_component.stamina
# Set initial player position in world.
global_position = LevelInfo.player_start_position
player_inventory.add_to_inventory(punch_item)
player_inventory.select_primary(punch_item)
movement_component.state_stamina_cost = state_stamina_cost
#var stamina_recovery :float = 0.0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
PlayerInfo.player_position = global_position.round()
# stamina_recovery += delta
# if stamina_recovery > 1.0:
# stamina_component.recover(1)
# stamina_recovery = 0.0
# #print("recover ", stamina_component.stamina)
PlayerInfo.player_stamina = stamina_component.stamina
match movement_state_machine.current_state.name:
"idle":
if Input.is_action_just_released("switch_primary_item_" + str(player_number)):
@ -39,10 +61,10 @@ func _process(delta):
func hit_Receiver(damage):
$Hurtbox_Component.set_hurtbox(false)
$Health_Component.take_damage(damage)
health_component.take_damage(damage)
if $Health_Component.health > 0:
movement_state_machine.change_to_known_state('hurt')
PlayerInfo.player_health = $Health_Component.health
PlayerInfo.player_health = health_component.health
if PlayerInfo.player_health <= 0:
return
yield( get_tree().create_timer(2 + movement_state_machine.get_state_reference('hurt').timeout_seconds), "timeout")
@ -70,6 +92,15 @@ func touch_the_thing(the_thing: Interactable) -> bool:
the_thing.trigger_interaction()
return true
func enough_stamina_for(_state_name :String) -> bool:
if state_stamina_cost.has(_state_name):
if stamina_component.stamina >= state_stamina_cost[_state_name]:
return true
else:
return false
## Return true by default because we don't have a cost for this move
return true
var state_to_item_map :Dictionary = {
"sword": "attack_sword" ,
"gun": "attack_shoot",
@ -78,7 +109,7 @@ var state_to_item_map :Dictionary = {
}
##TODO: We need to find a way to 'use' the item.
func primary_item() -> String:
func use_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)
@ -87,18 +118,32 @@ func primary_item() -> String:
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):
var state_name = state_to_item_map[_item_name]
## This item state has a cost associated with it.
if enough_stamina_for(state_name):
#print("Yup: ", state_stamina_cost[state_name], "<=", stamina_component.stamina)
player_inventory.remove_from_inventory(player_inventory.primary_selection)
return state_to_item_map[_item_name]
else:
## TODO: maybe some sort of 'fail' animation state
#print("Nope: ", state_stamina_cost[state_name], "<=", stamina_component.stamina)
return '' ## you can't use this
player_inventory.remove_from_inventory(player_inventory.primary_selection)
return state_to_item_map[_item_name]
return ''
func secondary_item() -> String:
func use_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]
var state_name = state_to_item_map[_item_name]
if enough_stamina_for(state_name):
player_inventory.remove_from_inventory(player_inventory.secondary_selection)
return state_to_item_map[_item_name]
else:
## TODO: maybe some sort of 'fail' animation state
return ''
return ''
#func check_state_change(_new_state_name: String) -> bool:
@ -111,3 +156,10 @@ func secondary_item() -> String:
# _: # None
# return true
# return true
func _on_Movement_StateMachine_state_changed(old_state_name, new_state):
# if new_state.name == "jump":
# stamina_component.reduce_stamina(state_stamina_cost["jump"])
if state_stamina_cost.has(new_state.name):
stamina_component.reduce_stamina(state_stamina_cost[new_state.name])

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=36 format=2]
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://lib/parent_scenes/actor.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
[ext_resource path="res://src/actors/players/playerE/PlayerE.gd" type="Script" id=3]
[ext_resource path="res://src/actors/players/playerE/states/idle.tres" type="Resource" id=4]
@ -27,8 +27,8 @@
[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]
[ext_resource path="res://src/PewMachine.gd" type="Script" id=28]
[ext_resource path="res://src/projectiles/MushroomPew.tscn" type="PackedScene" id=29]
[ext_resource path="res://src/components/PewMachine.tscn" type="PackedScene" id=28]
[ext_resource path="res://lib/components/Stamina_Component.tscn" type="PackedScene" id=29]
[sub_resource type="Resource" id=3]
resource_local_to_scene = true
@ -132,9 +132,15 @@ position = Vector2( 0, 2 )
shape = SubResource( 1 )
[node name="Health_Component" parent="." index="8" instance=ExtResource( 17 )]
unique_name_in_owner = true
max_health = 100
[node name="Hurtbox_Component" parent="." index="9" instance=ExtResource( 16 )]
[node name="Stamina_Component" parent="." index="9" instance=ExtResource( 29 )]
unique_name_in_owner = true
max_stamina = 50
recovery_rate = 12
[node name="Hurtbox_Component" parent="." index="10" instance=ExtResource( 16 )]
collision_layer = 16
collision_mask = 128
hurtbox_entered_function = "hit_Receiver"
@ -144,12 +150,10 @@ modulate = Color( 0, 0, 1, 1 )
position = Vector2( -1, 2 )
shape = SubResource( 2 )
[node name="Interactable_Receiver" type="Node" parent="." index="10"]
[node name="Interactable_Receiver" type="Node" parent="." index="11"]
script = ExtResource( 21 )
interactable_parent_callback = "touch_the_thing"
[node name="PewMachine" type="Position2D" parent="." index="11"]
unique_name_in_owner = true
position = Vector2( 21, -7 )
script = ExtResource( 28 )
scene_path = ExtResource( 29 )
[node name="PewMachine" parent="." index="12" instance=ExtResource( 28 )]
[connection signal="state_changed" from="Movement_StateMachine" to="." method="_on_Movement_StateMachine_state_changed"]

View File

@ -1,14 +1,17 @@
class_name Projectile
extends Area2D
##TODO: Probably implement some sort of object pooling option
## so wen're not just deleting itself every timemout or screen exit.
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var velocity_pps :float = 1
export var lifespan :float = -1
var direction_normal := Vector2(0,0)
var time_alive :float = 0.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
@ -16,9 +19,13 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if lifespan != -1:
time_alive += delta
if time_alive > lifespan:
queue_free()
rotate(delta * 10)
position += direction_normal * velocity_pps * delta
func _on_body_entered(body):
var colliding_node = body
@ -28,3 +35,7 @@ func _on_body_entered(body):
func _on_area_entered(area):
pass # Replace with function body.
func _on_VisibilityNotifier2D_screen_exited():
queue_free()

View File

@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/components/PewMachine.gd" type="Script" id=1]
[ext_resource path="res://src/projectiles/MushroomPew.tscn" type="PackedScene" id=2]
[node name="PewMachine" type="Position2D"]
unique_name_in_owner = true
position = Vector2( 21, -7 )
script = ExtResource( 1 )
scene_path = ExtResource( 2 )

View File

@ -2,9 +2,12 @@
[ext_resource path="res://src/classes/projectile.gd" type="Script" id=1]
[node name="Projectile_Template" type="Area2D"]
[node name="Projectile" type="Area2D"]
monitorable = false
script = ExtResource( 1 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://src/templates/projectile_template.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/parent_scenes/projectile.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/items/mushroom_icon.png" type="Texture" id=2]
[sub_resource type="CapsuleShape2D" id=1]
@ -9,6 +9,7 @@ height = 2.0
[node name="MushroomPew" instance=ExtResource( 1 )]
velocity_pps = 300.0
lifespan = 0.5
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]
shape = SubResource( 1 )

View File

@ -16,6 +16,8 @@ onready var DialogIndicator = $PanelContainer/Polygon2D
onready var health_bar = $HealthBar
onready var stamina_bar = $StaminaBar
## Cool I can bring this in with a ctrl drag
onready var selected_inventory_items = $"%SelectedInventoryItems"

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=2]
@ -8,6 +8,7 @@
[ext_resource path="res://assets/UI/Healthbar-Indicator.png" type="Texture" id=6]
[ext_resource path="res://assets/UI/Staminabar-Indicator.png" type="Texture" id=7]
[ext_resource path="res://src/ui/SelectedInventoryItems.gd" type="Script" id=8]
[ext_resource path="res://src/ui/StaminaBar.gd" type="Script" id=9]
[node name="HUD" type="CanvasLayer"]
pause_mode = 2
@ -71,7 +72,7 @@ value = 50.0
texture_under = ExtResource( 4 )
texture_progress = ExtResource( 7 )
texture_progress_offset = Vector2( 1, 1 )
script = ExtResource( 5 )
script = ExtResource( 9 )
[node name="Debug" type="Label" parent="."]
anchor_left = 1.0