105 lines
3.4 KiB
GDScript
105 lines
3.4 KiB
GDScript
extends Control
|
|
|
|
@onready var hud: Control = $"../.."
|
|
@onready var player = get_tree().current_scene.player
|
|
|
|
#INNER RING
|
|
var inner_ring_radius : float = 5
|
|
|
|
#OUTER RING
|
|
const OUTER_RING_START_RADIUS = 40
|
|
const SIZE_SNAP_AMT = 20
|
|
const SIZE_RETURN_AMT = 2
|
|
|
|
var outer_ring_radius : float = 50
|
|
var outer_ring_width : float = 4
|
|
var crosshair_color = ColorSwatch.FULL_WHITE
|
|
|
|
#STAMINA WHEEL
|
|
const STAMINA_RING_WIDTH = 20
|
|
var stamina_bar_color = ColorSwatch.FULL_WHITE
|
|
var stamina_alpha : float = 1.0
|
|
|
|
var crosshair_target : float = 0.0
|
|
|
|
func _ready() -> void:
|
|
SignalBus.shot_fired.connect(crosshair_size_change)
|
|
SignalBus.player_hit.connect(player_hit)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if hud.player != null:
|
|
position = hud.viewportCenter
|
|
|
|
var velocity_adjust = clamp(hud.player.velocity.length() * .1,1,3)
|
|
var crosshair_radius
|
|
|
|
if hud.player.gun != null:
|
|
crosshair_radius = hud.player.gun.weapon_info.crosshair_radius
|
|
else:
|
|
crosshair_radius = OUTER_RING_START_RADIUS
|
|
|
|
# Crosshair
|
|
outer_ring_radius = lerp(outer_ring_radius,(crosshair_radius + crosshair_target) * velocity_adjust,delta * SIZE_SNAP_AMT)
|
|
crosshair_target = lerp(crosshair_target,0.0,delta * SIZE_RETURN_AMT)
|
|
|
|
#if stamina is 25%, change colors to red
|
|
var crosshair_alpha = outer_ring_fade()
|
|
crosshair_color = lerp(crosshair_color,Color(crosshair_color_target().r,crosshair_color_target().g,crosshair_color_target().b,crosshair_alpha),(delta * 5)/Engine.time_scale)
|
|
stamina_alpha = lerp(stamina_alpha,stamina_fade(),(delta * 5)/Engine.time_scale)
|
|
stamina_bar_color = Color(crosshair_color.r,crosshair_color.g,crosshair_color.b,stamina_alpha)
|
|
|
|
queue_redraw()
|
|
|
|
func _draw() -> void:
|
|
|
|
#INNER RING
|
|
draw_circle(Vector2.ZERO, inner_ring_radius + 2, Color(0,0,0,1))
|
|
draw_circle(Vector2.ZERO, inner_ring_radius, Color(crosshair_color.r,crosshair_color.g,crosshair_color.b,1))
|
|
#OUTER RING
|
|
draw_circle(Vector2.ZERO, outer_ring_radius - 2, Color(0,0,0,crosshair_color.a),false,outer_ring_width,true)
|
|
draw_circle(Vector2.ZERO, outer_ring_radius + 2, Color(0,0,0,crosshair_color.a),false,outer_ring_width,true)
|
|
draw_circle(Vector2.ZERO, outer_ring_radius, crosshair_color,false,outer_ring_width,true)
|
|
|
|
if hud.player != null:
|
|
#STAMINA WHEEL
|
|
var stam_offset = -TAU * .25
|
|
var stam_start_angle = 0 + stam_offset
|
|
var stam_end_angle = TAU * (hud.player.remaining_stamina/hud.level_control.gamemode.max_stamina) + stam_offset
|
|
var stam_width = (outer_ring_radius / 5) + 10
|
|
draw_arc(Vector2(0,0),outer_ring_radius,stam_start_angle,stam_end_angle,100,Color(0,0,0,stamina_bar_color.a),stam_width + 4,true)
|
|
draw_arc(Vector2(0,0),outer_ring_radius,stam_start_angle,stam_end_angle,100,stamina_bar_color,stam_width,true)
|
|
|
|
func outer_ring_fade() -> float:
|
|
#fades the outer ring when the gun cannot fire or there is no gun
|
|
if hud.player.gun == null:
|
|
return 0.0
|
|
else :
|
|
if hud.player.gun.can_fire():
|
|
return 1.0
|
|
else:
|
|
return .25
|
|
|
|
func stamina_fade() -> float:
|
|
var stam_percent = hud.player.remaining_stamina/hud.level_control.gamemode.max_stamina
|
|
|
|
if stam_percent >= .99:
|
|
return 0.0
|
|
else:
|
|
return 1.0
|
|
|
|
func crosshair_color_target():
|
|
var stam_percent = hud.player.remaining_stamina/hud.level_control.gamemode.max_stamina
|
|
|
|
if stam_percent <= .1:
|
|
return ColorSwatch.RED_COLOR
|
|
else:
|
|
return ColorSwatch.FULL_WHITE
|
|
|
|
|
|
func crosshair_size_change(amount):
|
|
crosshair_target += amount
|
|
|
|
func player_hit():
|
|
crosshair_size_change(20)
|