diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2020-08-01 15:51:18 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2020-08-01 15:51:18 +0300 |
| commit | bc73f5f075540c2f60b3ec2e216a3ecda85fdfc3 (patch) | |
| tree | 3f8bb7878c8aa36ecb30f0fe85c5114ab256c8f5 | |
| parent | 5e45d3f7b24b022040f47a8ab2d6bf4bb4d9b8b6 (diff) | |
Add GUI
| -rw-r--r-- | project.godot | 6 | ||||
| -rw-r--r-- | scenes/GUI.tscn | 22 | ||||
| -rw-r--r-- | scenes/Scene1.tscn | 9 | ||||
| -rw-r--r-- | scenes/Scene2.tscn | 13 | ||||
| -rw-r--r-- | scripts/GUI.gd | 18 | ||||
| -rw-r--r-- | scripts/PlayerCharacter.gd | 3 |
6 files changed, 68 insertions, 3 deletions
diff --git a/project.godot b/project.godot index a1efac6..0233336 100644 --- a/project.godot +++ b/project.godot @@ -14,6 +14,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://scripts/DwarfNPC.gd" }, { +"base": "MarginContainer", +"class": "GUI", +"language": "GDScript", +"path": "res://scripts/GUI.gd" +}, { "base": "KinematicBody2D", "class": "PlayerCharacter", "language": "GDScript", @@ -21,6 +26,7 @@ _global_script_classes=[ { } ] _global_script_class_icons={ "DwarfNPC": "", +"GUI": "", "PlayerCharacter": "" } diff --git a/scenes/GUI.tscn b/scenes/GUI.tscn new file mode 100644 index 0000000..8a328c8 --- /dev/null +++ b/scenes/GUI.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://scripts/GUI.gd" type="Script" id=1] + +[node name="GUI" type="MarginContainer"] +anchor_right = 1.0 +margin_left = 20.0 +margin_top = 20.0 +margin_right = -20.0 +margin_bottom = -20.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +margin_right = 984.0 +margin_bottom = 14.0 + +[node name="Label" type="Label" parent="VBoxContainer"] +margin_right = 984.0 +margin_bottom = 14.0 diff --git a/scenes/Scene1.tscn b/scenes/Scene1.tscn index 2656dbd..d6652d9 100644 --- a/scenes/Scene1.tscn +++ b/scenes/Scene1.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=52 format=2] +[gd_scene load_steps=53 format=2] [ext_resource path="res://scenes/PlayerCharacter.tscn" type="PackedScene" id=1] [ext_resource path="res://textures/world_tileset.tres" type="Texture" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://scripts/Scene1.gd" type="Script" id=4] [ext_resource path="res://externals/point_light.png" type="Texture" id=5] [ext_resource path="res://scenes/Ladder.tscn" type="PackedScene" id=6] +[ext_resource path="res://scenes/GUI.tscn" type="PackedScene" id=7] [sub_resource type="OccluderPolygon2D" id=1] polygon = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 ) @@ -311,12 +312,12 @@ tile_data = PoolIntArray( -262152, 0, 0, -262151, 0, 0, -262150, 0, 0, -262149, [node name="PlayerCharacter" parent="YSort" instance=ExtResource( 1 )] position = Vector2( 12.8563, 19.5552 ) speed = 32 +gui_node = NodePath("../../CanvasLayer/GUI") [node name="Camera2D" type="Camera2D" parent="YSort/PlayerCharacter"] current = true zoom = Vector2( 0.2, 0.2 ) process_mode = 0 -smoothing_enabled = true smoothing_speed = 2.0 [node name="Light2D" type="Light2D" parent="YSort/PlayerCharacter"] @@ -338,3 +339,7 @@ target = NodePath("../PlayerCharacter") [node name="Ladder" parent="YSort" instance=ExtResource( 6 )] target_scene_num = 2 + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="GUI" parent="CanvasLayer" instance=ExtResource( 7 )] diff --git a/scenes/Scene2.tscn b/scenes/Scene2.tscn index 4888419..a19590b 100644 --- a/scenes/Scene2.tscn +++ b/scenes/Scene2.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=52 format=2] +[gd_scene load_steps=53 format=2] [ext_resource path="res://scenes/PlayerCharacter.tscn" type="PackedScene" id=1] [ext_resource path="res://textures/world_tileset.tres" type="Texture" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://scripts/Scene1.gd" type="Script" id=4] [ext_resource path="res://externals/point_light.png" type="Texture" id=5] [ext_resource path="res://scenes/Ladder.tscn" type="PackedScene" id=6] +[ext_resource path="res://scripts/GUI.gd" type="Script" id=7] [sub_resource type="OccluderPolygon2D" id=1] polygon = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 ) @@ -339,3 +340,13 @@ target = NodePath("../../../Scene2/YSort/PlayerCharacter") [node name="Ladder" parent="YSort" instance=ExtResource( 6 )] position = Vector2( 88, 48 ) target_scene_num = 1 + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="GUI" type="MarginContainer" parent="CanvasLayer"] +margin_right = 40.0 +margin_bottom = 40.0 +script = ExtResource( 7 ) +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/scripts/GUI.gd b/scripts/GUI.gd new file mode 100644 index 0000000..1e0a781 --- /dev/null +++ b/scripts/GUI.gd @@ -0,0 +1,18 @@ +extends MarginContainer +class_name GUI + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta): + pass + +func set_debug_text(text: String): + $VBoxContainer/Label.set_text(text) diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd index 9c95854..1df100c 100644 --- a/scripts/PlayerCharacter.gd +++ b/scripts/PlayerCharacter.gd @@ -3,6 +3,7 @@ class_name PlayerCharacter export (int) var speed = 8 export (float) var walk_wobble_coeff = 5 +export (NodePath) var gui_node var velocity = Vector2() var look_dir = 1 # right = 1, left = -1 @@ -67,8 +68,10 @@ func _physics_process(_delta): func change_level(num: int): var new_scene = "res://scenes/Scene" + String(num) + ".tscn" + var gui: GUI = get_node(gui_node) var success = get_tree().change_scene(new_scene) if success == OK: + gui.set_debug_text("Level: %s" % num) print("Changed level to " + new_scene) else: push_error("Failed to change level to " + new_scene) |
