fix: sticky wallslide, bounce consistency

This commit is contained in:
Jakob Feldmann 2023-09-05 18:09:58 +02:00
parent 53e8620c8c
commit 15c98361c0
21 changed files with 1161 additions and 994 deletions

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/grass swish 1.ogg-bdbb4d7db9f101b427a7017365253335.oggstr"
[deps]
source_file="res://assets/sounds/grass swish 1.ogg"
dest_files=[ "res://.import/grass swish 1.ogg-bdbb4d7db9f101b427a7017365253335.oggstr" ]
[params]
loop=false
loop_offset=0

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/grass swish 2.ogg-beebb4d61ae20e7e1fa9a915a809817d.oggstr"
[deps]
source_file="res://assets/sounds/grass swish 2.ogg"
dest_files=[ "res://.import/grass swish 2.ogg-beebb4d61ae20e7e1fa9a915a809817d.oggstr" ]
[params]
loop=false
loop_offset=0

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/grass swish 3.ogg-8d9986e80092be5e026c4d30b38c8a68.oggstr"
[deps]
source_file="res://assets/sounds/grass swish 3.ogg"
dest_files=[ "res://.import/grass swish 3.ogg-8d9986e80092be5e026c4d30b38c8a68.oggstr" ]
[params]
loop=false
loop_offset=0

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/grass swish 4.ogg-dde2025c601051c92eabce1a8be33538.oggstr"
[deps]
source_file="res://assets/sounds/grass swish 4.ogg"
dest_files=[ "res://.import/grass swish 4.ogg-dde2025c601051c92eabce1a8be33538.oggstr" ]
[params]
loop=false
loop_offset=0

View File

@ -35,13 +35,13 @@ var init_acceleration_force := {"": 0, "idle_walk": 4181, "idle_run": 5765, "wal
# Oriented around deltas of 0.0166666...s # Oriented around deltas of 0.0166666...s
# newtonmeters is the unit # newtonmeters is the unit
var acceleration_force := { var acceleration_force := {
"walk": Vector2(1800, 1385), "walk": Vector2(1800, 1300),
"fall": Vector2(1800, 1050), "fall": Vector2(1800, 1050),
"jump": Vector2(1800, 0), "jump": Vector2(1800, 0),
"idle": Vector2(1800, 1233), "idle": Vector2(1800, 1233),
"duck": Vector2(500, 1300), "duck": Vector2(500, 1300),
"duck_walk": Vector2(500, 1300), "duck_walk": Vector2(500, 1300),
"run": Vector2(2500, 1490), "run": Vector2(2500, 1400),
"walljump": Vector2(600, 1050), "walljump": Vector2(600, 1050),
"air_strafe": Vector2(333, 2000) "air_strafe": Vector2(333, 2000)
} }

View File

@ -28,435 +28,447 @@ var shielded = false
func execute_movement() -> void: func execute_movement() -> void:
if level_state.is_dead: if level_state.is_dead:
return return
var snap = Vector2.DOWN * 128 var snap = Vector2.DOWN * 128
var center_floor_rot = 0 var center_floor_rot = 0
var floor_rot = 0 var floor_rot = 0
var onfloor = is_on_floor() var onfloor = is_on_floor()
# get rotation of floor, compare collided floor with floor under center # get rotation of floor, compare collided floor with floor under center
if onfloor: if onfloor:
# TODO: Problem when correctly rotating? # TODO: Problem when correctly rotating?
center_floor_rot = $SlopeRaycast.get_collision_normal().rotated(PI / 2).angle() center_floor_rot = $SlopeRaycast.get_collision_normal().rotated(PI / 2).angle()
floor_rot = get_floor_normal().rotated(PI / 2).angle() floor_rot = get_floor_normal().rotated(PI / 2).angle()
if abs(center_floor_rot) > PI / 4 + 0.1: if abs(center_floor_rot) > PI / 4 + 0.1:
center_floor_rot = floor_rot center_floor_rot = floor_rot
# snap when on slopes # snap when on slopes
if (abs(floor_rot) > 0.1 || abs(center_floor_rot) > 0.1) && snap_possible: if (abs(floor_rot) > 0.1 || abs(center_floor_rot) > 0.1) && snap_possible:
velocity = move_and_slide_with_snap(velocity.rotated(floor_rot), snap, FLOOR_NORMAL, true) velocity = move_and_slide_with_snap(velocity.rotated(floor_rot), snap, FLOOR_NORMAL, true)
# normal slide on flat floor # normal slide on flat floor
else: else:
velocity = move_and_slide(velocity.rotated(floor_rot), FLOOR_NORMAL) velocity = move_and_slide(velocity.rotated(floor_rot), FLOOR_NORMAL)
rotation = 0 rotation = 0
if ( if (
$SlopeRaycastLeft.is_colliding() $SlopeRaycastLeft.is_colliding()
&& $SlopeRaycastRight.is_colliding() && $SlopeRaycastRight.is_colliding()
&& $SlopeRaycast.is_colliding() && $SlopeRaycast.is_colliding()
): ):
rotation = calculate_slope_rotation(onfloor) rotation = calculate_slope_rotation(onfloor)
# rotate related to floor slope # rotate related to floor slope
# Convert velocity back to local space. # Convert velocity back to local space.
# TODO: Downward velocity should be increased by gravity # TODO: Downward velocity should be increased by gravity
velocity = velocity.rotated(-floor_rot) if snap_possible else velocity velocity = velocity.rotated(-floor_rot) if snap_possible else velocity
func calculate_duck_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2: func calculate_duck_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2:
var state = player_state_machine.state var state = player_state_machine.state
var out_vel := linear_velocity var out_vel := linear_velocity
var velocity_direction = 1.0 var velocity_direction = 1.0
if velocity.x < 0: if velocity.x < 0:
velocity_direction = -1.0 velocity_direction = -1.0
# TODO Improve this to separate crawling(slow) and sliding # TODO Improve this to separate crawling(slow) and sliding
var deceleration_force = calculate_deceleration_force(_gravity, mass) * 0.333 var deceleration_force = calculate_deceleration_force(_gravity, mass) * 0.333
# Slowing down movement when not controlling direction # Slowing down movement when not controlling direction
if is_equal_approx(direction.x, 0): if is_equal_approx(direction.x, 0):
# TODO Handle Deadzones # TODO Handle Deadzones
out_vel.x = PhysicsFunc.two_step_euler( out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x, deceleration_force * -1 * velocity_direction, mass, delta out_vel.x, deceleration_force * -1 * velocity_direction, mass, delta
) )
if abs(out_vel.x) > abs(velocity.x): if abs(out_vel.x) > abs(velocity.x):
out_vel.x = 0 out_vel.x = 0
else: else:
# Reversing movement # Reversing movement
# When turning the opposite direction, friction is added to the opposite acceleration movement # When turning the opposite direction, friction is added to the opposite acceleration movement
var reverse_move = is_reversing_horizontal_movement(direction) var reverse_move = is_reversing_horizontal_movement(direction)
if reverse_move: if reverse_move:
# TODO dont put constants in here # TODO dont put constants in here
out_vel.x = PhysicsFunc.two_step_euler( out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x, deceleration_force * -3.42 * velocity_direction, mass, delta out_vel.x, deceleration_force * -3.42 * velocity_direction, mass, delta
) )
# Normal movement # Normal movement
if abs(velocity.x) < max_velocity[state]: if abs(velocity.x) < max_velocity[state]:
out_vel.x = PhysicsFunc.two_step_euler( out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x, (acceleration_force[state].x) * direction.x, mass, delta out_vel.x, (acceleration_force[state].x) * direction.x, mass, delta
) )
elif !reverse_move: elif !reverse_move:
out_vel.x = max_velocity[state] * direction.x out_vel.x = max_velocity[state] * direction.x
# TODO is_on_dropThrough does the action, is that ok? yEs, MaAsTeR-ChAn # TODO is_on_dropThrough does the action, is that ok? yEs, MaAsTeR-ChAn
# TODO Drop Through coyote time? # TODO Drop Through coyote time?
if Input.is_action_just_pressed("jump") && is_on_dropThrough(): if Input.is_action_just_pressed("jump") && is_on_dropThrough():
return Vector2(out_vel.x, _gravity * delta) return Vector2(out_vel.x, _gravity * delta)
# Jumping when grounded or jump is buffered # Jumping when grounded or jump is buffered
if Input.is_action_just_pressed("jump") || (jump_buffer_filled && is_on_floor()): if Input.is_action_just_pressed("jump") || (jump_buffer_filled && is_on_floor()) || stomping:
snap_possible = false snap_possible = false
return calculate_jump_velocity(velocity, delta, direction) return calculate_jump_velocity(velocity, delta, direction)
elif player_state_machine.coyote_hanging: elif player_state_machine.coyote_hanging:
out_vel.y = 0 out_vel.y = 0
else: else:
out_vel.y = _gravity * delta out_vel.y = _gravity * delta
return out_vel return out_vel
func is_on_dropThrough(): func is_on_dropThrough():
var bodies: Array = $BlobbySkin.get_overlapping_bodies() var bodies: Array = $BlobbySkin.get_overlapping_bodies()
for i in range(0, bodies.size()): for i in range(0, bodies.size()):
if bodies[i].get_collision_mask_bit(7): if bodies[i].get_collision_mask_bit(7):
set_collision_mask_bit(7, false) set_collision_mask_bit(7, false)
return true return true
return false return false
func calculate_grounded_velocity( func calculate_grounded_velocity(
linear_velocity: Vector2, delta: float, direction: Vector2 linear_velocity: Vector2, delta: float, direction: Vector2
) -> Vector2: ) -> Vector2:
var state = player_state_machine.state var state = player_state_machine.state
var out_vel := linear_velocity var out_vel := linear_velocity
var velocity_direction = 1.0 var velocity_direction = 1.0
if velocity.x < 0: if velocity.x < 0:
velocity_direction = -1.0 velocity_direction = -1.0
var deceleration_force = calculate_deceleration_force(_gravity, mass) var deceleration_force = calculate_deceleration_force(_gravity, mass)
# Slowing down movement when not controlling direction # Slowing down movement when not controlling direction
if is_equal_approx(direction.x, 0): if is_equal_approx(direction.x, 0):
# TODO Handle Deadzones # TODO Handle Deadzones
out_vel.x = PhysicsFunc.two_step_euler( out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x, deceleration_force * -1 * velocity_direction, mass, delta out_vel.x, deceleration_force * -1 * velocity_direction, mass, delta
) )
if abs(out_vel.x) > abs(velocity.x): if abs(out_vel.x) > abs(velocity.x):
out_vel.x = 0 out_vel.x = 0
else: else:
# Reversing movement # Reversing movement
# When turning the opposite direction, friction is added to the opposite acceleration movement # When turning the opposite direction, friction is added to the opposite acceleration movement
var reverse_move = is_reversing_horizontal_movement(direction) var reverse_move = is_reversing_horizontal_movement(direction)
if reverse_move: if reverse_move:
# TODO dont put constants in here # TODO dont put constants in here
out_vel.x = PhysicsFunc.two_step_euler( out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x, deceleration_force * -3.42 * velocity_direction, mass, delta out_vel.x, deceleration_force * -3.42 * velocity_direction, mass, delta
) )
# Normal movement # Normal movement
if abs(velocity.x) < max_velocity[state]: if abs(velocity.x) < max_velocity[state]:
out_vel.x = PhysicsFunc.two_step_euler( out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x, out_vel.x,
( (
( (
acceleration_force[state].x acceleration_force[state].x
+ (init_acceleration_force[init_boost_type] * int(init_boost)) + (init_acceleration_force[init_boost_type] * int(init_boost))
) )
* direction.x * direction.x
), ),
mass, mass,
delta delta
) )
elif !reverse_move: elif !reverse_move:
out_vel.x = max_velocity[state] * direction.x out_vel.x = max_velocity[state] * direction.x
# Jumping when grounded or jump is buffered # Jumping when grounded or jump is buffered
if Input.is_action_just_pressed("jump") || (jump_buffer_filled && is_on_floor()): if Input.is_action_just_pressed("jump") || (jump_buffer_filled && is_on_floor()) || stomping:
snap_possible = false snap_possible = false
return calculate_jump_velocity(velocity, delta, direction) return calculate_jump_velocity(velocity, delta, direction)
elif player_state_machine.coyote_hanging: elif player_state_machine.coyote_hanging:
out_vel.y = 0 out_vel.y = 0
else: else:
out_vel.y = _gravity * delta out_vel.y = _gravity * delta
return out_vel return out_vel
# Determines if the player has reversed the steering direction # Determines if the player has reversed the steering direction
# in reference to the current movement direction # in reference to the current movement direction
func is_reversing_horizontal_movement(direction: Vector2) -> bool: func is_reversing_horizontal_movement(direction: Vector2) -> bool:
return (direction.x > 0 && velocity.x < 0) || (direction.x < 0 && velocity.x > 0) return (direction.x > 0 && velocity.x < 0) || (direction.x < 0 && velocity.x > 0)
# Returns if the character is touching a wall with its whole body # Returns if the character is touching a wall with its whole body
# Being able to touch a vertical surface over this length also makes it a qualified "wall" # Being able to touch a vertical surface over this length also makes it a qualified "wall"
# Also sets wall_touch_direction # Also sets wall_touch_direction
func is_touching_wall_completely() -> bool: func is_touching_wall_completely() -> bool:
var value = true var value = true
for left_raycast in left_wall_raycasts.get_children(): for left_raycast in left_wall_raycasts.get_children():
wall_touch_direction = -1 wall_touch_direction = -1
if !left_raycast.is_colliding(): if !left_raycast.is_colliding():
value = false value = false
continue continue
if value == true: if value == true:
return value return value
value = true value = true
for right_raycast in right_wall_raycasts.get_children(): for right_raycast in right_wall_raycasts.get_children():
wall_touch_direction = 1 wall_touch_direction = 1
if !right_raycast.is_colliding(): if !right_raycast.is_colliding():
value = false value = false
continue continue
return value return value
# Attached to wall state is in the PlayerStateMachine # Attached to wall state is in the PlayerStateMachine
func is_correct_walljump_input(direction: Vector2) -> bool: func is_correct_walljump_input(direction: Vector2) -> bool:
return ( return (
Input.is_action_just_pressed("jump") Input.is_action_just_pressed("jump")
&& abs(direction.x + wall_touch_direction) < 1 && abs(direction.x + wall_touch_direction) < 1
&& abs(direction.x + wall_touch_direction) >= 0 && abs(direction.x + wall_touch_direction) >= 0
) )
func is_correct_airstrafe_input() -> bool: func is_correct_airstrafe_input() -> bool:
return ( return (
air_strafe_charges > 0 air_strafe_charges > 0
&& (Input.is_action_just_pressed("move_right") || Input.is_action_just_pressed("move_left")) && (Input.is_action_just_pressed("move_right") || Input.is_action_just_pressed("move_left"))
) )
# Calculates the force of the ground friction # Calculates the force of the ground friction
func calculate_deceleration_force(_gravity: float, mass: float) -> float: func calculate_deceleration_force(_gravity: float, mass: float) -> float:
return floor_friction * _gravity * mass return floor_friction * _gravity * mass
func calculate_stomp_velocity(delta: float) -> float:
var v = 0
if Input.is_action_pressed("jump"):
v += stomp_feedback
# print(stomp_time)
stomp_time -= delta
# print(stomp_time)
if stomp_time <= 0:
# print("stomping over")
stomping = false
stomp_time = init_stomp_time
return v
func calculate_jump_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2: func calculate_jump_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2:
var state = player_state_machine.state var state = player_state_machine.state
var additive_jump_force = velocity_jump_boost_ratio * abs(velocity.x) * mass var additive_jump_force = velocity_jump_boost_ratio * abs(velocity.x) * mass
#TODO Single out stomping and make betta #TODO Single out stomping and make betta
#TODO too much force intially and too high with frog jump #TODO too much force intially and too high with frog jump
if stomping: if stomping:
if Input.is_action_pressed("jump"): additive_jump_force += calculate_stomp_velocity(delta)
additive_jump_force += stomp_feedback
stomp_time -= delta
# print(stomp_time)
if stomp_time <= 0:
# print("stomping over")
stomping = false
stomp_time = init_stomp_time
if state != "jump": if state != "jump":
linear_velocity.y = PhysicsFunc.two_step_euler( linear_velocity.y = PhysicsFunc.two_step_euler(
linear_velocity.y, linear_velocity.y,
(acceleration_force[state].y / delta + additive_jump_force) * -1, (acceleration_force[state].y / delta + additive_jump_force) * -1,
mass, mass,
delta delta
) )
# print(acceleration_force[state].y) # print(acceleration_force[state].y)
# print(linear_velocity.y) # print(linear_velocity.y)
if !Input.is_action_pressed("jump") && !stomping: if !Input.is_action_pressed("jump") && !stomping:
# Smooth transition from jumping to falling # Smooth transition from jumping to falling
if velocity.y > _gravity * delta * 10: if velocity.y > _gravity * delta * 10:
linear_velocity.y += _gravity * delta * 10 linear_velocity.y += _gravity * delta * 10
else: else:
linear_velocity.y += (max(abs(linear_velocity.y), _gravity * delta) / 2) linear_velocity.y += (max(abs(linear_velocity.y), _gravity * delta) / 2)
else: else:
linear_velocity.y += _gravity * delta linear_velocity.y += _gravity * delta
# TODO This is poop too # TODO This is poop too
if ( if (
-max_velocity["jump"].x < velocity.x and direction.x < 0 -max_velocity["jump"].x < velocity.x and direction.x < 0
|| max_velocity["jump"].x > velocity.x and direction.x > 0 || max_velocity["jump"].x > velocity.x and direction.x > 0
): ):
var absolut = 1 - initial_velocity_dependence var absolut = 1 - initial_velocity_dependence
var divisor = 1 / max(0.1, initial_velocity_dependence) var divisor = 1 / max(0.1, initial_velocity_dependence)
var movement_factor = absolut + abs(velocity.x) / (max_velocity["fall"].x * divisor) var movement_factor = absolut + abs(velocity.x) / (max_velocity["fall"].x * divisor)
linear_velocity.x = PhysicsFunc.two_step_euler( linear_velocity.x = PhysicsFunc.two_step_euler(
linear_velocity.x, linear_velocity.x,
acceleration_force[state].x * movement_factor * direction.x, acceleration_force[state].x * movement_factor * direction.x,
mass, mass,
delta delta
) )
if is_correct_airstrafe_input(): if is_correct_airstrafe_input():
linear_velocity = execute_airstrafe(linear_velocity, delta, direction) linear_velocity = execute_airstrafe(linear_velocity, delta, direction)
# print(linear_velocity.y) # print(linear_velocity.y)
return linear_velocity return linear_velocity
# Only applicable to downwards gravity # Only applicable to downwards gravity
# Can set the jump buffer # Can set the jump buffer
func calculate_fall_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2: func calculate_fall_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2:
var state = player_state_machine.state var state = player_state_machine.state
if velocity.y < max_velocity["fall"].y: if velocity.y < max_velocity["fall"].y:
linear_velocity.y = PhysicsFunc.two_step_euler( linear_velocity.y = PhysicsFunc.two_step_euler(
linear_velocity.y, _gravity * mass, mass, delta linear_velocity.y, _gravity * mass, mass, delta
) )
else: else:
linear_velocity.y = max_velocity["fall"].y linear_velocity.y = max_velocity["fall"].y
if ( if (
-max_velocity["fall"].x < velocity.x and direction.x < 0 -max_velocity["fall"].x < velocity.x and direction.x < 0
|| max_velocity["fall"].x > velocity.x and direction.x > 0 || max_velocity["fall"].x > velocity.x and direction.x > 0
): ):
# TODO This is poop # TODO This is poop
var absolut = 1 - initial_velocity_dependence var absolut = 1 - initial_velocity_dependence
var divisor = 1 / max(0.1, initial_velocity_dependence) var divisor = 1 / max(0.1, initial_velocity_dependence)
var movementFactor = absolut + abs(velocity.x) / (max_velocity["fall"].x * divisor) var movementFactor = absolut + abs(velocity.x) / (max_velocity["fall"].x * divisor)
linear_velocity.x = PhysicsFunc.two_step_euler( linear_velocity.x = PhysicsFunc.two_step_euler(
linear_velocity.x, linear_velocity.x,
acceleration_force[state].x * movementFactor * direction.x, acceleration_force[state].x * movementFactor * direction.x,
mass, mass,
delta delta
) )
if Input.is_action_just_pressed("jump"): if Input.is_action_just_pressed("jump"):
jump_buffer_filled = true jump_buffer_filled = true
if is_correct_airstrafe_input(): if is_correct_airstrafe_input():
linear_velocity = execute_airstrafe(linear_velocity, delta, direction) linear_velocity = execute_airstrafe(linear_velocity, delta, direction)
if stomping: if stomping:
linear_velocity = calculate_jump_velocity(Vector2(linear_velocity.x, 0), delta, direction) linear_velocity = calculate_jump_velocity(Vector2(linear_velocity.x, 0), delta, direction)
return linear_velocity return linear_velocity
func calculate_wallslide_velocity( func calculate_wallslide_velocity(
linear_velocity: Vector2, delta: float, direction: Vector2 linear_velocity: Vector2, delta: float, direction: Vector2
) -> Vector2: ) -> Vector2:
# Walljump mechanics # Walljump mechanics
if is_correct_walljump_input(direction): if is_correct_walljump_input(direction):
linear_velocity.x = PhysicsFunc.two_step_euler( linear_velocity.x = PhysicsFunc.two_step_euler(
0, acceleration_force["walljump"].x / delta * direction.x, mass, delta 0, acceleration_force["walljump"].x / delta * direction.x, mass, delta
) )
linear_velocity.y = PhysicsFunc.two_step_euler( linear_velocity.y = PhysicsFunc.two_step_euler(
0, acceleration_force["walljump"].y / delta * -1, mass, delta 0, acceleration_force["walljump"].y / delta * -1, mass, delta
) )
elif is_correct_airstrafe_input(): elif is_correct_airstrafe_input():
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1 # var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
linear_velocity = execute_airstrafe(linear_velocity, delta, direction) linear_velocity = execute_airstrafe(linear_velocity, delta, direction)
else: else:
# TODO dont put constants in here # TODO dont put constants in here
linear_velocity.y = PhysicsFunc.two_step_euler( linear_velocity.y = PhysicsFunc.two_step_euler(
linear_velocity.y * 0.94, _gravity * mass, mass, delta linear_velocity.y * 0.94, _gravity * mass, mass, delta
) )
air_strafe_charges = ( air_strafe_charges = (
air_strafe_charges + 1 air_strafe_charges + 1
if max_air_strafe_charges > air_strafe_charges if max_air_strafe_charges > air_strafe_charges
else 0 else 0
) )
return linear_velocity.rotated(rotation) return linear_velocity.rotated(rotation)
func execute_airstrafe(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2: func execute_airstrafe(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2:
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1 # var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
# TODO Consider adding a extra state for airstrafing # TODO Consider adding a extra state for airstrafing
# TODO Make airstrafing less instantaneous and moderate the impulse # TODO Make airstrafing less instantaneous and moderate the impulse
if direction.x > 0: if direction.x > 0:
effect_player.play("airstrafing") effect_player.play("airstrafing")
else: else:
effect_player.play("airstrafingLeft") effect_player.play("airstrafingLeft")
if is_reversing_horizontal_movement(direction): if is_reversing_horizontal_movement(direction):
linear_velocity.x = 0 linear_velocity.x = 0
linear_velocity.x = PhysicsFunc.two_step_euler( linear_velocity.x = PhysicsFunc.two_step_euler(
linear_velocity.x, acceleration_force["air_strafe"].x / delta * direction.x, mass, delta linear_velocity.x, acceleration_force["air_strafe"].x / delta * direction.x, mass, delta
) )
if linear_velocity.y > 0: if linear_velocity.y > 0:
# TODO Put constant elsewhere # TODO Put constant elsewhere
linear_velocity.y = linear_velocity.y * 0.33 linear_velocity.y = linear_velocity.y * 0.33
air_strafe_charges -= 1 air_strafe_charges -= 1
return linear_velocity return linear_velocity
func calculate_slope_rotation(_onfloor: bool) -> float: func calculate_slope_rotation(_onfloor: bool) -> float:
var angle = 0 var angle = 0
var slope_angle_left = $SlopeRaycastLeft.get_collision_normal().rotated(PI / 2).angle() var slope_angle_left = $SlopeRaycastLeft.get_collision_normal().rotated(PI / 2).angle()
var slope_angle_right = $SlopeRaycastRight.get_collision_normal().rotated(PI / 2).angle() var slope_angle_right = $SlopeRaycastRight.get_collision_normal().rotated(PI / 2).angle()
# avoid invalid angles and stay in rotation when touching ground completely # avoid invalid angles and stay in rotation when touching ground completely
if ( if (
!(-PI / 2 <= slope_angle_left && slope_angle_left <= PI / 2) !(-PI / 2 <= slope_angle_left && slope_angle_left <= PI / 2)
|| !(-PI / 2 <= slope_angle_right && slope_angle_right <= PI / 2) || !(-PI / 2 <= slope_angle_right && slope_angle_right <= PI / 2)
|| (is_equal_approx(abs(slope_angle_left), abs(slope_angle_right))) || (is_equal_approx(abs(slope_angle_left), abs(slope_angle_right)))
): ):
return ( return (
previous_rotation previous_rotation
if abs(rad2deg(previous_rotation)) > 1 && !is_equal_approx(slope_angle_left, 0) if abs(rad2deg(previous_rotation)) > 1 && !is_equal_approx(slope_angle_left, 0)
else 0.0 else 0.0
) )
# downturn # downturn
if ( if (
abs(slope_angle_left) > abs(slope_angle_right) && velocity.x < -10 abs(slope_angle_left) > abs(slope_angle_right) && velocity.x < -10
|| abs(slope_angle_right) > abs(slope_angle_left) && velocity.x > 10 || abs(slope_angle_right) > abs(slope_angle_left) && velocity.x > 10
): ):
var length_vector: Vector2 = ( var length_vector: Vector2 = (
$SlopeRaycastRight.get_collision_point() $SlopeRaycastRight.get_collision_point()
- $SlopeRaycastLeft.get_collision_point() - $SlopeRaycastLeft.get_collision_point()
) )
angle = length_vector.angle() angle = length_vector.angle()
# upturn # upturn
else: else:
var length_vector: Vector2 = ( var length_vector: Vector2 = (
$SlopeRaycastLeft.get_collision_point() $SlopeRaycastLeft.get_collision_point()
- $SlopeRaycastRight.get_collision_point() - $SlopeRaycastRight.get_collision_point()
) )
angle = length_vector.angle() - PI angle = length_vector.angle() - PI
previous_rotation = angle previous_rotation = angle
if is_equal_approx(deg2rad(angle), 0): if is_equal_approx(deg2rad(angle), 0):
pass pass
return angle return angle
# TODO could be expanded with a parameter about what got stomped # TODO could be expanded with a parameter about what got stomped
func stomp() -> void: func stomp() -> void:
# print("stomping") # print("stomping")
stomping = true print(player_state_machine.state)
scene_audio.play_parallel_sound(
"res://assets/sounds/FABRIC_Flap_03_mono.wav", -15, false, 1.5, 0.2
)
scene_audio.play_parallel_sound("res://assets/sounds/CLASP_Plastic_Open_stereo.wav", -12)
stomping = true
# TOD lose_power_up function # TOD lose_power_up function
func receive_power_up(kind: String) -> void: func receive_power_up(kind: String) -> void:
if kind == "shield": if kind == "shield":
$BubbleShieldViewport/IridescenceBall.visible = true $BubbleShieldViewport/IridescenceBall.visible = true
shielded = true shielded = true
# TODO Maybe this should be a state in itself? # TODO Maybe this should be a state in itself?
func die(animation_number: int = 0) -> void: func die(animation_number: int = 0) -> void:
if level_state.is_dead: if level_state.is_dead:
return return
if shielded: if shielded:
shielded = false shielded = false
$BubbleShieldViewport/IridescenceBall.visible = false $BubbleShieldViewport/IridescenceBall.visible = false
$InvincibilityTimer.start() $InvincibilityTimer.start()
$BlobbySprite.material = invincible_shader $BlobbySprite.material = invincible_shader
return return
elif !$InvincibilityTimer.is_stopped(): elif !$InvincibilityTimer.is_stopped():
return return
z_index = 1 z_index = 1
$BlobbySprite.material = death_shader $BlobbySprite.material = death_shader
signal_manager.emit_signal("player_died", animation_number) signal_manager.emit_signal("player_died", animation_number)
$"%BlobbymationTree".active = false $"%BlobbymationTree".active = false
$"%BlobbymationPlayer".play("dying3") $"%BlobbymationPlayer".play("dying3")
if animation_number < 1: if animation_number < 1:
$"%BlobbymationPlayer".play("expandingDisolve") $"%BlobbymationPlayer".play("expandingDisolve")
scene_audio.play_parallel_sound(death_sound_1, -15) scene_audio.play_parallel_sound(death_sound_1, -15)
scene_audio.play_parallel_sound(death_sound_2, -16) scene_audio.play_parallel_sound(death_sound_2, -16)
func die_for_real(animation_number: int = 0) -> void: func die_for_real(animation_number: int = 0) -> void:
shielded = false shielded = false
$BubbleShieldViewport/IridescenceBall.visible = false $BubbleShieldViewport/IridescenceBall.visible = false
die(animation_number) die(animation_number)
# TODO Checkpoint system # TODO Checkpoint system
func respawn() -> void: func respawn() -> void:
# Is tied to the death animation # Is tied to the death animation
get_tree().reload_current_scene() get_tree().reload_current_scene()
# When the Enemy stomp AREA enters the enemy collision area -> stomp # When the Enemy stomp AREA enters the enemy collision area -> stomp
func _on_BlobbySkin_area_entered(area: Area2D) -> void: func _on_BlobbySkin_area_entered(area: Area2D) -> void:
if area.is_in_group("harmful"): if area.is_in_group("harmful"):
die() die()
if area.is_in_group("pit"): if area.is_in_group("pit"):
$PitfallTimer.start() $PitfallTimer.start()
# This problem stems from trying to decelerate a walk # This problem stems from trying to decelerate a walk
@ -464,49 +476,49 @@ func _on_BlobbySkin_area_entered(area: Area2D) -> void:
# It is particularly usefull for moving floor physics # It is particularly usefull for moving floor physics
# TODO Setting y velocity this way stopped is_on_floor() from working correctly # TODO Setting y velocity this way stopped is_on_floor() from working correctly
func _on_Blobby_got_grounded() -> void: func _on_Blobby_got_grounded() -> void:
velocity.x -= get_floor_velocity().x velocity.x -= get_floor_velocity().x
snap_possible = true snap_possible = true
var floor_object = get_last_slide_collision().collider.get_parent() var floor_object = get_last_slide_collision().collider.get_parent()
#TODO There is already a friction property in engine #TODO There is already a friction property in engine
if "slide_friction" in floor_object: if "slide_friction" in floor_object:
floor_friction = floor_object.slide_friction floor_friction = floor_object.slide_friction
else: else:
floor_friction = base_floor_friction floor_friction = base_floor_friction
air_strafe_charges = ( air_strafe_charges = (
air_strafe_charges + 1 air_strafe_charges + 1
if max_air_strafe_charges > air_strafe_charges if max_air_strafe_charges > air_strafe_charges
else 0 else 0
) )
func _on_BlobbySkin_body_exited(body: Node) -> void: func _on_BlobbySkin_body_exited(body: Node) -> void:
# This is for drop through platforms # This is for drop through platforms
if body.get_collision_mask_bit(7): if body.get_collision_mask_bit(7):
set_collision_mask_bit(7, true) set_collision_mask_bit(7, true)
func _on_InvincibilityTimer_timeout() -> void: func _on_InvincibilityTimer_timeout() -> void:
$BlobbySprite.material = null $BlobbySprite.material = null
for area in $BlobbySkin.get_overlapping_areas(): for area in $BlobbySkin.get_overlapping_areas():
if area.is_in_group("harmful"): if area.is_in_group("harmful"):
die() die()
func handle_grounded_movement(delta: float, direction: Vector2) -> Vector2: func handle_grounded_movement(delta: float, direction: Vector2) -> Vector2:
return calculate_grounded_velocity(velocity, delta, direction) return calculate_grounded_velocity(velocity, delta, direction)
func handle_jump_movement(delta: float, direction: Vector2) -> Vector2: func handle_jump_movement(delta: float, direction: Vector2) -> Vector2:
return calculate_jump_velocity(velocity, delta, direction) return calculate_jump_velocity(velocity, delta, direction)
func handle_duck_movement(delta: float, direction: Vector2) -> Vector2: func handle_duck_movement(delta: float, direction: Vector2) -> Vector2:
return calculate_duck_velocity(velocity, delta, direction) return calculate_duck_velocity(velocity, delta, direction)
func handle_fall_movement(delta: float, direction: Vector2) -> Vector2: func handle_fall_movement(delta: float, direction: Vector2) -> Vector2:
return calculate_fall_velocity(velocity, delta, direction) return calculate_fall_velocity(velocity, delta, direction)
func handle_wallslide_movement(delta: float, direction: Vector2) -> Vector2: func handle_wallslide_movement(delta: float, direction: Vector2) -> Vector2:
return calculate_wallslide_velocity(velocity, delta, direction) return calculate_wallslide_velocity(velocity, delta, direction)

View File

@ -4385,7 +4385,7 @@ texture = SubResource( 62 )
offset = Vector2( 1, 0 ) offset = Vector2( 1, 0 )
hframes = 6 hframes = 6
vframes = 6 vframes = 6
frame = 10 frame = 7
__meta__ = { __meta__ = {
"_editor_description_": "YXNlcHJpdGVfd2l6YXJkX2NvbmZpZwpwbGF5ZXJ8PUJsb2JieVNwcml0ZS9CbG9iYnltYXRpb25QbGF5ZXIKc291cmNlfD1yZXM6Ly9hc3NldHMvYmxvYmJ5L2Jsb2JieS1zcHJpdGVzaGVldHQuYXNlcHJpdGUKbGF5ZXJ8PUJsb2JieQpvcF9leHB8PUZhbHNlCm9fZm9sZGVyfD0Kb19uYW1lfD0Kb25seV92aXNpYmxlfD1GYWxzZQpvX2V4X3B8PQo=" "_editor_description_": "YXNlcHJpdGVfd2l6YXJkX2NvbmZpZwpwbGF5ZXJ8PUJsb2JieVNwcml0ZS9CbG9iYnltYXRpb25QbGF5ZXIKc291cmNlfD1yZXM6Ly9hc3NldHMvYmxvYmJ5L2Jsb2JieS1zcHJpdGVzaGVldHQuYXNlcHJpdGUKbGF5ZXJ8PUJsb2JieQpvcF9leHB8PUZhbHNlCm9fZm9sZGVyfD0Kb19uYW1lfD0Kb25seV92aXNpYmxlfD1GYWxzZQpvX2V4X3B8PQo="
} }

View File

@ -5,7 +5,7 @@ export var offset_reset_seconds := 1
export var offset_adapt_seconds := 1 export var offset_adapt_seconds := 1
export var offset_input_seconds := 0.618 * 2 export var offset_input_seconds := 0.618 * 2
export var alarm_light_shader: Material export var alarm_light_shader: Material
export var fixed_position : bool = false export var fixed_position: bool = false
onready var level_state := $"%LevelState" onready var level_state := $"%LevelState"
onready var signal_manager := $"%SignalManager" onready var signal_manager := $"%SignalManager"
@ -29,7 +29,7 @@ var original_limit_right: int
var original_limit_bottom: int var original_limit_bottom: int
var original_limit_top: int var original_limit_top: int
var camera_is_panning: bool = false var camera_is_panning: bool = false
var target_offset: Vector2 = Vector2(0,0) var target_offset: Vector2 = Vector2(0, 0)
var terminal_activated: bool = false var terminal_activated: bool = false
var image = Image.new() var image = Image.new()
@ -38,232 +38,252 @@ var prev_pos: Vector2
var camera_state := "centered" var camera_state := "centered"
var screen_rect = Vector2() var screen_rect = Vector2()
var old_screen_rect = Vector2(ProjectSettings.get_setting("display/window/size/width") * zoom.x, ProjectSettings.get_setting("display/window/size/height") * zoom.y ) var old_screen_rect = Vector2(
ProjectSettings.get_setting("display/window/size/width") * zoom.x,
ProjectSettings.get_setting("display/window/size/height") * zoom.y
)
var screen_center = Vector2() var screen_center = Vector2()
var screen_bottom = Vector2() var screen_bottom = Vector2()
var screen_top = Vector2() var screen_top = Vector2()
var screen_left = Vector2() var screen_left = Vector2()
var screen_right = Vector2() var screen_right = Vector2()
# Gets the camera limits from the tilemap of the level # Gets the camera limits from the tilemap of the level
# Requires "TileMap" to be a sibling of blobby # Requires "TileMap" to be a sibling of blobby
func _ready(): func _ready():
_set_boundaries() _set_boundaries()
get_tree().get_root().connect("size_changed", self, "_set_boundaries") get_tree().get_root().connect("size_changed", self, "_set_boundaries")
if !fixed_position: if !fixed_position:
self.position = blobby.global_position self.position = blobby.global_position
image.create(128, 2, false, Image.FORMAT_RGBAH) image.create(128, 2, false, Image.FORMAT_RGBAH)
# TODO Test Performance # TODO Test Performance
material.set_shader_param("light_data", null) material.set_shader_param("light_data", null)
_update_lighting_shader() _update_lighting_shader()
# TODO Trigger when needed # TODO Trigger when needed
signal_manager.connect("terminal_activated", self, "_on_SignalManager_terminal_activated") signal_manager.connect("terminal_activated", self, "_on_SignalManager_terminal_activated")
signal_manager.connect("player_died", self, "_death_cam") signal_manager.connect("player_died", self, "_death_cam")
func _on_SignalManager_terminal_activated(animation_number: int = 0): func _on_SignalManager_terminal_activated(animation_number: int = 0):
terminal_activated = true terminal_activated = true
get_node("LightAnimationPlayer").play("Pulsing") get_node("LightAnimationPlayer").play("Pulsing")
#func _draw(): #func _draw():
# draw_line(Vector2((limit_left - position.x), screen_center.y), screen_left, Color(255, 0, 0), 1) # draw_line(Vector2((limit_left - position.x), screen_center.y), screen_left, Color(255, 0, 0), 1)
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if fixed_position: if fixed_position:
return return
# update() # update()
screen_center = (get_camera_screen_center() - position) screen_center = (get_camera_screen_center() - position)
screen_bottom = screen_center + Vector2(0, screen_rect.y/2) screen_bottom = screen_center + Vector2(0, screen_rect.y / 2)
screen_top = screen_center - Vector2(0, screen_rect.y/2) screen_top = screen_center - Vector2(0, screen_rect.y / 2)
screen_left = screen_center - Vector2(screen_rect.x/2, 0) screen_left = screen_center - Vector2(screen_rect.x / 2, 0)
screen_right = screen_center + Vector2(screen_rect.x/2, 0) screen_right = screen_center + Vector2(screen_rect.x / 2, 0)
var was_adjusted := false var was_adjusted := false
if(!level_state.is_dead): if !level_state.is_dead:
was_adjusted = _adjust_offset(delta) was_adjusted = _adjust_offset(delta)
if(anim_player.is_playing() || was_adjusted): if anim_player.is_playing() || was_adjusted:
position = blobby.position position = blobby.position
prev_pos = position prev_pos = position
_update_lighting_shader() _update_lighting_shader()
return return
var player_vel = (blobby.position - prev_pos)/delta var player_vel = (blobby.position - prev_pos) / delta
# TODO Take average of velocity here # TODO Take average of velocity here
if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.97 if (
&& (sign(player_vel.x) == sign(target_offset.x) || target_offset.x == 0)): abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.97
if(player_vel.x > 0): && (sign(player_vel.x) == sign(target_offset.x) || target_offset.x == 0)
right_move_time += delta ):
left_move_time = max(0, left_move_time - delta) if player_vel.x > 0:
slow_time = max(0, slow_time - delta) right_move_time += delta
else: left_move_time = max(0, left_move_time - delta)
left_move_time += delta slow_time = max(0, slow_time - delta)
right_move_time = max(0, right_move_time - delta) else:
slow_time = max(0, slow_time - delta) left_move_time += delta
elif(abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9 right_move_time = max(0, right_move_time - delta)
|| sign(player_vel.x) != sign(target_offset.x) || target_offset.x == 0): slow_time = max(0, slow_time - delta)
slow_time += delta elif (
left_move_time = max(0, left_move_time - delta) abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9
right_move_time = max(0, right_move_time - delta) || sign(player_vel.x) != sign(target_offset.x)
|| target_offset.x == 0
):
slow_time += delta
left_move_time = max(0, left_move_time - delta)
right_move_time = max(0, right_move_time - delta)
_adapt_to_movement(player_vel)
if abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9:
_adapt_to_input(player_vel, delta)
position = blobby.position
prev_pos = position
_update_lighting_shader()
_adapt_to_movement(player_vel)
if abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9:
_adapt_to_input(player_vel, delta)
position = blobby.position
prev_pos = position
_update_lighting_shader()
# TODO This has to be redone when the screen is resized in any way # TODO This has to be redone when the screen is resized in any way
# Otherwise the boundaries will not be correct anymore # Otherwise the boundaries will not be correct anymore
func _set_boundaries(): func _set_boundaries():
screen_rect = get_viewport_rect().size screen_rect = get_viewport_rect().size
screen_rect.x *= zoom.x screen_rect.x *= zoom.x
screen_rect.y *= zoom.y screen_rect.y *= zoom.y
original_x_zoom = zoom.x original_x_zoom = zoom.x
original_y_zoom = zoom.y original_y_zoom = zoom.y
# This is ok, because it only happens on initialization # This is ok, because it only happens on initialization
# But it is also quite fickle # But it is also quite fickle
var tilemap = get_node("./%TileMap") var tilemap = get_node("./%TileMap")
# TODO: This goes wrong when overwriting old tiles with new sprites # TODO: This goes wrong when overwriting old tiles with new sprites
# New pngs -> completely new tiles and rebuild map # New pngs -> completely new tiles and rebuild map
var rect = tilemap.get_used_rect() var rect = tilemap.get_used_rect()
var cell_size = tilemap.cell_size var cell_size = tilemap.cell_size
# TODO is fixed for camera issue in adjust horizontal # TODO is fixed for camera issue in adjust horizontal
limit_right = rect.end.x * cell_size.x - 6 limit_right = rect.end.x * cell_size.x - 6
limit_left = rect.position.x * cell_size.x + 6 limit_left = rect.position.x * cell_size.x + 6
limit_top = rect.position.y * cell_size.y + 6 limit_top = rect.position.y * cell_size.y + 6
limit_bottom = rect.end.y * cell_size.y - 6 limit_bottom = rect.end.y * cell_size.y - 6
original_limit_left = limit_left original_limit_left = limit_left
original_limit_right = limit_right original_limit_right = limit_right
original_limit_top = limit_top original_limit_top = limit_top
original_limit_bottom = limit_bottom original_limit_bottom = limit_bottom
var screen_size = get_viewport_rect() var screen_size = get_viewport_rect()
var h_pixels = limit_right - limit_left var h_pixels = limit_right - limit_left
var v_pixels = limit_bottom - limit_top var v_pixels = limit_bottom - limit_top
# TODO: Fix that it can zoom both? # TODO: Fix that it can zoom both?
if screen_size.end.x * original_x_zoom - h_pixels > 0: if screen_size.end.x * original_x_zoom - h_pixels > 0:
zoom.x = h_pixels / screen_size.end.x zoom.x = h_pixels / screen_size.end.x
zoom.y = zoom.x zoom.y = zoom.x
if screen_size.end.y * original_y_zoom - v_pixels > 0: if screen_size.end.y * original_y_zoom - v_pixels > 0:
zoom.y = v_pixels / screen_size.end.y zoom.y = v_pixels / screen_size.end.y
zoom.x = zoom.y zoom.x = zoom.y
# Smoothing the camera limits in godot ruins something # Smoothing the camera limits in godot ruins something
func _adapt_to_movement(velocity: Vector2) -> void: func _adapt_to_movement(velocity: Vector2) -> void:
var offset_track var offset_track
var center = get_camera_screen_center() var center = get_camera_screen_center()
var left_edge_pos = center.x - screen_rect.x/2 + camera_horizontal_shift var left_edge_pos = center.x - screen_rect.x / 2 + camera_horizontal_shift
var right_edge_pos = center.x + screen_rect.x/2 - camera_horizontal_shift var right_edge_pos = center.x + screen_rect.x / 2 - camera_horizontal_shift
if(left_move_time >= offset_adapt_seconds && !anim_player.is_playing()): if left_move_time >= offset_adapt_seconds && !anim_player.is_playing():
left_move_time = 0 left_move_time = 0
target_offset.x = -camera_horizontal_shift target_offset.x = -camera_horizontal_shift
if(offset == target_offset): if offset == target_offset:
return return
offset_track = shiftLeft.find_track(".:offset") offset_track = shiftLeft.find_track(".:offset")
shiftLeft.track_set_key_value(offset_track, 0, offset) shiftLeft.track_set_key_value(offset_track, 0, offset)
shiftLeft.track_set_key_value(offset_track, 1, target_offset) shiftLeft.track_set_key_value(offset_track, 1, target_offset)
camera_state = "shiftedLeft" camera_state = "shiftedLeft"
anim_player.play("shiftingLeft") anim_player.play("shiftingLeft")
elif(right_move_time >= offset_adapt_seconds && !anim_player.is_playing()): elif right_move_time >= offset_adapt_seconds && !anim_player.is_playing():
right_move_time = 0 right_move_time = 0
target_offset.x = camera_horizontal_shift target_offset.x = camera_horizontal_shift
if(offset == target_offset): if offset == target_offset:
return return
offset_track = shiftRight.find_track(".:offset") offset_track = shiftRight.find_track(".:offset")
shiftRight.track_set_key_value(offset_track, 0, offset) shiftRight.track_set_key_value(offset_track, 0, offset)
shiftRight.track_set_key_value(offset_track, 1, target_offset) shiftRight.track_set_key_value(offset_track, 1, target_offset)
camera_state = "shiftedRight" camera_state = "shiftedRight"
anim_player.play("shiftingRight") anim_player.play("shiftingRight")
elif(slow_time >= offset_reset_seconds && elif (
!(Input.is_action_pressed("up") || Input.is_action_pressed("duck"))): slow_time >= offset_reset_seconds
slow_time = 0 && !(Input.is_action_pressed("up") || Input.is_action_pressed("duck"))
target_offset.x = 0 ):
if(offset == target_offset): slow_time = 0
return target_offset.x = 0
if(left_edge_pos > limit_left && limit_right > right_edge_pos): if offset == target_offset:
offset_track = shiftCenter.find_track(".:offset") return
shiftCenter.track_set_key_value(offset_track, 0, offset) if left_edge_pos > limit_left && limit_right > right_edge_pos:
shiftCenter.track_set_key_value(offset_track, 1, target_offset) offset_track = shiftCenter.find_track(".:offset")
camera_state = "centered" shiftCenter.track_set_key_value(offset_track, 0, offset)
anim_player.play("shiftingCenter") shiftCenter.track_set_key_value(offset_track, 1, target_offset)
return camera_state = "centered"
anim_player.play("shiftingCenter")
return
func _adapt_to_input(velocity: Vector2, delta: float) -> void: func _adapt_to_input(velocity: Vector2, delta: float) -> void:
# TODO Den bug dass man damit durch die map gucken kann wenn man sich weiter bewegt # TODO Den bug dass man damit durch die map gucken kann wenn man sich weiter bewegt
# lasse ich erstmal drin # lasse ich erstmal drin
if(velocity.length() > 20.0): if velocity.length() > 20.0:
input_time = 0 input_time = 0
return return
if(input_time < offset_input_seconds): if input_time < offset_input_seconds:
input_time += delta input_time += delta
return return
if Input.is_action_pressed("duck"): if Input.is_action_pressed("duck"):
if(original_limit_bottom - position.y - 2 > screen_bottom.y && offset.y < 48): if original_limit_bottom - position.y - 2 > screen_bottom.y && offset.y < 48:
offset.y += 0.5 offset.y += 0.5
elif Input.is_action_pressed("up"): elif Input.is_action_pressed("up"):
if(original_limit_top - position.y + 2 < screen_top.y && offset.y > -48): if original_limit_top - position.y + 2 < screen_top.y && offset.y > -48:
offset.y -= 0.5 offset.y -= 0.5
# TODO This is a regulatory problem, it doesn't adapt fast enough # TODO This is a regulatory problem, it doesn't adapt fast enough
# TODO Maybe just make background black and dont bother # TODO Maybe just make background black and dont bother
func _adjust_offset(delta: float) -> bool: func _adjust_offset(delta: float) -> bool:
var new_offset = offset var new_offset = offset
if (limit_left - position.x - screen_left.x > 0.1): if limit_left - position.x - screen_left.x > 0.1:
if (anim_player.is_playing()): if anim_player.is_playing():
anim_player.stop(true) anim_player.stop(true)
new_offset.x += (limit_left - position.x - screen_left.x)/1.5 new_offset.x += (limit_left - position.x - screen_left.x) / 1.5
if (limit_right - position.x - screen_right.x < 0.1): if limit_right - position.x - screen_right.x < 0.1:
if (anim_player.is_playing()): if anim_player.is_playing():
anim_player.stop(true) anim_player.stop(true)
new_offset.x += (limit_right - position.x - screen_right.x)/1.5 new_offset.x += (limit_right - position.x - screen_right.x) / 1.5
if (limit_top - position.y - screen_top.y > 0.001): if limit_top - position.y - screen_top.y > 0.001:
new_offset.y += (limit_top - position.y - screen_top.y)/1.5 new_offset.y += (limit_top - position.y - screen_top.y) / 1.5
if (limit_bottom - position.y - screen_bottom.y < 0.001): if limit_bottom - position.y - screen_bottom.y < 0.001:
new_offset.y += (limit_bottom - position.y - screen_bottom.y)/1.5 new_offset.y += (limit_bottom - position.y - screen_bottom.y) / 1.5
#print(abs(offset.x) - abs(new_offset.x)) #print(abs(offset.x) - abs(new_offset.x))
if(abs(offset.x) > abs(new_offset.x) || abs(offset.y) > abs(new_offset.y)): if abs(offset.x) > abs(new_offset.x) || abs(offset.y) > abs(new_offset.y):
offset = new_offset offset = new_offset
return true return true
else: else:
return false return false
func reset_limits() -> void: func reset_limits() -> void:
limit_left = original_limit_left limit_left = original_limit_left
limit_right = original_limit_right limit_right = original_limit_right
limit_bottom = original_limit_bottom limit_bottom = original_limit_bottom
limit_top = original_limit_top limit_top = original_limit_top
func _death_cam(animation_number: int = 0) -> void: func _death_cam(animation_number: int = 0) -> void:
if(animation_number < 1): if animation_number < 1:
$CameraAnimationPlayer.play("deathCamJustZoom") $CameraAnimationPlayer.play("deathCamJustZoom")
if(animation_number == 1): if animation_number == 1:
$CameraAnimationPlayer.play("deathCamLateRotation") $CameraAnimationPlayer.play("deathCamLateRotation")
# TODO Rename to alarm lights specially # TODO Rename to alarm lights specially
func _update_lighting_shader() -> void: func _update_lighting_shader() -> void:
if !terminal_activated: return if !terminal_activated:
# Props to gameendaevour return
# TODO get this into a central world update management system # Props to gameendaevour
var lights = get_tree().get_nodes_in_group("light") # TODO get this into a central world update management system
image.lock() var lights = get_tree().get_nodes_in_group("light")
for i in lights.size(): image.lock()
var light = lights[i] for i in lights.size():
# TODO To make the lighting affect all layers properly var light = lights[i]
# I would have the access the global positions of nodes in different Z layers # TODO To make the lighting affect all layers properly
# without the projection to the global center layer. # I would have the access the global positions of nodes in different Z layers
# without the projection to the global center layer.
# var vtrans = get_canvas_transform() # var vtrans = get_canvas_transform()
# var top_left = -vtrans.origin / vtrans.get_scale() # var top_left = -vtrans.origin / vtrans.get_scale()
# var vsize = get_viewport_rect().size # var vsize = get_viewport_rect().size
# var t = Transform2D(0, (top_left + 0.5*vsize/vtrans.get_scale()).rotated(rotation)) # var t = Transform2D(0, (top_left + 0.5*vsize/vtrans.get_scale()).rotated(rotation))
image.set_pixel(i, 0, Color( image.set_pixel(
light.position.x, light.position.y, i, 0, Color(light.position.x, light.position.y, light.strength, light.radius)
light.strength, light.radius )
)) image.set_pixel(i, 1, light.color)
image.set_pixel(i, 1, light.color) image.unlock()
image.unlock()
texture.create_from_image(image) texture.create_from_image(image)
material.set_shader_param("n_lights", lights.size()) material.set_shader_param("n_lights", lights.size())
material.set_shader_param("light_data", texture) material.set_shader_param("light_data", texture)
material.set_shader_param("global_transform", get_global_transform()) material.set_shader_param("global_transform", get_global_transform())
material.set_shader_param("viewport_transform", get_viewport_transform()) material.set_shader_param("viewport_transform", get_viewport_transform())

View File

@ -9,20 +9,29 @@ export var block_size := 16
var time = 0 var time = 0
var snap = Vector2.DOWN * block_size var snap = Vector2.DOWN * block_size
func _ready() -> void: func _ready() -> void:
velocity.x = -120 velocity.x = -120
func execute_movement(delta: float) -> void: func execute_movement(delta: float) -> void:
# rotation # rotation
var movement = max(0,sign(sin(time*15))) var movement = max(0, sign(sin(time * 15)))
if(left_src.is_colliding() && right_src.is_colliding() && !left_wrc.is_colliding() && !right_wrc.is_colliding()): if (
pass left_src.is_colliding()
elif(left_wrc.is_colliding() || (!right_src.is_colliding() && left_src.is_colliding())): && right_src.is_colliding()
rotation += delta * 7 * movement && !left_wrc.is_colliding()
else: && !right_wrc.is_colliding()
rotation += sign(velocity.x) * delta * 7 * movement ):
pass
# velocity elif left_wrc.is_colliding() || (!right_src.is_colliding() && left_src.is_colliding()):
var v = Vector2(velocity.x * movement, 0) rotation += delta * 7 * movement
time += delta else:
move_and_slide_with_snap(v.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI, false) rotation += sign(velocity.x) * delta * 7 * movement
# velocity
var v = Vector2(velocity.x * movement, 0)
time += delta
move_and_slide_with_snap(
v.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI, false
)

View File

@ -3,31 +3,35 @@ class_name Enemy
var player_entered_stomp = false var player_entered_stomp = false
func _on_StompDetector_body_entered(body: Node) -> void: func _on_StompDetector_body_entered(body: Node) -> void:
if !body.is_in_group("player"): if !body.is_in_group("player"):
return return
player_entered_stomp = true player_entered_stomp = true
var incoming_vel_vector: Vector2 = body.velocity.normalized() var incoming_vel_vector: Vector2 = body.velocity.normalized()
print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))))) print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation)))))
if abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))) > deg2rad(95): if abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))) > deg2rad(95):
print("too shallow entry") print("too shallow entry")
body.die() body.die()
player_entered_stomp = false player_entered_stomp = false
return return
signal_manager.emit_signal("got_stomped") signal_manager.emit_signal("got_stomped")
remove_from_group("harmful") remove_from_group("harmful")
$StompDetector.remove_from_group("weakpoint") $StompDetector.remove_from_group("weakpoint")
get_node("EnemyBody").disabled = true get_node("EnemyBody").disabled = true
die() die()
func die() -> void: func die() -> void:
queue_free() queue_free()
func _on_EnemySkin_area_entered(area: Area2D) -> void:
if area.is_in_group("harmful"):
get_node("EnemyBody").disabled = true
die()
func _on_EnemySkin_area_entered(area:Area2D) -> void:
if area.is_in_group("harmful"):
get_node("EnemyBody").disabled = true
die()
func _on_EnemySkin_body_entered(body: Node) -> void: func _on_EnemySkin_body_entered(body: Node) -> void:
if body.is_in_group("player") && !player_entered_stomp: if body.is_in_group("player") && !player_entered_stomp:
body.die() body.die()

View File

@ -3,9 +3,8 @@ const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
onready var players = get_tree().get_nodes_in_group("player") onready var players = get_tree().get_nodes_in_group("player")
onready var vision_raycast: RayCast2D = $VisionRayCast onready var vision_raycast: RayCast2D = $VisionRayCast
onready var orientation: RayCast2D = $Orientation onready var orientation: RayCast2D = $Orientation
onready var feeler_raycast: RayCast2D = $FeelerRayCast onready var feeler_raycast: RayCast2D = $FeelerRayCast
onready var tilemap: TileMap = $"../%TileMap" onready var tilemap: TileMap = $"../%TileMap"
onready var state_machine = $Statemachine onready var state_machine = $Statemachine
@ -28,8 +27,6 @@ export var jump_time_standard_deviation := 0.1
# TODO Make constant for project # TODO Make constant for project
export var block_size := 16 export var block_size := 16
# Also in blocks # Also in blocks
var movement_radius: float var movement_radius: float
var anchor: Node2D var anchor: Node2D
@ -56,288 +53,319 @@ var attached_player = null
func _ready(): func _ready():
default_jump_distance = default_jump_distance * tilemap.cell_size.x default_jump_distance = default_jump_distance * tilemap.cell_size.x
jump_timer = Timer.new() jump_timer = Timer.new()
jump_timer.set_one_shot(true) jump_timer.set_one_shot(true)
jump_timer.connect("timeout", self, "jump") jump_timer.connect("timeout", self, "jump")
target_lost_timer = Timer.new() target_lost_timer = Timer.new()
target_lost_timer.set_one_shot(true) target_lost_timer.set_one_shot(true)
target_lost_timer.connect("timeout", self, "loose_target") target_lost_timer.connect("timeout", self, "loose_target")
add_child(jump_timer) add_child(jump_timer)
add_child(target_lost_timer) add_child(target_lost_timer)
# TODO this is so bad ;_; # TODO this is so bad ;_;
if(get_parent().name.begins_with("Bound")): if get_parent().name.begins_with("Bound"):
is_bound = true is_bound = true
else: else:
level_state.free_a_frog(frog_number) level_state.free_a_frog(frog_number)
level_state.register_frog(frog_number, !is_bound) level_state.register_frog(frog_number, !is_bound)
# TODO Stays harmless for now # TODO Stays harmless for now
#if(is_bound): add_to_group("harmful") #if(is_bound): add_to_group("harmful")
func bind_to_anchor(anchor_node: Node2D, radius: float ) -> void: func bind_to_anchor(anchor_node: Node2D, radius: float) -> void:
anchor = anchor_node anchor = anchor_node
movement_radius = radius * block_size movement_radius = radius * block_size
is_bound = true is_bound = true
# TODO multiple free frogs # TODO multiple free frogs
$Digit.visible = true $Digit.visible = true
$Digit.frame = frog_number $Digit.frame = frog_number
$LeashAnchor.visible = is_bound $LeashAnchor.visible = is_bound
func execute_movement(delta: float) -> void: func execute_movement(delta: float) -> void:
# Navigation2DServer.map_get_path() # Navigation2DServer.map_get_path()
current_delta = delta current_delta = delta
# TODO what when the game runs really long and the float runs out of space? # TODO what when the game runs really long and the float runs out of space?
# Achievment maybe lul # Achievment maybe lul
detect_timer += delta detect_timer += delta
velocity.y += _gravity * delta velocity.y += _gravity * delta
if(is_bound): if is_bound:
var next_position = global_position + velocity * current_delta var next_position = global_position + velocity * current_delta
var current_distance = global_position.distance_to(anchor.global_position) var current_distance = global_position.distance_to(anchor.global_position)
var new_distance = next_position.distance_to(anchor.global_position) var new_distance = next_position.distance_to(anchor.global_position)
# TODO Fix this in respects to x and y distances and movement dampening # TODO Fix this in respects to x and y distances and movement dampening
# Maybe use mathemathematics or something idfc # Maybe use mathemathematics or something idfc
if(current_distance >= movement_radius && new_distance > current_distance): if current_distance >= movement_radius && new_distance > current_distance:
velocity.x = velocity.x * 0.8 velocity.x = velocity.x * 0.8
velocity.y = velocity.y * 0.8 velocity.y = velocity.y * 0.8
was_restricted = true was_restricted = true
velocity = move_and_slide(velocity, FLOOR_NORMAL, false, 4, 0.785398, false) velocity = move_and_slide(velocity, FLOOR_NORMAL, false, 4, 0.785398, false)
if($"%GroundDetector".get_overlapping_bodies().size() > 0): if $"%GroundDetector".get_overlapping_bodies().size() > 0:
velocity.y -= 10 * (delta/0.0083) velocity.y -= 10 * (delta / 0.0083)
var min_x_slide_velocity = 50 * (delta/0.0083) var min_x_slide_velocity = 50 * (delta / 0.0083)
velocity.x = sign(velocity.x) * max(min_x_slide_velocity, velocity.x * 0.99) velocity.x = sign(velocity.x) * max(min_x_slide_velocity, velocity.x * 0.99)
return return
elif(is_on_floor()): elif is_on_floor():
velocity = Vector2(0,0) velocity = Vector2(0, 0)
# Reverse direction when hitting limit # Reverse direction when hitting limit
func die() -> void: func die() -> void:
queue_free() queue_free()
func _on_EnemySkin_area_entered(area:Area2D) -> void: func _on_EnemySkin_area_entered(area: Area2D) -> void:
if area.is_in_group("harmful") && !area.is_in_group("frogfood"): if area.is_in_group("harmful") && !area.is_in_group("frogfood"):
get_node("EnemyBody").disabled = true get_node("EnemyBody").disabled = true
die() die()
func _on_EnemySkin_body_entered(body: Node) -> void: func _on_EnemySkin_body_entered(body: Node) -> void:
if body.is_in_group("frogfood"): if body.is_in_group("frogfood"):
loose_target() loose_target()
body.die() body.die()
func _on_StompDetector_body_entered(body: Node) -> void: func _on_StompDetector_body_entered(body: Node) -> void:
if body.is_in_group("player"): if body.is_in_group("player"):
attached_player = body attached_player = body
$FeelerRayCast.collision_mask -= 1 $FeelerRayCast.collision_mask -= 1
if !body.is_in_group("player") || is_hurt: if !body.is_in_group("player") || is_hurt:
return return
var incoming_vel_vector: Vector2 = body.velocity.normalized() var incoming_vel_vector: Vector2 = body.velocity.normalized()
# TODO This is not the right angle somehow # TODO This is not the right angle somehow
# print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))))) # print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation)))))
# if abs(incoming_vel_vector.angle_to(\Vector2.DOWN.rotated(rotation))) > deg2rad(60): # if abs(incoming_vel_vector.angle_to(\Vector2.DOWN.rotated(rotation))) > deg2rad(60):
# print("too shallow entry") # print("too shallow entry")
# return # return
signal_manager.emit_signal("got_stomped") signal_manager.emit_signal("got_stomped")
remove_from_group("harmful") remove_from_group("harmful")
# TODO Weakpoint group is not needed per se # TODO Weakpoint group is not needed per se
$StompDetector.remove_from_group("weakpoint") $StompDetector.remove_from_group("weakpoint")
get_node("EnemyBody").disabled = true get_node("EnemyBody").disabled = true
is_hurt = true is_hurt = true
$FrogSprite.material = invincible_shader $FrogSprite.material = invincible_shader
$HurtTimer.start() $HurtTimer.start()
func _on_StompDetector_body_exited(body: Node) -> void: func _on_StompDetector_body_exited(body: Node) -> void:
if attached_player == body: if attached_player == body:
$FeelerRayCast.collision_mask += 1 $FeelerRayCast.collision_mask += 1
attached_player = null attached_player = null
func searching() -> Vector2: func searching() -> Vector2:
if(detect_timer > 0.333): if detect_timer > 0.333:
search_next_target() search_next_target()
detect_timer = 0.0 detect_timer = 0.0
if(is_on_floor()): if is_on_floor():
if(jump_timer.is_stopped()): if jump_timer.is_stopped():
jump_timer.start(rng.randfn(jump_time_search, jump_time_standard_deviation)) jump_timer.start(rng.randfn(jump_time_search, jump_time_standard_deviation))
if(in_air): if in_air:
in_air = false in_air = false
else: else:
if(!in_air): if !in_air:
start_x = global_position.x start_x = global_position.x
reversing_possible_searching = true reversing_possible_searching = true
jump_timer.stop() jump_timer.stop()
in_air = true in_air = true
return velocity return velocity
func search_next_target(): func search_next_target():
if(target != null && !weakref(target).get_ref()): if target != null && !weakref(target).get_ref():
return return
detect_food() detect_food()
if(food_target == null && is_bound): if food_target == null && is_bound:
detect_player() detect_player()
func hunting() -> Vector2: func hunting() -> Vector2:
var was_target_freed = !weakref(target).get_ref() var was_target_freed = !weakref(target).get_ref()
if(detect_timer > 0.333): if detect_timer > 0.333:
search_next_target() search_next_target()
detect_timer = 0.0 detect_timer = 0.0
#TODO Dependent on block size #TODO Dependent on block size
elif(is_on_floor() && food_target != null && !was_target_freed && elif (
global_position.distance_to(food_target.global_position) <= attack_jump_range * block_size): is_on_floor()
&& food_target != null
var collider = check_feeler(food_target.global_position - global_position) && !was_target_freed
if(!was_restricted && collider != null && collider.is_in_group("frogfood")): && (
jump_timer.stop() global_position.distance_to(food_target.global_position)
return attack_jump(food_target.global_position) <= attack_jump_range * block_size
)
if(is_on_floor()): ):
if(jump_timer.is_stopped()): var collider = check_feeler(food_target.global_position - global_position)
jump_timer.start(rng.randfn(jump_time_hunt, jump_time_standard_deviation)) if !was_restricted && collider != null && collider.is_in_group("frogfood"):
if(in_air): jump_timer.stop()
in_air = false return attack_jump(food_target.global_position)
else:
if(!in_air):
start_x = global_position.x
reversing_possible_searching = true
jump_timer.stop()
in_air = true
if(barely_held_back_counter > 1): if is_on_floor():
barely_held_back_counter = 0 if jump_timer.is_stopped():
loose_target() jump_timer.start(rng.randfn(jump_time_hunt, jump_time_standard_deviation))
if in_air:
in_air = false
if(target != null && !was_target_freed && else:
sign((target.global_position - global_position).x) != get_facing_direction()): if !in_air:
# TODO Waits in front of too small tunnels if it sees the target on the other side start_x = global_position.x
# It's ok behavior for now reversing_possible_searching = true
reverse_facing_direction() jump_timer.stop()
in_air = true
return velocity if barely_held_back_counter > 1:
barely_held_back_counter = 0
loose_target()
if (
target != null
&& !was_target_freed
&& sign((target.global_position - global_position).x) != get_facing_direction()
):
# TODO Waits in front of too small tunnels if it sees the target on the other side
# It's ok behavior for now
reverse_facing_direction()
return velocity
func detect_food() -> void: func detect_food() -> void:
# TODO What if food spawns in # TODO What if food spawns in
food_sources = get_tree().get_nodes_in_group("frogfood") food_sources = get_tree().get_nodes_in_group("frogfood")
if(food_sources.empty()): if food_sources.empty():
return return
var i = 0
var min_dist_f_index = 0 #TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
var min_dist = (food_sources[0].global_position - global_position).length() var i = 0
var food_node = null var min_dist_f_index = 0
for f in food_sources: var min_dist = (food_sources[0].global_position - global_position).length()
var new_dist = (food_sources[i].global_position - global_position).length() var food_node = null
min_dist = new_dist if new_dist < min_dist else min_dist for f in food_sources:
min_dist_f_index = i if new_dist < min_dist else min_dist_f_index var new_dist = (food_sources[i].global_position - global_position).length()
i += 1 min_dist = new_dist if new_dist < min_dist else min_dist
food_node = food_sources[min_dist_f_index] min_dist_f_index = i if new_dist < min_dist else min_dist_f_index
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0 i += 1
vision_raycast.cast_to = (food_node.global_position - global_position).normalized() * block_size * vision_distance
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to) #TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
vision_raycast.force_raycast_update() food_node = food_sources[min_dist_f_index]
var collider = vision_raycast.get_collider() #TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
if(abs(ray_angle_to_facing) < PI/3 && collider != null && collider.is_in_group("frogfood")): vision_raycast.cast_to = (
target_lost_timer.stop() (food_node.global_position - global_position).normalized()
target = collider * block_size
food_target = collider * vision_distance
elif(target != null && target_lost_timer.is_stopped()): )
target_lost_timer.start(loose_target_seconds) var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
vision_raycast.force_raycast_update()
var collider = vision_raycast.get_collider()
if abs(ray_angle_to_facing) < PI / 3 && collider != null && collider.is_in_group("frogfood"):
target_lost_timer.stop()
target = collider
food_target = collider
elif target != null && target_lost_timer.is_stopped():
target_lost_timer.start(loose_target_seconds)
func detect_player() -> void: func detect_player() -> void:
var player var player
if(players.empty()): if players.empty():
# print("no player found") # print("no player found")
return return
player = players[0]
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0 #TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
vision_raycast.cast_to = (player.global_position - global_position - Vector2(0, 9)).normalized() * block_size * vision_distance player = players[0]
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to) #TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
vision_raycast.force_raycast_update() vision_raycast.cast_to = (
var collider = vision_raycast.get_collider() (player.global_position - global_position - Vector2(0, 9)).normalized()
if(abs(ray_angle_to_facing) < PI/4 && collider != null && collider.is_in_group("player")): * block_size
target_lost_timer.stop() * vision_distance
target = collider )
elif(target != null && target_lost_timer.is_stopped()): var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
target_lost_timer.start(loose_target_seconds) vision_raycast.force_raycast_update()
var collider = vision_raycast.get_collider()
if abs(ray_angle_to_facing) < PI / 4 && collider != null && collider.is_in_group("player"):
target_lost_timer.stop()
target = collider
elif target != null && target_lost_timer.is_stopped():
target_lost_timer.start(loose_target_seconds)
func sleeping() -> Vector2: func sleeping() -> Vector2:
jump_timer.stop() jump_timer.stop()
# detect_player() # detect_player()
return velocity return velocity
func loose_target() -> void: func loose_target() -> void:
# print("frog target lost") # print("frog target lost")
target = null target = null
food_target = null food_target = null
func jump(): func jump():
# print("jump calculation initiated") # print("jump calculation initiated")
# Can only reverse once per jump calculation # Can only reverse once per jump calculation
has_reversed = false has_reversed = false
var zero_vector = Vector2(0,0) var zero_vector = Vector2(0, 0)
var v: Vector2 = velocity_for_jump_distance(default_jump_distance, deg2rad(default_jump_angle)) var v: Vector2 = velocity_for_jump_distance(default_jump_distance, deg2rad(default_jump_angle))
v = correct_jump_direction(v) v = correct_jump_direction(v)
if is_bound:
var next_position = global_position + v * current_delta
var current_distance = global_position.distance_to(anchor.global_position)
var new_distance = next_position.distance_to(anchor.global_position)
# print(current_distance)
# print(new_distance)
# Would go out of distance
if (
(new_distance >= movement_radius && new_distance > current_distance)
|| (new_distance > current_distance && was_restricted)
):
if state_machine.state == "hunting":
barely_held_back_counter += 1
if (
can_reverse_facing_direction()
&& (barely_held_back_counter == 0 || barely_held_back_counter > 1)
):
reverse_facing_direction()
was_restricted = false
if $Right_Wallcast.is_colliding() && $Left_Wallcast.is_colliding():
# TODO No idea what it might do in these situations
print("help this is a really tight space :(")
elif get_facing_direction() < 0 && $Left_Wallcast.is_colliding():
v = zero_vector
elif get_facing_direction() > 0 && $Right_Wallcast.is_colliding():
v = zero_vector
v = correct_jump_direction(v)
if v != zero_vector:
v = consider_jump_headspace(v)
if v != zero_vector:
v = consider_jump_landing_space(v)
if v == zero_vector:
# TODO fix that you could call jump from jumping on top
# and let it fail if the top is dangerous for jump height or not safe
v = consider_jumping_on_top()
if v == zero_vector && can_reverse_facing_direction():
reverse_facing_direction()
if(is_bound):
var next_position = global_position + v * current_delta
var current_distance = global_position.distance_to(anchor.global_position)
var new_distance = next_position.distance_to(anchor.global_position)
# print(current_distance)
# print(new_distance)
# Would go out of distance
if((new_distance >= movement_radius && new_distance > current_distance) || (new_distance > current_distance && was_restricted)):
if(state_machine.state == "hunting"):
barely_held_back_counter += 1
if can_reverse_facing_direction() && (barely_held_back_counter == 0 || barely_held_back_counter > 1):
reverse_facing_direction()
was_restricted = false
if ($Right_Wallcast.is_colliding() && $Left_Wallcast.is_colliding()):
# TODO No idea what it might do in these situations
print("help this is a really tight space :(")
elif (get_facing_direction() < 0 && $Left_Wallcast.is_colliding()):
v = zero_vector
elif (get_facing_direction() > 0 && $Right_Wallcast.is_colliding()):
v = zero_vector
v = correct_jump_direction(v)
if(v != zero_vector):
v = consider_jump_headspace(v)
if(v != zero_vector):
v = consider_jump_landing_space(v)
if(v == zero_vector):
# TODO fix that you could call jump from jumping on top
# and let it fail if the top is dangerous for jump height or not safe
v = consider_jumping_on_top()
if(v == zero_vector && can_reverse_facing_direction()):
reverse_facing_direction()
# if attached_player != null && v != zero_vector: # if attached_player != null && v != zero_vector:
# move_with_player(v) # move_with_player(v)
velocity = v velocity = v
#func move_with_player(v: Vector2): #func move_with_player(v: Vector2):
# print(v) # print(v)
# attached_player.move_and_slide(v * 10) # attached_player.move_and_slide(v * 10)
func correct_jump_direction(v: Vector2) -> Vector2: func correct_jump_direction(v: Vector2) -> Vector2:
if sign(v.x) != get_facing_direction(): if sign(v.x) != get_facing_direction():
v.x *= -1 v.x *= -1
return v return v
# Cast a ray to the highest point of the jump # Cast a ray to the highest point of the jump
@ -345,215 +373,245 @@ func correct_jump_direction(v: Vector2) -> Vector2:
# Calculate safe jump height and then a safe jump velocity # Calculate safe jump height and then a safe jump velocity
# Returns 0,0 if theres no headspace # Returns 0,0 if theres no headspace
func consider_jump_headspace(v: Vector2, recursive_check_count = 0, max_checks = 2) -> Vector2: func consider_jump_headspace(v: Vector2, recursive_check_count = 0, max_checks = 2) -> Vector2:
if recursive_check_count >= max_checks: if recursive_check_count >= max_checks:
print("Frog has no safe headspace") print("Frog has no safe headspace")
return Vector2(0,0) return Vector2(0, 0)
var height = calculate_jump_height(v) var height = calculate_jump_height(v)
var distance = calculate_jump_distance(v) var distance = calculate_jump_distance(v)
var angle = (v * get_facing_direction()).angle() var angle = (v * get_facing_direction()).angle()
# Half distance is an estimate of the jumps apex() # Half distance is an estimate of the jumps apex()
#TODO Consider sprite size for height #TODO Consider sprite size for height
var height_collider = check_feeler(Vector2(get_facing_direction()*(distance/2), -(height+23))) var height_collider = check_feeler(
if(height_collider != null): Vector2(get_facing_direction() * (distance / 2), -(height + 23))
var collision_point = feeler_raycast.get_collision_point() )
var target_height = collision_point.y - (feeler_raycast.global_position.y - 23) if height_collider != null:
# print(feeler_raycast.global_position) var collision_point = feeler_raycast.get_collision_point()
var new_angle = angle * (0.75 if target_height > -26 else 0.95) var target_height = collision_point.y - (feeler_raycast.global_position.y - 23)
var new_distance = abs(distance) * (0.66 if target_height < -26 else 0.75) # print(feeler_raycast.global_position)
v = velocity_for_jump_distance(new_distance, abs(new_angle)) var new_angle = angle * (0.75 if target_height > -26 else 0.95)
v = correct_jump_direction(v) var new_distance = abs(distance) * (0.66 if target_height < -26 else 0.75)
height = calculate_jump_height(v) * -1 v = velocity_for_jump_distance(new_distance, abs(new_angle))
distance = calculate_jump_distance(v) * get_facing_direction() v = correct_jump_direction(v)
if(height < target_height && can_reverse_facing_direction()): height = calculate_jump_height(v) * -1
v = consider_jump_headspace(v, recursive_check_count + 1) distance = calculate_jump_distance(v) * get_facing_direction()
return v if height < target_height && can_reverse_facing_direction():
v = consider_jump_headspace(v, recursive_check_count + 1)
return v
# Check the block in jump distance for danger or height # Check the block in jump distance for danger or height
# If danger check neighboring blocks: if still danger, then jump closer (or jump over) # If danger check neighboring blocks: if still danger, then jump closer (or jump over)
# If height move to distance which allows 1 block high jump # If height move to distance which allows 1 block high jump
func consider_jump_landing_space(v: Vector2) -> Vector2: func consider_jump_landing_space(v: Vector2) -> Vector2:
var jump_distance = calculate_jump_distance(v) var jump_distance = calculate_jump_distance(v)
var jump_height = calculate_jump_height(v) var jump_height = calculate_jump_height(v)
var collider = check_feeler(Vector2(jump_distance * get_facing_direction(), - jump_height/2)) var collider = check_feeler(Vector2(jump_distance * get_facing_direction(), -jump_height / 2))
# TODO Unpacked loop, make function or something? # TODO Unpacked loop, make function or something?
# Shortens the jump in steps to make it more safe # Shortens the jump in steps to make it more safe
if(!is_jump_path_safe(v, global_position) || collider != null): if !is_jump_path_safe(v, global_position) || collider != null:
jump_distance = calculate_jump_distance(v) - block_size/1.5 jump_distance = calculate_jump_distance(v) - block_size / 1.5
v = change_jump_distance(jump_distance, v) v = change_jump_distance(jump_distance, v)
jump_height = calculate_jump_height(v) jump_height = calculate_jump_height(v)
v = correct_jump_direction(v) v = correct_jump_direction(v)
collider = check_feeler(Vector2(jump_distance * get_facing_direction(), - jump_height/2)) collider = check_feeler(Vector2(jump_distance * get_facing_direction(), -jump_height / 2))
if(!is_jump_path_safe(v, global_position) || collider != null): if !is_jump_path_safe(v, global_position) || collider != null:
jump_distance = calculate_jump_distance(v) - block_size/2.0 jump_distance = calculate_jump_distance(v) - block_size / 2.0
v = change_jump_distance(jump_distance, v) v = change_jump_distance(jump_distance, v)
jump_height = calculate_jump_height(v) jump_height = calculate_jump_height(v)
v = correct_jump_direction(v) v = correct_jump_direction(v)
collider = check_feeler(Vector2(jump_distance * get_facing_direction(), - jump_height/2)) collider = check_feeler(Vector2(jump_distance * get_facing_direction(), -jump_height / 2))
if((!is_jump_path_safe(v, global_position) || collider != null) && can_reverse_facing_direction()): if (
# Can be printed when frog would jump into a wall too (!is_jump_path_safe(v, global_position) || collider != null)
print("at wall or no safe landing spot") && can_reverse_facing_direction()
return Vector2(0,0) ):
return v # Can be printed when frog would jump into a wall too
print("at wall or no safe landing spot")
return Vector2(0, 0)
return v
func consider_jumping_on_top() -> Vector2: func consider_jumping_on_top() -> Vector2:
var collider = check_feeler(Vector2(42 * get_facing_direction(),0)) var collider = check_feeler(Vector2(42 * get_facing_direction(), 0))
# 0 just for tile coordinate calculation # 0 just for tile coordinate calculation
var facing = 0 if get_facing_direction() >= 0 else - 1 var facing = 0 if get_facing_direction() >= 0 else -1
if (collider == null): if collider == null:
return Vector2(0,0) return Vector2(0, 0)
var local_position = tilemap.to_local(feeler_raycast.get_collision_point()) var local_position = tilemap.to_local(feeler_raycast.get_collision_point())
var map_position = tilemap.world_to_map(local_position) var map_position = tilemap.world_to_map(local_position)
var tile_position = Vector2(map_position.x + facing, map_position.y - 1) var tile_position = Vector2(map_position.x + facing, map_position.y - 1)
# TODO Here the climb height of frog is limited to one constantly # TODO Here the climb height of frog is limited to one constantly
var cell_id = tilemap.get_cell(tile_position.x, tile_position.y - 1) var cell_id = tilemap.get_cell(tile_position.x, tile_position.y - 1)
if (cell_id != -1 && if (
#TODO 0 is the navigation tile, but thats subject to change! cell_id != -1
cell_id != 7): #TODO 0 is the navigation tile, but thats subject to change!
return Vector2(0,0) && cell_id != 7
var tile_upper_left_corner = tilemap.to_global(tilemap.map_to_world(tile_position)) ):
var tile_upper_right_corner = Vector2(tile_upper_left_corner.x + tilemap.cell_size.x, tile_upper_left_corner.y) return Vector2(0, 0)
var tile_upper_left_corner = tilemap.to_global(tilemap.map_to_world(tile_position))
var jump_angle = 0 var tile_upper_right_corner = Vector2(
if(facing < 0): tile_upper_left_corner.x + tilemap.cell_size.x, tile_upper_left_corner.y
var frog_bottom_left_corner = Vector2($EnemyBody.global_position.x - $EnemyBody.shape.extents.x, )
$EnemyBody.global_position.y + $EnemyBody.shape.extents.y)
jump_angle = frog_bottom_left_corner.angle_to_point(tile_upper_right_corner) var jump_angle = 0
else: if facing < 0:
var frog_bottom_right_corner = Vector2($EnemyBody.global_position.x + $EnemyBody.shape.extents.x, var frog_bottom_left_corner = Vector2(
$EnemyBody.global_position.y + $EnemyBody.shape.extents.y) $EnemyBody.global_position.x - $EnemyBody.shape.extents.x,
jump_angle = frog_bottom_right_corner.angle_to_point(tile_upper_left_corner) - PI $EnemyBody.global_position.y + $EnemyBody.shape.extents.y
)
if(abs(rad2deg(jump_angle)) < 78): jump_angle = frog_bottom_left_corner.angle_to_point(tile_upper_right_corner)
return correct_jump_direction(velocity_for_jump_distance(default_jump_distance/2, abs(deg2rad(80)))) else:
else: var frog_bottom_right_corner = Vector2(
var v = velocity_for_jump_distance(block_size/1.5, abs(deg2rad(45))) $EnemyBody.global_position.x + $EnemyBody.shape.extents.x,
return Vector2(v.x * -1 * get_facing_direction(), v.y) $EnemyBody.global_position.y + $EnemyBody.shape.extents.y
)
jump_angle = frog_bottom_right_corner.angle_to_point(tile_upper_left_corner) - PI
if abs(rad2deg(jump_angle)) < 78:
return correct_jump_direction(
velocity_for_jump_distance(default_jump_distance / 2, abs(deg2rad(80)))
)
else:
var v = velocity_for_jump_distance(block_size / 1.5, abs(deg2rad(45)))
return Vector2(v.x * -1 * get_facing_direction(), v.y)
# Tries to shorten the jump, so that it lands in a tiles center # Tries to shorten the jump, so that it lands in a tiles center
func jump_to_tile_center(v: Vector2) -> Vector2: func jump_to_tile_center(v: Vector2) -> Vector2:
var distance = stepify(calculate_jump_distance(v), 0.01) var distance = stepify(calculate_jump_distance(v), 0.01)
if !is_equal_approx(fmod(abs(global_position.x + distance * get_facing_direction()), block_size), (block_size/2.0)): if !is_equal_approx(
# print(distance) fmod(abs(global_position.x + distance * get_facing_direction()), block_size),
# print(global_position.x + distance) block_size / 2.0
# print(fmod((global_position.x + distance), block_size)) ):
var new_distance = distance # print(distance)
if(get_facing_direction() < 0): # print(global_position.x + distance)
new_distance = fmod((global_position.x + distance), block_size) - (block_size/2.0) + distance # print(fmod((global_position.x + distance), block_size))
else: var new_distance = distance
new_distance = distance + block_size/2.0 - fmod((global_position.x + distance), block_size) if get_facing_direction() < 0:
# print("centering distance") new_distance = (
# print(new_distance) fmod(global_position.x + distance, block_size)
v = change_jump_distance(abs(new_distance), v) - (block_size / 2.0)
v = correct_jump_direction(v) + distance
return v )
else:
new_distance = (
distance
+ block_size / 2.0
- fmod(global_position.x + distance, block_size)
)
# print("centering distance")
# print(new_distance)
v = change_jump_distance(abs(new_distance), v)
v = correct_jump_direction(v)
return v
# TODO Depends on Frog Shape and Tile Shape # TODO Depends on Frog Shape and Tile Shape
func is_jump_path_safe(v: Vector2, pos: Vector2) -> bool: func is_jump_path_safe(v: Vector2, pos: Vector2) -> bool:
var v0 = v.length() var v0 = v.length()
var angle = v.angle() var angle = v.angle()
var jump_distance = calculate_jump_distance(v) var jump_distance = calculate_jump_distance(v)
var harmful_nodes = get_tree().get_nodes_in_group("harmful") var harmful_nodes = get_tree().get_nodes_in_group("harmful")
harmful_nodes.append_array(get_tree().get_nodes_in_group("pit")) harmful_nodes.append_array(get_tree().get_nodes_in_group("pit"))
for node in harmful_nodes: for node in harmful_nodes:
var node_pos = node.global_position var node_pos = node.global_position
# TODO Ignores spikes more than 4 blocks below and 3 jumps away # TODO Ignores spikes more than 4 blocks below and 3 jumps away
# Also when its too near to one # Also when its too near to one
if (abs(node_pos.x - pos.x) > abs(jump_distance) * 3 if (
||abs(node_pos.y - pos.y) > block_size * 4 abs(node_pos.x - pos.x) > abs(jump_distance) * 3
|| abs(node_pos.x - pos.x) < 1): || abs(node_pos.y - pos.y) > block_size * 4
continue || abs(node_pos.x - pos.x) < 1
var node_y = node_pos.y - block_size/2.0 ):
var initial_throw_height = node_y - (global_position.y + 9) continue
var term1 = (pow(v0, 2) * sin(2 * angle)) / (2 * _gravity) var node_y = node_pos.y - block_size / 2.0
var term2 = ((v0 * cos(angle))/_gravity) * sqrt(pow(v0, 2) * pow(sin(angle), 2) + 2 * _gravity * initial_throw_height) var initial_throw_height = node_y - (global_position.y + 9)
var distance = abs(term1) + abs(term2) var term1 = (pow(v0, 2) * sin(2 * angle)) / (2 * _gravity)
# print("distance to next spike") var term2 = (
# print(pos.x + sign(v.x) * distance - node_pos.x) ((v0 * cos(angle)) / _gravity)
var safe_distance = block_size/2.0 * sqrt(pow(v0, 2) * pow(sin(angle), 2) + 2 * _gravity * initial_throw_height)
if (sign(initial_throw_height) < 0): )
safe_distance = block_size var distance = abs(term1) + abs(term2)
if(abs(pos.x + sign(v.x) * distance - node_pos.x) < safe_distance): # print("distance to next spike")
return false # print(pos.x + sign(v.x) * distance - node_pos.x)
return true var safe_distance = block_size / 2.0
if sign(initial_throw_height) < 0:
safe_distance = block_size
if abs(pos.x + sign(v.x) * distance - node_pos.x) < safe_distance:
return false
return true
func calculate_jump_height(v: Vector2) -> float: func calculate_jump_height(v: Vector2) -> float:
return abs((pow(v.length(), 2) * pow(sin(v.angle()), 2))/(2*_gravity)) return abs((pow(v.length(), 2) * pow(sin(v.angle()), 2)) / (2 * _gravity))
# Only works for jumps on straight ground # Only works for jumps on straight ground
func calculate_jump_distance(v: Vector2) -> float: func calculate_jump_distance(v: Vector2) -> float:
return abs((pow(v.length(), 2) * sin(-1 * 2 * v.angle()))/(_gravity)) return abs((pow(v.length(), 2) * sin(-1 * 2 * v.angle())) / (_gravity))
func jump_height_to_velocity(target_height: float, v: Vector2) -> Vector2: func jump_height_to_velocity(target_height: float, v: Vector2) -> Vector2:
var initial_height = calculate_jump_height(v) var initial_height = calculate_jump_height(v)
return v.normalized() * sqrt(pow(v.length(),2)/(initial_height/target_height)) return v.normalized() * sqrt(pow(v.length(), 2) / (initial_height / target_height))
# Changes a Vector for a jump to the targeted distance, keeping the angle # Changes a Vector for a jump to the targeted distance, keeping the angle
func change_jump_distance(target_distance: float, v: Vector2) -> Vector2: func change_jump_distance(target_distance: float, v: Vector2) -> Vector2:
var initial_distance = calculate_jump_distance(v) var initial_distance = calculate_jump_distance(v)
return v.normalized() * sqrt(pow(v.length(),2)/(initial_distance/target_distance)) return v.normalized() * sqrt(pow(v.length(), 2) / (initial_distance / target_distance))
# Takes an angle and a distance to calculate a jump launching at that angle and covering the distance # Takes an angle and a distance to calculate a jump launching at that angle and covering the distance
func velocity_for_jump_distance(distance: float = default_jump_distance*block_size, angle: float = deg2rad(default_jump_angle)) -> Vector2: func velocity_for_jump_distance(
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle)) distance: float = default_jump_distance * block_size, angle: float = deg2rad(default_jump_angle)
return Vector2(abs_velocity,0).rotated(-1*angle) ) -> Vector2:
var abs_velocity = sqrt((distance * _gravity) / sin(2 * angle))
return Vector2(abs_velocity, 0).rotated(-1 * angle)
func can_reverse_facing_direction() -> bool: func can_reverse_facing_direction() -> bool:
if(is_on_floor() && !has_reversed): if is_on_floor() && !has_reversed:
return true return true
return false return false
# Returns a jump velocity that has the target_position in it's path # Returns a jump velocity that has the target_position in it's path
func attack_jump(target_position: Vector2) -> Vector2: func attack_jump(target_position: Vector2) -> Vector2:
var target_vector = target_position - global_position var target_vector = target_position - global_position
target_vector = Vector2(abs(target_vector.x), target_vector.y) target_vector = Vector2(abs(target_vector.x), target_vector.y)
var jump_angle = target_vector.angle() var jump_angle = target_vector.angle()
var v = Vector2() var v = Vector2()
# TODO Tunable parameters # TODO Tunable parameters
if jump_angle < deg2rad(-30): if jump_angle < deg2rad(-30):
v = velocity_for_jump_distance(target_vector.x, deg2rad(default_jump_angle)) v = velocity_for_jump_distance(target_vector.x, deg2rad(default_jump_angle))
v = jump_height_to_velocity(abs(target_vector.y), v) v = jump_height_to_velocity(abs(target_vector.y), v)
else: else:
v = velocity_for_jump_distance(target_vector.x * 1.5,deg2rad(45)) v = velocity_for_jump_distance(target_vector.x * 1.5, deg2rad(45))
v = correct_jump_direction(v) v = correct_jump_direction(v)
return v return v
# Checks the feeler ray for collisions and returns collider or null # Checks the feeler ray for collisions and returns collider or null
func check_feeler(v: Vector2, _offset = Vector2(0,0)) -> Object: func check_feeler(v: Vector2, _offset = Vector2(0, 0)) -> Object:
var prev_position = feeler_raycast.position var prev_position = feeler_raycast.position
feeler_raycast.position += _offset feeler_raycast.position += _offset
feeler_raycast.cast_to = v feeler_raycast.cast_to = v
feeler_raycast.force_raycast_update() feeler_raycast.force_raycast_update()
var collider = feeler_raycast.get_collider() var collider = feeler_raycast.get_collider()
feeler_raycast.position = prev_position feeler_raycast.position = prev_position
return collider return collider
func reverse_facing_direction() -> void: func reverse_facing_direction() -> void:
has_reversed = true has_reversed = true
# print("reversing direction") # print("reversing direction")
orientation.cast_to.x *= -1 orientation.cast_to.x *= -1
func get_facing_direction() -> float: func get_facing_direction() -> float:
return orientation.cast_to.x return orientation.cast_to.x
func _on_HurtTimer_timeout() -> void: func _on_HurtTimer_timeout() -> void:
is_hurt = false is_hurt = false
#if(is_bound): add_to_group("harmful") #if(is_bound): add_to_group("harmful")
$FrogSprite.material = null $FrogSprite.material = null

View File

@ -212,6 +212,9 @@ unique_name_in_owner = true
position = Vector2( -70, 1 ) position = Vector2( -70, 1 )
scale = Vector2( 0.878906, 0.936025 ) scale = Vector2( 0.878906, 0.936025 )
[node name="BlobbySprite" parent="Blobby" index="5"]
frame = 8
[node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"] [node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"]
parameters/playback = SubResource( 14 ) parameters/playback = SubResource( 14 )
parameters/jumpStretching/blend_position = 1 parameters/jumpStretching/blend_position = 1

View File

@ -1040,7 +1040,7 @@ position = Vector2( -156, -51 )
scale = Vector2( 0.878906, 0.936025 ) scale = Vector2( 0.878906, 0.936025 )
[node name="BlobbySprite" parent="Blobby" index="5"] [node name="BlobbySprite" parent="Blobby" index="5"]
frame = 6 frame = 5
[node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"] [node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"]
parameters/playback = SubResource( 6 ) parameters/playback = SubResource( 6 )

View File

@ -44,17 +44,14 @@ wait_time = 20.0
[node name="BlobbyCam" parent="." instance=ExtResource( 9 )] [node name="BlobbyCam" parent="." instance=ExtResource( 9 )]
unique_name_in_owner = true unique_name_in_owner = true
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 13
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 3
[node name="Blobby" parent="." instance=ExtResource( 15 )] [node name="Blobby" parent="." instance=ExtResource( 15 )]
unique_name_in_owner = true unique_name_in_owner = true
position = Vector2( 251, -24 ) position = Vector2( 251, -24 )
scale = Vector2( 0.878906, 0.936025 ) scale = Vector2( 0.878906, 0.936025 )
[node name="BlobbySprite" parent="Blobby" index="5"]
frame = 6
[node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"] [node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"]
parameters/playback = SubResource( 1 ) parameters/playback = SubResource( 1 )

View File

@ -5,8 +5,8 @@ onready var signal_manager := $"%SignalManager"
onready var level_state := $"%LevelState" onready var level_state := $"%LevelState"
func _ready() -> void: func _ready() -> void:
# should spawn the tutorial thingies which are still remembered in the progress dictionary # should spawn the tutorial thingies which are still remembered in the progress dictionary
signal_manager.emit_signal("level_loaded") signal_manager.emit_signal("level_loaded")
get_tree().paused = false get_tree().paused = false

View File

@ -41,12 +41,12 @@ resource_name = "LowPassFilter"
cutoff_hz = 3000.0 cutoff_hz = 3000.0
[resource] [resource]
bus/0/volume_db = -6.0206 bus/0/volume_db = -10.4576
bus/1/name = "Music" bus/1/name = "Music"
bus/1/solo = false bus/1/solo = false
bus/1/mute = false bus/1/mute = false
bus/1/bypass_fx = false bus/1/bypass_fx = false
bus/1/volume_db = -20.0 bus/1/volume_db = -6.0206
bus/1/send = "Master" bus/1/send = "Master"
bus/1/effect/0/effect = SubResource( 1 ) bus/1/effect/0/effect = SubResource( 1 )
bus/1/effect/0/enabled = false bus/1/effect/0/enabled = false
@ -68,7 +68,7 @@ bus/3/name = "UI"
bus/3/solo = false bus/3/solo = false
bus/3/mute = false bus/3/mute = false
bus/3/bypass_fx = false bus/3/bypass_fx = false
bus/3/volume_db = -4.43698 bus/3/volume_db = -6.0206
bus/3/send = "Master" bus/3/send = "Master"
bus/3/effect/0/effect = SubResource( 6 ) bus/3/effect/0/effect = SubResource( 6 )
bus/3/effect/0/enabled = true bus/3/effect/0/enabled = true

View File

@ -165,6 +165,9 @@ func _get_transition(_delta):
) )
anim_tree.set("parameters/wallsliding/blend_position", parent.wall_touch_direction) anim_tree.set("parameters/wallsliding/blend_position", parent.wall_touch_direction)
new_state = states.wallslide new_state = states.wallslide
# TODO Wallslide has to stick because the animation disconnects the wall raycasts
if self.state == states.wallslide && state_time < 0.2:
new_state = states.wallslide
# Begins coyote time only if walking from ledge # Begins coyote time only if walking from ledge
elif [states.walk, states.run].has(self.state) && !was_coyote_hanging: elif [states.walk, states.run].has(self.state) && !was_coyote_hanging:
$CoyoteTimer.start() $CoyoteTimer.start()
@ -180,6 +183,7 @@ func _get_transition(_delta):
if coyote_hanging: if coyote_hanging:
new_state = self.state new_state = self.state
elif abs(parent.velocity.x) > 5: elif abs(parent.velocity.x) > 5:
was_coyote_hanging = false was_coyote_hanging = false
if Input.is_action_pressed("boost_move"): if Input.is_action_pressed("boost_move"):
@ -263,7 +267,7 @@ func _exit_state(old_state, new_state):
running_particles.emitting = false running_particles.emitting = false
if old_state == "fall" && new_state != "wallslide": if old_state == "fall" && new_state != "wallslide":
scene_audio.play_parallel_sound(landing_sound_1, 0.0, true, 1.0, 0.1) scene_audio.play_parallel_sound(landing_sound_1, 0.0, true, 1.0, 0.1)
elif old_state == "fall" && new_state == "wallslide": elif new_state == "wallslide":
scene_audio.play_parallel_sound(landing_sound_2, -15.0, true, 1.0, 0.1) scene_audio.play_parallel_sound(landing_sound_2, -15.0, true, 1.0, 0.1)