summaryrefslogtreecommitdiff
path: root/Game/Client.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Game/Client.gd')
-rw-r--r--Game/Client.gd75
1 files changed, 75 insertions, 0 deletions
diff --git a/Game/Client.gd b/Game/Client.gd
new file mode 100644
index 0000000..77ce500
--- /dev/null
+++ b/Game/Client.gd
@@ -0,0 +1,75 @@
+extends Node
+
+
+var state: State
+var stage: Stage
+var player: Player = Player.new()
+
+
+func update_player(local_player: Player):
+ player = local_player
+ Network.players[multiplayer.get_unique_id()] = local_player
+
+
+func initialize_stage(current_stage: Stage):
+ stage = current_stage
+ player = Player.new()
+
+
+func place_tower(tower: Tower, position: Vector2):
+ tower.owner_id = multiplayer.get_unique_id()
+
+ stage.place_tower(tower, position)
+ Network.place_tower.rpc(Network.to_rpc_object(tower), position)
+
+ player.towers[position] = tower
+ player.score += 1
+ update_player(player)
+
+
+func remove_tower(tower: Tower):
+ if tower.owner_id == multiplayer.get_unique_id():
+ destroy_tower(tower)
+ player.score -= 1
+ update_player(player)
+
+
+func destroy_tower(tower: Tower):
+ stage.destroy_tower(tower)
+ Network.destroy_tower.rpc(Network.to_rpc_object(tower))
+
+ player.towers.erase(tower.global_position)
+ update_player(player)
+
+
+func select_tower(tower: Tower):
+ if tower.owner_id == multiplayer.get_unique_id():
+ tower.is_selected = true
+
+
+func deselect_tower():
+ if not Tower.selected_towers.is_empty():
+ for tower in Tower.selected_towers:
+ tower.is_selected = false
+
+
+func spawn_unit(unit: Unit, spawn: Spawn):
+ unit.global_position = spawn.spawn_position
+ unit.target = spawn.next_node
+ unit.hp = 20000
+ unit.speed = randi_range(50, 150)
+
+ stage.spawn_unit(unit, spawn)
+ Network.spawn_unit.rpc(Network.to_rpc_object(unit), Network.to_rpc_object(spawn))
+
+
+func array_intersect(first, second):
+ var compare = {}
+ for value in first:
+ compare[value] = true
+
+ for value in second:
+ if compare.get(value, false):
+ return true
+
+ return false