144 lines
4.7 KiB
GDScript
144 lines
4.7 KiB
GDScript
extends Control
|
|
|
|
@export var radial_stamina : bool = false
|
|
|
|
var current_stam_bar
|
|
var stam_bar_visible : bool = false
|
|
var interact_visible : bool = false
|
|
var health_bar_start_pos
|
|
var money_count : int = 0
|
|
|
|
@onready var level_control = get_tree().current_scene
|
|
@onready var player = level_control.player
|
|
@onready var stamina_bar: TextureProgressBar = $StaminaBar
|
|
@onready var stamina_bar_2: ProgressBar = $StaminaBar2
|
|
@onready var health_bar: ProgressBar = $HealthBar
|
|
@onready var gun_name: Label = $"MarginContainer/VBoxContainer/Gun Name"
|
|
@onready var ammo: Label = $MarginContainer/VBoxContainer/Ammo
|
|
@onready var money: Label = $Money
|
|
@onready var crosshair: TextureRect = $Crosshair
|
|
|
|
const FULL_WHITE = Color(1, 1, 1, 1)
|
|
const TRANSPARENT = Color(1, 1, 1, 0)
|
|
const RED_COLOR = Color(1, 0, 0)
|
|
const ORANGE_COLOR = Color(0.822, 0.318, 0.086)
|
|
const GREEN_COLOR = Color(0, 0.608, 0.172)
|
|
|
|
const STAM_BAR_MAX_OPACITY = 1.0
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
SignalBus.player_hit.connect(player_hit)
|
|
health_bar.max_value = level_control.start_health
|
|
|
|
health_bar_start_pos = health_bar.position
|
|
|
|
if radial_stamina:
|
|
current_stam_bar = stamina_bar
|
|
stamina_bar_2.visible = false
|
|
else:
|
|
current_stam_bar = stamina_bar_2
|
|
stamina_bar.visible = false
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
player = level_control.player
|
|
if player != null:
|
|
#HEALTH
|
|
health_bar.value = level_control.health
|
|
if level_control.health <= 2:
|
|
change_color(health_bar,RED_COLOR,10,delta)
|
|
health_bar.position = health_bar_start_pos + shake_element(15)
|
|
elif level_control.health < ((level_control.start_health / 2) + 1):
|
|
change_color(health_bar,ORANGE_COLOR,10,delta)
|
|
else:
|
|
change_color(health_bar,FULL_WHITE,10,delta)
|
|
|
|
#MONEY
|
|
if money_count < level_control.money:
|
|
money_count += 1
|
|
change_color(money,GREEN_COLOR,10,delta)
|
|
elif money_count > level_control.money:
|
|
change_color(money,RED_COLOR,10,delta)
|
|
money_count -= 1
|
|
else:
|
|
change_color(money,FULL_WHITE,10,delta)
|
|
|
|
money.text = "$" + str(money_count)
|
|
if player.remaining_stamina/player.MAX_STAMINA >= .99:
|
|
stam_bar_visible = false
|
|
else:
|
|
stam_bar_visible = true
|
|
current_stam_bar.value = player.remaining_stamina
|
|
|
|
if player.gun != null:
|
|
ammo.text = str(level_control.ammo_current[level_control.current_gun_index]) +" | " + str(level_control.ammo_reserve[level_control.current_gun_index])
|
|
lerp_color(ammo,RED_COLOR,FULL_WHITE,level_control.ammo_current[level_control.current_gun_index],player.gun.max_ammo,.5)
|
|
else:
|
|
fade_in_out(ammo,1,false,10,delta)
|
|
fade_in_out(crosshair,1,false,10,delta)
|
|
|
|
if player.gun != null:
|
|
gun_name.text = player.gun.gun_name
|
|
else:
|
|
gun_name.visible = false
|
|
|
|
|
|
if player.remaining_stamina < 25:
|
|
change_color(current_stam_bar,RED_COLOR,10,delta)
|
|
change_color(crosshair,RED_COLOR,10,delta)
|
|
else:
|
|
change_color(current_stam_bar,FULL_WHITE,10,delta)
|
|
change_color(crosshair,FULL_WHITE,10,delta)
|
|
|
|
if player.interact_ray.is_colliding():
|
|
if player.interact_ray.get_collider() != null:
|
|
if player.interact_ray.get_collider().is_in_group("interact"):
|
|
interact_visible = true
|
|
else:
|
|
interact_visible = false
|
|
else:
|
|
interact_visible = false
|
|
|
|
if interact_visible == true:
|
|
change_color(crosshair,GREEN_COLOR,10,delta)
|
|
else:
|
|
change_color(crosshair,FULL_WHITE,10,delta)
|
|
|
|
if player.ads:
|
|
if player.gun.ads:
|
|
fade_in_out(crosshair,1,false,5,delta)
|
|
else:
|
|
fade_in_out(crosshair,1,true,5,delta)
|
|
else:
|
|
fade_in_out(crosshair,1,true,5,delta)
|
|
|
|
## FADE ELEMENTS IN AND OUT
|
|
fade_in_out(current_stam_bar,STAM_BAR_MAX_OPACITY,stam_bar_visible,5,delta)
|
|
|
|
func shake_element(amount):
|
|
var rand_x = randf_range(-amount,amount)
|
|
var rand_y = randf_range(-amount,amount)
|
|
return Vector2(rand_x,rand_y)
|
|
|
|
func lerp_color(element,colorA,colorB,cur_value,max_value,active_percent):
|
|
var value : float = float(cur_value)/float(max_value)
|
|
if value <= active_percent:
|
|
element.modulate = lerp(colorA,colorB,value)
|
|
else:
|
|
element.modulate = colorB
|
|
|
|
func change_color(element,color,speed,delta):
|
|
element.modulate = lerp(element.modulate, Color(color.r,color.g,color.b,element.modulate.a), (delta * speed)/Engine.time_scale)
|
|
|
|
func fade_in_out(element,MAX_OPACITY,visible,speed,delta):
|
|
var element_color = element.modulate
|
|
if visible:
|
|
element.modulate = lerp(element_color, Color(element_color.r,element_color.g,element_color.b,MAX_OPACITY),(delta * speed)/Engine.time_scale)
|
|
else:
|
|
element.modulate = lerp(element_color, Color(element_color.r,element_color.g,element_color.b,0),(delta * speed)/Engine.time_scale)
|
|
|
|
func player_hit():
|
|
pass
|
|
#self.position += wiggle_element(25)
|