diff --git a/scripts/gui/ranking.gd b/scripts/gui/ranking.gd index 9cbc17b..8ee792f 100644 --- a/scripts/gui/ranking.gd +++ b/scripts/gui/ranking.gd @@ -42,24 +42,27 @@ func more_checkpoint(a: Participant, b: Participant) -> bool: var b_marble = b.get_marble() var out: bool - if ( - a_marble.has_finish() and b_marble.has_finish() - or a_marble.get_checkpoint_count() == b_marble.get_checkpoint_count() - ): + if a_marble.has_finish() and b_marble.has_finish(): out = a.get_rank() < b.get_rank() elif a_marble.has_finish(): out = true elif b_marble.has_finish(): out = false else: - if a_marble.has_explode() and b_marble.has_explode(): + if ( + (a_marble.has_explode() or a_marble.has_oob()) + and (b_marble.has_explode() or b_marble.has_oob()) + ): out = a.get_rank() < b.get_rank() - elif a_marble.has_explode(): + elif a_marble.has_explode() or a_marble.has_oob(): out = false - elif b_marble.has_explode(): + elif b_marble.has_explode() or b_marble.has_oob(): out = true else: - out = a_marble.get_checkpoint_count() > b_marble.get_checkpoint_count() + if a_marble.get_checkpoint_count() == b_marble.get_checkpoint_count(): + out = a.get_rank() < b.get_rank() + else: + out = a_marble.get_checkpoint_count() > b_marble.get_checkpoint_count() return out diff --git a/scripts/main.gd b/scripts/main.gd index e6f67f2..dbda8a4 100644 --- a/scripts/main.gd +++ b/scripts/main.gd @@ -17,6 +17,7 @@ var _current_marble_index := 0 var _time := 0.0 var _explosion_enabled := false var _race_has_started := false +var _lower_boundary = null # Variables used in explosion mode to check # if we need to generate another chunk of the race @@ -105,6 +106,7 @@ func _unhandled_input(event): KEY_R: if _mode == State.MODE_MARBLE: _race.generate_race(!_explosion_enabled) + _lower_boundary = get_lowest_piece(_race, true).global_transform.origin.y KEY_SPACE: for marble in _marbles: @@ -157,13 +159,39 @@ func get_highest_piece() -> Piece: var pieces = _race.get_children() if len(pieces) == 0: return null - var highest_piece = pieces[0] + var highest_piece = null for piece in pieces: - if piece.position.y > highest_piece.position.y: + if not piece is Piece: + continue + if highest_piece == null: + highest_piece = piece + elif piece.position.y > highest_piece.position.y: highest_piece = piece return highest_piece +func get_lowest_piece(piece_or_race, recursive: bool = false) -> Piece: + var pieces = piece_or_race.get_children() + if len(pieces) == 0: + return null + + # Find the lower piece from children of the current node3d + var lowest_piece = null + for piece in pieces: + if not piece is Piece: + continue + if lowest_piece == null: + lowest_piece = piece + elif piece.position.y < lowest_piece.position.y: + lowest_piece = piece + + if recursive: + var child_lowest_piece = get_lowest_piece(lowest_piece) + if child_lowest_piece != null: + lowest_piece = child_lowest_piece + return lowest_piece + + # Replace cameras with a new one func replace_camera(new_camera, old_cameras) -> void: # Ensure old cameras are removed from the current scene @@ -212,11 +240,12 @@ func set_mode(mode): # If no marbles exist if start_a_new_race: _podium.hide() - + await Fade.fade_out(1, Color.BLACK, "Diamond", false, false).finished _explosion_enabled = SettingsManager.get_value(&"marbles", &"explosion_enabled") as bool _race.generate_race(!_explosion_enabled) + _lower_boundary = get_lowest_piece(_race, true).global_transform.origin.y _overlay.reset() reset_position() @@ -316,6 +345,7 @@ func _process(delta): if lap_count > _old_lap_count: # Generate a chunk _race.generate_chunk() + _lower_boundary = get_lowest_piece(_race, true).global_transform.origin.y _old_lap_count = lap_count else: _panel_timer.hide() @@ -344,6 +374,16 @@ func _process(delta): _podium.set_second(_ranking._second_marble) _podium.set_third(_ranking._third_marble) + # Check if some marbles are out of bound + if _race_has_started and _lower_boundary != null: + for marble in _marbles: + if ( + marble.visible + and marble._state == Marble.State.ROLL + and marble.global_transform.origin.y + 100 < _lower_boundary + ): + marble.out_of_bound() + # Handle victory conditions on explosion mode func explosion_victory(_last_marble: Marble) -> bool: diff --git a/scripts/marble.gd b/scripts/marble.gd index bee4eef..e17f55f 100644 --- a/scripts/marble.gd +++ b/scripts/marble.gd @@ -86,9 +86,6 @@ func _process(_delta: float) -> void: _name.global_transform.origin = offset _score.global_transform.origin = offset + Vector3(-0.4, -0.2, 0) - if global_transform.origin.y < -10000: - out_of_bound() - func reset() -> void: _start()