diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-06-05 14:09:41 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-06-05 14:09:41 -0600 |
commit | 14538d486de312af41ce012836861468b8fb7897 (patch) | |
tree | 569d09c43fd7724a5fbb0898f5c1d1db3fd64b3d /src/tools/score_manager/scripts | |
parent | 4b42a8ba26f21e2c6c766fa747c8b93a115a53b2 (diff) |
finish all necessary for playability
Diffstat (limited to 'src/tools/score_manager/scripts')
-rw-r--r-- | src/tools/score_manager/scripts/score_label.gd | 14 | ||||
-rw-r--r-- | src/tools/score_manager/scripts/score_manager.gd | 79 |
2 files changed, 87 insertions, 6 deletions
diff --git a/src/tools/score_manager/scripts/score_label.gd b/src/tools/score_manager/scripts/score_label.gd index 13a34c8..633ea0e 100644 --- a/src/tools/score_manager/scripts/score_label.gd +++ b/src/tools/score_manager/scripts/score_label.gd @@ -6,11 +6,17 @@ onready var timer: Timer = $Hbox/Label/Timer onready var texture_rect: TextureRect = $Hbox/Center/VBox/TextureRect enum Type { - BODY_SEGMENT + BODY_SEGMENT, + DASH_SEGMENT, + SLOW_SEGMENT, + JUMP_SEGMENT } var texture: Dictionary = { - Type.BODY_SEGMENT: preload("res://ui/hud/progress_bars/sprites/grow_progress_icon.png") + Type.BODY_SEGMENT: preload("res://ui/hud/progress_bars/sprites/grow/grow_progress_icon.png"), + Type.DASH_SEGMENT: preload("res://ui/hud/progress_bars/sprites/dash/dash_progress_icon.png"), + Type.SLOW_SEGMENT: preload("res://ui/hud/progress_bars/sprites/slow/slow_progress_icon.png"), + Type.JUMP_SEGMENT: preload("res://ui/hud/progress_bars/sprites/jump/jump_progress_icon.png") } var alive_time: float = 2.0 @@ -31,9 +37,7 @@ func set_properties(_points: int, color: Color, location: Vector2, type: int=-1) set_global_position(location) if type != -1: texture_rect.visible = true - match type: - Type.BODY_SEGMENT: - texture_rect.texture = texture[type] + texture_rect.texture = texture[type] label.update() diff --git a/src/tools/score_manager/scripts/score_manager.gd b/src/tools/score_manager/scripts/score_manager.gd index 95fcfce..53df3ce 100644 --- a/src/tools/score_manager/scripts/score_manager.gd +++ b/src/tools/score_manager/scripts/score_manager.gd @@ -10,8 +10,15 @@ var mutation_stats: Array = [ Stats.new() ] +var special_values: Dictionary = { + FoodSpecial.Type.BUNNY: [Global.POINTS_TO_DASH, Color.gray, ScoreLabel.Type.DASH_SEGMENT], + FoodSpecial.Type.TURTLE: [Global.POINTS_TO_SLOW, Color.green, ScoreLabel.Type.SLOW_SEGMENT], + FoodSpecial.Type.FROG: [Global.POINTS_TO_JUMP, Color.greenyellow, ScoreLabel.Type.JUMP_SEGMENT] +} + var last_snake_pos: Vector2 = Vector2.ZERO var snake_location_offset: Vector2 = Vector2(8.0, 8.0) +var special_snake_location_offset: Vector2 = - snake_location_offset func _ready(): @@ -21,12 +28,37 @@ func _ready(): func _on_food_eaten(properties: Dictionary) -> void: + var is_special: bool = properties["special"] + var type: int = properties["type"] var points: int = properties["points"] + var special_points: int = properties["special_points"] var location: Vector2 = properties["global_position"] - var amount_to_grow: int = _process_points(points) + var amount_to_grow: int + var special_amount_to_grow: int + + amount_to_grow = _process_points(points) _spawn_added_score_text(points, location) _spawn_added_segment_text(amount_to_grow) + if is_special: + special_amount_to_grow = _process_special_points(special_points, type) + # _spawn_added_score_text(points, location) + _spawn_added_special_segment_text(special_amount_to_grow, type) + _check_if_unlocked(type) + + +func _check_if_unlocked(type: int) -> void: + match type: + FoodSpecial.Type.BUNNY: + if not stats.trait_dash and stats.dash_segments != 0: + stats.trait_dash = true + FoodSpecial.Type.TURTLE: + if not stats.trait_slow and stats.slow_segments != 0: + stats.trait_slow = true + FoodSpecial.Type.FROG: + if not stats.trait_jump and stats.jump_segments != 0: + stats.trait_jump = true + func _process_points(points: int) -> int: var score_to_grow: int = (stats.segments + 1) * Global.POINTS_TO_GROW - stats.points @@ -46,6 +78,44 @@ func _process_points(points: int) -> int: return amount_to_grow +func _process_special_points(points: int, type: int) -> int: + var score_to_grow: int + var amount_to_grow: int = 0 + var growth_progress: int + + match type: + FoodSpecial.Type.BUNNY: + score_to_grow = (stats.dash_segments + 1) * special_values[type][0] - stats.dash_points + stats.dash_points += points + FoodSpecial.Type.TURTLE: + score_to_grow = (stats.slow_segments + 1) * special_values[type][0] - stats.slow_points + stats.slow_points += points + FoodSpecial.Type.FROG: + score_to_grow = (stats.jump_segments + 1) * special_values[type][0] - stats.jump_points + stats.jump_points += points + + if points >= score_to_grow: + amount_to_grow += 1 + points -= score_to_grow + # maybe be careful with this + amount_to_grow += points / special_values[type][0] + + match type: + FoodSpecial.Type.BUNNY: + stats.dash_segments += amount_to_grow + growth_progress = special_values[type][0] - ((stats.dash_segments + 1) * special_values[type][0] - stats.dash_points) + Event.emit_signal("snake_dash_progress", growth_progress) + FoodSpecial.Type.TURTLE: + stats.slow_segments += amount_to_grow + growth_progress = special_values[type][0] - ((stats.slow_segments + 1) * special_values[type][0] - stats.slow_points) + Event.emit_signal("snake_slow_progress", growth_progress) + FoodSpecial.Type.FROG: + stats.jump_segments += amount_to_grow + growth_progress = special_values[type][0] - ((stats.jump_segments + 1) * special_values[type][0] - stats.jump_points) + Event.emit_signal("snake_jump_progress", growth_progress) + return amount_to_grow + + func _spawn_added_score_text(points: int, location: Vector2) -> void: var label: ScoreLabel = SCORE_LABEL.instance() add_child(label) @@ -59,6 +129,13 @@ func _spawn_added_segment_text(amount: int) -> void: label.set_properties(amount, Color.green, last_snake_pos + snake_location_offset, ScoreLabel.Type.BODY_SEGMENT) +func _spawn_added_special_segment_text(amount: int, type: int)-> void: + if amount > 0: + var label: ScoreLabel = SCORE_LABEL.instance() + add_child(label) + label.set_properties(amount, special_values[type][1], last_snake_pos + special_snake_location_offset, special_values[type][2]) + + func _on_snake_path_new_point(coordinates: Vector2) -> void: last_snake_pos = coordinates |