Compare commits
12 Commits
a87955eb0d
...
3f19a92db6
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f19a92db6 | |||
| 4125e9351c | |||
| 761fe8d66c | |||
| 44a32e2e47 | |||
| 195b8f064f | |||
| 020cae1caf | |||
| 98c92dbeaf | |||
| 402ce4456f | |||
| 0af4a19828 | |||
| 20c5240dc2 | |||
| 7e03daa236 | |||
| f35ab3703b |
Binary file not shown.
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 16 KiB |
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_resource type="TileSet" load_steps=13 format=2]
|
[gd_resource type="TileSet" load_steps=15 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=1]
|
[ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=1]
|
||||||
|
|
||||||
|
|
@ -35,6 +35,12 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
||||||
[sub_resource type="ConvexPolygonShape2D" id=12]
|
[sub_resource type="ConvexPolygonShape2D" id=12]
|
||||||
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape2D" id=13]
|
||||||
|
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape2D" id=14]
|
||||||
|
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
0/name = "Assets.png 0"
|
0/name = "Assets.png 0"
|
||||||
0/texture = ExtResource( 1 )
|
0/texture = ExtResource( 1 )
|
||||||
|
|
@ -122,5 +128,17 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
||||||
"one_way_margin": 1.0,
|
"one_way_margin": 1.0,
|
||||||
"shape": SubResource( 12 ),
|
"shape": SubResource( 12 ),
|
||||||
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
|
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||||
|
}, {
|
||||||
|
"autotile_coord": Vector2( 8, 2 ),
|
||||||
|
"one_way": false,
|
||||||
|
"one_way_margin": 1.0,
|
||||||
|
"shape": SubResource( 13 ),
|
||||||
|
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||||
|
}, {
|
||||||
|
"autotile_coord": Vector2( 9, 2 ),
|
||||||
|
"one_way": false,
|
||||||
|
"one_way_margin": 1.0,
|
||||||
|
"shape": SubResource( 14 ),
|
||||||
|
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||||
} ]
|
} ]
|
||||||
0/z_index = 0
|
0/z_index = 0
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,11 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/state_modifier_properties.gd"
|
"path": "res://src/state_modifier_properties.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Node2D",
|
||||||
|
"class": "Modifier_Receiver",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/components/Modifier_Receiver.gd"
|
||||||
|
}, {
|
||||||
"base": "Node",
|
"base": "Node",
|
||||||
"class": "MovementComponent",
|
"class": "MovementComponent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
|
@ -93,6 +98,7 @@ _global_script_class_icons={
|
||||||
"Interactable_Receiver": "",
|
"Interactable_Receiver": "",
|
||||||
"Level": "",
|
"Level": "",
|
||||||
"ModifierProperties": "",
|
"ModifierProperties": "",
|
||||||
|
"Modifier_Receiver": "",
|
||||||
"MovementComponent": "",
|
"MovementComponent": "",
|
||||||
"State": "",
|
"State": "",
|
||||||
"StateAnimatedActor": "",
|
"StateAnimatedActor": "",
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
52
src/components/Modifier_Component.gd
Normal file
52
src/components/Modifier_Component.gd
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
var modifier_type = 0
|
||||||
|
|
||||||
|
export var modifier_name :String = ''
|
||||||
|
var animation_name: String = '' # Not using this one
|
||||||
|
var timeout_seconds: float = 0.0 # Not doing timeout based ones yet either.
|
||||||
|
|
||||||
|
export var directional_modifier: bool = false
|
||||||
|
|
||||||
|
export var move_speed: float = 0.0
|
||||||
|
export var move_acceleration: float = 0.0
|
||||||
|
export var move_speed_modifier: float = 0.0
|
||||||
|
export var move_modifier_move_acceleration: float = 0.0
|
||||||
|
export var jerk_factor: float = 0
|
||||||
|
|
||||||
|
export var gravity_modifier: int = 0
|
||||||
|
|
||||||
|
#var state_timeout: Timer
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
var modifier :StateModifier
|
||||||
|
#var modifier_properties: ModifierProperties
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
modifier = StateModifier.new()
|
||||||
|
modifier.ready( modifier_name, animation_name , modifier.TYPE.NONE, timeout_seconds)
|
||||||
|
modifier.modifier_properties = ModifierProperties.new( move_speed,
|
||||||
|
gravity_modifier,
|
||||||
|
move_acceleration,
|
||||||
|
move_speed_modifier,
|
||||||
|
move_modifier_move_acceleration,
|
||||||
|
jerk_factor)
|
||||||
|
print("Debug Direction property shy are you stopid?! ", directional_modifier)
|
||||||
|
modifier.modifier_properties.directional_modifier = directional_modifier
|
||||||
|
|
||||||
|
func _on_Modifier_Component_body_entered(body):
|
||||||
|
var colliding_node = body
|
||||||
|
if colliding_node.has_node("Modifier_Receiver"):
|
||||||
|
colliding_node.get_node("Modifier_Receiver").register_modifier(modifier)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Modifier_Component_body_exited(body):
|
||||||
|
var colliding_node = body
|
||||||
|
if colliding_node.has_node("Modifier_Receiver"):
|
||||||
|
colliding_node.get_node("Modifier_Receiver").remove_modifier(modifier)
|
||||||
9
src/components/Modifier_Component.tscn
Normal file
9
src/components/Modifier_Component.tscn
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://src/components/Modifier_Component.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Modifier_Component" type="Area2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_Modifier_Component_body_entered"]
|
||||||
|
[connection signal="body_exited" from="." to="." method="_on_Modifier_Component_body_exited"]
|
||||||
53
src/components/Modifier_Receiver.gd
Normal file
53
src/components/Modifier_Receiver.gd
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
class_name Modifier_Receiver
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
# This may be stupid but we're going to have two kinds of callbacks here.
|
||||||
|
# It's going to be up to the parent/actor/kinematicbody2d/whatever to know
|
||||||
|
# what conditions have to be met before being able to call that interactible's
|
||||||
|
# function.
|
||||||
|
# This is a nice and generic interface that I might be able to use for
|
||||||
|
# things like opening doors in a level, opening chests/flipping switches etc.
|
||||||
|
|
||||||
|
# This node can keep an array of various interactibles within a level
|
||||||
|
# and provide several helper functions for managing them perhaps.
|
||||||
|
|
||||||
|
export(String) var modifier_parent_callback = ""
|
||||||
|
export var debug_receiver :bool = false
|
||||||
|
|
||||||
|
var call_function: FuncRef
|
||||||
|
|
||||||
|
#var interactable_function_callables = []
|
||||||
|
|
||||||
|
var modifier_collection = []
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
##NOTE:
|
||||||
|
## Call function should be implemented as two parameters, one expecting a modifier
|
||||||
|
## and the other expecting a boolean as to whether its being added
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
if modifier_parent_callback:
|
||||||
|
call_function = funcref(owner, modifier_parent_callback)
|
||||||
|
else:
|
||||||
|
print("Warning: No modifier receiver function defined on ", owner.name)
|
||||||
|
|
||||||
|
# Switching to a new model that starts with Hitbox
|
||||||
|
func register_modifier(modifier: StateModifier):
|
||||||
|
if modifier_collection.has(modifier) == false:
|
||||||
|
print("New Modifier Registered " + modifier.name)
|
||||||
|
modifier_collection.append(modifier)
|
||||||
|
if call_function.is_valid():
|
||||||
|
call_function.call_func(modifier, true)
|
||||||
|
|
||||||
|
func remove_modifier(modifier):
|
||||||
|
print("Modifier Removal " + modifier.name)
|
||||||
|
if modifier_collection.has(modifier):
|
||||||
|
var modifier_index = modifier_collection.rfind(modifier)
|
||||||
|
if modifier_index != -1:
|
||||||
|
modifier_collection.remove(modifier_index)
|
||||||
|
if call_function.is_valid():
|
||||||
|
call_function.call_func(modifier, false)
|
||||||
6
src/components/Modifier_Receiver.tscn
Normal file
6
src/components/Modifier_Receiver.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://src/components/Modifier_Receiver.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Modifier_Receiver" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
@ -17,6 +17,11 @@ var current_movement_state:String
|
||||||
# Since animactor state machine can actually view properties from this type
|
# Since animactor state machine can actually view properties from this type
|
||||||
# I'm thinking about moving the velocity tracker in here instead of player.
|
# I'm thinking about moving the velocity tracker in here instead of player.
|
||||||
var velocity = Vector2(0,0)
|
var velocity = Vector2(0,0)
|
||||||
|
var momentum = Vector2(0,0)
|
||||||
|
var acceleration = Vector2(0,0)
|
||||||
|
|
||||||
|
var sim_velocity = Vector2(0,0)
|
||||||
|
|
||||||
|
|
||||||
#Can't use floats here, switched to constants.
|
#Can't use floats here, switched to constants.
|
||||||
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,17 @@ func hit_Receiver(damage):
|
||||||
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
|
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
|
||||||
$Hurtbox_Component.set_hurtbox(true)
|
$Hurtbox_Component.set_hurtbox(true)
|
||||||
|
|
||||||
|
func receive_modifier(incomming_modifier :StateModifier, is_adding_modifier_operation: bool):
|
||||||
|
#var mod :StateModifier
|
||||||
|
if is_adding_modifier_operation:
|
||||||
|
print("Player Received modifier:", incomming_modifier.name)
|
||||||
|
if movement_state_machine.current_state is StateAnimatedActor:
|
||||||
|
movement_state_machine.current_state.physics_modifier = incomming_modifier
|
||||||
|
else:
|
||||||
|
print("Player Removed modifier:", incomming_modifier.name)
|
||||||
|
if movement_state_machine.current_state is StateAnimatedActor:
|
||||||
|
movement_state_machine.current_state.physics_modifier = null
|
||||||
|
|
||||||
func touch_the_thing(the_thing: Interactable) -> bool:
|
func touch_the_thing(the_thing: Interactable) -> bool:
|
||||||
print("You see! a THING...", the_thing.name)
|
print("You see! a THING...", the_thing.name)
|
||||||
if the_thing is HealthPickup:
|
if the_thing is HealthPickup:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=126 format=2]
|
[gd_scene load_steps=127 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
|
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
|
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
|
||||||
|
[ext_resource path="res://src/components/Modifier_Receiver.tscn" type="PackedScene" id=9]
|
||||||
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
|
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
|
||||||
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
|
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
|
||||||
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
|
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
|
||||||
|
|
@ -569,7 +570,7 @@ interactable_node = NodePath("../Interactable_Receiver")
|
||||||
|
|
||||||
[node name="idle" parent="movement_state_machine" index="0"]
|
[node name="idle" parent="movement_state_machine" index="0"]
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
move_speed = 1.0
|
move_speed = 0.0
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
attack_node = NodePath("../attack")
|
attack_node = NodePath("../attack")
|
||||||
|
|
@ -578,14 +579,12 @@ roll_node = NodePath("../roll")
|
||||||
|
|
||||||
[node name="fall" parent="movement_state_machine" index="1"]
|
[node name="fall" parent="movement_state_machine" index="1"]
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
debug_state = true
|
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
animation_sequence = [ "jump" ]
|
animation_sequence = [ "jump" ]
|
||||||
landing_node = NodePath("")
|
landing_node = NodePath("")
|
||||||
|
|
||||||
[node name="move" parent="movement_state_machine" index="2"]
|
[node name="move" parent="movement_state_machine" index="2"]
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
debug_state = true
|
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
animation_sequence = [ "step", "run" ]
|
animation_sequence = [ "step", "run" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
|
|
@ -593,8 +592,8 @@ attack_node = NodePath("../attack")
|
||||||
|
|
||||||
[node name="jump" type="Node" parent="movement_state_machine" index="3"]
|
[node name="jump" type="Node" parent="movement_state_machine" index="3"]
|
||||||
script = ExtResource( 8 )
|
script = ExtResource( 8 )
|
||||||
debug_state = true
|
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
|
move_modifier_move_acceleration = -100.0
|
||||||
animation_sequence = [ "jump" ]
|
animation_sequence = [ "jump" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
|
|
@ -621,9 +620,8 @@ idle_node = NodePath("../idle")
|
||||||
[node name="dash" type="Node" parent="movement_state_machine" index="6"]
|
[node name="dash" type="Node" parent="movement_state_machine" index="6"]
|
||||||
script = ExtResource( 11 )
|
script = ExtResource( 11 )
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
move_speed_modifier = 160.0
|
move_speed_modifier = 90.0
|
||||||
move_modifier_move_acceleration = -160.0
|
move_modifier_move_acceleration = -180.0
|
||||||
jerk_factor = -190.0
|
|
||||||
animation_sequence = [ "dash" ]
|
animation_sequence = [ "dash" ]
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
|
|
@ -675,6 +673,10 @@ default_color = Color( 1, 0.607843, 0, 1 )
|
||||||
script = ExtResource( 16 )
|
script = ExtResource( 16 )
|
||||||
interactable_parent_callback = "touch_the_thing"
|
interactable_parent_callback = "touch_the_thing"
|
||||||
|
|
||||||
|
[node name="Modifier_Receiver" parent="." index="9" instance=ExtResource( 9 )]
|
||||||
|
modifier_parent_callback = "receive_modifier"
|
||||||
|
debug_receiver = true
|
||||||
|
|
||||||
[connection signal="do_attack" from="movement_state_machine/attack" to="." method="_on_attack_do_attack"]
|
[connection signal="do_attack" from="movement_state_machine/attack" to="." method="_on_attack_do_attack"]
|
||||||
[connection signal="frame_reached" from="movement_state_machine/roll" to="." method="_on_roll_frame_reached"]
|
[connection signal="frame_reached" from="movement_state_machine/roll" to="." method="_on_roll_frame_reached"]
|
||||||
[connection signal="state_exited" from="movement_state_machine/roll" to="." method="_on_roll_state_exited"]
|
[connection signal="state_exited" from="movement_state_machine/roll" to="." method="_on_roll_state_exited"]
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ onready var roll_state: State = get_node(roll_node)
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
# parent.set_hurtbox(true)
|
# parent.set_hurtbox(true)
|
||||||
move_component.velocity.x = 0
|
#move_component.velocity.x = 0
|
||||||
|
#move_component.momentum.x *= -1
|
||||||
if debug_state:
|
if debug_state:
|
||||||
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
||||||
|
|
||||||
|
|
@ -39,7 +40,7 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
if move_component.velocity.x != 0.0:
|
if move_component.desired_movement_vector.x != 0 and move_component.velocity.x != 0:
|
||||||
return move_state
|
return move_state
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,6 @@ func enter() -> void:
|
||||||
# if modifier_stack_ref.has(landing_mod):
|
# if modifier_stack_ref.has(landing_mod):
|
||||||
# print("Jump from Landing Mod at: ", modifier_stack_ref.rfind(landing_mod))
|
# print("Jump from Landing Mod at: ", modifier_stack_ref.rfind(landing_mod))
|
||||||
.enter()
|
.enter()
|
||||||
if previous_speed_multiplier > 1.0:
|
|
||||||
speed_multiplier = previous_speed_multiplier
|
|
||||||
else:
|
|
||||||
speed_multiplier = 1.0
|
|
||||||
# Apply initial jump velocity on state enter
|
# Apply initial jump velocity on state enter
|
||||||
move_component.velocity.y = -jump_force
|
move_component.velocity.y = -jump_force
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,16 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
if move_component.velocity.x == 0.0:
|
# if move_component.velocity.x == 0.0:
|
||||||
return idle_state
|
# return idle_state
|
||||||
|
|
||||||
#Flip the character before tha actual move maybe.
|
#Flip the character before tha actual move maybe.
|
||||||
if move_component.get_movement_direction() != 0.0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.transform.x.x = move_component.get_movement_direction()
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
|
|
||||||
|
if move_component.desired_movement_vector.x == 0:
|
||||||
|
return idle_state
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
return fall_state
|
return fall_state
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,11 @@ export var move_speed_modifier: float = 0
|
||||||
export var move_modifier_move_acceleration: float = 0
|
export var move_modifier_move_acceleration: float = 0
|
||||||
export var jerk_factor: float = 0
|
export var jerk_factor: float = 0
|
||||||
|
|
||||||
var adjusted_move_speed: float
|
#var adjusted_move_speed: float
|
||||||
var jerk: float
|
var jerk: float
|
||||||
|
|
||||||
|
var physics_modifier :StateModifier
|
||||||
|
|
||||||
##TODO: Deprecate this useless fool!
|
##TODO: Deprecate this useless fool!
|
||||||
var speed_multiplier: float = 1.0
|
var speed_multiplier: float = 1.0
|
||||||
|
|
||||||
|
|
@ -166,7 +168,7 @@ func enter() -> void:
|
||||||
update_animation()
|
update_animation()
|
||||||
|
|
||||||
# Reset movespeed counters
|
# Reset movespeed counters
|
||||||
adjusted_move_speed = move_speed_modifier
|
#move_component.momentum.x = move_speed_modifier
|
||||||
jerk = 0
|
jerk = 0
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -258,52 +260,216 @@ func process_physics(_delta: float) -> State:
|
||||||
# if animations.frames.get_animation_loop(animations.animation) == false:
|
# if animations.frames.get_animation_loop(animations.animation) == false:
|
||||||
# animation_index += 1
|
# animation_index += 1
|
||||||
|
|
||||||
func move_actor_as_desired(delta: float, x_direction: float = 0):
|
func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
||||||
# Assuming adjusted_move_speed is set to the mood speed modifier on state entry
|
|
||||||
# Move speed is the base speed plus the modifier minus the decay adjusted for time
|
|
||||||
jerk += jerk_factor * delta
|
|
||||||
adjusted_move_speed += move_modifier_move_acceleration * delta
|
|
||||||
var new_move_speed = move_speed + (move_acceleration * delta) + adjusted_move_speed + jerk
|
|
||||||
|
|
||||||
# A really crappy normalization to prevent modifying past the base move speed.
|
var _move_speed = move_speed
|
||||||
if move_speed_modifier > 0 and new_move_speed < move_speed: # positive modifier
|
var _move_speed_modifier = move_speed_modifier
|
||||||
#print("nope1")
|
var _move_modifier_move_acceleration = move_modifier_move_acceleration
|
||||||
new_move_speed = move_speed
|
var _move_acceleration = move_acceleration
|
||||||
elif move_speed_modifier < 0 and new_move_speed > move_speed: # negative modifier
|
var _jerk_factor = jerk_factor
|
||||||
#print("nope2")
|
var _gravity = gravity
|
||||||
new_move_speed = move_speed
|
|
||||||
# else:
|
if physics_modifier:
|
||||||
# UiManager.debug_text = str(round(adjusted_move_speed)) + "," + str(round(new_move_speed)) + "," + str(round(jerk))
|
#physics_modifier.modifier_properties.jerk_factor
|
||||||
# #print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
#print(physics_modifier.name)
|
||||||
|
#UiManager.debug_text = physics_modifier.name + str(round(adjusted_move_speed))
|
||||||
|
var mod_props :ModifierProperties = physics_modifier.get_modifier_properties()
|
||||||
|
if mod_props.move_speed != 0 and mod_props.directional_modifier == false:
|
||||||
|
_move_speed = mod_props.move_speed
|
||||||
|
_move_speed_modifier += mod_props.move_speed_modifier
|
||||||
|
_move_acceleration += mod_props.move_acceleration
|
||||||
|
_move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
|
||||||
|
_jerk_factor += mod_props.jerk_factor
|
||||||
|
|
||||||
|
var help_me_not_be_dumb = ''
|
||||||
|
|
||||||
|
# Allow us to bump out of halt.
|
||||||
|
if _move_speed == 0 and move_component.desired_movement_vector.x != 0:
|
||||||
|
_move_speed = abs(move_component.desired_movement_vector.x)
|
||||||
|
|
||||||
|
# Determine or physics movement direction
|
||||||
|
var current_x_velocity = move_component.velocity.x #move_component.velocity.x
|
||||||
|
var move_direction = 0.0
|
||||||
|
# Determine movement direction if we have momentum
|
||||||
|
if move_component.momentum.x != 0:
|
||||||
|
if x_move_direction_override == 0:
|
||||||
|
move_direction = sign(current_x_velocity)
|
||||||
|
# if move_component.desired_movement_vector.x != 0:
|
||||||
|
# # set the move direction to the desired direction
|
||||||
|
# move_direction = move_component.desired_movement_vector.x
|
||||||
|
# else:
|
||||||
|
# # Set move direction to the transform direction
|
||||||
|
# move_direction = parent.transform.x.x
|
||||||
|
else:
|
||||||
|
move_direction = x_move_direction_override
|
||||||
|
else: # No current momentum in place
|
||||||
|
if x_move_direction_override == 0:
|
||||||
|
move_direction = move_component.desired_movement_vector.x
|
||||||
|
else:
|
||||||
|
move_direction = x_move_direction_override
|
||||||
|
|
||||||
|
## TODO: I hate that I have to do this check again.
|
||||||
|
if physics_modifier:
|
||||||
|
var mod_props :ModifierProperties = physics_modifier.get_modifier_properties()
|
||||||
|
if mod_props.move_speed != 0 and mod_props.directional_modifier == true:
|
||||||
|
# Since move_direction is always positive
|
||||||
|
if sign(move_direction) == sign(mod_props.move_speed):
|
||||||
|
_move_speed += mod_props.move_speed
|
||||||
|
else:
|
||||||
|
_move_speed -= mod_props.move_speed
|
||||||
|
if sign(move_direction) == 0:
|
||||||
|
move_direction = sign(mod_props.move_speed) * -1
|
||||||
|
#print("doing this? ")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the maximum move speed
|
||||||
|
var MAX_SPEED :float = 0
|
||||||
|
var MIN_SPEED :float = 0
|
||||||
|
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||||
|
help_me_not_be_dumb += '-SpeedMod'
|
||||||
|
# Move speed cannot go below zero with modifier applied
|
||||||
|
MIN_SPEED = _move_speed + _move_speed_modifier
|
||||||
|
# Poor man's clamp
|
||||||
|
if MIN_SPEED < 0:
|
||||||
|
MIN_SPEED = 0
|
||||||
|
MAX_SPEED = _move_speed
|
||||||
|
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||||
|
help_me_not_be_dumb += '+SpeedMod'
|
||||||
|
MIN_SPEED = _move_speed
|
||||||
|
MAX_SPEED = _move_speed + _move_speed_modifier
|
||||||
|
else: # physics won't apply here
|
||||||
|
help_me_not_be_dumb += '_Speed' # Neutral Speed
|
||||||
|
MIN_SPEED = _move_speed
|
||||||
|
MAX_SPEED = _move_speed
|
||||||
|
|
||||||
|
# get the latest aggregate acceleration
|
||||||
|
# If we have any acceleration applying
|
||||||
|
if (_move_modifier_move_acceleration + _move_acceleration) != 0:
|
||||||
|
# The acceleration is differant
|
||||||
|
# Perhaps it would be better to trigger this on a difference in modifier but they usually go together.
|
||||||
|
if abs(move_component.acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration):
|
||||||
|
if move_direction:
|
||||||
|
print("Acceleration changed.", abs(move_component.acceleration.x), "-", (_move_modifier_move_acceleration + _move_acceleration))
|
||||||
|
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||||
|
|
||||||
|
# ##TODO: I don't know where I should actually set the momentum. :
|
||||||
|
# if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||||
|
# move_component.momentum.x = 0
|
||||||
|
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||||
|
# move_component.momentum.x = abs(move_speed_modifier)
|
||||||
|
|
||||||
|
# If we're no longer tryingg to move int the direction of our movement and momentum.
|
||||||
|
if sign(current_x_velocity) != sign(move_component.desired_movement_vector.x) and move_component.momentum.x != 0:
|
||||||
|
if sign(_move_speed_modifier) == -1 : # decreased speed modifier
|
||||||
|
|
||||||
|
# Maybe we can compare the direction of the acceleration
|
||||||
|
# The direction of the acceleration should usually be positive at this point.
|
||||||
|
# when the modifier is negative.
|
||||||
|
if sign(move_direction) == sign(current_x_velocity):
|
||||||
|
if sign(move_component.acceleration.x) == sign(move_component.momentum.x):
|
||||||
|
print("Whoh Woah")
|
||||||
|
# Flip the direction of the acceleration
|
||||||
|
move_component.acceleration.x *= -1
|
||||||
|
if (sign(move_component.desired_movement_vector.x) == -1 and
|
||||||
|
sign(current_x_velocity) == 1) or (sign(move_component.desired_movement_vector.x) == -1 and
|
||||||
|
sign(current_x_velocity) == -1):
|
||||||
|
print("be more opposite")
|
||||||
|
if sign(_move_speed_modifier) == 1:
|
||||||
|
print("faster faster.")
|
||||||
|
elif sign(move_component.desired_movement_vector.x) == sign(current_x_velocity) and move_component.momentum.x != 0:
|
||||||
|
if sign(move_component.acceleration.x) != sign(move_component.momentum.x) and x_move_direction_override == 0:
|
||||||
|
print("Step it up!")
|
||||||
|
# Flip the direction of the acceleration
|
||||||
|
move_component.acceleration.x *= -1
|
||||||
|
if move_component.momentum.x <= 0 and _move_speed_modifier !=0:
|
||||||
|
#if we're trying to move but we have no momentum applied currently
|
||||||
|
#if move_component.desired_movement_vector.x != 0:
|
||||||
|
if move_direction:
|
||||||
|
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||||
|
##TODO: I don't know where I should actually set the momentum. :
|
||||||
|
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||||
|
move_component.momentum.x = 0
|
||||||
|
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||||
|
move_component.momentum.x = abs(move_speed_modifier)
|
||||||
|
if move_component.momentum.x > 0 and _move_speed_modifier == 0:
|
||||||
|
if sign(move_component.acceleration.x) == sign(move_component.momentum.x):
|
||||||
|
print("Whoh Woah your done.")
|
||||||
|
# Flip the direction of the acceleration
|
||||||
|
move_component.acceleration.x *= -1
|
||||||
|
##TODO: I don't know where I should actually set the momentum. :
|
||||||
|
# This was not the place
|
||||||
|
# if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||||
|
# move_component.momentum.x = 0
|
||||||
|
# move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
||||||
|
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||||
|
# move_component.momentum.x = abs(move_speed_modifier)
|
||||||
|
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||||
|
# print("wait does it matter")
|
||||||
|
# else: # physics won't apply here
|
||||||
|
# print("uh")
|
||||||
|
|
||||||
|
# else:
|
||||||
|
# print("Direction changed")
|
||||||
|
# if move_component.momentum.x > abs(current_x_velocity):
|
||||||
|
# move_component.momentum.x = abs(current_x_velocity)
|
||||||
|
|
||||||
|
# flip the acceleration to apply against the momentum
|
||||||
|
#move_component.acceleration.x *= -1 * sign(move_component.momentum.x)
|
||||||
|
# If the movement direction changes and we have momentum
|
||||||
|
# print("Flip that thing!")
|
||||||
|
# move_component.momentum.x *= -1
|
||||||
|
# if sign(move_component.acceleration.x ) == sign(_move_speed_modifier):
|
||||||
|
# move_component.acceleration.x *= -1 * sign(current_x_velocity)
|
||||||
|
|
||||||
|
|
||||||
|
# We're going to adjust our move speed only to the modifier
|
||||||
|
move_component.momentum.x += move_component.acceleration.x * delta
|
||||||
|
jerk += _jerk_factor * delta
|
||||||
|
|
||||||
|
# Momentum should always be the inverse of the speed modifier
|
||||||
|
|
||||||
|
var new_move_speed :float = 0
|
||||||
|
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
||||||
|
# MIN_SPEED = _move_speed + _move_speed_modifier
|
||||||
|
# MAX_SPEED = _move_speed
|
||||||
|
move_component.momentum.x = clamp(move_component.momentum.x, 0, abs(_move_speed_modifier))
|
||||||
|
# new_move_speed = (_move_speed + _move_speed_modifier ) + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
|
||||||
|
new_move_speed = MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
|
||||||
|
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
||||||
|
# MIN_SPEED = _move_speed
|
||||||
|
# MAX_SPEED = _move_speed + _move_speed_modifier
|
||||||
|
move_component.momentum.x = clamp(move_component.momentum.x, 0, _move_speed_modifier )
|
||||||
|
new_move_speed = _move_speed + move_component.momentum.x # + jerk
|
||||||
|
else: # physics won't apply here
|
||||||
|
# move_component.acceleration.x = 0
|
||||||
|
# move_component.momentum.x = 0
|
||||||
|
# new_move_speed = _move_speed
|
||||||
|
move_component.momentum.x = clamp(move_component.momentum.x, 0, MIN_SPEED )
|
||||||
|
new_move_speed = _move_speed + move_component.momentum.x # + jerk
|
||||||
|
|
||||||
|
#new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED)
|
||||||
|
|
||||||
|
var sim_move_speed = (MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x))
|
||||||
|
|
||||||
|
# if move_component.momentum.x != 0:
|
||||||
|
if true:
|
||||||
|
UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(move_direction) + ") Vel(" + str(sign(current_x_velocity)) + ") Mov(" + str(sign(move_component.desired_movement_vector.x)) +
|
||||||
|
")\nNS:" + str(round(sim_move_speed)) + #" Z:" + str(sign(_move_speed_modifier) * -1 * move_component.momentum.x) +
|
||||||
|
"\nS:" + str(round(_move_speed + _move_speed_modifier)) + ",M" + str(round(move_component.momentum.x)) +
|
||||||
|
",A" + str(round(move_component.acceleration.x)) +
|
||||||
|
"\nVel:" + str(round(move_component.velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED))
|
||||||
|
) # str(round(jerk))
|
||||||
|
|
||||||
|
move_component.sim_velocity.x = move_direction * sim_move_speed
|
||||||
|
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
||||||
|
|
||||||
#print(new_move_speed, " ", adjusted_move_speed)
|
#print(new_move_speed, " ", adjusted_move_speed)
|
||||||
|
|
||||||
move_component.velocity.y += gravity * delta
|
move_component.velocity.y += _gravity * delta
|
||||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
#print(speed_multiplier)
|
#print(speed_multiplier)
|
||||||
if (x_direction != 0):
|
# move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed
|
||||||
move_component.velocity.x = x_direction * new_move_speed
|
move_component.velocity.x = move_direction * new_move_speed
|
||||||
else:
|
|
||||||
move_component.velocity.x = move_component.desired_movement_vector.x * new_move_speed
|
|
||||||
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
|
||||||
# var new_speed = move_speed * speed_multiplier
|
|
||||||
# if speed_multiplier > 1.0:
|
|
||||||
# speed_multiplier -= delta * speed_multiplier
|
|
||||||
# #speed_decay_rate += delta * speed_decay_rate
|
|
||||||
#
|
|
||||||
# elif speed_multiplier < 1.0:
|
|
||||||
# speed_multiplier += delta * speed_multiplier
|
|
||||||
# #speed_decay_rate += delta * speed_decay_rate
|
|
||||||
#
|
|
||||||
# # Deadzone
|
|
||||||
# if speed_multiplier < 1.1 and speed_multiplier > 0.9:
|
|
||||||
# speed_multiplier = 1.0
|
|
||||||
## if (new_speed > move_speed):
|
|
||||||
## print("Go Faster Booooy! ", move_speed)
|
|
||||||
# move_component.velocity.y += gravity * delta
|
|
||||||
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
||||||
# move_component.velocity.x = move_component.desired_movement_vector.x * new_speed
|
|
||||||
# move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
class_name StateMachineAnimatedActor extends StateMachine
|
class_name StateMachineAnimatedActor extends StateMachine
|
||||||
|
|
||||||
|
#var physics_modifier : StateModifier
|
||||||
|
|
||||||
func change_state(new_state: State) -> void:
|
func change_state(new_state: State) -> void:
|
||||||
if new_state.state_ready == false:
|
if new_state.state_ready == false:
|
||||||
# Don't transition to unready state
|
# Don't transition to unready state
|
||||||
|
|
@ -12,6 +14,9 @@ func change_state(new_state: State) -> void:
|
||||||
if current_state.modifier: # Current state has a modifier
|
if current_state.modifier: # Current state has a modifier
|
||||||
new_state.transfer_modifiers(current_state.modifier)
|
new_state.transfer_modifiers(current_state.modifier)
|
||||||
current_state.modifier = null
|
current_state.modifier = null
|
||||||
|
if current_state.physics_modifier: # Current state has a physics modifier
|
||||||
|
new_state.physics_modifier = current_state.physics_modifier
|
||||||
|
current_state.physics_modifier = null
|
||||||
|
|
||||||
current_state = new_state
|
current_state = new_state
|
||||||
current_state.enter()
|
current_state.enter()
|
||||||
|
|
|
||||||
|
|
@ -84,14 +84,17 @@ func merge_modifier(merging_mod: ModifierProperties):
|
||||||
func get_modifier_properties() -> ModifierProperties:
|
func get_modifier_properties() -> ModifierProperties:
|
||||||
#( p_move_speed:float, p_gravity:int , p_move_acceleration , p_move_speed_modifier:float,
|
#( p_move_speed:float, p_gravity:int , p_move_acceleration , p_move_speed_modifier:float,
|
||||||
# p_move_modifier_move_acceleration:float, p_jerk_factor: float):
|
# p_move_modifier_move_acceleration:float, p_jerk_factor: float):
|
||||||
return ModifierProperties.new( modifier_properties.move_speed,
|
var mp = ModifierProperties.new( modifier_properties.move_speed,
|
||||||
modifier_properties.gravity,
|
modifier_properties.gravity,
|
||||||
modifier_properties.move_acceleration,
|
modifier_properties.move_acceleration,
|
||||||
modifier_properties.move_speed_modifier,
|
modifier_properties.move_speed_modifier,
|
||||||
modifier_properties.move_modifier_move_acceleration,
|
modifier_properties.move_modifier_move_acceleration,
|
||||||
modifier_properties.jerk_factor)
|
modifier_properties.jerk_factor)
|
||||||
|
mp.directional_modifier = modifier_properties.directional_modifier
|
||||||
|
return mp
|
||||||
|
|
||||||
func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
|
func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
|
||||||
|
name = modifier_name
|
||||||
# If somebody forgot to specify the type
|
# If somebody forgot to specify the type
|
||||||
if anim_name != '' and type == TYPE.NONE:
|
if anim_name != '' and type == TYPE.NONE:
|
||||||
modifier_type = TYPE.REPLACE_ANIMATION
|
modifier_type = TYPE.REPLACE_ANIMATION
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ var jerk_factor: float = 0
|
||||||
|
|
||||||
var gravity:int = 0
|
var gravity:int = 0
|
||||||
|
|
||||||
|
# Bad name. Just means that it is intended to apply in a certain direction
|
||||||
|
# (Positive or negative) not an offset of the existing values.
|
||||||
|
var directional_modifier: bool = false
|
||||||
|
|
||||||
|
|
||||||
func _init( p_move_speed:float, p_gravity:int , p_move_acceleration , p_move_speed_modifier:float,
|
func _init( p_move_speed:float, p_gravity:int , p_move_acceleration , p_move_speed_modifier:float,
|
||||||
p_move_modifier_move_acceleration:float, p_jerk_factor: float):
|
p_move_modifier_move_acceleration:float, p_jerk_factor: float):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user