diff --git a/autoloads/global.gd b/autoloads/global.gd index c167777..4b18260 100644 --- a/autoloads/global.gd +++ b/autoloads/global.gd @@ -1,6 +1,10 @@ extends Node +signal on_create_block_text(unit: Node2D) +signal on_create_damage_text(unit: Node2D, hitbox: HitboxComponent) + const FLASH_MATERIAL = preload("uid://cwtrdmkrsmw23") +const FLOATING_TEXT_SCENE = preload("uid://qkwyrg22h3gi") var player: Player diff --git a/resources/units/players/stats_player_well_rounded.tres b/resources/units/players/stats_player_well_rounded.tres index 5bd69b5..573cf95 100644 --- a/resources/units/players/stats_player_well_rounded.tres +++ b/resources/units/players/stats_player_well_rounded.tres @@ -12,6 +12,6 @@ health_increase_per_wave = 0.0 damage = 3 damage_increase_per_wave = 0.0 luck = 5.0 -block_chance = 1.0 +block_chance = 50.0 gold_drop = 0 metadata/_custom_type_script = "uid://dgjdpmaiufhs6" diff --git a/scenes/arena/arena.gd b/scenes/arena/arena.gd index 36526a7..7bf0041 100644 --- a/scenes/arena/arena.gd +++ b/scenes/arena/arena.gd @@ -3,11 +3,35 @@ class_name Arena @export var player: Player +@export var normal_color: Color +@export var bloacked_color: Color +@export var critical_color: Color +@export var hp_color: Color + # Called when the node enters the scene tree for the first time. func _ready() -> void: Global.player = player + Global.on_create_block_text.connect(_on_create_block_text) + Global.on_create_damage_text.connect(_on_create_damage_text) +func crteat_floating_text(unit: Node2D) -> FloatingText: + var instace := Global.FLOATING_TEXT_SCENE.instantiate() as FloatingText + get_tree().root.add_child(instace) + var random_pos := randf_range(0, TAU) * 35 + var spawn_pos := unit.global_position + Vector2.RIGHT.rotated(random_pos) + instace.global_position = spawn_pos + + return instace -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass +func _on_create_block_text(unit: Node2D) -> void: + var text := crteat_floating_text(unit) + text.setup("Blocked!", bloacked_color) + + + +func _on_create_damage_text(unit: Node2D, hitbox: HitboxComponent) -> void: + var text := crteat_floating_text(unit) + var color := critical_color if hitbox.critical else normal_color + text.setup(str(hitbox.damage), color) + + diff --git a/scenes/arena/arena.tscn b/scenes/arena/arena.tscn index bff9a73..1c8dd7c 100644 --- a/scenes/arena/arena.tscn +++ b/scenes/arena/arena.tscn @@ -10,6 +10,10 @@ [node name="Arena" type="Node2D" unique_id=1021720471 node_paths=PackedStringArray("player")] script = ExtResource("1_asdgj") player = NodePath("PlayerWellRounded") +normal_color = Color(1, 1, 1, 1) +bloacked_color = Color(1, 0.2901961, 0.45490196, 1) +critical_color = Color(0.99607843, 0.78039217, 0.38039216, 1) +hp_color = Color(0, 0.627451, 0.48235294, 1) [node name="BlackBG" type="Sprite2D" parent="." unique_id=29383651] scale = Vector2(2, 2) diff --git a/scenes/ui/floating_text/floating_text.gd b/scenes/ui/floating_text/floating_text.gd new file mode 100644 index 0000000..9e61199 --- /dev/null +++ b/scenes/ui/floating_text/floating_text.gd @@ -0,0 +1,34 @@ +extends Node2D +class_name FloatingText + +@onready var value_label: Label = $ValueLabel + +func setup(value: String, color) -> void: + value_label.text = value + modulate = color + scale = Vector2.ZERO + + rotation = deg_to_rad(randf_range(-10, 10)) + var random_scale := randf_range(0.8,1.6) + + var tween := create_tween() + + tween.parallel().tween_property(self, "scale", random_scale * Vector2.ONE, 0.4) + tween.parallel().tween_property(self, "global_position", global_position + Vector2.UP * 15, 0.4) + + tween .tween_interval(0.5) + + tween.parallel().tween_property(self,"scale", Vector2.ZERO, 0.4) + tween.parallel().tween_property(self, "modulate:a", 0.0, 0.4) + + await tween.finished + queue_free() + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/scenes/ui/floating_text/floating_text.gd.uid b/scenes/ui/floating_text/floating_text.gd.uid new file mode 100644 index 0000000..f3a89a6 --- /dev/null +++ b/scenes/ui/floating_text/floating_text.gd.uid @@ -0,0 +1 @@ +uid://crydqt4saprcl diff --git a/scenes/ui/floating_text/floating_text.tscn b/scenes/ui/floating_text/floating_text.tscn new file mode 100644 index 0000000..3fff76b --- /dev/null +++ b/scenes/ui/floating_text/floating_text.tscn @@ -0,0 +1,29 @@ +[gd_scene format=3 uid="uid://qkwyrg22h3gi"] + +[ext_resource type="Script" uid="uid://crydqt4saprcl" path="res://scenes/ui/floating_text/floating_text.gd" id="1_32222"] + +[sub_resource type="LabelSettings" id="LabelSettings_dsam5"] +font_size = 32 +outline_size = 10 +outline_color = Color(0.029506557, 0.029506557, 0.029506557, 1) + +[node name="FloatingText" type="Node2D" unique_id=176496435] +z_index = 10 +rotation = 0.13613568 +script = ExtResource("1_32222") + +[node name="ValueLabel" type="Label" parent="." unique_id=481881550] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -19.333334 +offset_right = 20.0 +offset_bottom = 19.333334 +grow_horizontal = 2 +grow_vertical = 2 +text = "10" +label_settings = SubResource("LabelSettings_dsam5") +horizontal_alignment = 1 diff --git a/scenes/unit/unit.gd b/scenes/unit/unit.gd index 812d5ab..d4791cb 100644 --- a/scenes/unit/unit.gd +++ b/scenes/unit/unit.gd @@ -23,13 +23,13 @@ func _on_hurtbox_component_on_damaged(hitbox: HitboxComponent) -> void: var blocked := Global.get_chance_success(stats.block_chance / 100) if blocked: - print("Blocked!") + #print("Blocked!") + Global.on_create_block_text.emit(self) return set_flash_material() - health_component.take_damage(hitbox.damage) - print("%s: %d" % [name, health_component.current_health] ) + Global.on_create_damage_text.emit(self, hitbox) func _on_flash_timer_timeout() -> void: