Compare commits

..

2 Commits

8 changed files with 167 additions and 54 deletions

View File

@ -0,0 +1,19 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/classes/state_modifier_movement.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
script = ExtResource( 1 )
modifier_type = 0
name = "low_gravity"
timeout_seconds = 0.0
direction = 0
speed_start = Vector2( 0, 0 )
speed_end = Vector2( 0, 0 )
min_acceleration = Vector2( 1.36422e-12, 20 )
acceleration = Vector2( 1.36422e-12, -100 )
max_acceleration = Vector2( 0, 0 )
gravity = 0
only_grounded = false
processing_mode = 0

View File

@ -362,17 +362,19 @@ func _state_process_physics_jump():
# #modifier.reference() # #modifier.reference()
# #idle_state.modifier = landing_modifier # #idle_state.modifier = landing_modifier
# request_state_change.call_func('idle') # request_state_change.call_func('idle')
if velocity_controller.velocity.y > 0:
request_state_change.call_func('fall')
return
desired_movement_vector.y = UP desired_movement_vector.y = UP
#move_actor_as_desired() #move_actor_as_desired()
apply_movement_to_parent( apply_movement_to_parent(
velocity_controller.calculate_velocity( velocity_controller.calculate_velocity(
physics_delta , physics_delta ,
apply_state_modifier(current_state.get_movement_parameters()), apply_state_modifier(current_state.get_movement_parameters()),
desired_movement_vector ) desired_movement_vector )
) )
## TODO: Our impulse model can't handle zero
if velocity_controller.velocity.y > - 2:
request_state_change.call_func('fall')
return
## Just slightly bump away from ledge we're bumping into ## Just slightly bump away from ledge we're bumping into
if (($"%JumpAdjustorBack".is_colliding() and !$"%JumpAdjustorFront".is_colliding()) or if (($"%JumpAdjustorBack".is_colliding() and !$"%JumpAdjustorFront".is_colliding()) or

View File

@ -123,7 +123,7 @@ __meta__ = {
[node name="Movement_StateReceiver" parent="." index="2"] [node name="Movement_StateReceiver" parent="." index="2"]
script = ExtResource( 6 ) script = ExtResource( 6 )
debug_velocity_controller = false debug_velocity_controller = true
[node name="Modifier_Receiver" parent="." index="3" instance=ExtResource( 35 )] [node name="Modifier_Receiver" parent="." index="3" instance=ExtResource( 35 )]
callable_state_machine = NodePath("../Movement_StateMachine") callable_state_machine = NodePath("../Movement_StateMachine")

View File

@ -9,7 +9,7 @@ script = ExtResource( 1 )
debug_state = false debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "fall" name = "fall"
speed_start = Vector2( 60, 1.36422e-12 ) speed_start = Vector2( 60, 1 )
speed_end = Vector2( 60, 1000 ) speed_end = Vector2( 60, 1000 )
min_acceleration = Vector2( 0, 0 ) min_acceleration = Vector2( 0, 0 )
acceleration = Vector2( 1.36422e-12, 500 ) acceleration = Vector2( 1.36422e-12, 500 )

View File

@ -10,7 +10,7 @@ debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "jump" name = "jump"
speed_start = Vector2( 90, 200 ) speed_start = Vector2( 90, 200 )
speed_end = Vector2( 90, -8 ) speed_end = Vector2( 90, 1 )
min_acceleration = Vector2( 0, 0 ) min_acceleration = Vector2( 0, 0 )
acceleration = Vector2( 1.36422e-12, 360 ) acceleration = Vector2( 1.36422e-12, 360 )
max_acceleration = Vector2( 0, 0 ) max_acceleration = Vector2( 0, 0 )

View File

@ -21,10 +21,11 @@ enum IMPULSE_PLACEMENT {
## Could these be datatypes or a class? Sure ## Could these be datatypes or a class? Sure
var _h_impulse_applied :bool = false var _h_impulse_applied :bool = false
var _h_impulse_speed_tracking :Vector2 #var _h_impulse_speed_tracking :Vector2
var _h_impulse_placement_tracking :int = -1 var _h_impulse_placement_tracking :int = -1
var _v_impulse_applied :bool = false var _v_impulse_applied :bool = false
var _v_impulse_speed_tracking :Vector2 #var _v_impulse_speed_tracking :Vector2
var _v_impulse_placement_tracking :int = -1
func calculate_velocity(_delta :float, func calculate_velocity(_delta :float,
movement_parameters :MovementParameters, movement_parameters :MovementParameters,
@ -127,31 +128,27 @@ func calculate_velocity(_delta :float,
if debug: if debug:
print("Resetting H impulse (Impulse Placement Change)") print("Resetting H impulse (Impulse Placement Change)")
# if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and if _v_impulse_applied == true:
# _h_impulse_speed_tracking != h_speed): if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE):
# if debug: _v_impulse_applied = false
# print("Resetting H impulse (Within Range)") if debug:
# _h_impulse_applied = false print("Resetting V impulse (Within Range)")
# elif(h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE): elif (calc_inertia.y < v_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.LEFT_SIDE or
# if debug: calc_inertia.y >= v_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.RIGHT_SIDE):
# print("Resetting H impulse (Before Range) ", _h_impulse_speed_tracking ) _v_impulse_applied = false
if debug:
if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and print("Resetting V impulse (Impulse Placement Change)")
_v_impulse_applied == true and
_v_impulse_speed_tracking != v_speed):
if debug:
print("resetting V impulse")
_v_impulse_applied = false
## Separate impulse function ## Separate impulse function
if _h_impulse_applied == false and is_zero_approx(h_speed.x) == false:# and _h_impulse_speed_tracking != h_speed: if _h_impulse_applied == false and is_zero_approx(h_speed.x) == false:# and _h_impulse_speed_tracking != h_speed:
#(range_placement :int, inertia :float, impulse_speed_range :Vector2) #(range_placement :int, inertia :float, impulse_speed_range :Vector2)
#_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed ) #_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed )
var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed ) #var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed )
if h_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(h_speed.x) > abs(h_speed.y): if h_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(h_speed.x) > abs(h_speed.y):
if debug: if debug:
print("Applying H impulse (Past Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x) print("Applying H impulse (Past Range): Imp: ", ", In:", calc_inertia.x)
_h_impulse_speed_tracking = h_speed #_h_impulse_speed_tracking = h_speed
_h_impulse_applied = true _h_impulse_applied = true
## This might not make sense ## This might not make sense
if (calc_inertia.x + h_speed.x) < h_speed.x: if (calc_inertia.x + h_speed.x) < h_speed.x:
@ -162,8 +159,8 @@ func calculate_velocity(_delta :float,
calc_inertia.x = h_speed.x calc_inertia.x = h_speed.x
elif h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE: elif h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE:
if debug: if debug:
print("Applying H impulse (Before Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x) print("Applying H impulse (Before Range): Imp: ", ", In:", calc_inertia.x)
_h_impulse_speed_tracking = h_speed #_h_impulse_speed_tracking = h_speed
_h_impulse_applied = true _h_impulse_applied = true
if calc_inertia.x < h_speed.x: if calc_inertia.x < h_speed.x:
_h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE _h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
@ -174,25 +171,42 @@ func calculate_velocity(_delta :float,
else: else:
##TODO: Maybe this should be something else ##TODO: Maybe this should be something else
calc_inertia.x = 0 calc_inertia.x = 0
## F this, didn't work well
# if impulse_inertia != calc_inertia.x: ## We have an impulse to apply
# if debug:
# print("Applying H impulse: Imp: ", impulse_inertia, ", In:", calc_inertia.x)
# #var foo = 2+2
# _h_impulse_speed_tracking = h_speed
# _h_impulse_applied = true
# ## We want to add impulse in the direction of movement so we need to determine
# ## what that is.
# calc_inertia.x += impulse_inertia
if _v_impulse_applied == false:# and _v_impulse_speed_tracking != v_speed: if _v_impulse_applied == false and is_zero_approx(v_speed.x) == false:
var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed) #var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed)
if impulse_inertia != calc_inertia.y: if v_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(v_speed.x) > abs(v_speed.y):
_v_impulse_speed_tracking = v_speed if debug:
print("Applying V impulse (Past range)")
_v_impulse_applied = true _v_impulse_applied = true
calc_inertia.y += impulse_inertia if (calc_inertia.y + v_speed.x) < v_speed.x:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
else:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
## We don't blow past the acceleration
calc_inertia.y = v_speed.x
elif v_range_placement == RANGE_PLACEMENT.BEFORE_RANGE:
if debug:
print("Applying V impulse (Before Range)")
_v_impulse_applied = true
if calc_inertia.y < v_speed.x:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
else:
_v_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
if sign(v_speed.x) == sign(v_speed.y):
calc_inertia.y += v_speed.x
else:
##TODO : this should probably be smarter
calc_inertia.y = 0
# elif v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and _v_impulse_placement_tracking != range_placement:
# if debug:
# print("Apply V impulse (within range)")
# _v_impulse_applied = true
# if calc_inertia.y < v_speed.x:
# _v_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE
# else:
# _v_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE
# calc_inertia.y = v_speed.x
if debug and movement_parameters.debug_name == 'roll': if debug and movement_parameters.debug_name == 'roll':
var foo = 2+2 var foo = 2+2
## We are always moving from h_speed.x towards y at a given rate ## We are always moving from h_speed.x towards y at a given rate
@ -227,13 +241,6 @@ func calculate_velocity(_delta :float,
# if is_zero_approx(_movement_direction.y) == false: # if is_zero_approx(_movement_direction.y) == false:
# calc_inertia.y = v_speed.x # calc_inertia.y = v_speed.x
calc_inertia.y = v_speed.x calc_inertia.y = v_speed.x
## Track or last speed for in range impulses
# _h_impulse_speed_tracking = h_speed
# _v_impulse_speed_tracking = v_speed
#calc_velocity.y = calc_inertia.y
#calc_velocity.x = calc_inertia.x
if debug: if debug:
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +

View File

@ -51,7 +51,7 @@ __meta__ = {
[node name="LevelTransition2" parent="." index="7" instance=ExtResource( 4 )] [node name="LevelTransition2" parent="." index="7" instance=ExtResource( 4 )]
position = Vector2( 333, 64 ) position = Vector2( 333, 64 )
_destination_level = "res://src/levels/CloneBox.tscn" _destination_level = "res://src/levels/TC_04.tscn"
_destination_position_name = "EnterLeft" _destination_position_name = "EnterLeft"
[node name="CollisionShape2D" type="CollisionShape2D" parent="LevelTransition2" index="0"] [node name="CollisionShape2D" type="CollisionShape2D" parent="LevelTransition2" index="0"]

85
src/levels/TC_04.tscn Normal file
View File

@ -0,0 +1,85 @@
[gd_scene load_steps=9 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]
[ext_resource path="res://src/Interactables/modifiers/low_gravity.tres" type="Resource" id=3]
[ext_resource path="res://src/Interactables/LevelTransition.tscn" type="PackedScene" id=4]
[ext_resource path="res://lib/components/Modifier_Component.tscn" type="PackedScene" id=6]
[ext_resource path="res://assets/Fonts/default_font.tres" type="Theme" id=7]
[sub_resource type="RectangleShape2D" id=2]
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 162, 71.5 )
[node name="TC_04" groups=["world"] instance=ExtResource( 1 )]
[node name="TileMap Background" parent="." index="0"]
z_index = -2
[node name="TileMap Collision" parent="." index="1"]
tile_set = ExtResource( 2 )
tile_data = PoolIntArray( -262145, 4, 0, -327661, 4, 0, -196609, 4, 0, -262125, 4, 0, -131073, 4, 0, -196589, 4, 0, -65537, 4, 0, -131053, 4, 65536, -1, 4, 0, -65517, 4, 65536, 65535, 4, 0, 19, 4, 65536, 131069, 4, 0, 131070, 4, 0, 131071, 4, 0, 65555, 4, 0, 65556, 4, 65536, 65557, 4, 65536, 65558, 4, 65536, 196605, 4, 0, 131094, 4, 65536, 262141, 4, 0, 196630, 4, 65536, 327677, 4, 0, 262145, 2, 1, 262146, 2, 2, 262161, 2, 0, 262162, 2, 1, 262166, 4, 65536, 393213, 4, 0, 393214, 4, 0, 393215, 4, 0, 327680, 4, 65536, 327681, 2, 65537, 327682, 2, 65538, 327697, 2, 65536, 327698, 2, 65537, 327699, 4, 65536, 327700, 4, 65536, 327701, 4, 65536, 327702, 4, 65536, 393216, 4, 0, 393235, 4, 0, 458752, 4, 65536, 458771, 4, 65536, 589823, 0, 1, 524288, 4, 131072, 524289, 0, 3, 524290, 0, 1, 524291, 0, 2, 524292, 0, 3, 524293, 0, 1, 524294, 0, 2, 524295, 0, 3, 524296, 0, 1, 524297, 0, 2, 524298, 0, 3, 524299, 0, 1, 524300, 0, 2, 524301, 0, 3, 524302, 0, 1, 524303, 0, 2, 524304, 0, 3, 524305, 0, 1, 524306, 0, 2, 524307, 4, 0, 524308, 0, 1, 524309, 0, 2, 524310, 0, 3, 655359, 0, 65537, 589824, 0, 65538, 589825, 0, 65539, 589826, 0, 65537, 589827, 0, 65538, 589828, 0, 65539, 589829, 0, 65537, 589830, 0, 65538, 589831, 0, 65539, 589832, 0, 65537, 589833, 0, 65538, 589834, 0, 65539, 589835, 0, 65537, 589836, 0, 65538, 589837, 0, 65539, 589838, 0, 65537, 589839, 0, 65538, 589840, 0, 65539, 589841, 0, 65537, 589842, 0, 65538, 589843, 0, 65539, 589844, 0, 65537, 589845, 0, 65538, 589846, 0, 65539, 720895, 0, 131073, 655360, 0, 131074, 655361, 0, 131075, 655362, 0, 131073, 655363, 0, 131074, 655364, 0, 131075, 655365, 0, 131073, 655366, 0, 131074, 655367, 0, 131075, 655368, 0, 131073, 655369, 0, 131074, 655370, 0, 131075, 655371, 0, 131073, 655372, 0, 131074, 655373, 0, 131075, 655374, 0, 131073, 655375, 0, 131074, 655376, 0, 131075, 655377, 0, 131073, 655378, 0, 131074, 655379, 0, 131075, 655380, 0, 131073, 655381, 0, 131074, 655382, 0, 131075, 786431, 0, 196609, 720896, 0, 196610, 720897, 0, 196611, 720898, 0, 196609, 720899, 0, 196610, 720900, 0, 196611, 720901, 0, 196609, 720902, 0, 196610, 720903, 0, 196611, 720904, 0, 196609, 720905, 0, 196610, 720906, 0, 196611, 720907, 0, 196609, 720908, 0, 196610, 720909, 0, 196611, 720910, 0, 196609, 720911, 0, 196610, 720912, 0, 196611, 720913, 0, 196609, 720914, 0, 196610, 720915, 0, 196611, 720916, 0, 196609, 720917, 0, 196610, 720918, 0, 196611, 851967, 0, 262145, 786432, 0, 262146, 786433, 0, 262147, 786434, 0, 262145, 786435, 0, 262146, 786436, 0, 262147, 786437, 0, 262145, 786438, 0, 262146, 786439, 0, 262147, 786440, 0, 262145, 786441, 0, 262146, 786442, 0, 262147, 786443, 0, 262145, 786444, 0, 262146, 786445, 0, 262147, 786446, 0, 262145, 786447, 0, 262146, 786448, 0, 262147, 786449, 0, 262145, 786450, 0, 262146, 786451, 0, 262147, 786452, 0, 262145, 786453, 0, 262146, 786454, 0, 262147 )
[node name="TileMap Foreground" parent="." index="2"]
tile_set = ExtResource( 2 )
collision_layer = 0
collision_mask = 0
tile_data = PoolIntArray( 524288, 0, 2, 524307, 0, 3 )
[node name="PlayerStart" parent="." index="3"]
position = Vector2( 50, 131 )
[node name="EnterLeft" type="Position2D" parent="." index="4"]
position = Vector2( -12, 61 )
[node name="EnterRight" type="Position2D" parent="." index="5"]
position = Vector2( 332, 61 )
[node name="LevelTransition" parent="." index="6" instance=ExtResource( 4 )]
position = Vector2( -11, 64 )
_transition_type = "door_left"
_destination_level = "res://src/levels/TC_02.tscn"
_destination_position_name = "EnterRight"
[node name="CollisionShape2D" type="CollisionShape2D" parent="LevelTransition" index="0"]
modulate = Color( 1, 0, 1, 1 )
shape = SubResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="LevelTransition2" parent="." index="7" instance=ExtResource( 4 )]
position = Vector2( 333, 64 )
_destination_level = "res://src/levels/CloneBox.tscn"
_destination_position_name = "EnterLeft"
[node name="CollisionShape2D" type="CollisionShape2D" parent="LevelTransition2" index="0"]
modulate = Color( 1, 0, 1, 1 )
shape = SubResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="Camera Bounds" parent="." index="8"]
tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, 65535, 0, 0, 16, 0, 0, 524287, 0, 0, 458768, 0, 0, 589824, 0, 0, 589839, 0, 0 )
[node name="Modifier_Component" parent="." index="9" instance=ExtResource( 6 )]
position = Vector2( 162, 141 )
modifier = ExtResource( 3 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Modifier_Component" index="0"]
modulate = Color( 0, 0, 1, 1 )
position = Vector2( -2, -68.5 )
shape = SubResource( 3 )
[node name="Label" type="Label" parent="." index="10"]
margin_left = 78.0
margin_top = 9.0
margin_right = 244.0
margin_bottom = 41.0
theme = ExtResource( 7 )
text = "Test chamber 04:
low gravity"
align = 1
valign = 1