Skip to content

Commit 2a740b2

Browse files
committed
Refactor hud, align properly
1 parent 7f8d142 commit 2a740b2

File tree

6 files changed

+71
-54
lines changed

6 files changed

+71
-54
lines changed

comet/Arrow.svg.import

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/Arrow.svg-45e3c82569d9080f75efd5e39fa5cdac.stex"
6+
7+
[deps]
8+
9+
source_file="res://comet/Arrow.svg"
10+
source_md5="2e57f099d49df2d8e3ca5ac79f610d38"
11+
12+
dest_files=[ "res://.import/Arrow.svg-45e3c82569d9080f75efd5e39fa5cdac.stex" ]
13+
dest_md5="8bd816b2aa65bbb3d3386d01aa1ad083"
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/normal_map=0
21+
flags/repeat=0
22+
flags/filter=true
23+
flags/mipmaps=false
24+
flags/anisotropic=false
25+
flags/srgb=2
26+
process/fix_alpha_border=true
27+
process/premult_alpha=false
28+
process/HDR_as_SRGB=false
29+
stream=false
30+
size_limit=0
31+
detect_3d=true
32+
svg/scale=1.0

game/game.gd

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ func _ready():
44
for i in range(1,10):
55
spawn_chicken(i)
66

7+
$level/spaceship.connect("health_changed", $hud_layer/hud, "set_health_percentage")
8+
79
func spawn_chicken(id):
810
var chicken = preload("res://spr_chickenWing.tscn").instance()
911
#chicken.position = pos

game/game.tscn

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[ext_resource path="res://game/background.png" type="Texture" id=3]
66
[ext_resource path="res://level_heist/level_heist.tscn" type="PackedScene" id=4]
77

8-
[node name="game" type="Node2D" index="0"]
8+
[node name="game" type="Node2D"]
99

1010
script = ExtResource( 1 )
1111

hud/hud.gd

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends Control
2+
3+
func set_health_percentage(val):
4+
$health_bar/health_bar_background.rect_scale = Vector2(val, 1)

hud/hud.tscn

+24-48
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,47 @@
11
[gd_scene load_steps=4 format=2]
22

3-
[ext_resource path="res://fonts/Cousine-Bold.ttf" type="DynamicFontData" id=1]
4-
5-
[sub_resource type="DynamicFont" id=1]
6-
7-
size = 60
8-
use_mipmaps = false
9-
use_filter = false
10-
font_data = ExtResource( 1 )
11-
_sections_unfolded = [ "Extra Spacing", "Font/fallback", "Settings" ]
3+
[ext_resource path="res://hud/hud.gd" type="Script" id=1]
4+
[ext_resource path="res://fonts/Cousine-Bold.ttf" type="DynamicFontData" id=2]
125

136
[sub_resource type="DynamicFont" id=2]
147

158
size = 60
169
use_mipmaps = false
1710
use_filter = false
18-
font_data = ExtResource( 1 )
11+
font_data = ExtResource( 2 )
1912
_sections_unfolded = [ "Extra Spacing", "Font", "Settings" ]
2013

21-
[node name="hud" type="Node2D"]
22-
23-
position = Vector2( 349, 218.5 )
24-
_sections_unfolded = [ "Transform" ]
25-
26-
[node name="health" type="Label" parent="." index="0"]
14+
[node name="hud" type="Control" index="0"]
2715

2816
anchor_left = 0.0
2917
anchor_top = 0.0
30-
anchor_right = 0.0
31-
anchor_bottom = 0.0
32-
margin_left = 438.0
33-
margin_top = -193.0
34-
margin_right = 654.0
35-
margin_bottom = -124.0
18+
anchor_right = 1.0
19+
anchor_bottom = 1.0
3620
rect_pivot_offset = Vector2( 0, 0 )
3721
rect_clip_content = false
38-
mouse_filter = 2
22+
mouse_filter = 0
3923
mouse_default_cursor_shape = 0
4024
size_flags_horizontal = 1
41-
size_flags_vertical = 0
42-
custom_fonts/font = SubResource( 1 )
43-
text = "999 HP"
44-
percent_visible = 1.0
45-
lines_skipped = 0
46-
max_lines_visible = -1
47-
_sections_unfolded = [ "Focus", "Material", "Mouse", "Rect", "Size Flags", "Theme", "Visibility", "custom_fonts", "custom_styles" ]
25+
size_flags_vertical = 1
26+
script = ExtResource( 1 )
27+
_sections_unfolded = [ "Rect", "Transform" ]
4828

49-
[node name="health_bar" type="ColorRect" parent="." index="1"]
29+
[node name="health_bar" type="ColorRect" parent="." index="0"]
5030

51-
anchor_left = 1.0
52-
anchor_top = 0.0
53-
anchor_right = 1.0
54-
anchor_bottom = 0.0
55-
margin_left = -400.0
56-
margin_top = -180.0
57-
margin_right = 350.0
58-
margin_bottom = -150.0
31+
anchor_left = 0.0
32+
anchor_top = 1.0
33+
anchor_right = 0.0
34+
anchor_bottom = 1.0
35+
margin_top = -30.0
36+
margin_right = 750.0
5937
rect_pivot_offset = Vector2( 0, 0 )
6038
rect_clip_content = false
6139
mouse_filter = 0
6240
mouse_default_cursor_shape = 0
6341
size_flags_horizontal = 1
6442
size_flags_vertical = 1
6543
color = Color( 1, 0, 0, 0.613255 )
66-
_sections_unfolded = [ "Anchor", "Margin" ]
44+
_sections_unfolded = [ "Anchor", "Margin", "Rect" ]
6745

6846
[node name="health_bar_background" type="ColorRect" parent="health_bar" index="0"]
6947

@@ -80,18 +58,16 @@ mouse_default_cursor_shape = 0
8058
size_flags_horizontal = 1
8159
size_flags_vertical = 1
8260
color = Color( 1, 1, 1, 0.187843 )
83-
_sections_unfolded = [ "Anchor", "Margin" ]
61+
_sections_unfolded = [ "Anchor", "Margin", "Rect" ]
8462

85-
[node name="easter_eggs" type="Label" parent="." index="2"]
63+
[node name="easter_eggs" type="Label" parent="." index="1"]
8664

87-
anchor_left = 0.0
65+
anchor_left = 1.0
8866
anchor_top = 0.0
89-
anchor_right = 0.0
67+
anchor_right = 1.0
9068
anchor_bottom = 0.0
91-
margin_left = 370.0
92-
margin_top = -130.0
93-
margin_right = 658.0
94-
margin_bottom = -61.0
69+
margin_left = -288.0
70+
margin_bottom = 69.0
9571
rect_pivot_offset = Vector2( 0, 0 )
9672
rect_clip_content = false
9773
mouse_filter = 2

spaceship.gd

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ extends RigidBody2D
22

33
var tween
44

5+
signal health_changed(percentage)
6+
57
var torque = 5000
68
var speed = 200
79
var handling = 20
810
var fire_intervall = 0.6
9-
# Remaining space ship health
10-
var health = 10000000000.0
11+
12+
const MAX_HEALTH = 200
13+
var health = MAX_HEALTH
1114

1215
# Whether or not the player is still alive
1316
var alive = true
@@ -32,9 +35,9 @@ func take_proportional_damage(damage, other_velocity):
3235
func set_health(new_health):
3336
health = new_health
3437
# TODO Do something when spaceship is dead.
35-
get_node('/root/game/hud_layer/hud/health').text = str(ceil(health)) + ' HP'
36-
get_node('/root/game/hud_layer/hud/health_bar').margin_right = 7.5*health - 400
37-
38+
39+
emit_signal("health_changed", new_health / MAX_HEALTH)
40+
3841
if health == 0 and alive:
3942
die()
4043

0 commit comments

Comments
 (0)