diff --git a/scripts/objective.gd b/scripts/objective.gd index 4d0aede..4768c2e 100644 --- a/scripts/objective.gd +++ b/scripts/objective.gd @@ -6,7 +6,7 @@ var active = false var right_active = false var activation_margin = 0.1 -var update_frequency = 1 # In secs. This isn't too fast-paced, so don't clog the network with updates every frame +var update_frequency = 2 # In secs. This isn't too fast-paced, so don't clog the network with updates every frame var update_count = 0 var master_team_right = null @@ -17,26 +17,15 @@ var build_rate = 1.5 var restart_count = 0 var restart_time = 15 -func _integrate_forces(state): - var rot = get_rotation().x +slave func set_status(status): + transform = status[0] + angular_velocity = status[1] - if active: - activation_margin = 0 - if rot > activation_margin: - active = true - right_active = false - if rot < -activation_margin: - active = true - right_active = true - if active: - if right_active == master_team_right: - # We DO own the correct one; display left counting, blue - get_node("../HUD/LeftTeam").add_color_override("font_color_shadow", friend_color) - get_node("../HUD/RightTeam").add_color_override("font_color_shadow", Color(0,0,0,0)) - else: - # We DO NOT own the correct one; display right counting, red - get_node("../HUD/LeftTeam").add_color_override("font_color_shadow", Color(0,0,0,0)) - get_node("../HUD/RightTeam").add_color_override("font_color_shadow", enemy_color) +func get_status(): + return [ + transform, + angular_velocity, + ] func _process(delta): @@ -56,17 +45,39 @@ func _process(delta): var full_name = "res://assets/objective-%s.png" % name get_node("MeshInstance").get_surface_material(0).albedo_texture = load(full_name) + # Check what's active + var rot = rotation.x + if active: + activation_margin = 0 + if rot > activation_margin: + active = true + right_active = false + if rot < -activation_margin: + active = true + right_active = true + if active: + if right_active == master_team_right: + # We DO own the correct one; display left counting, blue + get_node("../HUD/LeftTeam").add_color_override("font_color_shadow", friend_color) + get_node("../HUD/RightTeam").add_color_override("font_color_shadow", Color(0,0,0,0)) + else: + # We DO NOT own the correct one; display right counting, red + get_node("../HUD/LeftTeam").add_color_override("font_color_shadow", Color(0,0,0,0)) + get_node("../HUD/RightTeam").add_color_override("font_color_shadow", enemy_color) + # Count the percents if active: if right_active: right += delta * build_rate else: left += delta * build_rate - update_count += delta + update_count += delta / Engine.time_scale # This is important so we update at 100% as well if is_network_master() and update_count > update_frequency: update_count = 0 rset("left", left) rset("right", right) + if is_network_master(): + rpc_unreliable("set_status", get_status()) # Check for game over var game_over = false @@ -84,12 +95,12 @@ func _process(delta): if winner_right == master_team_right: text = "You win!!!" get_node("../HUD/Finish").set_text(text) - Engine.set_time_scale(0.1) + Engine.time_scale = 0.1 # You won't believe this, but because time_scale is 0.1 we have to multiply times 10 for proper timing - restart_count += delta * 10 + restart_count += delta / Engine.time_scale if restart_count > restart_time: + Engine.time_scale = 1 get_node("/root/Lobby").reset_state() - Engine.set_time_scale(1) # Render the percents var on_left = left