diff --git a/project.godot b/project.godot index 818d873..8b69f5f 100644 --- a/project.godot +++ b/project.godot @@ -14,6 +14,10 @@ config/name="mv-moba" run/main_scene="res://scenes/lobby.tscn" config/icon="res://icon.png" +[autoload] + +util="*res://scripts/util.gd" + [input] move_forwards=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":44,"unicode":0,"echo":false,"script":null) diff --git a/scripts/heroes/1_wall.gd b/scripts/heroes/1_wall.gd index a41ea4f..c8f7475 100644 --- a/scripts/heroes/1_wall.gd +++ b/scripts/heroes/1_wall.gd @@ -13,7 +13,7 @@ func init(maker): player.connect("body_entered", self, "count_bodies", [player, 1]) player.connect("body_exited", self, "count_bodies", [player, -1]) - var master_player = get_node("/root/Level/Players/%d" % get_tree().get_network_unique_id()) + var master_player = util.get_master_player() var friendly = maker.player_info.is_right_team == master_player.player_info.is_right_team var color = maker.friend_color if friendly else maker.enemy_color diff --git a/scripts/heroes/5.gd b/scripts/heroes/5.gd index 93d881f..0a55245 100644 --- a/scripts/heroes/5.gd +++ b/scripts/heroes/5.gd @@ -2,6 +2,11 @@ extends "res://scripts/player.gd" onready var placement = preload("res://scripts/placement.gd").new(self, "res://scenes/heroes/5_portal.tscn") +var radius = 10 +# The spaces make the bracket centered, rather than on of the dots +var first_crosshair = " [..." +var second_crosshair = "...] " + # --- Godot overrides --- func _ready(): @@ -12,7 +17,10 @@ func _ready(): func _process(delta): if is_network_master(): - placement.place_input() + placement.place_input(radius) + var is_second = placement.placed.size() % 2 != 0 + var crosshair = second_crosshair if is_second else first_crosshair + get_node("MasterOnly/Crosshair").set_text(crosshair) func _exit_tree(): ._exit_tree() diff --git a/scripts/heroes/5_portal.gd b/scripts/heroes/5_portal.gd index 278c040..640508e 100644 --- a/scripts/heroes/5_portal.gd +++ b/scripts/heroes/5_portal.gd @@ -4,8 +4,15 @@ var portal_charge = 15 var other var index -var first_color = Color("#d14013") -var second_color = Color("#ecb521") +var enemy_colors = [ + Color("#d14013"), + Color("#ecb521"), +] + +var friend_colors = [ + Color("#1209c4"), + Color("#2066e7"), +] func _ready(): for player in get_node("/root/Level/Players").get_children(): @@ -17,7 +24,9 @@ func init(maker): index = maker_portals.size() # No -1, because we haven't actually been added to the array yet # If index is odd, we're the second (1, 3...), if even, first (0, 4...) var second = index % 2 != 0 - var color = second_color if second else first_color + var is_friend = util.is_friendly(maker) + var color_set = friend_colors if is_friend else enemy_colors + var color = color_set[int(second)] var mat = SpatialMaterial.new() color.a = 0.5 @@ -44,12 +53,14 @@ func find_other(): return null func portal(player): - if find_other(): - var spawn_distance = 2 - # Find a sane place to spawn - # -Z is in the direction of the portal - # X is enough away from the portal to avoid infinite loop - # With both axes, gravity could never bring us to hit the portal - var to = other.to_global(Vector3(spawn_distance,0,-spawn_distance)) - player.set_translation(to) + if player.player_info.is_right_team == maker_node.player_info.is_right_team: + if find_other(): + var spawn_distance = 2 + # Find a sane place to spawn + # -Z is in the direction of the portal + # X is enough away from the portal to avoid infinite loop + # With both axes, gravity could never bring us to hit the portal + var to = other.to_global(Vector3(spawn_distance,0,-spawn_distance)) + player.set_translation(to) + maker_node.switch_charge += portal_charge diff --git a/scripts/objective.gd b/scripts/objective.gd index 0bdb151..ec1b5f8 100644 --- a/scripts/objective.gd +++ b/scripts/objective.gd @@ -41,7 +41,7 @@ func _process(delta): # Figure out what team we're on # We have to do this here because we never know when the master player will actually be added if master_team_right == null: - var master_player = get_node("/root/Level/Players/%d" % get_tree().get_network_unique_id()) + var master_player = util.get_master_player() master_team_right = master_player.player_info.is_right_team friend_color = master_player.friend_color enemy_color = master_player.enemy_color diff --git a/scripts/placeable.gd b/scripts/placeable.gd index bab6911..97e350a 100644 --- a/scripts/placeable.gd +++ b/scripts/placeable.gd @@ -1,6 +1,7 @@ extends StaticBody var maker_node +var material func _ready(): get_node("CollisionShape").disabled = true @@ -8,20 +9,25 @@ func _ready(): func init(maker): maker_node = maker - var mat = get_node("MeshInstance").get_surface_material(0) - if not mat: - mat = SpatialMaterial.new() - get_node("MeshInstance").set_surface_material(0, mat) - mat.flags_transparent = true - mat.albedo_color.a = 0.5 + material = get_node("MeshInstance").get_surface_material(0) + if not material: + material = SpatialMaterial.new() + get_node("MeshInstance").set_surface_material(0, material) + material.flags_transparent = true + material.albedo_color.a = 0.5 func place(): # Originally, the ghost is disabled to avoid weird physics get_node("CollisionShape").disabled = false - get_node("MeshInstance").get_surface_material(0).flags_transparent = false + material.flags_transparent = false func make_last(): - var mat = get_node("MeshInstance").get_surface_material(0) - mat.flags_transparent = true - mat.albedo_color.a = 0.9 + material.flags_transparent = true + material.albedo_color.a = 0.9 + +func out_of_range(): + material.albedo_color.a = 0.2 + +func within_range(): + material.albedo_color.a = 0.5 diff --git a/scripts/placement.gd b/scripts/placement.gd index d0bd61c..67b21d1 100644 --- a/scripts/placement.gd +++ b/scripts/placement.gd @@ -24,7 +24,7 @@ func _init(parent, scene_path): set_network_master(int(player.get_name())) scene = load(scene_path) -func place_input(): +func place_input(radius=-1): # We allow you to just click to place, without needing to press E var confirm = Input.is_action_just_pressed(confirm_action) @@ -47,6 +47,13 @@ func place_input(): if is_placing or confirm: position_placement(placing_node) + if radius > 0: # A radius is specified + var distance = placing_node.get_translation() - player.get_translation() + if distance.length() > radius: + placing_node.out_of_range() + confirm = false + else: + placing_node.within_range() if confirm: # Order matters here: confirm_placement resets placing_node so we have to do anything with it first @@ -115,7 +122,6 @@ sync func remove_placed(index): func create(): var node = scene.instance() - print(node) player.get_node("/root/Level").add_child(node) # We have to call_deferred because we're `load`ing instead of `preload`ing. TODO: preload? node.init(player) diff --git a/scripts/player.gd b/scripts/player.gd index 1f5ae48..452c65c 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -148,7 +148,7 @@ func event_to_obj(event): return d func begin(): - master_player = get_node("/root/Level/Players/%d" % get_tree().get_network_unique_id()) + master_player = util.get_master_player() # Set color to blue (teammate) or red (enemy) var color if master_player.player_info.is_right_team == player_info.is_right_team: diff --git a/scripts/util.gd b/scripts/util.gd new file mode 100644 index 0000000..70b6263 --- /dev/null +++ b/scripts/util.gd @@ -0,0 +1,8 @@ +extends Node + +func get_master_player(): + return get_node("/root/Level/Players/%d" % get_tree().get_network_unique_id()) + +func is_friendly(player): + return player.player_info.is_right_team == get_master_player().player_info.is_right_team +