v0.1.0-alpha: first playable
20 rooms, Crumb board token, Home and Game screens only.
This commit is contained in:
commit
f4b4a773f3
113 files changed
+4167
No files matched your search
@@ -0,0 +1,69 @@
|
||||
extends Control
|
||||
|
||||
const HomeScene = preload("res://scenes/Home.tscn")
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
var home
|
||||
var game
|
||||
var screens := {}
|
||||
var current := "home"
|
||||
var nav_stack: Array[String] = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var background := ColorRect.new()
|
||||
background.color = Palette.CREAM
|
||||
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(background)
|
||||
|
||||
home = HomeScene.instantiate()
|
||||
_add_screen(home)
|
||||
home.play_pressed.connect(_on_play)
|
||||
|
||||
game = GameScene.instantiate()
|
||||
_add_screen(game)
|
||||
game.back_pressed.connect(go_back)
|
||||
|
||||
screens = {
|
||||
"home": home,
|
||||
"game": game,
|
||||
}
|
||||
|
||||
show_screen("home", false)
|
||||
|
||||
|
||||
func _add_screen(screen: Control) -> void:
|
||||
add_child(screen)
|
||||
screen.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
screen.visible = false
|
||||
|
||||
|
||||
func show_screen(name: String, push: bool = true) -> void:
|
||||
if not screens.has(name):
|
||||
return
|
||||
if name == current:
|
||||
screens[name].visible = true
|
||||
return
|
||||
if push:
|
||||
nav_stack.append(current)
|
||||
|
||||
for key in screens:
|
||||
screens[key].visible = key == name
|
||||
|
||||
current = name
|
||||
|
||||
|
||||
func go_back() -> void:
|
||||
if nav_stack.is_empty():
|
||||
show_screen("home", false)
|
||||
return
|
||||
var previous: String = nav_stack.pop_back()
|
||||
show_screen(previous, false)
|
||||
|
||||
|
||||
func _on_play() -> void:
|
||||
var max_index: int = max(0, game.levels.size() - 1)
|
||||
var start_index: int = clampi(int(SaveGame.data.get("last_room", 0)), 0, max_index)
|
||||
show_screen("game")
|
||||
game.start_level(start_index)
|
||||
Reference in new issue
Block a user