- Introduced explicit typing to variables and functions across multiple scripts for better code clarity. - Specified 'void' as the return type for functions that do not return a value. - Removed redundant code in some scripts.
112 lines
2.8 KiB
GDScript
112 lines
2.8 KiB
GDScript
class_name GameStateManager extends Node
|
|
|
|
## THIS SHOULD NOT EXIST HERE BUT I AM NOT GOING TO MAKE A NEW CLASS FOR IT RIGHT NOW
|
|
@onready var default_cursor : Resource = preload("res://resources/cursors/pointer_a.png")
|
|
|
|
var placing_drone : bool = false
|
|
|
|
var level_timer : float = 0.0
|
|
|
|
var level_number : int = 0
|
|
|
|
var level_started : bool = false
|
|
var level_complete : bool = false
|
|
var game_over : bool = false
|
|
|
|
## Game Rules ##############################################################
|
|
|
|
# Nectar levels - Depleted by snails, increased by bee visits?? Or time, TBD
|
|
# TODO: Decide how to renew the nectar levels
|
|
# This is capped out at 10... Seems like a good amount
|
|
var flower_nectar_level : int = 10 :
|
|
get:
|
|
return flower_nectar_level
|
|
set(value):
|
|
if value > 10:
|
|
flower_nectar_level = 10
|
|
else:
|
|
flower_nectar_level = value
|
|
|
|
# Snails
|
|
var spawn_snails : bool = false
|
|
var snail_spawn_interval : float = 10.0
|
|
|
|
var gathered_nectar : int = 0 :
|
|
get:
|
|
return gathered_nectar
|
|
set(value):
|
|
gathered_nectar = value
|
|
if gathered_nectar > required_nectar and !level_complete:
|
|
game_win()
|
|
|
|
var required_nectar : int = 100
|
|
var level_par : int = 2
|
|
var drones_used : int = 0
|
|
var bees_available : int = 0
|
|
var dead_bees : int = 0 :
|
|
get:
|
|
return dead_bees
|
|
set(value):
|
|
dead_bees = value
|
|
if dead_bees >= bees_available and !game_over:
|
|
game_lose()
|
|
|
|
var level_points : int = 0 :
|
|
get:
|
|
return required_nectar * 100 - round(level_timer) * 10 - drones_used * 100
|
|
|
|
var judge_level_par : int = 0 :
|
|
get:
|
|
## Return an amount of points based on the difference between the number of drones_used and the level_par
|
|
## Using more drones than the par is bad and should result in less points
|
|
var diff : int = drones_used - level_par
|
|
if diff > 0:
|
|
return -diff * 100
|
|
else:
|
|
return 0
|
|
|
|
func _process(delta : float) -> void:
|
|
if level_started and !level_complete and !game_over:
|
|
level_timer += delta
|
|
|
|
func bee_died() -> void:
|
|
dead_bees += 1
|
|
|
|
# Add the nectar to the total gathered nectar
|
|
func add_nectar(nectar : int) -> void:
|
|
gathered_nectar += nectar
|
|
|
|
func add_drone() -> void:
|
|
drones_used += 1
|
|
|
|
func remove_drone() -> void:
|
|
drones_used -= 1
|
|
|
|
func game_start() -> void:
|
|
level_started = true
|
|
|
|
func game_win() -> void:
|
|
Log.pr("Game win")
|
|
level_complete = true
|
|
HighScoreMgr.add_honey(gathered_nectar)
|
|
HighScoreMgr.update_highscore(level_number, level_points)
|
|
HighScoreMgr.add_dead_bees(dead_bees)
|
|
HighScoreMgr.save()
|
|
|
|
func game_lose() -> void:
|
|
Log.pr("Game lose")
|
|
game_over = true
|
|
HighScoreMgr.add_dead_bees(dead_bees)
|
|
HighScoreMgr.save()
|
|
|
|
func reset() -> void:
|
|
level_timer = 0.0
|
|
level_started = false
|
|
level_complete = false
|
|
gathered_nectar = 0
|
|
drones_used = 0
|
|
dead_bees = 0
|
|
spawn_snails = false
|
|
|
|
func reset_cursor() -> void:
|
|
Input.set_custom_mouse_cursor(default_cursor, Input.CURSOR_ARROW, Vector2(8, 8))
|