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
# newtonmeters is the unit
var acceleration_force := {
"walk": Vector2(1800, 1385),
"walk": Vector2(1800, 1300),
"fall": Vector2(1800, 1050),
"jump": Vector2(1800, 0),
"idle": Vector2(1800, 1233),
"duck": Vector2(500, 1300),
"duck_walk": Vector2(500, 1300),
"run": Vector2(2500, 1490),
"run": Vector2(2500, 1400),
"walljump": Vector2(600, 1050),
"air_strafe": Vector2(333, 2000)
}

View File

@ -100,7 +100,7 @@ func calculate_duck_velocity(linear_velocity: Vector2, delta: float, direction:
if Input.is_action_just_pressed("jump") && is_on_dropThrough():
return Vector2(out_vel.x, _gravity * delta)
# 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
return calculate_jump_velocity(velocity, delta, direction)
@ -167,7 +167,7 @@ func calculate_grounded_velocity(
elif !reverse_move:
out_vel.x = max_velocity[state] * direction.x
# 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
return calculate_jump_velocity(velocity, delta, direction)
@ -229,20 +229,27 @@ func calculate_deceleration_force(_gravity: float, mass: float) -> float:
return floor_friction * _gravity * mass
func calculate_jump_velocity(linear_velocity: Vector2, delta: float, direction: Vector2) -> Vector2:
var state = player_state_machine.state
var additive_jump_force = velocity_jump_boost_ratio * abs(velocity.x) * mass
#TODO Single out stomping and make betta
#TODO too much force intially and too high with frog jump
if stomping:
func calculate_stomp_velocity(delta: float) -> float:
var v = 0
if Input.is_action_pressed("jump"):
additive_jump_force += stomp_feedback
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:
var state = player_state_machine.state
var additive_jump_force = velocity_jump_boost_ratio * abs(velocity.x) * mass
#TODO Single out stomping and make betta
#TODO too much force intially and too high with frog jump
if stomping:
additive_jump_force += calculate_stomp_velocity(delta)
if state != "jump":
linear_velocity.y = PhysicsFunc.two_step_euler(
@ -406,6 +413,11 @@ func calculate_slope_rotation(_onfloor: bool) -> float:
# TODO could be expanded with a parameter about what got stomped
func stomp() -> void:
# print("stomping")
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

View File

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

View File

@ -5,7 +5,7 @@ export var offset_reset_seconds := 1
export var offset_adapt_seconds := 1
export var offset_input_seconds := 0.618 * 2
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 signal_manager := $"%SignalManager"
@ -29,7 +29,7 @@ var original_limit_right: int
var original_limit_bottom: int
var original_limit_top: int
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 image = Image.new()
@ -38,13 +38,17 @@ var prev_pos: Vector2
var camera_state := "centered"
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_bottom = Vector2()
var screen_top = Vector2()
var screen_left = Vector2()
var screen_right = Vector2()
# Gets the camera limits from the tilemap of the level
# Requires "TileMap" to be a sibling of blobby
func _ready():
@ -60,36 +64,41 @@ func _ready():
signal_manager.connect("terminal_activated", self, "_on_SignalManager_terminal_activated")
signal_manager.connect("player_died", self, "_death_cam")
func _on_SignalManager_terminal_activated(animation_number: int = 0):
terminal_activated = true
get_node("LightAnimationPlayer").play("Pulsing")
#func _draw():
# draw_line(Vector2((limit_left - position.x), screen_center.y), screen_left, Color(255, 0, 0), 1)
func _physics_process(delta: float) -> void:
if fixed_position:
return
# update()
screen_center = (get_camera_screen_center() - position)
screen_bottom = 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_right = screen_center + Vector2(screen_rect.x/2, 0)
screen_bottom = 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_right = screen_center + Vector2(screen_rect.x / 2, 0)
var was_adjusted := false
if(!level_state.is_dead):
if !level_state.is_dead:
was_adjusted = _adjust_offset(delta)
if(anim_player.is_playing() || was_adjusted):
if anim_player.is_playing() || was_adjusted:
position = blobby.position
prev_pos = position
_update_lighting_shader()
return
var player_vel = (blobby.position - prev_pos)/delta
var player_vel = (blobby.position - prev_pos) / delta
# TODO Take average of velocity here
if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.97
&& (sign(player_vel.x) == sign(target_offset.x) || target_offset.x == 0)):
if(player_vel.x > 0):
if (
abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.97
&& (sign(player_vel.x) == sign(target_offset.x) || target_offset.x == 0)
):
if player_vel.x > 0:
right_move_time += delta
left_move_time = max(0, left_move_time - delta)
slow_time = max(0, slow_time - delta)
@ -97,8 +106,11 @@ func _physics_process(delta: float) -> void:
left_move_time += delta
right_move_time = max(0, right_move_time - delta)
slow_time = max(0, slow_time - delta)
elif(abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9
|| sign(player_vel.x) != sign(target_offset.x) || target_offset.x == 0):
elif (
abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9
|| 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)
@ -110,6 +122,7 @@ func _physics_process(delta: float) -> void:
prev_pos = position
_update_lighting_shader()
# TODO This has to be redone when the screen is resized in any way
# Otherwise the boundaries will not be correct anymore
func _set_boundaries():
@ -145,39 +158,42 @@ func _set_boundaries():
zoom.y = v_pixels / screen_size.end.y
zoom.x = zoom.y
# Smoothing the camera limits in godot ruins something
func _adapt_to_movement(velocity: Vector2) -> void:
var offset_track
var center = get_camera_screen_center()
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
if(left_move_time >= offset_adapt_seconds && !anim_player.is_playing()):
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
if left_move_time >= offset_adapt_seconds && !anim_player.is_playing():
left_move_time = 0
target_offset.x = -camera_horizontal_shift
if(offset == target_offset):
if offset == target_offset:
return
offset_track = shiftLeft.find_track(".:offset")
shiftLeft.track_set_key_value(offset_track, 0, offset)
shiftLeft.track_set_key_value(offset_track, 1, target_offset)
camera_state = "shiftedLeft"
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
target_offset.x = camera_horizontal_shift
if(offset == target_offset):
if offset == target_offset:
return
offset_track = shiftRight.find_track(".:offset")
shiftRight.track_set_key_value(offset_track, 0, offset)
shiftRight.track_set_key_value(offset_track, 1, target_offset)
camera_state = "shiftedRight"
anim_player.play("shiftingRight")
elif(slow_time >= offset_reset_seconds &&
!(Input.is_action_pressed("up") || Input.is_action_pressed("duck"))):
elif (
slow_time >= offset_reset_seconds
&& !(Input.is_action_pressed("up") || Input.is_action_pressed("duck"))
):
slow_time = 0
target_offset.x = 0
if(offset == target_offset):
if offset == target_offset:
return
if(left_edge_pos > limit_left && limit_right > right_edge_pos):
if left_edge_pos > limit_left && limit_right > right_edge_pos:
offset_track = shiftCenter.find_track(".:offset")
shiftCenter.track_set_key_value(offset_track, 0, offset)
shiftCenter.track_set_key_value(offset_track, 1, target_offset)
@ -185,40 +201,42 @@ func _adapt_to_movement(velocity: Vector2) -> void:
anim_player.play("shiftingCenter")
return
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
# lasse ich erstmal drin
if(velocity.length() > 20.0):
if velocity.length() > 20.0:
input_time = 0
return
if(input_time < offset_input_seconds):
if input_time < offset_input_seconds:
input_time += delta
return
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
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
# TODO This is a regulatory problem, it doesn't adapt fast enough
# TODO Maybe just make background black and dont bother
func _adjust_offset(delta: float) -> bool:
var new_offset = offset
if (limit_left - position.x - screen_left.x > 0.1):
if (anim_player.is_playing()):
if limit_left - position.x - screen_left.x > 0.1:
if anim_player.is_playing():
anim_player.stop(true)
new_offset.x += (limit_left - position.x - screen_left.x)/1.5
if (limit_right - position.x - screen_right.x < 0.1):
if (anim_player.is_playing()):
new_offset.x += (limit_left - position.x - screen_left.x) / 1.5
if limit_right - position.x - screen_right.x < 0.1:
if anim_player.is_playing():
anim_player.stop(true)
new_offset.x += (limit_right - position.x - screen_right.x)/1.5
if (limit_top - position.y - screen_top.y > 0.001):
new_offset.y += (limit_top - position.y - screen_top.y)/1.5
if (limit_bottom - position.y - screen_bottom.y < 0.001):
new_offset.y += (limit_bottom - position.y - screen_bottom.y)/1.5
new_offset.x += (limit_right - position.x - screen_right.x) / 1.5
if limit_top - position.y - screen_top.y > 0.001:
new_offset.y += (limit_top - position.y - screen_top.y) / 1.5
if limit_bottom - position.y - screen_bottom.y < 0.001:
new_offset.y += (limit_bottom - position.y - screen_bottom.y) / 1.5
#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
return true
else:
@ -231,15 +249,18 @@ func reset_limits() -> void:
limit_bottom = original_limit_bottom
limit_top = original_limit_top
func _death_cam(animation_number: int = 0) -> void:
if(animation_number < 1):
if animation_number < 1:
$CameraAnimationPlayer.play("deathCamJustZoom")
if(animation_number == 1):
if animation_number == 1:
$CameraAnimationPlayer.play("deathCamLateRotation")
# TODO Rename to alarm lights specially
func _update_lighting_shader() -> void:
if !terminal_activated: return
if !terminal_activated:
return
# Props to gameendaevour
# TODO get this into a central world update management system
var lights = get_tree().get_nodes_in_group("light")
@ -254,10 +275,9 @@ func _update_lighting_shader() -> void:
# var top_left = -vtrans.origin / vtrans.get_scale()
# var vsize = get_viewport_rect().size
# var t = Transform2D(0, (top_left + 0.5*vsize/vtrans.get_scale()).rotated(rotation))
image.set_pixel(i, 0, Color(
light.position.x, light.position.y,
light.strength, light.radius
))
image.set_pixel(
i, 0, Color(light.position.x, light.position.y, light.strength, light.radius)
)
image.set_pixel(i, 1, light.color)
image.unlock()

View File

@ -9,15 +9,22 @@ export var block_size := 16
var time = 0
var snap = Vector2.DOWN * block_size
func _ready() -> void:
velocity.x = -120
func execute_movement(delta: float) -> void:
# rotation
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()):
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()
):
pass
elif(left_wrc.is_colliding() || (!right_src.is_colliding() && left_src.is_colliding())):
elif left_wrc.is_colliding() || (!right_src.is_colliding() && left_src.is_colliding()):
rotation += delta * 7 * movement
else:
rotation += sign(velocity.x) * delta * 7 * movement
@ -25,4 +32,6 @@ func execute_movement(delta: float) -> void:
# 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)
move_and_slide_with_snap(
v.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI, false
)

View File

@ -3,6 +3,7 @@ class_name Enemy
var player_entered_stomp = false
func _on_StompDetector_body_entered(body: Node) -> void:
if !body.is_in_group("player"):
return
@ -20,14 +21,17 @@ func _on_StompDetector_body_entered(body: Node) -> void:
get_node("EnemyBody").disabled = true
die()
func die() -> void:
queue_free()
func _on_EnemySkin_area_entered(area:Area2D) -> void:
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:
if body.is_in_group("player") && !player_entered_stomp:
body.die()

View File

@ -3,7 +3,6 @@ const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
onready var players = get_tree().get_nodes_in_group("player")
onready var vision_raycast: RayCast2D = $VisionRayCast
onready var orientation: RayCast2D = $Orientation
onready var feeler_raycast: RayCast2D = $FeelerRayCast
@ -28,8 +27,6 @@ export var jump_time_standard_deviation := 0.1
# TODO Make constant for project
export var block_size := 16
# Also in blocks
var movement_radius: float
var anchor: Node2D
@ -66,7 +63,7 @@ func _ready():
add_child(jump_timer)
add_child(target_lost_timer)
# TODO this is so bad ;_;
if(get_parent().name.begins_with("Bound")):
if get_parent().name.begins_with("Bound"):
is_bound = true
else:
level_state.free_a_frog(frog_number)
@ -75,7 +72,7 @@ func _ready():
#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
movement_radius = radius * block_size
is_bound = true
@ -92,25 +89,25 @@ func execute_movement(delta: float) -> void:
# Achievment maybe lul
detect_timer += delta
velocity.y += _gravity * delta
if(is_bound):
if is_bound:
var next_position = global_position + velocity * current_delta
var current_distance = global_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
# 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.y = velocity.y * 0.8
was_restricted = true
velocity = move_and_slide(velocity, FLOOR_NORMAL, false, 4, 0.785398, false)
if($"%GroundDetector".get_overlapping_bodies().size() > 0):
velocity.y -= 10 * (delta/0.0083)
var min_x_slide_velocity = 50 * (delta/0.0083)
if $"%GroundDetector".get_overlapping_bodies().size() > 0:
velocity.y -= 10 * (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)
return
elif(is_on_floor()):
velocity = Vector2(0,0)
elif is_on_floor():
velocity = Vector2(0, 0)
# Reverse direction when hitting limit
@ -119,7 +116,7 @@ func die() -> void:
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"):
get_node("EnemyBody").disabled = true
die()
@ -152,6 +149,7 @@ func _on_StompDetector_body_entered(body: Node) -> void:
$FrogSprite.material = invincible_shader
$HurtTimer.start()
func _on_StompDetector_body_exited(body: Node) -> void:
if attached_player == body:
$FeelerRayCast.collision_mask += 1
@ -159,16 +157,16 @@ func _on_StompDetector_body_exited(body: Node) -> void:
func searching() -> Vector2:
if(detect_timer > 0.333):
if detect_timer > 0.333:
search_next_target()
detect_timer = 0.0
if(is_on_floor()):
if(jump_timer.is_stopped()):
if is_on_floor():
if jump_timer.is_stopped():
jump_timer.start(rng.randfn(jump_time_search, jump_time_standard_deviation))
if(in_air):
if in_air:
in_air = false
else:
if(!in_air):
if !in_air:
start_x = global_position.x
reversing_possible_searching = true
jump_timer.stop()
@ -177,46 +175,55 @@ func searching() -> Vector2:
func search_next_target():
if(target != null && !weakref(target).get_ref()):
if target != null && !weakref(target).get_ref():
return
detect_food()
if(food_target == null && is_bound):
if food_target == null && is_bound:
detect_player()
func hunting() -> Vector2:
var was_target_freed = !weakref(target).get_ref()
if(detect_timer > 0.333):
if detect_timer > 0.333:
search_next_target()
detect_timer = 0.0
#TODO Dependent on block size
elif(is_on_floor() && food_target != null && !was_target_freed &&
global_position.distance_to(food_target.global_position) <= attack_jump_range * block_size):
elif (
is_on_floor()
&& food_target != null
&& !was_target_freed
&& (
global_position.distance_to(food_target.global_position)
<= attack_jump_range * block_size
)
):
var collider = check_feeler(food_target.global_position - global_position)
if(!was_restricted && collider != null && collider.is_in_group("frogfood")):
if !was_restricted && collider != null && collider.is_in_group("frogfood"):
jump_timer.stop()
return attack_jump(food_target.global_position)
if(is_on_floor()):
if(jump_timer.is_stopped()):
if is_on_floor():
if jump_timer.is_stopped():
jump_timer.start(rng.randfn(jump_time_hunt, jump_time_standard_deviation))
if(in_air):
if in_air:
in_air = false
else:
if(!in_air):
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 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()):
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()
@ -227,8 +234,10 @@ func hunting() -> Vector2:
func detect_food() -> void:
# TODO What if food spawns in
food_sources = get_tree().get_nodes_in_group("frogfood")
if(food_sources.empty()):
if food_sources.empty():
return
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
var i = 0
var min_dist_f_index = 0
var min_dist = (food_sources[0].global_position - global_position).length()
@ -238,35 +247,47 @@ func detect_food() -> void:
min_dist = new_dist if new_dist < min_dist else min_dist
min_dist_f_index = i if new_dist < min_dist else min_dist_f_index
i += 1
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
food_node = food_sources[min_dist_f_index]
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
vision_raycast.cast_to = (food_node.global_position - global_position).normalized() * block_size * vision_distance
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)
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")):
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()):
elif target != null && target_lost_timer.is_stopped():
target_lost_timer.start(loose_target_seconds)
func detect_player() -> void:
var player
if(players.empty()):
if players.empty():
# print("no player found")
return
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
player = players[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
vision_raycast.cast_to = (
(player.global_position - global_position - Vector2(0, 9)).normalized()
* block_size
* vision_distance
)
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/4 && collider != null && collider.is_in_group("player")):
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()):
elif target != null && target_lost_timer.is_stopped():
target_lost_timer.start(loose_target_seconds)
@ -286,43 +307,48 @@ func jump():
# print("jump calculation initiated")
# Can only reverse once per jump calculation
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))
v = correct_jump_direction(v)
if(is_bound):
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"):
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):
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()):
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()):
elif get_facing_direction() < 0 && $Left_Wallcast.is_colliding():
v = zero_vector
elif (get_facing_direction() > 0 && $Right_Wallcast.is_colliding()):
elif get_facing_direction() > 0 && $Right_Wallcast.is_colliding():
v = zero_vector
v = correct_jump_direction(v)
if(v != zero_vector):
if v != zero_vector:
v = consider_jump_headspace(v)
if(v != zero_vector):
if v != zero_vector:
v = consider_jump_landing_space(v)
if(v == zero_vector):
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()):
if v == zero_vector && can_reverse_facing_direction():
reverse_facing_direction()
# if attached_player != null && v != zero_vector:
@ -330,10 +356,12 @@ func jump():
velocity = v
#func move_with_player(v: Vector2):
# print(v)
# attached_player.move_and_slide(v * 10)
func correct_jump_direction(v: Vector2) -> Vector2:
if sign(v.x) != get_facing_direction():
v.x *= -1
@ -347,14 +375,16 @@ func correct_jump_direction(v: Vector2) -> Vector2:
func consider_jump_headspace(v: Vector2, recursive_check_count = 0, max_checks = 2) -> Vector2:
if recursive_check_count >= max_checks:
print("Frog has no safe headspace")
return Vector2(0,0)
return Vector2(0, 0)
var height = calculate_jump_height(v)
var distance = calculate_jump_distance(v)
var angle = (v * get_facing_direction()).angle()
# Half distance is an estimate of the jumps apex()
#TODO Consider sprite size for height
var height_collider = check_feeler(Vector2(get_facing_direction()*(distance/2), -(height+23)))
if(height_collider != null):
var height_collider = check_feeler(
Vector2(get_facing_direction() * (distance / 2), -(height + 23))
)
if height_collider != null:
var collision_point = feeler_raycast.get_collision_point()
var target_height = collision_point.y - (feeler_raycast.global_position.y - 23)
# print(feeler_raycast.global_position)
@ -364,7 +394,7 @@ func consider_jump_headspace(v: Vector2, recursive_check_count = 0, max_checks =
v = correct_jump_direction(v)
height = calculate_jump_height(v) * -1
distance = calculate_jump_distance(v) * get_facing_direction()
if(height < target_height && can_reverse_facing_direction()):
if height < target_height && can_reverse_facing_direction():
v = consider_jump_headspace(v, recursive_check_count + 1)
return v
@ -375,75 +405,99 @@ func consider_jump_headspace(v: Vector2, recursive_check_count = 0, max_checks =
func consider_jump_landing_space(v: Vector2) -> Vector2:
var jump_distance = calculate_jump_distance(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?
# Shortens the jump in steps to make it more safe
if(!is_jump_path_safe(v, global_position) || collider != null):
jump_distance = calculate_jump_distance(v) - block_size/1.5
if !is_jump_path_safe(v, global_position) || collider != null:
jump_distance = calculate_jump_distance(v) - block_size / 1.5
v = change_jump_distance(jump_distance, v)
jump_height = calculate_jump_height(v)
v = correct_jump_direction(v)
collider = check_feeler(Vector2(jump_distance * get_facing_direction(), - jump_height/2))
if(!is_jump_path_safe(v, global_position) || collider != null):
jump_distance = calculate_jump_distance(v) - block_size/2.0
collider = check_feeler(Vector2(jump_distance * get_facing_direction(), -jump_height / 2))
if !is_jump_path_safe(v, global_position) || collider != null:
jump_distance = calculate_jump_distance(v) - block_size / 2.0
v = change_jump_distance(jump_distance, v)
jump_height = calculate_jump_height(v)
v = correct_jump_direction(v)
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()):
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()
):
# Can be printed when frog would jump into a wall too
print("at wall or no safe landing spot")
return Vector2(0,0)
return Vector2(0, 0)
return v
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
var facing = 0 if get_facing_direction() >= 0 else - 1
if (collider == null):
return Vector2(0,0)
var facing = 0 if get_facing_direction() >= 0 else -1
if collider == null:
return Vector2(0, 0)
var local_position = tilemap.to_local(feeler_raycast.get_collision_point())
var map_position = tilemap.world_to_map(local_position)
var tile_position = Vector2(map_position.x + facing, map_position.y - 1)
# 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)
if (cell_id != -1 &&
if (
cell_id != -1
#TODO 0 is the navigation tile, but thats subject to change!
cell_id != 7):
return Vector2(0,0)
&& cell_id != 7
):
return Vector2(0, 0)
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)
var tile_upper_right_corner = Vector2(
tile_upper_left_corner.x + tilemap.cell_size.x, tile_upper_left_corner.y
)
var jump_angle = 0
if(facing < 0):
var frog_bottom_left_corner = Vector2($EnemyBody.global_position.x - $EnemyBody.shape.extents.x,
$EnemyBody.global_position.y + $EnemyBody.shape.extents.y)
if facing < 0:
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)
else:
var frog_bottom_right_corner = Vector2($EnemyBody.global_position.x + $EnemyBody.shape.extents.x,
$EnemyBody.global_position.y + $EnemyBody.shape.extents.y)
var frog_bottom_right_corner = Vector2(
$EnemyBody.global_position.x + $EnemyBody.shape.extents.x,
$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))))
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)))
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
func jump_to_tile_center(v: Vector2) -> Vector2:
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(
fmod(abs(global_position.x + distance * get_facing_direction()), block_size),
block_size / 2.0
):
# print(distance)
# print(global_position.x + distance)
# print(fmod((global_position.x + distance), block_size))
var new_distance = distance
if(get_facing_direction() < 0):
new_distance = fmod((global_position.x + distance), block_size) - (block_size/2.0) + distance
if get_facing_direction() < 0:
new_distance = (
fmod(global_position.x + distance, block_size)
- (block_size / 2.0)
+ distance
)
else:
new_distance = distance + block_size/2.0 - fmod((global_position.x + distance), block_size)
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)
@ -462,53 +516,60 @@ func is_jump_path_safe(v: Vector2, pos: Vector2) -> bool:
var node_pos = node.global_position
# TODO Ignores spikes more than 4 blocks below and 3 jumps away
# Also when its too near to one
if (abs(node_pos.x - pos.x) > abs(jump_distance) * 3
||abs(node_pos.y - pos.y) > block_size * 4
|| abs(node_pos.x - pos.x) < 1):
if (
abs(node_pos.x - pos.x) > abs(jump_distance) * 3
|| abs(node_pos.y - pos.y) > block_size * 4
|| abs(node_pos.x - pos.x) < 1
):
continue
var node_y = node_pos.y - block_size/2.0
var node_y = node_pos.y - block_size / 2.0
var initial_throw_height = node_y - (global_position.y + 9)
var term1 = (pow(v0, 2) * sin(2 * angle)) / (2 * _gravity)
var term2 = ((v0 * cos(angle))/_gravity) * sqrt(pow(v0, 2) * pow(sin(angle), 2) + 2 * _gravity * initial_throw_height)
var term2 = (
((v0 * cos(angle)) / _gravity)
* sqrt(pow(v0, 2) * pow(sin(angle), 2) + 2 * _gravity * initial_throw_height)
)
var distance = abs(term1) + abs(term2)
# print("distance to next spike")
# print(pos.x + sign(v.x) * distance - node_pos.x)
var safe_distance = block_size/2.0
if (sign(initial_throw_height) < 0):
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):
if abs(pos.x + sign(v.x) * distance - node_pos.x) < safe_distance:
return false
return true
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
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:
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
func change_jump_distance(target_distance: float, v: Vector2) -> Vector2:
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
func velocity_for_jump_distance(distance: float = default_jump_distance*block_size, angle: float = deg2rad(default_jump_angle)) -> Vector2:
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle))
return Vector2(abs_velocity,0).rotated(-1*angle)
func velocity_for_jump_distance(
distance: float = default_jump_distance * block_size, angle: float = deg2rad(default_jump_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:
if(is_on_floor() && !has_reversed):
if is_on_floor() && !has_reversed:
return true
return false
@ -524,13 +585,13 @@ func attack_jump(target_position: Vector2) -> Vector2:
v = velocity_for_jump_distance(target_vector.x, deg2rad(default_jump_angle))
v = jump_height_to_velocity(abs(target_vector.y), v)
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)
return v
# 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
feeler_raycast.position += _offset
feeler_raycast.cast_to = v
@ -554,6 +615,3 @@ func _on_HurtTimer_timeout() -> void:
is_hurt = false
#if(is_bound): add_to_group("harmful")
$FrogSprite.material = null

View File

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

View File

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

View File

@ -44,17 +44,14 @@ wait_time = 20.0
[node name="BlobbyCam" parent="." instance=ExtResource( 9 )]
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 )]
unique_name_in_owner = true
position = Vector2( 251, -24 )
scale = Vector2( 0.878906, 0.936025 )
[node name="BlobbySprite" parent="Blobby" index="5"]
frame = 6
[node name="BlobbymationTree" parent="Blobby/BlobbySprite" index="0"]
parameters/playback = SubResource( 1 )

View File

@ -41,12 +41,12 @@ resource_name = "LowPassFilter"
cutoff_hz = 3000.0
[resource]
bus/0/volume_db = -6.0206
bus/0/volume_db = -10.4576
bus/1/name = "Music"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = -20.0
bus/1/volume_db = -6.0206
bus/1/send = "Master"
bus/1/effect/0/effect = SubResource( 1 )
bus/1/effect/0/enabled = false
@ -68,7 +68,7 @@ bus/3/name = "UI"
bus/3/solo = false
bus/3/mute = false
bus/3/bypass_fx = false
bus/3/volume_db = -4.43698
bus/3/volume_db = -6.0206
bus/3/send = "Master"
bus/3/effect/0/effect = SubResource( 6 )
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)
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
elif [states.walk, states.run].has(self.state) && !was_coyote_hanging:
$CoyoteTimer.start()
@ -180,6 +183,7 @@ func _get_transition(_delta):
if coyote_hanging:
new_state = self.state
elif abs(parent.velocity.x) > 5:
was_coyote_hanging = false
if Input.is_action_pressed("boost_move"):
@ -263,7 +267,7 @@ func _exit_state(old_state, new_state):
running_particles.emitting = false
if old_state == "fall" && new_state != "wallslide":
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)