From 5cbd9b58a7f505b7768978a68fa1e55bb1c04df0 Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Mon, 15 Feb 2021 14:30:25 +0000 Subject: [PATCH] add death screen and some early scene handling --- scenes/DeathScreen.tscn | 35 +++++++++++++++++++++++++++++++++++ scenes/Tree.tscn | 10 +++++----- scenes/World.tscn | 15 ++++++++++++--- scripts/World.gd | 21 +++++++++++++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 scenes/DeathScreen.tscn create mode 100644 scripts/World.gd diff --git a/scenes/DeathScreen.tscn b/scenes/DeathScreen.tscn new file mode 100644 index 0000000..fa2b383 --- /dev/null +++ b/scenes/DeathScreen.tscn @@ -0,0 +1,35 @@ +[gd_scene format=2] + +[node name="DeathScreen" type="PopupPanel"] +pause_mode = 2 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -960.0 +margin_top = -540.0 +margin_right = 960.0 +margin_bottom = 540.0 +popup_exclusive = true + +[node name="Box" type="VBoxContainer" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Header" type="Label" parent="Box"] +margin_right = 61.0 +margin_bottom = 31.0 +text = "You Died! +" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Score" type="Label" parent="Box"] +margin_top = 35.0 +margin_right = 61.0 +margin_bottom = 49.0 +text = "Score: " diff --git a/scenes/Tree.tscn b/scenes/Tree.tscn index 589c635..c15bec1 100644 --- a/scenes/Tree.tscn +++ b/scenes/Tree.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://scripts/Tree.gd" type="Script" id=2] [ext_resource path="res://assets/bare_tree.png" type="Texture" id=3] -[sub_resource type="SpriteFrames" id=2] +[sub_resource type="SpriteFrames" id=1] animations = [ { "frames": [ ExtResource( 1 ), ExtResource( 3 ) ], "loop": true, @@ -12,21 +12,21 @@ animations = [ { "speed": 5.0 } ] -[sub_resource type="RectangleShape2D" id=1] +[sub_resource type="RectangleShape2D" id=2] extents = Vector2( 112.784, 53.9413 ) [sub_resource type="RectangleShape2D" id=3] -extents = Vector2( 49.9564, 83.1256 ) +extents = Vector2( 50.4981, 83.1256 ) [node name="Tree" type="KinematicBody2D"] script = ExtResource( 2 ) [node name="Sprite" type="AnimatedSprite" parent="."] -frames = SubResource( 2 ) +frames = SubResource( 1 ) [node name="Leaves" type="CollisionShape2D" parent="."] position = Vector2( 0.629959, -28.6632 ) -shape = SubResource( 1 ) +shape = SubResource( 2 ) [node name="Trunk" type="CollisionShape2D" parent="."] position = Vector2( -57.0114, 4.03472 ) diff --git a/scenes/World.tscn b/scenes/World.tscn index 6a7b418..59199fd 100644 --- a/scenes/World.tscn +++ b/scenes/World.tscn @@ -1,14 +1,23 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://scenes/GiraffeHead.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/Tree.tscn" type="PackedScene" id=2] +[ext_resource path="res://scripts/World.gd" type="Script" id=3] +[ext_resource path="res://scenes/DeathScreen.tscn" type="PackedScene" id=4] [node name="World" type="Node2D"] +script = ExtResource( 3 ) [node name="GiraffeHead" parent="." instance=ExtResource( 1 )] position = Vector2( 1089.79, 940.571 ) [node name="Tree" parent="." instance=ExtResource( 2 )] -position = Vector2( 704.278, 463.862 ) +position = Vector2( 748, 463.862 ) -[node name="Borders" type="Node2D" parent="."] +[node name="DeathScreen" parent="." instance=ExtResource( 4 )] +margin_left = 820.184 +margin_top = 537.476 +margin_right = 889.184 +margin_bottom = 594.476 +[connection signal="death" from="Tree" to="." method="_on_Tree_death"] +[connection signal="eaten" from="Tree" to="." method="_on_Tree_eaten"] diff --git a/scripts/World.gd b/scripts/World.gd new file mode 100644 index 0000000..f986043 --- /dev/null +++ b/scripts/World.gd @@ -0,0 +1,21 @@ +extends Node2D + + +var score = 0 + +# 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 _on_Tree_eaten(): + score += 1 + +func _on_Tree_death(): + get_tree().paused = true + $DeathScreen/Box/Score.text = "Score: " + str(score) + $DeathScreen.popup_centered()