Update game to start from title and transition to level
This commit is contained in:
parent
dd28145a88
commit
d95a50dc2b
|
@ -0,0 +1,18 @@
|
|||
extends Node
|
||||
|
||||
var num_levels = 1
|
||||
var current_level = 0
|
||||
|
||||
var game_scene = "res://main.tscn"
|
||||
var title_screen = "res://ui/title.tscn"
|
||||
|
||||
|
||||
func restart():
|
||||
current_level = 0
|
||||
get_tree().change_scene_to_file(title_screen)
|
||||
|
||||
|
||||
func next_level():
|
||||
current_level += 1
|
||||
if current_level <= num_levels:
|
||||
get_tree().change_scene_to_file(game_scene)
|
|
@ -39,3 +39,7 @@ func _on_item_picked_up():
|
|||
func set_score(value: int):
|
||||
score = value
|
||||
score_changed.emit(score)
|
||||
|
||||
|
||||
func _on_player_died():
|
||||
GameState.restart()
|
||||
|
|
|
@ -55,4 +55,5 @@ format = 2
|
|||
[node name="HUD" parent="CanvasLayer" instance=ExtResource("8_0n14g")]
|
||||
|
||||
[connection signal="score_changed" from="." to="CanvasLayer/HUD" method="update_score"]
|
||||
[connection signal="died" from="Player" to="." method="_on_player_died"]
|
||||
[connection signal="life_changed" from="Player" to="CanvasLayer/HUD" method="update_life"]
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
extends Node
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
var level_num = str(GameState.current_level).pad_zeros(2)
|
||||
var path = "res://levels/level_%s.tscn" % level_num
|
||||
var level = load(path).instantiate()
|
||||
add_child(level)
|
16
main.tscn
16
main.tscn
|
@ -1,16 +1,6 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dwqy1qngxc88y"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dwqy1qngxc88y"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dytoa1mc6ukah" path="res://player/player.tscn" id="1_wey0g"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vpa4s"]
|
||||
size = Vector2(165.5, 9)
|
||||
[ext_resource type="Script" path="res://main.gd" id="1_5fob1"]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_wey0g")]
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
position = Vector2(47.25, 20.5)
|
||||
shape = SubResource("RectangleShape2D_vpa4s")
|
||||
script = ExtResource("1_5fob1")
|
||||
|
|
|
@ -11,10 +11,14 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="Jungle Jump"
|
||||
run/main_scene="res://main.tscn"
|
||||
run/main_scene="res://ui/title.tscn"
|
||||
config/features=PackedStringArray("4.1", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
GameState="*res://game_state.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/stretch/mode="canvas_items"
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
extends Control
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event.is_action_pressed("ui_select"):
|
||||
GameState.next_level()
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://bqb0ccbvsye1i"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://bqb0ccbvsye1i"]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/title.gd" id="1_h6jgx"]
|
||||
[ext_resource type="Texture2D" uid="uid://b3tvlo0v6j4bi" path="res://assets/environment/back.png" id="1_rpjij"]
|
||||
[ext_resource type="Texture2D" uid="uid://d0rqiaxuha1p6" path="res://assets/environment/middle.png" id="2_tfyow"]
|
||||
[ext_resource type="FontFile" uid="uid://cxp0s6ifyv2ue" path="res://assets/Kenney Thick.ttf" id="3_glnlm"]
|
||||
|
@ -71,6 +72,7 @@ anchor_right = 1.0
|
|||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_h6jgx")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
|
@ -98,10 +100,10 @@ anchor_left = 0.5
|
|||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -360.0
|
||||
offset_top = -42.0
|
||||
offset_right = 360.0
|
||||
offset_bottom = 42.0002
|
||||
offset_left = 216.0
|
||||
offset_top = 282.0
|
||||
offset_right = 936.0
|
||||
offset_bottom = 366.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
|
|
Loading…
Reference in New Issue