Skip to content

Commit

Permalink
custom theme and font with damage text
Browse files Browse the repository at this point in the history
creating custom theme resource and project wide theme usage
using tween effects for floating damage text scene effect on hurtbox component with dynamic text based on hitbox damage dealt on enemy
  • Loading branch information
KartikWatts committed Jan 17, 2024
1 parent a14135d commit 54c3143
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 2d-survivors-course/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ window/size/window_width_override=1920
window/size/window_height_override=1080
window/stretch/mode="viewport"

[gui]

theme/custom="res://resources/theme/theme.tres"

[input]

move_left={
Expand Down
Binary file not shown.
38 changes: 38 additions & 0 deletions 2d-survivors-course/resources/theme/Rockboxcond12.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://b7708ebmlmygw"
path="res://.godot/imported/Rockboxcond12.ttf-6ec46e755c0cb4bc7bf74c19c1d5cac8.fontdata"

[deps]

source_file="res://resources/theme/Rockboxcond12.ttf"
dest_files=["res://.godot/imported/Rockboxcond12.ttf-6ec46e755c0cb4bc7bf74c19c1d5cac8.fontdata"]

[params]

Rendering=null
antialiasing=0
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=0
subpixel_positioning=0
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[{
"chars": [],
"glyphs": [],
"name": "New Configuration",
"size": Vector2i(16, 0)
}]
language_support={}
script_support={}
opentype_features={}
7 changes: 7 additions & 0 deletions 2d-survivors-course/resources/theme/theme.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_resource type="Theme" load_steps=2 format=3 uid="uid://dppehnirbmmb0"]

[ext_resource type="FontFile" uid="uid://b7708ebmlmygw" path="res://resources/theme/Rockboxcond12.ttf" id="1_8cegc"]

[resource]
default_font = ExtResource("1_8cegc")
default_font_size = 16
7 changes: 7 additions & 0 deletions 2d-survivors-course/scenes/components/hurt_box_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class_name HurtBoxComponent

@export var health_component: HealthComponent

var floating_text_scence = preload("res://scenes/ui/floating_text.tscn")

func _ready():
area_entered.connect(on_area_entered)
Expand All @@ -17,3 +18,9 @@ func on_area_entered(other_area: Area2D):

var hitbox_component = other_area as HitBoxComponent
health_component.damage(hitbox_component.damage)

var floating_text = floating_text_scence.instantiate() as FloatingText
get_tree().get_first_node_in_group("foreground_layer").add_child(floating_text)

floating_text.global_position = global_position + (Vector2.UP * 16)
floating_text.start(str(hitbox_component.damage))
5 changes: 5 additions & 0 deletions 2d-survivors-course/scenes/ui/arena_time_ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 0
theme_override_colors/font_shadow_color = Color(0.247059, 0.14902, 0.192157, 1)
theme_override_colors/font_outline_color = Color(0.247059, 0.14902, 0.192157, 1)
theme_override_constants/shadow_offset_x = 0
theme_override_constants/shadow_offset_y = 0
theme_override_constants/outline_size = 6
text = "test"
27 changes: 27 additions & 0 deletions 2d-survivors-course/scenes/ui/floating_text.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Node2D
class_name FloatingText

func _ready():
pass


func start(text: String):
$Label.text = text

var tween = create_tween()
tween.set_parallel()

tween.tween_property(self, "global_position", global_position + (Vector2.UP * 16), .3)\
.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC)
tween.chain()

tween.tween_property(self, "global_position", global_position + (Vector2.UP * 16), .5)\
.set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC)
tween.tween_property(self, "scale", Vector2.ONE, .5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC)
tween.chain()

tween.tween_callback(queue_free)

var scale_tween = create_tween()
scale_tween.tween_property(self, "scale", Vector2.ONE * 1.5, .15).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC)
scale_tween.tween_property(self, "scale", Vector2.ONE, .15).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC)
21 changes: 21 additions & 0 deletions 2d-survivors-course/scenes/ui/floating_text.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[gd_scene load_steps=2 format=3 uid="uid://l5bn3rnkbcgi"]

[ext_resource type="Script" path="res://scenes/ui/floating_text.gd" id="1_ets41"]

[node name="FloatingText" type="Node2D"]
script = ExtResource("1_ets41")

[node name="Label" type="Label" parent="."]
custom_minimum_size = Vector2(100, 32)
offset_left = -50.0
offset_top = -14.0
offset_right = 50.0
offset_bottom = 18.0
theme_override_colors/font_shadow_color = Color(0.247059, 0.14902, 0.192157, 1)
theme_override_colors/font_outline_color = Color(0.247059, 0.14902, 0.192157, 1)
theme_override_constants/shadow_offset_x = 0
theme_override_constants/shadow_offset_y = 0
theme_override_constants/outline_size = 6
text = "108"
horizontal_alignment = 1
vertical_alignment = 1

0 comments on commit 54c3143

Please sign in to comment.