diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-07 15:46:05 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-07 15:46:05 +0200 |
commit | 9d5f101ae04e629e542084397d016f74c8fe9763 (patch) | |
tree | 6721c1f9c137b86bfeb0995fc1f2396c9db72e7f /client/player/controllable_player.gd | |
parent | 84100fac9f1ba4c283b58c429821f7daae38d151 (diff) | |
download | hurrycurry-9d5f101ae04e629e542084397d016f74c8fe9763.tar hurrycurry-9d5f101ae04e629e542084397d016f74c8fe9763.tar.bz2 hurrycurry-9d5f101ae04e629e542084397d016f74c8fe9763.tar.zst |
send boosting state in client
Diffstat (limited to 'client/player/controllable_player.gd')
-rw-r--r-- | client/player/controllable_player.gd | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd index da2cffcd..f83a08f6 100644 --- a/client/player/controllable_player.gd +++ b/client/player/controllable_player.gd @@ -28,7 +28,6 @@ var onscreen_controls = preload("res://player/onscreen_controls/controls.tscn"). var facing = Vector2(1, 0) var velocity_ = Vector2(0, 0) var stamina = 0 -var boosting := false var was_boosting := false var chat_open := false @@ -41,7 +40,7 @@ func _ready(): add_child(timer) timer.start() timer.connect("timeout", func(): - game.mp.send_position(position_, rotation_) + game.mp.send_position(position_, rotation_, boosting) ) add_child(onscreen_controls) super() @@ -67,8 +66,6 @@ func _process_movement(delta): var input = Input.get_vector("left", "right", "forward", "backwards") var boost = Input.is_action_pressed("boost") or (Global.get_setting("latch_boost") and boosting) input = input.rotated( - game.camera.angle_target) - position_anim = position_ - rotation_anim = rotation_ if Input.is_action_pressed("interact") or Input.is_action_just_released("interact"): input *= 0 else: @@ -77,9 +74,13 @@ func _process_movement(delta): int(floor(position.z + cos(rotation.y))) ) interact() + var was_boosting = boosting update(delta, input, boost) - character.walking = input.length_squared() > 0.1 - character.boosting = boosting + if boosting and not was_boosting: + Input.start_joy_vibration(0, 0, 1, 0.15) + walking = input.length_squared() > 0.1 + position_anim = position_ + rotation_anim = rotation_ func update(dt: float, input: Vector2, boost: bool): input = input.limit_length(1.); @@ -88,14 +89,8 @@ func update(dt: float, input: Vector2, boost: bool): rotation_ = atan2(self.facing.x, self.facing.y); boost = boost and input.length() > 0.1 boosting = boost and (boosting or stamina >= 1.0) and stamina > 0 - if boosting: - stamina -= dt / BOOST_DURATION - if not was_boosting: - Input.start_joy_vibration(0, 0, 1, 0.15) - was_boosting = true - else: - stamina += dt / BOOST_RESTORE - was_boosting = false + if boosting: stamina -= dt / BOOST_DURATION + else: stamina += dt / BOOST_RESTORE stamina = max(min(stamina, 1.0), 0.0) var speed = PLAYER_SPEED * (BOOST_FACTOR if boosting else 1.) self.velocity_ += input * dt * speed; @@ -132,7 +127,7 @@ func collide(dt: float): func aabb_point_distance(mi: Vector2, ma: Vector2, p: Vector2) -> float: return (p - p.clamp(mi, ma)).length() -func update_position(_new_position: Vector2, _new_rotation: float): +func update_position(_new_position: Vector2, _new_rotation: float, _new_boosting: bool): pass func submit_message(text: String): |