diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-06-26 16:53:07 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-06-26 16:53:07 +0200 | 
| commit | 2ca6ac7ab329036d0155de2de4b0a11f3a785414 (patch) | |
| tree | 7472368efb282a4380b45931f3462e9930f48a36 /client/player | |
| parent | c4b0f8d698b574c711b1e205371adfd3e3339487 (diff) | |
| download | hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.bz2 hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.zst | |
boosting
Diffstat (limited to 'client/player')
| -rw-r--r-- | client/player/controllable_player.gd | 36 | 
1 files changed, 24 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) | 
