This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
Jessist/Scripts/GameManager.gd

105 lines
4.3 KiB
GDScript3
Raw Normal View History

2022-06-18 13:05:48 +02:00
######################
### Jessist Script ###
######################
# This script is part of Jessist
# Jessist is licensed under GNU GPLv3
#
# This script manages all relevant ingame menus
extends Camera2D
onready var MenuNode = get_node("Menu")
onready var GameOverNode = get_node("GameOver")
# Camera settings
export var levelBoundary = 0 # If set to zero, bounds are disabled.
export var showFPS = true
export var showXY = true
export var currentLevel = ""
export var countersUse = false
var followPlayer = false
# Debugging settings
var debugging_delta_new=-999
var debugging_delta_old=-999
func _ready():
gameController.logInfo("GameManager","_ready","Making pause menu invisible")
gameController.gamePaused = false
MenuNode.visible = false
GameOverNode.visible = false
#if get_tree().get_root().get_node("Counters") == null:
# print("Counters == null")
#else:
# print("Counters != null")
#if showFPS:
# get_tree().get_root().get_node("Counters").enableFPSCounter = true
#if showXY:
# get_tree().get_root().get_node("Counters").enableXYCounters = true
#countersUse = true
func _process(delta):
gameController.logCall("GameManager","_process",delta)
if gameController.debuggingMode:
debugging_delta_new = delta
if debugging_delta_old == -999:
gameController.logVerbose("GameManager","_process","DELTA CHANGED: " + String(debugging_delta_new))
debugging_delta_old = debugging_delta_new
elif debugging_delta_new == debugging_delta_old:
pass
else:
gameController.logVerbose("GameManager","_process","DELTA CHANGED: " + String(debugging_delta_new))
debugging_delta_old = debugging_delta_new
#if showXY and countersUse:
# get_parent().get_node("Counters").playerPosition.x = get_parent().get_node("Player").position.x
# get_parent().get_node("Counters").playerPosition.y = get_parent().get_node("Player").position.y
gameController.logVerbose("GameManager","_process","RAW Level boundary: " + str(levelBoundary) + " | PROCESSED Level boundary: " + str(levelBoundary-960))
gameController.logVerbose("GameMaanger","_process","Camera X: " + str(position.x))
if not levelBoundary == 0 and position.x >= levelBoundary-960:
gameController.logWarn("GameManager","_process","Level boundary reached")
position.x = levelBoundary-960
followPlayer = false
else:
followPlayer = true
if MenuNode.visible or GameOverNode.visible:
gameController.gamePaused = true
if not gameController.gamePaused:
#print("==> CamX: " + String(position.x) + " | Boundary: " + String(levelBoundaryProcessed))
#print("==> PlayerPos: x" + String(get_parent().get_node("Player").position.x) + " | y" + String(get_parent().get_node("Player").position.y))
if followPlayer:
position.x = 826.032 + get_parent().get_node("Player").position.x
if position.x < 960:
position.x = 960
#if position.x <= levelBoundary and not levelBoundary == 0:
# position.x = levelBoundaryProcessed
if GameOverNode.visible and gameController.musicVolume == -5:
gameController.changeVolume("volumePaused")
if Input.is_action_just_pressed("ui_cancel"):
if not GameOverNode.visible:
if MenuNode.visible:
gameController.logInfo("GameManager","_process","ESC pressed, making pause menu invisible")
MenuNode.visible = false
gameController.gamePaused = false
gameController.changeVolume("volumeDefault")
else:
gameController.logInfo("GameManager","_process","ESC pressed, displaying pause menu")
MenuNode.visible = true
gameController.changeVolume("volumePaused")
func continueButtonPressed():
gameController.logCall("GameManager","continueButtonPressed",null)
gameController.logInfo("GameManager","continueButtonPressed","Continue button pressed, making pause menu invisible")
MenuNode.visible = false
gameController.gamePaused = false
gameController.changeVolume("volumeDefault")
func menuButtonPressed():
gameController.logCall("GameManager","menuButtonPressed",null)
gameController.logInfo("GameManager","menuButtonPressed","Menu button pressed, going back to main screen")
gameController.changeVolume("volumeDefault")
gameController.switchToMainScreen(false)
func retryButtonPressed():
gameController.logCall("GameManager","retryButtonPressed",null)
gameController.logInfo("GameManager","retryButtonPressed","Retry button pressed, reloading scene")
gameController.switchScene("res://Scenes/" + currentLevel + ".tscn")