Reworked health indicator. Added blink charge indicator
This commit is contained in:
@@ -36,6 +36,7 @@ material = SubResource("ShaderMaterial_bkxo4")
|
||||
[node name="Health" parent="." instance=ExtResource("2_xxtvk")]
|
||||
|
||||
[node name="HeathBar" parent="." node_paths=PackedStringArray("health") instance=ExtResource("3_l62e5")]
|
||||
z_index = 101
|
||||
health = NodePath("../Health")
|
||||
|
||||
[node name="WeaponSlots" type="Node2D" parent="."]
|
||||
|
||||
@@ -42,8 +42,8 @@ rect = Rect2(-29, -21, 58, 42)
|
||||
max_hull = 200
|
||||
|
||||
[node name="HeathBar" parent="." index="7"]
|
||||
offset_top = 30.0
|
||||
offset_bottom = 30.0
|
||||
offset_top = 27.0
|
||||
offset_bottom = 27.0
|
||||
|
||||
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
|
||||
position = Vector2(-8, 0)
|
||||
|
||||
@@ -42,8 +42,8 @@ rect = Rect2(-13, -21, 26, 42)
|
||||
max_hull = 100
|
||||
|
||||
[node name="HeathBar" parent="." index="7"]
|
||||
offset_top = 30.0
|
||||
offset_bottom = 30.0
|
||||
offset_top = 19.0
|
||||
offset_bottom = 19.0
|
||||
|
||||
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
|
||||
position = Vector2(4, -8)
|
||||
|
||||
@@ -42,8 +42,8 @@ rect = Rect2(-13, -5, 26, 10)
|
||||
max_hull = 50
|
||||
|
||||
[node name="HeathBar" parent="." index="7"]
|
||||
offset_top = 14.0
|
||||
offset_bottom = 14.0
|
||||
offset_top = 11.0
|
||||
offset_bottom = 11.0
|
||||
|
||||
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
|
||||
position = Vector2(5, 0)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
class_name BlinkChargeIndicator
|
||||
extends Node2D
|
||||
|
||||
|
||||
var maximum: float = 0:
|
||||
set = _set_maximum
|
||||
|
||||
var value: float = 0:
|
||||
set = _set_value
|
||||
|
||||
|
||||
@onready var progress_bar : TextureProgressBar = $ProgressBar
|
||||
@onready var charged_sprite : Sprite2D = $ChargedSprite
|
||||
|
||||
|
||||
func _set_maximum(new_value: float) -> void:
|
||||
maximum = new_value
|
||||
value = clampf(value, 0, maximum)
|
||||
progress_bar.max_value = maximum
|
||||
_update_charged_sprite()
|
||||
|
||||
|
||||
func _set_value(new_value: float) -> void:
|
||||
value = clampf(new_value, 0, maximum)
|
||||
progress_bar.value = value
|
||||
_update_charged_sprite()
|
||||
|
||||
|
||||
func _update_charged_sprite() -> void:
|
||||
if is_equal_approx(value, maximum):
|
||||
charged_sprite.show()
|
||||
else:
|
||||
charged_sprite.hide()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bpfr1laquec3u
|
||||
@@ -0,0 +1,27 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://d20nvskf38vpo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bpfr1laquec3u" path="res://game/entities/ships/player/blink_charge_indicator.gd" id="1_5n4fu"]
|
||||
[ext_resource type="Texture2D" uid="uid://y2yfli24n51v" path="res://images/ships/player.png" id="2_i476t"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fo48j"]
|
||||
atlas = ExtResource("2_i476t")
|
||||
region = Rect2(0, 128, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i476t"]
|
||||
atlas = ExtResource("2_i476t")
|
||||
region = Rect2(16, 128, 16, 16)
|
||||
|
||||
[node name="BlinkChargeIndicator" type="Node2D"]
|
||||
script = ExtResource("1_5n4fu")
|
||||
|
||||
[node name="ProgressBar" type="TextureProgressBar" parent="."]
|
||||
offset_left = -8.0
|
||||
offset_top = -8.0
|
||||
offset_right = 8.0
|
||||
offset_bottom = 8.0
|
||||
step = 0.1
|
||||
value = 100.0
|
||||
texture_progress = SubResource("AtlasTexture_fo48j")
|
||||
|
||||
[node name="ChargedSprite" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_i476t")
|
||||
@@ -4,31 +4,51 @@ extends AbstractShip
|
||||
|
||||
const ENEMY_LAYER = 4
|
||||
|
||||
const BLINK_CHARGE_MAXIMUM = 3.0
|
||||
|
||||
|
||||
@export_range(0, 200) var blink_range := 0
|
||||
|
||||
|
||||
@onready var blink_timer : Timer = $BlinkTimer
|
||||
var blink_charge: float:
|
||||
set(value):
|
||||
blink_charge = value
|
||||
if blink_charge_indicator != null:
|
||||
blink_charge_indicator.value = blink_charge
|
||||
|
||||
|
||||
@onready var blink_shadow : GPUParticles2D = $BlinkShadow
|
||||
@onready var blink_charge_indicator : BlinkChargeIndicator = $BlinkChargeIndicator
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
blink_charge_indicator.maximum = BLINK_CHARGE_MAXIMUM
|
||||
blink_charge = BLINK_CHARGE_MAXIMUM
|
||||
|
||||
for weapon_position in weapon_positions:
|
||||
var weapon : AbstractWeapon = WEAPONS.pick_random().instantiate()
|
||||
_add_weapon(weapon, weapon_position)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
|
||||
if blink_charge < BLINK_CHARGE_MAXIMUM:
|
||||
blink_charge += delta
|
||||
blink_charge_indicator.value = blink_charge
|
||||
|
||||
|
||||
func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void:
|
||||
super._add_weapon(weapon, weapon_position)
|
||||
weapon.set_belonging(AbstractWeapon.Belonging.PLAYER)
|
||||
|
||||
|
||||
func _blink(direction: Vector2) -> void:
|
||||
if not blink_timer.is_stopped(): return
|
||||
if blink_charge < BLINK_CHARGE_MAXIMUM: return
|
||||
|
||||
blink_timer.start()
|
||||
blink_charge = 0
|
||||
|
||||
var shadow : GPUParticles2D = blink_shadow.duplicate()
|
||||
var process_material : ParticleProcessMaterial = shadow.process_material
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://br074cqcnul3d"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://br074cqcnul3d"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ships/abstract_ship.tscn" id="1_6otxb"]
|
||||
[ext_resource type="Script" uid="uid://ruxw1n03iq4i" path="res://game/entities/ships/player/player_ship.gd" id="2_625ti"]
|
||||
[ext_resource type="PackedScene" uid="uid://dh1oj1w5wx4je" path="res://game/controllers/player_controller.tscn" id="3_4mjo1"]
|
||||
[ext_resource type="Texture2D" uid="uid://y2yfli24n51v" path="res://images/ships/player.png" id="3_uf2n1"]
|
||||
[ext_resource type="PackedScene" uid="uid://d20nvskf38vpo" path="res://game/entities/ships/player/blink_charge_indicator.tscn" id="5_uf2n1"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_4mjo1"]
|
||||
atlas = ExtResource("3_uf2n1")
|
||||
@@ -70,8 +71,8 @@ one_shot = true
|
||||
process_material = SubResource("ParticleProcessMaterial_pjmi2")
|
||||
|
||||
[node name="HeathBar" parent="." index="8"]
|
||||
offset_top = 22.0
|
||||
offset_bottom = 22.0
|
||||
offset_top = 19.0
|
||||
offset_bottom = 19.0
|
||||
|
||||
[node name="First" type="Node2D" parent="WeaponSlots" index="0"]
|
||||
position = Vector2(-2, 8)
|
||||
@@ -79,6 +80,9 @@ position = Vector2(-2, 8)
|
||||
[node name="Second" type="Node2D" parent="WeaponSlots" index="1"]
|
||||
position = Vector2(-2, -8)
|
||||
|
||||
[node name="BlinkChargeIndicator" parent="." index="10" instance=ExtResource("5_uf2n1")]
|
||||
position = Vector2(-11, 0)
|
||||
|
||||
[connection signal="accelerate" from="PlayerController" to="." method="accelerate"]
|
||||
[connection signal="blink" from="PlayerController" to="." method="_blink"]
|
||||
[connection signal="shoot" from="PlayerController" to="." method="shoot"]
|
||||
|
||||
Reference in New Issue
Block a user