From 7ee336c7d50a8fa45148cbc5146e7250f577eedc Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Sat, 30 Sep 2023 19:37:52 +0200 Subject: [PATCH] Add HP Logic --- icon.png.import | 4 ++-- project.godot | 12 +++++++++++- src/global.gd | 4 ++-- src/scenes/game/Game.tscn | 18 ++++++++++++++---- src/scenes/game/game.gd | 4 ++++ 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 src/scenes/game/game.gd diff --git a/icon.png.import b/icon.png.import index a4c02e6..eb3cdb6 100644 --- a/icon.png.import +++ b/icon.png.import @@ -20,7 +20,7 @@ compress/hdr_mode=0 compress/bptc_ldr=0 compress/normal_map=0 flags/repeat=0 -flags/filter=true +flags/filter=false flags/mipmaps=false flags/anisotropic=false flags/srgb=2 @@ -31,5 +31,5 @@ process/invert_color=false process/normal_map_invert_y=false stream=false size_limit=0 -detect_3d=true +detect_3d=false svg/scale=1.0 diff --git a/project.godot b/project.godot index e759724..61c5cb7 100644 --- a/project.godot +++ b/project.godot @@ -8,6 +8,16 @@ config_version=4 +_global_script_classes=[ { +"base": "EditorVCSInterface", +"class": "GitAPI", +"language": "NativeScript", +"path": "res://addons/godot-git-plugin/git_api.gdns" +} ] +_global_script_class_icons={ +"GitAPI": "" +} + [application] config/name="LD54" @@ -38,7 +48,7 @@ version_control_plugin_name="GitAPI" [gdnative] -singletons=[ ] +singletons=[ "res://addons/godot-git-plugin/git_api.gdnlib" ] [global] diff --git a/src/global.gd b/src/global.gd index d0c1555..a7cb5d4 100644 --- a/src/global.gd +++ b/src/global.gd @@ -3,10 +3,10 @@ extends Node var GAME_SCENE = preload("res://src/scenes/game/Game.tscn") var playing = true -var health = 0 +var health = 2 func add_health(amount): health = clamp(health + amount, 0, 3) - emit_signal("health_update") + get_tree().get_root().get_node("Game/UI/Health/HealthSprite").frame = health if health == 0: pass # TODO endgame diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 3737123..06d59c8 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=16 format=2] [ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1] [ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2] @@ -9,12 +9,14 @@ [ext_resource path="res://src/scenes/game/sprites/health/1.png" type="Texture" id=7] [ext_resource path="res://src/scenes/game/sprites/health/2.png" type="Texture" id=8] [ext_resource path="res://src/scenes/game/sprites/health/0.png" type="Texture" id=9] +[ext_resource path="res://icon.png" type="Texture" id=10] +[ext_resource path="res://src/scenes/game/game.gd" type="Script" id=11] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 60 ) [sub_resource type="RectangleShape2D" id=3] -extents = Vector2( 140, 10.25 ) +extents = Vector2( 140, 10.125 ) [sub_resource type="DynamicFont" id=1] size = 8 @@ -29,6 +31,7 @@ animations = [ { } ] [node name="Game" type="Node"] +script = ExtResource( 11 ) [node name="View" type="Node2D" parent="."] @@ -59,7 +62,7 @@ position = Vector2( 160, 10.25 ) shape = SubResource( 3 ) [node name="CollisionShape2D4" type="CollisionShape2D" parent="View/Background/Houses"] -position = Vector2( 160, 110 ) +position = Vector2( 160, 109.875 ) shape = SubResource( 3 ) [node name="Player" parent="View" instance=ExtResource( 5 )] @@ -88,7 +91,14 @@ text = "spell modifiers" margin_right = 40.0 margin_bottom = 40.0 -[node name="AnimatedSprite" type="AnimatedSprite" parent="UI/Health"] +[node name="HealthSprite" type="AnimatedSprite" parent="UI/Health"] position = Vector2( 70, 145 ) frames = SubResource( 4 ) +frame = 2 +centered = false + +[node name="PlayerIcon" type="Sprite" parent="UI"] +position = Vector2( 20, 134 ) +scale = Vector2( 0.5, 0.5 ) +texture = ExtResource( 10 ) centered = false diff --git a/src/scenes/game/game.gd b/src/scenes/game/game.gd new file mode 100644 index 0000000..4f7ae8b --- /dev/null +++ b/src/scenes/game/game.gd @@ -0,0 +1,4 @@ +extends Node + +func _ready(): + Global.add_health(1)