diff --git a/character/PlayerCharacter.gd b/character/PlayerCharacter.gd index 3f7e098..067bf30 100644 --- a/character/PlayerCharacter.gd +++ b/character/PlayerCharacter.gd @@ -8,6 +8,10 @@ export var walk_sound_interval: float = 0.5 export var swing_sounds: Array export var hit_sounds: Array +var heart_full = preload("res://character/Heart_Full.tres") +var heart_half = preload("res://character/Heart_Half.tres") +var heart_empty = preload("res://character/Heart_Empty.tres") + onready var sprite: AnimatedSprite = $AnimatedSprite var inventory: Dictionary = {} @@ -40,7 +44,7 @@ func _physics_process(delta: float) -> void: Input.get_action_strength("move_down") - Input.get_action_strength("move_up") ).clamped(1.0) var moving: bool = !direction.is_equal_approx(Vector2.ZERO) - + if moving: last_movement_dir = direction.normalized() if walk_sound_timer > walk_sound_interval: @@ -50,7 +54,9 @@ func _physics_process(delta: float) -> void: else: walk_sound_timer = 0.0 move_and_slide(direction * run_speed) - + + _update_health_display() + if playing_action: return var angle = direction.angle() if moving else last_movement_dir.angle() @@ -182,3 +188,13 @@ func print_inventory(): func _process(delta): DebugLabel.display(self, self.health) + +func _update_health_display(): + for heart in range($CanvasLayer.get_child_count()): + if health > heart * 20.0 + 10: + $CanvasLayer.get_child(heart).texture = heart_full + elif health > heart * 20.0: + + $CanvasLayer.get_child(heart).texture = heart_half + else: + $CanvasLayer.get_child(heart).texture = heart_empty diff --git a/character/PlayerCharacter.tscn b/character/PlayerCharacter.tscn index 41cbc37..0c16ad2 100644 --- a/character/PlayerCharacter.tscn +++ b/character/PlayerCharacter.tscn @@ -132,46 +132,51 @@ bus = "Effects" [node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="TextureRect" type="TextureRect" parent="CanvasLayer"] -margin_left = 16.0 -margin_top = 16.0 -margin_right = 48.0 -margin_bottom = 48.0 +margin_left = 80.0 +margin_top = 592.0 +margin_right = 144.0 +margin_bottom = 656.0 +expand = true __meta__ = { "_edit_use_anchors_": false } [node name="TextureRect2" type="TextureRect" parent="CanvasLayer"] -margin_left = 48.0 -margin_top = 16.0 -margin_right = 80.0 -margin_bottom = 48.0 +margin_left = 144.0 +margin_top = 592.0 +margin_right = 208.0 +margin_bottom = 656.0 +expand = true __meta__ = { "_edit_use_anchors_": false } [node name="TextureRect3" type="TextureRect" parent="CanvasLayer"] -margin_left = 80.0 -margin_top = 16.0 -margin_right = 112.0 -margin_bottom = 48.0 +margin_left = 208.0 +margin_top = 592.0 +margin_right = 272.0 +margin_bottom = 656.0 +expand = true __meta__ = { "_edit_use_anchors_": false } [node name="TextureRect4" type="TextureRect" parent="CanvasLayer"] -margin_left = 112.0 -margin_top = 16.0 -margin_right = 144.0 -margin_bottom = 48.0 +margin_left = 272.0 +margin_top = 592.0 +margin_right = 336.0 +margin_bottom = 656.0 +expand = true __meta__ = { "_edit_use_anchors_": false } [node name="TextureRect5" type="TextureRect" parent="CanvasLayer"] -margin_left = 144.0 -margin_top = 16.0 -margin_right = 176.0 -margin_bottom = 48.0 +margin_left = 336.0 +margin_top = 592.0 +margin_right = 400.0 +margin_bottom = 656.0 +expand = true __meta__ = { "_edit_use_anchors_": false } diff --git a/level/Level0.tscn b/level/Level0.tscn index 8552ae2..bc6fafb 100644 --- a/level/Level0.tscn +++ b/level/Level0.tscn @@ -41,10 +41,10 @@ extents = Vector2( 160, 96 ) extents = Vector2( 128, 128 ) [sub_resource type="RectangleShape2D" id=5] -extents = Vector2( 320, 224 ) +extents = Vector2( 288, 160 ) [sub_resource type="RectangleShape2D" id=6] -extents = Vector2( 288, 160 ) +extents = Vector2( 320, 224 ) [sub_resource type="CapsuleShape2D" id=7] radius = 192.0 @@ -121,7 +121,7 @@ position = Vector2( 336, -1424 ) position = Vector2( 272, -1296 ) [node name="StaticBody2D82" parent="YSort" instance=ExtResource( 2 )] -position = Vector2( 112, -1296 ) +position = Vector2( 80, -1296 ) [node name="StaticBody2D83" parent="YSort" instance=ExtResource( 2 )] position = Vector2( -80, -1392 )