Browse Source

Add util.gd; Make Hero 5 portals only for friends

master
Luna 7 years ago
parent
commit
67c74db3e5
9 changed files with 70 additions and 27 deletions
  1. +4
    -0
      project.godot
  2. +1
    -1
      scripts/heroes/1_wall.gd
  3. +9
    -1
      scripts/heroes/5.gd
  4. +22
    -11
      scripts/heroes/5_portal.gd
  5. +1
    -1
      scripts/objective.gd
  6. +16
    -10
      scripts/placeable.gd
  7. +8
    -2
      scripts/placement.gd
  8. +1
    -1
      scripts/player.gd
  9. +8
    -0
      scripts/util.gd

+ 4
- 0
project.godot View File

@ -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)


+ 1
- 1
scripts/heroes/1_wall.gd View File

@ -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


+ 9
- 1
scripts/heroes/5.gd View File

@ -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()


+ 22
- 11
scripts/heroes/5_portal.gd View File

@ -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

+ 1
- 1
scripts/objective.gd View File

@ -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


+ 16
- 10
scripts/placeable.gd View File

@ -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

+ 8
- 2
scripts/placement.gd View File

@ -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)


+ 1
- 1
scripts/player.gd View File

@ -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:


+ 8
- 0
scripts/util.gd View File

@ -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

Loading…
Cancel
Save