summaryrefslogtreecommitdiff
path: root/Game
diff options
context:
space:
mode:
Diffstat (limited to 'Game')
-rw-r--r--Game/Client.gd30
-rw-r--r--Game/Network.gd9
-rw-r--r--Game/Selection/multi_select_area.gd3
-rw-r--r--Game/States/Build/StateBuild.gd9
4 files changed, 34 insertions, 17 deletions
diff --git a/Game/Client.gd b/Game/Client.gd
index 60efbb8..98a8e6c 100644
--- a/Game/Client.gd
+++ b/Game/Client.gd
@@ -3,6 +3,10 @@ extends Node
signal stage_state_changed(state: State)
+@warning_ignore("unused_signal")
+signal placed_tower(tower: Tower)
+
+
var state: State :
set(value):
state = value
@@ -31,6 +35,14 @@ func place_tower(tower: Tower):
tower.owner_id = network_id
tower.name = "Tower@" + str(network_id) + "@" + str(Time.get_ticks_usec())
+ tower.attack_range = [
+ current_stage.map.tile_set.tile_size.x * 2,
+ current_stage.map.tile_set.tile_size.x * 3,
+ current_stage.map.tile_set.tile_size.x * 4,
+ ].pick_random()
+ tower.attack_power = [1, 2, 3, 4].pick_random()
+ tower.attack_speed = [1, 2, 3, 4].pick_random()
+
current_stage.place_tower.rpc(inst_to_dict(tower.to_network_data()))
@@ -41,7 +53,7 @@ func remove_tower(tower: Tower):
func destroy_tower(tower: Tower):
current_stage.destroy_tower(tower)
- Network.destroy_tower.rpc(tower.global_position)
+ Network.destroy_tower.rpc(inst_to_dict(tower.to_network_data()))
player.towers.erase(tower.global_position)
@@ -51,10 +63,14 @@ func select_tower(tower: Tower):
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 multi_select(layer: int):
+ var selection_area = preload("res://Game/Selection/MultiSelectArea.tscn").instantiate()
+ selection_area.set_collision_mask_value(layer, true)
+ selection_area.select.connect(func(nodes):
+ for node in nodes:
+ Client.select_tower(node)
+ )
+ get_tree().current_scene.add_child(selection_area)
func update_tower(path: NodePath, data: Tower.NetworkData):
@@ -71,8 +87,8 @@ func spawn_unit(unit: Unit, spawn: Spawn, overwrite_target: PathNode = null):
unit.global_position = spawn.spawn_position
unit.target = spawn.next_node
- unit.hp = randi_range(50, 150) #20000b
- unit.speed = randi_range(100, 150)
+ unit.hp = randi_range(5, 10) #20000b
+ unit.speed = randi_range(50, 150)
if overwrite_target:
unit.target = overwrite_target
diff --git a/Game/Network.gd b/Game/Network.gd
index 5a435b7..be5bb20 100644
--- a/Game/Network.gd
+++ b/Game/Network.gd
@@ -114,10 +114,11 @@ func update_player(id: int, remote_data: Dictionary):
@rpc("any_peer")
#func destroy_tower(remote_tower: Dictionary):
-func destroy_tower(position: Vector2):
- var owner_id = multiplayer.get_remote_sender_id()
- var player = get_player(owner_id)
- var tower = player.towers.get(position)
+func destroy_tower(remote_data: Dictionary):
+ var data: Tower.NetworkData = dict_to_inst(remote_data)
+ var remote_tower = Tower.from_network_data(data)
+ var player = get_player(remote_tower.owner_id)
+ var tower = player.towers.get(remote_tower.global_position)
Client.current_stage.destroy_tower(tower)
diff --git a/Game/Selection/multi_select_area.gd b/Game/Selection/multi_select_area.gd
index c3cc902..88e4f7f 100644
--- a/Game/Selection/multi_select_area.gd
+++ b/Game/Selection/multi_select_area.gd
@@ -5,7 +5,8 @@ signal select(nodes: Array)
func _ready() -> void:
- var camera_rect = Client.current_stage.get_node("Camera").get_rect()
+ var camera: Camera = get_viewport().get_camera_2d()
+ var camera_rect = camera.get_rect()
global_position = camera_rect.position + camera_rect.size / 2
diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd
index dee5084..e7f122d 100644
--- a/Game/States/Build/StateBuild.gd
+++ b/Game/States/Build/StateBuild.gd
@@ -7,6 +7,10 @@ static var current_builder_element: BuilderElement
func _state_enter():
%BuildGrid.visible = true
+
+ if Tower.selected_towers:
+ for tower in Tower.selected_towers.duplicate():
+ tower.is_selected = false
func _state_exit():
@@ -20,11 +24,6 @@ func _state_input(event: InputEvent):
var placed_tower = current_builder_element.element.instantiate() as Tower
placed_tower.global_position = current_builder_element.global_position
- placed_tower.attack_range = [
- Client.current_stage.map.tile_set.tile_size.x * 2,
- Client.current_stage.map.tile_set.tile_size.x * 3,
- Client.current_stage.map.tile_set.tile_size.x * 4,
- ].pick_random()
Client.place_tower(placed_tower)