From ebae6d04ffc95c6648e863d3de71835f6cd4be96 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 2 Jan 2021 14:54:57 +0100 Subject: Initial working commit --- Global.gd | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'Global.gd') diff --git a/Global.gd b/Global.gd index d9414c8..7371ff5 100644 --- a/Global.gd +++ b/Global.gd @@ -1,6 +1,10 @@ extends Node +signal level_map_updated() +signal game_won() + + const Levels = [ "Level_0001", "Level_0001", @@ -20,7 +24,10 @@ func _ready(): for level in self.Levels: self.Level_Map.push_back({ time = 0, - cleared_by = -1, + cleared_by = { # Network.player + idx = -1, + name = "" + }, meta = { path = "res://Levels/%s.tscn" % level, name = level, @@ -55,6 +62,51 @@ func end_level(instance_level): var time = stepify(instance_level.timer, 0.01) if (global_level.time == 0 or time < global_level.time): global_level.time = time - global_level.cleared_by = randi() & 1 + global_level.cleared_by = Network.player + for id in Network.players: + rpc_id(id, "_update_level_map", instance_level.idx, global_level) get_tree().change_scene("res://UI/LevelSelect.tscn") + + self.check_win() + + +remote func _update_level_map(idx, global_level): + self.Level_Map[idx] = global_level + emit_signal("level_map_updated") + + +func check_win(): + var has_won = false + + var cleared_levels_idx = [] + for idx in range(self.Level_Map.size()): + if self.Level_Map[idx].cleared_by.idx == Network.player.idx: + cleared_levels_idx.push_back(idx) + + var possible_winning_conditions = [ + [0, 1, 2], + [3, 4, 5], + [6, 7, 8], + + [0, 3, 6], + [1, 4, 7], + [2, 5, 8], + + [0, 4, 8], + [2, 4, 6], + ] + + # because there's no intersection method on arrays.. + for cond in possible_winning_conditions: + var has_cleared = 0 + for digit in cond: + if digit in cleared_levels_idx: + has_cleared += 1 + + if has_cleared == 3: + has_won = true + break + + if has_won: + emit_signal("game_won", Network.player) -- cgit v1.2.3