make charging framerate-independent
This commit is contained in:
@@ -948,7 +948,7 @@ rotation = 0.785397
|
||||
shape = SubResource("RectangleShape2D_32c8b")
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_bl13t")]
|
||||
position = Vector2(271, -2253)
|
||||
position = Vector2(240, 328)
|
||||
|
||||
[node name="MainCamera" type="Camera2D" parent="."]
|
||||
position = Vector2(240, 180)
|
||||
@@ -970,7 +970,7 @@ _do_collisions = false
|
||||
metadata/_custom_type_script = "uid://ceyu5der8j8gq"
|
||||
|
||||
[node name="Trajectory2" type="Marker2D" parent="Trajectories"]
|
||||
position = Vector2(248, 327)
|
||||
position = Vector2(240, 328)
|
||||
script = ExtResource("4_74lek")
|
||||
flip = true
|
||||
_steps = 48
|
||||
|
||||
@@ -20,7 +20,6 @@ static var instance: Player
|
||||
|
||||
var _direction: float = 0
|
||||
var _is_charging_jump: bool = false
|
||||
var _jump_charge_frames: float = 0
|
||||
var _charge_strength: float = 0
|
||||
var _jump_released: bool = false
|
||||
var _floor_angle: float = 0
|
||||
@@ -62,7 +61,7 @@ static func process_movement(
|
||||
|
||||
# jump charge release
|
||||
if jump_released:
|
||||
new_velocity.y = -jump_force * charge_strength
|
||||
new_velocity.y = -jump_force * minf(charge_strength, 1.0)
|
||||
new_velocity.x = direction * jump_speed
|
||||
|
||||
return new_velocity
|
||||
@@ -182,7 +181,6 @@ func _physics_process(delta: float) -> void:
|
||||
Debugger.text("velocity", new_velocity)
|
||||
Debugger.text("velocity_modified", velocity)
|
||||
Debugger.text("is_charging_jump", _is_charging_jump)
|
||||
Debugger.text("jump_charge_frames", _jump_charge_frames)
|
||||
Debugger.text("charge_strength", _charge_strength)
|
||||
Debugger.text("is_on_ceiling", is_on_ceiling())
|
||||
Debugger.text("is_on_ceiling_only", is_on_ceiling_only())
|
||||
@@ -215,15 +213,11 @@ func _gather_input(delta: float, on_floor: bool) -> void:
|
||||
and is_zero_approx(_floor_angle)
|
||||
):
|
||||
_is_charging_jump = true
|
||||
_jump_charge_frames = 0
|
||||
_charge_strength = 0
|
||||
|
||||
# jump charging
|
||||
if _is_charging_jump:
|
||||
_jump_charge_frames += delta * Engine.physics_ticks_per_second
|
||||
_charge_strength = (
|
||||
minf(_jump_charge_frames, _jump_full_charge_frames)
|
||||
/ _jump_full_charge_frames
|
||||
)
|
||||
_charge_strength += delta / (_jump_full_charge_frames / 60.0)
|
||||
_trajectory.global_position = global_position
|
||||
_trajectory.charge_strength = _charge_strength
|
||||
_trajectory.flip = _direction < 0
|
||||
@@ -234,11 +228,7 @@ func _gather_input(delta: float, on_floor: bool) -> void:
|
||||
_is_charging_jump
|
||||
and on_floor
|
||||
and is_zero_approx(_floor_angle)
|
||||
and (
|
||||
Input.is_action_just_released("jump")
|
||||
or _jump_charge_frames >= _jump_full_charge_frames
|
||||
)
|
||||
and (Input.is_action_just_released("jump") or _charge_strength >= 1.0)
|
||||
)
|
||||
if _jump_released:
|
||||
_is_charging_jump = false
|
||||
_jump_charge_frames = 0
|
||||
|
||||
@@ -169,7 +169,7 @@ func _draw() -> void:
|
||||
_player_shape = RectangleShape2D.new()
|
||||
_player_shape.size = _player_size
|
||||
|
||||
var delta: float = 1.0 / 60.0
|
||||
var delta: float = 1.0 / Engine.physics_ticks_per_second
|
||||
|
||||
var points: PackedVector2Array = []
|
||||
var pos: Vector2 = Vector2.ZERO
|
||||
@@ -274,22 +274,9 @@ func _draw() -> void:
|
||||
if hit_floor or hit_slope:
|
||||
is_on_floor = true
|
||||
_draw_collision_hit(pos, SIDE_BOTTOM, _floor_hit_color)
|
||||
draw_dashed_line(
|
||||
pos + Vector2.LEFT * _player_size.x / 2,
|
||||
pos + Vector2.RIGHT * _player_size.x / 2,
|
||||
_floor_hit_color
|
||||
)
|
||||
if hit_ceiling:
|
||||
draw_rect(
|
||||
Rect2(_get_hitbox_pos(pos), _player_size),
|
||||
Color(_ceiling_hit_color, 0.25)
|
||||
)
|
||||
_draw_collision_hit(pos, SIDE_TOP, _ceiling_hit_color)
|
||||
if hit_wall:
|
||||
draw_rect(
|
||||
Rect2(_get_hitbox_pos(pos), _player_size),
|
||||
Color(_wall_hit_color, 0.25)
|
||||
)
|
||||
_draw_collision_hit(
|
||||
pos,
|
||||
SIDE_LEFT if velocity.x > 0 else SIDE_RIGHT,
|
||||
@@ -360,27 +347,34 @@ func _get_hitbox_pos(pos: Vector2) -> Vector2:
|
||||
|
||||
|
||||
func _draw_collision_hit(pos: Vector2, side: Side, color: Color) -> void:
|
||||
if side == SIDE_BOTTOM:
|
||||
draw_line(pos, pos + Vector2(0, -4), color)
|
||||
draw_line(pos, pos + Vector2(-3, -3), color)
|
||||
draw_line(pos, pos + Vector2(3, -3), color)
|
||||
var angle: float = 0
|
||||
if side == SIDE_TOP:
|
||||
pos.y -= _player_size.y
|
||||
draw_line(pos, pos + Vector2(0, 4), color)
|
||||
draw_line(pos, pos + Vector2(-3, 3), color)
|
||||
draw_line(pos, pos + Vector2(3, 3), color)
|
||||
angle = PI
|
||||
if side == SIDE_LEFT:
|
||||
pos.y -= _player_size.y / 2.0
|
||||
pos.x -= _player_size.x / 2.0
|
||||
draw_line(pos, pos + Vector2(4, 0), color)
|
||||
draw_line(pos, pos + Vector2(3, 3), color)
|
||||
draw_line(pos, pos + Vector2(3, -3), color)
|
||||
angle = PI / 2.0
|
||||
if side == SIDE_RIGHT:
|
||||
pos.y -= _player_size.y / 2.0
|
||||
pos.x += _player_size.x / 2.0
|
||||
draw_line(pos, pos + Vector2(-4, 0), color)
|
||||
draw_line(pos, pos + Vector2(-3, 3), color)
|
||||
draw_line(pos, pos + Vector2(-3, -3), color)
|
||||
angle = -PI / 2.0
|
||||
|
||||
var ray_up := Vector2(0, -4).rotated(angle)
|
||||
var ray_left := Vector2(-3, -3).rotated(angle)
|
||||
var ray_right := Vector2(3, -3).rotated(angle)
|
||||
draw_line(pos, pos + ray_up, color)
|
||||
draw_line(pos, pos + ray_left, color)
|
||||
draw_line(pos, pos + ray_right, color)
|
||||
|
||||
var is_left_or_right := side == SIDE_LEFT or side == SIDE_RIGHT
|
||||
var line_from := (
|
||||
(Vector2.UP if is_left_or_right else Vector2.LEFT) * _player_size.x / 2
|
||||
)
|
||||
var line_to := (
|
||||
(Vector2.DOWN if is_left_or_right else Vector2.RIGHT) * _player_size.x / 2
|
||||
)
|
||||
draw_dashed_line(pos + line_from, pos + line_to, color)
|
||||
|
||||
|
||||
func _draw_arrowhead(from: Vector2, to: Vector2, color: Color) -> void:
|
||||
|
||||
Reference in New Issue
Block a user