add death screen and some early scene handling
This commit is contained in:
		
							parent
							
								
									1dfe6da904
								
							
						
					
					
						commit
						5cbd9b58a7
					
				
							
								
								
									
										35
									
								
								scenes/DeathScreen.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								scenes/DeathScreen.tscn
									
									
									
									
									
										Normal file
									
								
							@ -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: "
 | 
			
		||||
@ -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 )
 | 
			
		||||
 | 
			
		||||
@ -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"]
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								scripts/World.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								scripts/World.gd
									
									
									
									
									
										Normal file
									
								
							@ -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()
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user