Add utility strings, update game state with drone count and points calculation.
This commit is contained in:
parent
d879ca30bd
commit
491395e6b9
7 changed files with 105 additions and 5 deletions
|
|
@ -1,7 +1,9 @@
|
|||
class_name GameStateManager extends Node
|
||||
|
||||
var level_timer : float = 0.0
|
||||
|
||||
var level_started : bool = false
|
||||
var level_complete : bool = false
|
||||
var level_complete_time : float = 0.0
|
||||
|
||||
var gathered_nectar : int = 0 :
|
||||
get:
|
||||
|
|
@ -13,13 +15,37 @@ var gathered_nectar : int = 0 :
|
|||
|
||||
@export var required_nectar : int = 100
|
||||
@export var level_par : int = 2
|
||||
@export var level_text : String = ""
|
||||
@export var drones_used : int = 0
|
||||
|
||||
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 = drones_used - level_par
|
||||
if diff > 0:
|
||||
return -diff * 100
|
||||
else:
|
||||
return 0
|
||||
|
||||
func _process(delta):
|
||||
if level_started and !level_complete:
|
||||
level_timer += delta
|
||||
|
||||
func add_nectar():
|
||||
gathered_nectar += 1
|
||||
|
||||
func add_drone():
|
||||
drones_used += 1
|
||||
|
||||
func remove_drone():
|
||||
drones_used -= 1
|
||||
|
||||
func game_start():
|
||||
pass
|
||||
level_started = true
|
||||
|
||||
func game_win():
|
||||
Log.pr("Game win")
|
||||
|
|
|
|||
37
utility/utility_strings.gd
Normal file
37
utility/utility_strings.gd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
class_name StringUtilities extends Node
|
||||
|
||||
func seconds_to_hms(seconds: float) -> String:
|
||||
var ms = fmod(seconds, 1) * 100
|
||||
var s = fmod(seconds, 60)
|
||||
var m = fmod(seconds, 3600) / 60
|
||||
|
||||
var formatted : String = "%02d:%02d:%02d" % [m, s, ms]
|
||||
|
||||
return formatted
|
||||
|
||||
####
|
||||
## Formats the given number with commas every 3 digits.
|
||||
####
|
||||
func format_number(number: int) -> String:
|
||||
# Handle negative numbers by adding the "minus" sign in advance, as we discard it
|
||||
# when looping over the number.
|
||||
var formatted_number := "-" if sign(number) == -1 else ""
|
||||
var index := 0
|
||||
var number_string := str(abs(number))
|
||||
|
||||
for digit in number_string:
|
||||
formatted_number += digit
|
||||
|
||||
var counter := number_string.length() - index
|
||||
|
||||
# Don't add a comma at the end of the number, but add a comma every 3 digits
|
||||
# (taking into account the number's length).
|
||||
if counter >= 2 and counter % 3 == 1:
|
||||
formatted_number += ","
|
||||
|
||||
index += 1
|
||||
|
||||
return formatted_number
|
||||
|
||||
func float_to_percentage(value: float) -> String:
|
||||
return "%d%%" % int(value * 100)
|
||||
Loading…
Add table
Add a link
Reference in a new issue