tutorial
This commit is contained in:
+86
-1
@@ -27,6 +27,16 @@ var kills_for_next: int = 10
|
||||
var game_active: bool = false
|
||||
var upgrading: bool = false
|
||||
|
||||
# Tutorial
|
||||
var tutorial_canvas: CanvasLayer
|
||||
var tutorial_image: TextureRect
|
||||
var tutorial_hint: Label
|
||||
var tutorial_active: bool = false
|
||||
var tutorial_hint_ready: bool = false
|
||||
var tutorial_timer: float = 0.0
|
||||
var tutorial_on_dismiss: Callable = Callable()
|
||||
var shown_tutorials: Dictionary = {}
|
||||
|
||||
# UI nodes
|
||||
var canvas: CanvasLayer
|
||||
var score_label: Label
|
||||
@@ -40,17 +50,25 @@ var upgrade_panel: Panel
|
||||
var gameover_panel: Panel
|
||||
|
||||
func _ready() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
_spawn_level()
|
||||
_create_camera()
|
||||
_create_ui()
|
||||
_create_tutorial_overlay()
|
||||
_spawn_player()
|
||||
_spawn_rocks()
|
||||
_spawn_sticks()
|
||||
_start_game()
|
||||
add_to_group("main")
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
show_tutorial("Tutorial_StartGame", _start_game)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if tutorial_active and tutorial_hint_ready:
|
||||
var mb := event as InputEventMouseButton
|
||||
if mb != null and mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed:
|
||||
_dismiss_tutorial()
|
||||
return
|
||||
|
||||
var motion := event as InputEventMouseMotion
|
||||
if motion != null and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
cam_yaw -= motion.relative.x * MOUSE_SENS
|
||||
@@ -80,6 +98,12 @@ func _create_camera() -> void:
|
||||
add_child(camera)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if tutorial_active:
|
||||
tutorial_timer -= delta
|
||||
if tutorial_timer <= 0.0 and not tutorial_hint_ready:
|
||||
tutorial_hint_ready = true
|
||||
tutorial_hint.visible = true
|
||||
return
|
||||
if is_instance_valid(player):
|
||||
var yaw_r: float = deg_to_rad(cam_yaw)
|
||||
var pitch_r: float = deg_to_rad(cam_pitch)
|
||||
@@ -335,6 +359,67 @@ func _restart() -> void:
|
||||
get_tree().paused = false
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
# ─── Tutorial ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _create_tutorial_overlay() -> void:
|
||||
tutorial_canvas = CanvasLayer.new()
|
||||
tutorial_canvas.process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
tutorial_canvas.visible = false
|
||||
add_child(tutorial_canvas)
|
||||
|
||||
var bg := ColorRect.new()
|
||||
bg.color = Color(0.0, 0.0, 0.0, 0.78)
|
||||
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
tutorial_canvas.add_child(bg)
|
||||
|
||||
tutorial_image = TextureRect.new()
|
||||
tutorial_image.anchor_left = 0.1
|
||||
tutorial_image.anchor_right = 0.9
|
||||
tutorial_image.anchor_top = 0.07
|
||||
tutorial_image.anchor_bottom = 0.84
|
||||
tutorial_image.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
tutorial_image.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
|
||||
tutorial_canvas.add_child(tutorial_image)
|
||||
|
||||
tutorial_hint = Label.new()
|
||||
tutorial_hint.anchor_left = 0.5
|
||||
tutorial_hint.anchor_right = 0.5
|
||||
tutorial_hint.anchor_top = 0.88
|
||||
tutorial_hint.offset_left = -280
|
||||
tutorial_hint.offset_right = 280
|
||||
tutorial_hint.text = "Нажмите ЛКМ чтобы продолжить"
|
||||
tutorial_hint.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
tutorial_hint.add_theme_font_size_override("font_size", 22)
|
||||
tutorial_hint.add_theme_color_override("font_color", Color.WHITE)
|
||||
tutorial_hint.add_theme_color_override("font_shadow_color", Color(0, 0, 0, 0.9))
|
||||
tutorial_hint.add_theme_constant_override("shadow_offset_x", 2)
|
||||
tutorial_hint.add_theme_constant_override("shadow_offset_y", 2)
|
||||
tutorial_hint.visible = false
|
||||
tutorial_canvas.add_child(tutorial_hint)
|
||||
|
||||
func show_tutorial(key: String, on_dismiss: Callable = Callable()) -> void:
|
||||
if shown_tutorials.get(key, false):
|
||||
if on_dismiss.is_valid():
|
||||
on_dismiss.call()
|
||||
return
|
||||
shown_tutorials[key] = true
|
||||
var path := "res://assets/%s.png" % key
|
||||
tutorial_image.texture = load(path) if ResourceLoader.exists(path) else null
|
||||
tutorial_on_dismiss = on_dismiss
|
||||
tutorial_active = true
|
||||
tutorial_hint_ready = false
|
||||
tutorial_timer = 3.0
|
||||
tutorial_hint.visible = false
|
||||
tutorial_canvas.visible = true
|
||||
get_tree().paused = true
|
||||
|
||||
func _dismiss_tutorial() -> void:
|
||||
tutorial_active = false
|
||||
tutorial_canvas.visible = false
|
||||
get_tree().paused = false
|
||||
if tutorial_on_dismiss.is_valid():
|
||||
tutorial_on_dismiss.call()
|
||||
|
||||
# ─── UI ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _create_ui() -> void:
|
||||
|
||||
Reference in New Issue
Block a user