Browse Source

Add hero switching interface, tweak charge rate

master
Luna 7 years ago
parent
commit
1f40515f6e
3 changed files with 109 additions and 18 deletions
  1. +72
    -0
      scenes/HeroSelect.tscn
  2. +5
    -4
      scenes/player.tscn
  3. +32
    -14
      scripts/player.gd

+ 72
- 0
scenes/HeroSelect.tscn View File

@ -0,0 +1,72 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/hero_select.gd" type="Script" id=1]
[node name="HeroSelect" type="ColorRect"]
pause_mode = 2
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
color = Color( 0.097229, 0.104696, 0.105469, 1 )
_sections_unfolded = [ "Anchor", "Margin", "Material", "Pause", "Visibility" ]
[node name="Hero" type="OptionButton" parent="." index="0"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -192.0
margin_top = -103.0
margin_right = 191.0
margin_bottom = -6.0
rect_rotation = -0.0115615
rect_pivot_offset = Vector2( 0, 0 )
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
action_mode = 0
enabled_focus_mode = 2
shortcut = null
group = null
flat = false
align = 0
selected = -1
items = [ ]
script = ExtResource( 1 )
[node name="Confirm" type="Button" parent="." index="1"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -163.0
margin_top = 21.0
margin_right = 163.0
margin_bottom = 79.0
rect_pivot_offset = Vector2( 0, 0 )
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "Select Hero"
flat = false
align = 1

+ 5
- 4
scenes/player.tscn View File

@ -152,15 +152,16 @@ anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -20.0
margin_top = -108.0
margin_right = 20.0
margin_bottom = -94.0
margin_left = -62.0
margin_top = -98.0
margin_right = 61.0
margin_bottom = -84.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
align = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1


+ 32
- 14
scripts/player.gd View File

@ -15,7 +15,7 @@ var air_friction = 0.98
var player_info # Set by lobby
var switch_charge = 0
var movement_charge = 0.0015
var movement_charge = 0.15 # In percent per meter (except when heroes change that)
var debug_node
@ -61,12 +61,7 @@ func _input(event):
# Toggle mouse capture:
if Input.is_action_pressed("toggle_mouse_capture"):
if (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
view_sensitivity = 0
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
view_sensitivity = 0.25
toggle_mouse_capture()
if Input.is_action_just_pressed("switch_hero"):
switch_hero_interface()
@ -74,6 +69,14 @@ func _input(event):
if Input.is_action_pressed("quit"):
quit()
func toggle_mouse_capture():
if (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
view_sensitivity = 0
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
view_sensitivity = 0.25
func set_rotation():
get_node("Yaw").set_rotation(Vector3(0, deg2rad(yaw), 0))
get_node("Yaw/Pitch").set_rotation(Vector3(deg2rad(pitch), 0, 0))
@ -140,16 +143,31 @@ func control_player(state):
lin_v.z *= air_friction
state.set_linear_velocity(lin_v)
var vel = get_linear_velocity()
switch_charge += movement_charge * vel.length()
get_node("MasterOnly/SwitchCharge").set_text("%.f%%" % switch_charge)
state.integrate_forces()
func _process(delta):
# All player code not caused by input, and not causing movement
var vel = get_linear_velocity()
switch_charge += movement_charge * vel.length() * delta
var switch_node = get_node("MasterOnly/SwitchCharge")
switch_node.set_text("%.f%%" % switch_charge)
if switch_charge >= 100:
switch_node.set_text("100%\nQ - Switch hero")
func switch_hero_interface():
# TODO: Make a real interface
player_info.hero += 1
rpc("switch_hero", player_info.hero)
# Interface needs the mouse!
toggle_mouse_capture()
# Pause so if we have walls and such nothing funny happens
get_tree().set_pause(true)
var interface = preload("res://scenes/HeroSelect.tscn").instance()
add_child(interface)
interface.get_node("Confirm").connect("pressed", self, "switch_hero_master")
func switch_hero_master():
rpc("switch_hero", get_node("HeroSelect/Hero").get_selected_id())
# Remove the mouse and enable looking again
toggle_mouse_capture()
get_tree().set_pause(false)
sync func switch_hero(hero):
var new_hero = load("res://scenes/heroes/%d.tscn" % hero).instance()


Loading…
Cancel
Save