Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDE20_2024_Grupp2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Berglund
TDDE20_2024_Grupp2
Merge requests
!19
early platforming level
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
early platforming level
early-platforming-level
into
main
Overview
0
Commits
8
Pipelines
0
Changes
3
Merged
Jack Kolm
requested to merge
early-platforming-level
into
main
3 months ago
Overview
0
Commits
8
Pipelines
0
Changes
14
Expand
level!
0
0
Merge request reports
Compare
version 2
version 4
58b87d78
3 months ago
version 3
2daeaf61
3 months ago
version 2
42cfed03
3 months ago
version 1
42cfed03
3 months ago
main (base)
and
version 4
latest version
e4063940
8 commits,
3 months ago
version 4
58b87d78
7 commits,
3 months ago
version 3
2daeaf61
6 commits,
3 months ago
version 2
42cfed03
5 commits,
3 months ago
version 1
42cfed03
51 commits,
3 months ago
Show latest version
14 files
+
480
−
153
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
14
Search (e.g. *.vue) (Ctrl+P)
gui/heart_container.gd
+
111
−
6
Options
@@ -4,9 +4,114 @@ const heart_full = preload("res://assets/hearts/hud_heart_full.png")
const
heart_empty
=
preload
(
"res://assets/hearts/hud_heart_empty.png"
)
#var heart_half = preload("res://assets/hearts/hud_heart_half.png")
func
update_health
(
current_health
:
int
)
->
void
:
for
i
in
get_child_count
():
if
current_health
>
i
:
get_child
(
i
)
.
texture
=
heart_full
else
:
get_child
(
i
)
.
texture
=
heart_empty
const
FADE_DURATION
:
=
0.5
# Fade time in seconds
const
FADE_FULL_OPACITY
:
=
1.0
const
FADE_LOW_OPACITY
:
=
0.3
const
SHOW_DURATION
:
=
2.0
# Time to keep the UI visible after health change
const
MAX_HEALTH
:
=
5
# Ensure this matches the Player's MAX_HEALTH
var
always_visible_due_to_low_health
:
=
false
var
fade_tween
:
Tween
=
null
var
scale_tween
:
Tween
=
null
var
flash_tween
:
Tween
=
null
var
original_position
:
=
position
var
is_flashing
:
=
false
var
fade_timer
:
=
Timer
.
new
()
func
_ready
()
->
void
:
modulate
.
a
=
0.0
add_child
(
fade_timer
)
fade_timer
.
one_shot
=
true
func
update_health
(
current_health
:
int
)
->
void
:
for
i
in
range
(
get_child_count
()):
var
child
=
get_child
(
i
)
if
child
is
TextureRect
:
child
.
texture
=
heart_full
if
current_health
>
i
else
heart_empty
if
current_health
==
MAX_HEALTH
:
modulate
=
Color
(
1
,
1
,
1
,
1
)
fade_out
()
elif
current_health
==
1
:
show_ui
(
true
)
start_flashing
()
start_scaling_warning
()
else
:
modulate
=
Color
(
1
,
1
,
1
,
1
)
show_ui
(
false
)
stop_flashing
()
stop_scaling_warning
()
pulse_ui
()
func
fade_out
()
->
void
:
if
fade_tween
:
fade_tween
.
stop
()
fade_tween
=
get_tree
()
.
create_tween
()
fade_tween
.
tween_property
(
self
,
"modulate:a"
,
0.0
,
FADE_DURATION
)
always_visible_due_to_low_health
=
false
func
show_ui
(
permanent
:
bool
=
false
)
->
void
:
if
fade_tween
:
fade_tween
.
stop
()
modulate
.
a
=
FADE_FULL_OPACITY
if
permanent
:
always_visible_due_to_low_health
=
true
else
:
always_visible_due_to_low_health
=
false
fade_timer
.
start
(
SHOW_DURATION
)
fade_timer
.
timeout
.
connect
(
fade_to_low_opacity
)
func
fade_to_low_opacity
()
->
void
:
if
not
always_visible_due_to_low_health
:
if
fade_tween
:
fade_tween
.
stop
()
fade_tween
=
get_tree
()
.
create_tween
()
fade_tween
.
tween_property
(
self
,
"modulate:a"
,
FADE_LOW_OPACITY
,
FADE_DURATION
)
func
pulse_ui
()
->
void
:
if
scale_tween
:
scale_tween
.
stop
()
scale_tween
=
get_tree
()
.
create_tween
()
scale_tween
.
tween_property
(
self
,
"scale"
,
Vector2
(
1.2
,
1.2
),
0.1
)
scale_tween
.
tween_property
(
self
,
"scale"
,
Vector2
(
1
,
1
),
0.1
)
func
start_flashing
()
->
void
:
if
is_flashing
:
return
is_flashing
=
true
continue_flashing
()
func
continue_flashing
()
->
void
:
if
not
is_flashing
:
return
if
flash_tween
:
flash_tween
.
stop
()
flash_tween
=
get_tree
()
.
create_tween
()
flash_tween
.
tween_property
(
self
,
"modulate"
,
Color
(
1
,
0.2
,
0.2
),
0.1
)
flash_tween
.
tween_property
(
self
,
"modulate"
,
Color
(
1
,
1
,
1
),
0.1
)
flash_tween
.
finished
.
connect
(
continue_flashing
)
func
stop_flashing
()
->
void
:
is_flashing
=
false
if
flash_tween
:
flash_tween
.
stop
()
func
start_scaling_warning
()
->
void
:
if
scale_tween
:
scale_tween
.
stop
()
continue_scaling_warning
()
func
continue_scaling_warning
()
->
void
:
if
scale_tween
:
scale_tween
.
stop
()
scale_tween
=
get_tree
()
.
create_tween
()
scale_tween
.
tween_property
(
self
,
"scale"
,
Vector2
(
1.2
,
1.2
),
0.5
)
scale_tween
.
tween_property
(
self
,
"scale"
,
Vector2
(
1.0
,
1.0
),
0.5
)
scale_tween
.
finished
.
connect
(
continue_scaling_warning
)
func
stop_scaling_warning
()
->
void
:
if
scale_tween
:
scale_tween
.
stop
()
Loading