diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-06-05 04:38:44 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-06-05 04:38:44 -0600 |
commit | e4423cc8490b7f5ec3449f568bf64e81f4d03248 (patch) | |
tree | 167f178e1197c21260f70eaffd0a3375742f3447 /src/tools/score_manager | |
parent | 36abc689d783774ce4f2d7b5a1bb621d8684be45 (diff) |
add more food types, refactored code and tidy up stuff
Diffstat (limited to 'src/tools/score_manager')
-rw-r--r-- | src/tools/score_manager/scenes/ScoreLabel.tscn | 2 | ||||
-rw-r--r-- | src/tools/score_manager/scripts/score_label.gd | 3 | ||||
-rw-r--r-- | src/tools/score_manager/scripts/score_manager.gd | 26 |
3 files changed, 26 insertions, 5 deletions
diff --git a/src/tools/score_manager/scenes/ScoreLabel.tscn b/src/tools/score_manager/scenes/ScoreLabel.tscn index 365aff1..0a078e1 100644 --- a/src/tools/score_manager/scenes/ScoreLabel.tscn +++ b/src/tools/score_manager/scenes/ScoreLabel.tscn @@ -18,7 +18,7 @@ margin_right = 12.0 margin_bottom = 13.0 custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) custom_fonts/font = ExtResource( 1 ) -text = "x1" +text = "+1" [node name="Timer" type="Timer" parent="Hbox/Label"] one_shot = true diff --git a/src/tools/score_manager/scripts/score_label.gd b/src/tools/score_manager/scripts/score_label.gd index f1ccb9d..13a34c8 100644 --- a/src/tools/score_manager/scripts/score_label.gd +++ b/src/tools/score_manager/scripts/score_label.gd @@ -14,7 +14,7 @@ var texture: Dictionary = { } var alive_time: float = 2.0 -var fmt: String = "x%s" +var fmt: String = "+%s" var points: int @@ -25,7 +25,6 @@ func _ready(): func set_properties(_points: int, color: Color, location: Vector2, type: int=-1) -> void: - print("Constructing") points = _points label.text = fmt % points label.add_color_override("font_color", color) diff --git a/src/tools/score_manager/scripts/score_manager.gd b/src/tools/score_manager/scripts/score_manager.gd index 27a8dd4..492ceb5 100644 --- a/src/tools/score_manager/scripts/score_manager.gd +++ b/src/tools/score_manager/scripts/score_manager.gd @@ -11,6 +11,7 @@ var mutation_stats: Array = [ ] var last_snake_pos: Vector2 = Vector2.ZERO +var snake_location_offset: Vector2 = Vector2(8.0, 8.0) func _ready(): @@ -55,7 +56,7 @@ func _spawn_added_segment_text(amount: int) -> void: if amount > 0: var label: ScoreLabel = SCORE_LABEL.instance() add_child(label) - label.set_properties(amount, Color.green, last_snake_pos, ScoreLabel.Type.BODY_SEGMENT) + label.set_properties(amount, Color.green, last_snake_pos + snake_location_offset, ScoreLabel.Type.BODY_SEGMENT) func _on_snake_path_new_point(coordinates: Vector2) -> void: @@ -63,5 +64,26 @@ func _on_snake_path_new_point(coordinates: Vector2) -> void: func _on_game_over() -> void: - print("Show comparison.") + var max_stats: Stats = _get_max_stats() + SaveData.save_data(max_stats) Event.emit_signal("display_stats", initial_stats, stats, mutation_stats) + + +func _get_max_stats() -> Stats: + var old_stats_dict: Dictionary = initial_stats.get_stats() + var new_stats_dict: Dictionary = stats.get_stats() + var max_stats: Stats = Stats.new() + var max_stats_dict: Dictionary = max_stats.get_stats() + var bool_stats: Array = [ + "trait_dash", + "trait_slow", + "trait_jump" + ] + + for i in old_stats_dict: + if bool_stats.has(i): + max_stats_dict[i] = old_stats_dict[i] or new_stats_dict[i] + else: + max_stats_dict[i] = max(old_stats_dict[i], new_stats_dict[i]) + max_stats.set_stats(max_stats_dict) + return max_stats |