134 lines
4.5 KiB
GDScript
134 lines
4.5 KiB
GDScript
class_name GameManager
|
|
extends Node
|
|
|
|
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
|
|
|
@onready var world: World = $Tileset
|
|
@onready var player: PlayerManager = $PlayerManager
|
|
@onready var camera: CameraController = $Camera2D as CameraController
|
|
@onready var game_ticker: Timer = $GameTick
|
|
#
|
|
@onready var health_bar: ProgressBar = %HealthBar
|
|
@onready var food_bar: ProgressBar = %FoodBar
|
|
@onready var temperature_bar: ProgressBar = %TemperatureBar
|
|
@onready var temperature_resistance_bar: ProgressBar = %TemperatureResistanceBar
|
|
|
|
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
|
|
var waiting_for_input = true
|
|
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
|
|
@onready var animation_player = $Camera2D/AnimationPlayer
|
|
@onready var sprite = $Camera2D/Sprite2D
|
|
@onready var color_rect = $Camera2D/ColorRect
|
|
|
|
func _ready() -> void:
|
|
tilemap_navigation.world = world
|
|
tilemap_navigation.player = player
|
|
player.game_manager = self
|
|
world.camp_manager.game_manager = self
|
|
world.step_visualizer.game_manager = self
|
|
world.step_visualizer.world = world
|
|
update_bars()
|
|
if animation_player and sprite:
|
|
animation_player.play("Fade in")
|
|
print("Warte auf Tasteneingabe...")
|
|
await wait_for_key_press()
|
|
animation_player.play("Fade out")
|
|
await get_tree().create_timer(3.0).timeout
|
|
call_deferred("defer_ready")
|
|
else:
|
|
print("Knoten nicht gefunden!")
|
|
call_deferred("defer_ready")
|
|
|
|
func defer_ready() -> void:
|
|
tree_visualizer.behavior_tree = player.behavior_tree
|
|
tree_visualizer.build_tree()
|
|
|
|
|
|
# game_ticker.start()
|
|
|
|
func _process(delta: float) -> void:
|
|
if Input.is_action_just_pressed("key_6"):
|
|
camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561)
|
|
if Input.is_action_just_pressed("key_3"):
|
|
camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448)
|
|
if Input.is_action_just_pressed("key_9"):
|
|
world.camp_manager.campfire_light()
|
|
world.camp_manager.sleep_effect()
|
|
world.camp_manager.campfire_extinguish()
|
|
if Input.is_action_just_pressed("force_game_tick"):
|
|
Task.print_behavior_tree_evaluation = true
|
|
_on_game_tick_timeout()
|
|
Task.print_behavior_tree_evaluation = false
|
|
if Input.is_action_pressed("force_game_tick_fast"):
|
|
_on_game_tick_timeout()
|
|
if Input.is_action_just_pressed("key_2"):
|
|
toggle_temperature_layer()
|
|
|
|
|
|
func player_health_depleted():
|
|
# TODO
|
|
pass
|
|
|
|
|
|
func _on_game_tick_timeout() -> void:
|
|
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
|
timer_on_game_tick_timeout.display_name = "frame"
|
|
|
|
tilemap_navigation.game_tick_start()
|
|
world.game_tick_start()
|
|
|
|
player.game_tick()
|
|
|
|
tilemap_navigation.game_tick_end()
|
|
world.game_tick_end()
|
|
EventsTracker.populate_visual_log(%RecentEventsLog, self)
|
|
|
|
update_bars()
|
|
handle_result_game_state(player.behavior_tree.blackboard)
|
|
|
|
timer_on_game_tick_timeout.stop()
|
|
|
|
|
|
func handle_result_game_state(blackboard: Dictionary) -> void:
|
|
if blackboard.has("game_state_win"):
|
|
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
|
|
game_ticker.stop()
|
|
|
|
|
|
func update_bars() -> void:
|
|
if health_bar != null:
|
|
health_bar.max_value = player.max_health
|
|
health_bar.value = clamp(player.health, 0, player.max_health)
|
|
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
|
|
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
|
|
|
|
if food_bar != null:
|
|
food_bar.max_value = player.max_food
|
|
food_bar.value = clamp(player.food, 0, player.max_food)
|
|
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
|
|
|
|
if temperature_resistance_bar != null:
|
|
temperature_resistance_bar.max_value = player.temperature_set_buff_value
|
|
temperature_resistance_bar.value = clamp(player.temperature_buff_timer, 0, player.temperature_set_buff_value)
|
|
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
|
|
|
|
if temperature_bar != null:
|
|
temperature_bar.max_value = player.temperature_endure
|
|
# invert the value to show the time left
|
|
var countdown: int = player.temperature_endure - player.temperature_timer
|
|
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
|
|
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
|
|
|
|
|
|
func toggle_temperature_layer() -> void:
|
|
world.tilemap_temperature.tilemap.visible = not world.tilemap_temperature.tilemap.visible
|
|
|
|
|
|
func wait_for_key_press():
|
|
while waiting_for_input:
|
|
await get_tree().process_frame
|
|
|
|
func _input(event):
|
|
if event is InputEventKey and event.pressed:
|
|
waiting_for_input = false
|