Skip to content

Commit

Permalink
Movement of countries is now synchronized across the network.
Browse files Browse the repository at this point in the history
  • Loading branch information
ra314 committed Aug 26, 2021
1 parent 9741d8d commit 264f6ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Scripts/Levels/Level Components/Country.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ func _input_event(viewport, event, shape_idx):
if event.is_action_just_released():
self.on_click(event)

func move_to(duration, destination):
get_node("Tween").interpolate_property(self, "position", position, destination, duration)
func move_to_location_with_duration(location, duration):
get_node("Tween").interpolate_property(self, "position", position, location, duration)

# Moving to a country and back
func move_to_country(destination_country):
move_to_location_with_duration(destination_country.position, destination_movement_duration)
get_node("Tween").interpolate_callback(self, destination_movement_duration, "move_to_location_with_duration", position, origin_movement_duration)
get_node("Tween").start()

func on_click(event):
Expand Down Expand Up @@ -144,22 +149,23 @@ func on_click(event):
# And if it is a neighbour and the attacker has sufficient troops, then attack
var attacker = Game_Manager.selected_country
if (attacker in connected_countries) and (attacker.num_troops > num_troops):
# Movement animation
attacker.move_to(destination_movement_duration, position)
attacker.get_node("Tween").interpolate_callback(attacker, destination_movement_duration, "move_to", origin_movement_duration, attacker.position)

# Attack logic that changes troops and updates labels
num_troops = attacker.num_troops - num_troops
attacker.num_troops = 1
update_labels()
attacker.update_labels()

change_ownership_to(attacker.belongs_to)
if Game_Manager.is_attack_over():
Game_Manager.change_to_reinforcement()

Game_Manager.selected_country = null

# Movement animation
attacker.move_to_country(self)
# Networked component of movement animation
if Game_Manager._root.online_game:
Game_Manager.move_country_across_network(attacker.country_name, country_name)

# Phase change
if Game_Manager.is_attack_over():
Game_Manager.change_to_reinforcement()
# Check if the opponent has any troops left
if Game_Manager.get_next_player().get_num_troops() == 0:
Game_Manager.end_game()
Expand Down
8 changes: 8 additions & 0 deletions Scripts/Levels/Level Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ remote func synchronise_meta_info(_curr_player_index, _round_number, _game_start
curr_player_index = _curr_player_index
curr_player = players.values()[curr_player_index]
update_labels()

# Below functions are for the movement of countries during the attack phase to propagate across network
func move_country_across_network(origin_country_name, destination_country_name):
rpc_id(get_next_player().network_id, "move_to_country", origin_country_name, destination_country_name)
synchronize(get_next_player().network_id)

remote func move_to_country(origin_country_name, destination_country_name):
all_countries[origin_country_name].move_to_country(all_countries[destination_country_name])
#######

const sync_period = 2
Expand Down

0 comments on commit 264f6ff

Please sign in to comment.