2025-12-01 22:35:07 +00:00
|
|
|
extends RigidBody2D
|
|
|
|
|
|
|
|
|
|
var health = 1000
|
2025-12-02 00:34:27 +00:00
|
|
|
var boost = 100
|
2025-12-02 00:10:54 +00:00
|
|
|
var time_since_last_collision = 1
|
|
|
|
|
var camera_shake_power = 0
|
2025-12-02 00:34:27 +00:00
|
|
|
var boosting = false
|
2025-12-02 00:10:54 +00:00
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
2025-12-02 17:57:09 +00:00
|
|
|
modulate.g = health / 1000.0
|
|
|
|
|
modulate.b = health / 1000.0
|
2025-12-02 00:10:54 +00:00
|
|
|
$Camera.offset.x = randi_range(-camera_shake_power, camera_shake_power)
|
|
|
|
|
$Camera.offset.y = randi_range(-camera_shake_power, camera_shake_power)
|
|
|
|
|
|
2025-12-02 00:34:27 +00:00
|
|
|
if boosting:
|
|
|
|
|
if Input.is_action_pressed("boost"):
|
|
|
|
|
boost -= delta * 40
|
|
|
|
|
|
2025-12-02 01:21:10 +00:00
|
|
|
if camera_shake_power < 2:
|
|
|
|
|
camera_shake_power = 2
|
|
|
|
|
|
2025-12-02 00:34:27 +00:00
|
|
|
if boost <= 0:
|
|
|
|
|
boost = 0
|
|
|
|
|
boosting = false
|
|
|
|
|
$BoostFinish.play()
|
|
|
|
|
else:
|
|
|
|
|
boosting = false
|
|
|
|
|
$BoostFinish.play()
|
|
|
|
|
else:
|
|
|
|
|
boost += delta * 25
|
|
|
|
|
if boost > 100: boost = 100
|
|
|
|
|
|
|
|
|
|
$Boost.stop()
|
|
|
|
|
if Input.is_action_just_pressed("boost") and (boost > 33):
|
|
|
|
|
boosting = true
|
|
|
|
|
$Boost.play()
|
|
|
|
|
|
2025-12-02 00:10:54 +00:00
|
|
|
if camera_shake_power > 0:
|
|
|
|
|
camera_shake_power -= delta * 20
|
|
|
|
|
|
|
|
|
|
if camera_shake_power < 0:
|
|
|
|
|
camera_shake_power = 0
|
|
|
|
|
|
|
|
|
|
if time_since_last_collision <= 1:
|
|
|
|
|
time_since_last_collision += delta
|
2025-12-01 22:35:07 +00:00
|
|
|
|
2025-12-01 22:45:28 +00:00
|
|
|
func _physics_process(delta: float) -> void:
|
2025-12-01 22:35:07 +00:00
|
|
|
var axis = Input.get_axis("turn_left", "turn_right")
|
2025-12-02 01:21:10 +00:00
|
|
|
var movement_axis = Input.get_axis("forward", "backward")
|
2025-12-01 22:35:07 +00:00
|
|
|
|
|
|
|
|
angular_velocity = deg_to_rad(180 * axis)
|
|
|
|
|
|
2025-12-02 00:34:27 +00:00
|
|
|
var final_speed = 512
|
|
|
|
|
|
|
|
|
|
if boosting:
|
2025-12-02 01:21:10 +00:00
|
|
|
movement_axis = -1
|
2025-12-02 00:34:27 +00:00
|
|
|
final_speed = 1024
|
|
|
|
|
|
|
|
|
|
# Slow down on collision and gradually speed up
|
2025-12-02 01:21:10 +00:00
|
|
|
if time_since_last_collision < 0.85: final_speed *= (time_since_last_collision + 0.15)
|
2025-12-02 00:34:27 +00:00
|
|
|
|
2025-12-02 01:21:10 +00:00
|
|
|
var new_velocity = transform.y * movement_axis * final_speed
|
2025-12-01 22:35:07 +00:00
|
|
|
|
2025-12-02 00:34:27 +00:00
|
|
|
if (new_velocity.length() > linear_velocity.length() - 12):
|
|
|
|
|
linear_velocity = new_velocity
|
2025-12-02 00:10:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
|
|
|
|
|
if body.linear_velocity.length() + linear_velocity.length() > 256:
|
|
|
|
|
health -= 100
|
|
|
|
|
camera_shake_power = 4
|
|
|
|
|
|
|
|
|
|
$Collision.play()
|
|
|
|
|
|
|
|
|
|
time_since_last_collision = 0
|