diff options
author | Jonas Bernard <public.jbernard@web.de> | 2021-04-24 22:00:16 +0200 |
---|---|---|
committer | Jonas Bernard <public.jbernard@web.de> | 2021-04-24 22:00:16 +0200 |
commit | a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd (patch) | |
tree | 4e5482f769268ca48f4f019a3d3888d0893cc1d1 /components | |
parent | 5d74b160790f35f201f2dd1876b84201a8be9534 (diff) | |
download | ldjam48-a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd.tar.gz ldjam48-a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd.tar.bz2 ldjam48-a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd.zip |
healthbar
Diffstat (limited to 'components')
-rw-r--r-- | components/buttontest.tscn | 20 | ||||
-rw-r--r-- | components/healthbar/healtbar.gd | 25 | ||||
-rw-r--r-- | components/healthbar/healtbar.tscn | 7 | ||||
-rw-r--r-- | components/healthbar/heart.gd | 22 | ||||
-rw-r--r-- | components/healthbar/heart.tscn | 14 |
5 files changed, 79 insertions, 9 deletions
diff --git a/components/buttontest.tscn b/components/buttontest.tscn index cd9ff17..d0d4e6b 100644 --- a/components/buttontest.tscn +++ b/components/buttontest.tscn @@ -1,10 +1,9 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://textures/components/button/middle.png" type="Texture" id=1] [ext_resource path="res://textures/components/button/right.png" type="Texture" id=2] [ext_resource path="res://fonts/Fipps-Regular.otf" type="DynamicFontData" id=3] [ext_resource path="res://textures/components/button/left.png" type="Texture" id=4] -[ext_resource path="res://components/buttontest.gd" type="Script" id=5] [sub_resource type="DynamicFont" id=1] outline_color = Color( 0, 0, 0, 1 ) @@ -13,8 +12,7 @@ font_data = ExtResource( 3 ) [sub_resource type="Theme" id=2] default_font = SubResource( 1 ) -[node name="ButtonTest" type="Node2D"] -script = ExtResource( 5 ) +[node name="Node2D" type="Node2D"] [node name="Left" type="Sprite" parent="."] position = Vector2( -100, 0 ) @@ -27,18 +25,22 @@ scale = Vector2( 4, 4 ) texture = ExtResource( 2 ) [node name="Middle" type="Sprite" parent="."] -position = Vector2( -0.5, 0 ) scale = Vector2( 30.321, 4 ) texture = ExtResource( 1 ) -[node name="FontSource" type="RichTextLabel" parent="."] +[node name="RichTextLabel" type="RichTextLabel" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -31.9373 +margin_top = -19.027 +margin_right = 76.0627 +margin_bottom = 27.973 grow_horizontal = 2 grow_vertical = 2 -rect_clip_content = false -size_flags_horizontal = 3 theme = SubResource( 2 ) text = "Menu" -scroll_active = false __meta__ = { "_edit_use_anchors_": false } diff --git a/components/healthbar/healtbar.gd b/components/healthbar/healtbar.gd new file mode 100644 index 0000000..ee9915f --- /dev/null +++ b/components/healthbar/healtbar.gd @@ -0,0 +1,25 @@ +extends Node2D + +export var maxhealth = 3 +export var offset = 40 + +var h: PackedScene = preload("res://components/healthbar/heart.tscn") +var hearts: Array = [] + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + for i in maxhealth: + var heart = h.instance() + hearts.append(heart) + heart.position = Vector2(i * offset, 0) + add_child(heart) + + +func _process(delta): + pass + +func set_health(health: int=maxhealth): + for i in maxhealth: + hearts[i].set_filled(i < health) diff --git a/components/healthbar/healtbar.tscn b/components/healthbar/healtbar.tscn new file mode 100644 index 0000000..e7cf26c --- /dev/null +++ b/components/healthbar/healtbar.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://components/healthbar/healtbar.gd" type="Script" id=2] + +[node name="Node2D" type="Node2D"] +script = ExtResource( 2 ) +maxhealth = 8 diff --git a/components/healthbar/heart.gd b/components/healthbar/heart.gd new file mode 100644 index 0000000..6177452 --- /dev/null +++ b/components/healthbar/heart.gd @@ -0,0 +1,22 @@ +extends Node2D + + +onready var fill = $fill +onready var notfill = $notfill + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +func _process(delta): + pass + +func set_filled(filled: bool): + if filled: + fill.visible = true + notfill.visible = false + else: + notfill.visible = true + fill.visible = false + diff --git a/components/healthbar/heart.tscn b/components/healthbar/heart.tscn new file mode 100644 index 0000000..b4b14e5 --- /dev/null +++ b/components/healthbar/heart.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://textures/icons/heart_fill.png" type="Texture" id=1] +[ext_resource path="res://components/healthbar/heart.gd" type="Script" id=2] +[ext_resource path="res://textures/icons/heart.png" type="Texture" id=3] + +[node name="Node2D" type="Node2D"] +script = ExtResource( 2 ) + +[node name="fill" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="notfill" type="Sprite" parent="."] +texture = ExtResource( 3 ) |