# This file is part of sunder. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . class_name Singleplayer extends Node @export var player:Player @export var flag:Flag @export var map:Map func _ready() -> void: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED player.health.exhausted.connect(_on_player_dead) var spawn:Node = map.get_objective_spawn() flag.global_position = spawn.global_position player.damage.connect( func(_source: Node, target: Node, amount: int) -> void: target.health.damage(amount, 0)) var _on_exit := func() -> void: Input.mouse_mode = Input.MOUSE_MODE_VISIBLE Game.change_scene() func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("exit"): if OS.is_debug_build(): _on_exit.call() else: player.hud.ask("Are you sure you want to leave?", _on_exit) func _on_player_dead(_player:Player) -> void: var spawn:Node3D = map.get_player_spawn() player.respawn(spawn.global_position)