aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-26 16:53:07 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-26 16:53:07 +0200
commit2ca6ac7ab329036d0155de2de4b0a11f3a785414 (patch)
tree7472368efb282a4380b45931f3462e9930f48a36 /client
parentc4b0f8d698b574c711b1e205371adfd3e3339487 (diff)
downloadhurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar
hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.bz2
hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.zst
boosting
Diffstat (limited to 'client')
-rw-r--r--client/player/controllable_player.gd36
-rw-r--r--client/project.godot6
2 files changed, 30 insertions, 12 deletions
diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd
index 62b15c66..a2321fef 100644
--- a/client/player/controllable_player.gd
+++ b/client/player/controllable_player.gd
@@ -17,11 +17,16 @@
class_name ControllablePlayer
extends Player
-
-const PLAYER_SPEED: float = 65.;
+const PLAYER_FRICTION = 10
+const PLAYER_SPEED = 40
+const BOOST_FACTOR = 3
+const BOOST_DURATION = 0.3
+const BOOST_RESTORE = 0.5
var facing = Vector2(1, 0)
var velocity_ = Vector2(0, 0)
+var stamina = 0
+var boosting = false
var target: Vector2i = Vector2i(0, 0)
@@ -38,7 +43,8 @@ func _ready():
func _process(delta):
var input = Input.get_vector("left", "right", "forward", "backwards")
- input = input.rotated(-game.camera.angle_target)
+ var boost = Input.is_action_pressed("boost")
+ 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"):
@@ -49,23 +55,29 @@ func _process(delta):
int(floor(position.z + cos(rotation.y)))
)
interact()
- update(delta, input)
+ update(delta, input, boost)
super(delta)
character.walking = input.length_squared() > 0.1
-func update(dt: float, input: Vector2):
- var direction = input.limit_length(1.);
+func update(dt: float, input: Vector2, boost: bool):
+ input = input.limit_length(1.);
+ if input.length() > 0.1:
+ self.facing = input + (self.facing - input) * exp( - dt * 10.);
rotation_ = atan2(self.facing.x, self.facing.y);
- if direction.length() > 0.1:
- self.facing = direction + (self.facing - direction) * exp(-dt * 10.);
- self.velocity_ += direction * dt * PLAYER_SPEED;
+ boost = boost and input.length() > 0.1
+ boosting = boost and (boosting or stamina >= 1.0) and stamina > 0
+ 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;
self.position_ += self.velocity_ * dt;
- self.velocity_ = self.velocity_ * exp(-dt * 15.);
+ self.velocity_ = self.velocity_ * exp( - dt * 15.);
collide(dt);
func collide(dt: float):
- for xo in range(-1,2):
- for yo in range(-1,2):
+ for xo in range( - 1, 2):
+ for yo in range( - 1, 2):
var tile = Vector2i(xo, yo) + Vector2i(self.position_);
if !game.get_tile_collision(tile): continue
tile = Vector2(tile)
diff --git a/client/project.godot b/client/project.godot
index bb2b6896..679bd9e0 100644
--- a/client/project.godot
+++ b/client/project.godot
@@ -91,6 +91,12 @@ pause={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
]
}
+boost={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
+]
+}
[internationalization]