score label vfx; increase building collider size
This commit is contained in:
parent
69faf54dc3
commit
962c4cb469
6 changed files with 60 additions and 18 deletions
|
|
@ -23,9 +23,10 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
shake_duration = move_toward(shake_duration, 0., delta)
|
shake_duration = move_toward(shake_duration, 0., delta)
|
||||||
|
|
||||||
func _show_score_label() -> void:
|
func _show_score_label(score: int) -> void:
|
||||||
%ScoreLabel.position.x += randf_range(-2, 2)
|
%ScoreLabel.position.x += randf_range(-2, 2)
|
||||||
%ScoreLabel.position.y += randf_range(-2, 2)
|
%ScoreLabel.position.y += randf_range(-2, 2)
|
||||||
|
%ScoreLabel.text = "+%d" % score
|
||||||
%ScoreLabel.show()
|
%ScoreLabel.show()
|
||||||
create_tween().tween_property(%ScoreLabel, "position:y", %ScoreLabel.position.y + 2., 1.)
|
create_tween().tween_property(%ScoreLabel, "position:y", %ScoreLabel.position.y + 2., 1.)
|
||||||
await get_tree().create_timer(.5, false).timeout
|
await get_tree().create_timer(.5, false).timeout
|
||||||
|
|
@ -39,14 +40,15 @@ func _show_score_label() -> void:
|
||||||
func hit(_proj: Node3D, damage: float) -> bool:
|
func hit(_proj: Node3D, damage: float) -> bool:
|
||||||
health -= damage
|
health -= damage
|
||||||
if health <= 0.:
|
if health <= 0.:
|
||||||
SignalBus.building_destroyed.emit(self)
|
var score := randi_range(10, 20)
|
||||||
|
SignalBus.building_destroyed.emit(self, score)
|
||||||
collision_layer = 1 # World collision only
|
collision_layer = 1 # World collision only
|
||||||
|
|
||||||
%Shaker.hide()
|
%Shaker.hide()
|
||||||
%DestroyedMesh.show()
|
%DestroyedMesh.show()
|
||||||
%GPUParticles3D.preprocess = randf()
|
%GPUParticles3D.preprocess = randf()
|
||||||
|
|
||||||
_show_score_label()
|
_show_score_label(score)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
shake_duration += 0.5
|
shake_duration += 0.5
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
[ext_resource type="Script" uid="uid://d1xiar6hicypm" path="res://buildings/building_behavior.gd" id="10_umrlk"]
|
[ext_resource type="Script" uid="uid://d1xiar6hicypm" path="res://buildings/building_behavior.gd" id="10_umrlk"]
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_5j34s"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_5j34s"]
|
||||||
size = Vector3(4.989258, 5, 5.453125)
|
size = Vector3(5.9665527, 5, 5.453125)
|
||||||
|
|
||||||
[sub_resource type="Gradient" id="Gradient_2yopf"]
|
[sub_resource type="Gradient" id="Gradient_2yopf"]
|
||||||
offsets = PackedFloat32Array(0.06315789, 0.6421053, 1)
|
offsets = PackedFloat32Array(0.06315789, 0.6421053, 1)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -64,13 +64,6 @@ mesh = SubResource("SphereMesh_4flbx")
|
||||||
[node name="PlayerHUD" type="CanvasLayer" parent="." unique_id=1676328708]
|
[node name="PlayerHUD" type="CanvasLayer" parent="." unique_id=1676328708]
|
||||||
script = ExtResource("2_g6k8r")
|
script = ExtResource("2_g6k8r")
|
||||||
|
|
||||||
[node name="ScoreLabel" type="Label" parent="PlayerHUD" unique_id=1108751125]
|
|
||||||
offset_right = 40.0
|
|
||||||
offset_bottom = 23.0
|
|
||||||
theme_override_font_sizes/font_size = 48
|
|
||||||
text = "Score: %s"
|
|
||||||
script = ExtResource("2_onrkg")
|
|
||||||
|
|
||||||
[node name="HealthLabel" type="Label" parent="PlayerHUD" unique_id=1653322479]
|
[node name="HealthLabel" type="Label" parent="PlayerHUD" unique_id=1653322479]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
visible = false
|
visible = false
|
||||||
|
|
@ -119,6 +112,30 @@ theme_override_font_sizes/font_size = 32
|
||||||
text = "BasicGun"
|
text = "BasicGun"
|
||||||
horizontal_alignment = 2
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="Score" type="Control" parent="PlayerHUD" unique_id=1241180984]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 5
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
grow_horizontal = 2
|
||||||
|
script = ExtResource("2_onrkg")
|
||||||
|
metadata/_edit_use_anchors_ = true
|
||||||
|
|
||||||
|
[node name="ScoreText" type="Label" parent="PlayerHUD/Score" unique_id=1108751125]
|
||||||
|
custom_minimum_size = Vector2(1152, 0)
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 5
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
offset_left = -576.0
|
||||||
|
offset_right = 576.0
|
||||||
|
offset_bottom = 132.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
theme_override_constants/outline_size = 31
|
||||||
|
theme_override_font_sizes/font_size = 96
|
||||||
|
text = "14"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="Guns" type="Node3D" parent="." unique_id=2018109083]
|
[node name="Guns" type="Node3D" parent="." unique_id=2018109083]
|
||||||
|
|
||||||
[node name="Sharpshooter" type="Node3D" parent="Guns" unique_id=1677055720]
|
[node name="Sharpshooter" type="Node3D" parent="Guns" unique_id=1677055720]
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,35 @@
|
||||||
extends Label
|
extends Control
|
||||||
|
|
||||||
|
const DESIRED_SCALE := Vector2.ONE * .5
|
||||||
|
|
||||||
|
@onready var label: Label = get_child(0)
|
||||||
|
var tween: Tween
|
||||||
|
var _display_score := 0
|
||||||
var score := 0:
|
var score := 0:
|
||||||
set(v):
|
set(v):
|
||||||
|
var delta = abs(v - score)
|
||||||
score = v
|
score = v
|
||||||
text = "Score: %d" % v
|
|
||||||
|
if label != null:
|
||||||
|
if tween != null: tween.stop()
|
||||||
|
tween = create_tween()
|
||||||
|
tween.tween_method((func(n):
|
||||||
|
_display_score = n
|
||||||
|
label.text = str(n)
|
||||||
|
), _display_score, score, .25)
|
||||||
|
|
||||||
|
scale += Vector2.ONE * pow(delta, 1.25) / 400
|
||||||
|
|
||||||
|
func exp_lerp(a: Variant, b: Variant, decay: float, dt: float) -> Variant:
|
||||||
|
return lerp(a, b, 1 - exp(-decay * dt))
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
scale = DESIRED_SCALE
|
||||||
score = score
|
score = score
|
||||||
SignalBus.building_destroyed.connect(func(_building):
|
SignalBus.building_destroyed.connect(func(_building, increment):
|
||||||
score += 10
|
score += increment
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
|
scale = exp_lerp(scale, DESIRED_SCALE, 05, delta)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
signal building_destroyed(building: Building)
|
signal building_destroyed(building: Building, score: int)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue