Skip to content

Commit

Permalink
refactor(score): update hud when score is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpo committed Jul 18, 2022
1 parent 1f078a9 commit cdfaf90
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Game/Scripts/Score.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const CONTAMINATION_POINTS := 2
const CONTAMINATED_CATCH_POINTS := -1
const UNCONTAMINATED_CATCH_POINTS := 1

var _score := 0
var _score: int setget _set_score
var _number_of_bears: int
var _hud : Control

Expand All @@ -21,10 +21,14 @@ func _ready() -> void:
func init(number_of_bears: int, hud: Control):
_number_of_bears = number_of_bears
_hud = hud
self._score = 0

func _set_score(new_value: int) -> void:
_score = new_value
_hud.update_score(_score)
print_score()

func print_score() -> void:
_hud.update_score(_score)
Logger.debug("Score: %d" % _score)

func _update_number_of_bears() -> void:
Expand All @@ -38,17 +42,14 @@ func _round_ending() -> void:
print_score()

func _on_contaminated_non_playable_bear_caught() -> void:
_score += CONTAMINATED_CATCH_POINTS
print_score()
self._score += CONTAMINATED_CATCH_POINTS

func _on_uncontaminated_non_playable_bear_caught() -> void:
_score += UNCONTAMINATED_CATCH_POINTS
print_score()
self._score += UNCONTAMINATED_CATCH_POINTS

func _on_wherebear_caught() -> void:
_round_ending()

func _on_non_playable_bear_contaminated() -> void:
_score += CONTAMINATION_POINTS
self._score += CONTAMINATION_POINTS
_update_number_of_bears()
print_score()

0 comments on commit cdfaf90

Please sign in to comment.