Browse Source

Add hero selection, add Hero 0 with wallriding

master
Luna 7 years ago
parent
commit
c68f62aad0
5 changed files with 218 additions and 17 deletions
  1. +28
    -0
      hero_0.gd
  2. +133
    -0
      hero_0.tscn
  3. +4
    -0
      hero_select.gd
  4. +10
    -4
      lobby.gd
  5. +43
    -13
      lobby.tscn

+ 28
- 0
hero_0.gd View File

@ -0,0 +1,28 @@
extends "res://player.gd"
const wallride_speed = 2
master func _integrate_forces(state):
._integrate_forces(state)
wallride(state)
func wallride(state):
var ray = get_node("Ray")
# If our feet aren't touching, but we are colliding, we are wall-riding
if !ray.is_colliding() and get_colliding_bodies():
print("riding")
var aim = get_node("Yaw").get_global_transform().basis
var direction = Vector3()
if Input.is_action_pressed("move_forwards"):
direction -= aim[2]
if Input.is_action_pressed("move_backwards"):
direction += aim[2]
#var n = -1 * (state.get_transform() * state.get_contact_local_normal(0))
#direction = n.slide(direction) * wallride_speed
direction *= 0.1
set_gravity_scale(-0.1)
apply_impulse(Vector3(), direction)
state.integrate_forces()
else:
# We need to return to falling (we aren't riding anymore)
set_gravity_scale(1)

+ 133
- 0
hero_0.tscn View File

@ -0,0 +1,133 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://hero_0.gd" type="Script" id=1]
[sub_resource type="CapsuleShape" id=1]
radius = 0.4
height = 0.5
[sub_resource type="RayShape" id=2]
length = 0.3
_sections_unfolded = [ "Resource" ]
[sub_resource type="CapsuleMesh" id=3]
radius = 0.4
mid_height = 0.5
radial_segments = 64
rings = 8
_sections_unfolded = [ "Resource" ]
[node name="RigidBody" type="RigidBody" index="0"]
input_ray_pickable = true
input_capture_on_drag = false
collision_layer = 1
collision_mask = 1
mode = 2
mass = 1.0
friction = 0.0
bounce = 0.0
gravity_scale = 1.0
custom_integrator = true
continuous_cd = true
contacts_reported = 8
contact_monitor = true
sleeping = false
can_sleep = false
axis_lock_linear_x = false
axis_lock_linear_y = false
axis_lock_linear_z = false
axis_lock_angular_x = false
axis_lock_angular_y = false
axis_lock_angular_z = false
linear_velocity = Vector3( 0, 0, 0 )
linear_damp = -1.0
angular_velocity = Vector3( 0, 0, 0 )
angular_damp = -1.0
script = ExtResource( 1 )
_sections_unfolded = [ "Angular", "Collision", "Linear", "Transform", "Visibility" ]
[node name="Body" type="CollisionShape" parent="." index="0"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.95, 0 )
shape = SubResource( 1 )
disabled = false
_sections_unfolded = [ "Pause", "Transform", "Visibility" ]
[node name="Leg" type="CollisionShape" parent="." index="1"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0.05, 0.35, 0 )
shape = SubResource( 2 )
disabled = false
_sections_unfolded = [ "Transform", "Visibility" ]
[node name="Ray" type="RayCast" parent="." index="2"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0 )
enabled = true
exclude_parent = true
cast_to = Vector3( 0, -0.3, 0 )
collision_mask = 1
_sections_unfolded = [ "Transform", "Visibility" ]
[node name="Yaw" type="Spatial" parent="." index="3"]
_sections_unfolded = [ "Transform", "Visibility" ]
[node name="Camera" type="Camera" parent="Yaw" index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4, 0 )
keep_aspect = 0
cull_mask = 1048575
environment = null
h_offset = 0.0
v_offset = 0.0
doppler_tracking = 0
projection = 0
current = false
fov = 70.0
size = 1.0
near = 0.05
far = 100.0
_sections_unfolded = [ "Transform", "Visibility" ]
[node name="Crosshair" type="Label" parent="." index="4"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -20.0
margin_top = -7.0
margin_right = 20.0
margin_bottom = 7.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="MeshInstance" type="MeshInstance" parent="." index="5"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.95, 0 )
layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 3 )
skeleton = NodePath("..")
material/0 = null
_sections_unfolded = [ "Transform" ]

+ 4
- 0
hero_select.gd View File

@ -0,0 +1,4 @@
extends OptionButton
func _ready():
add_item("Wallriding mfer", 0)

+ 10
- 4
lobby.gd View File

@ -22,14 +22,14 @@ func _ready():
get_tree().connect("connected_to_server", self, "_connected_ok") get_tree().connect("connected_to_server", self, "_connected_ok")
func _client_init(): func _client_init():
my_info.username = get_node("Username").get_text()
collect_info()
var peer = NetworkedMultiplayerENet.new() var peer = NetworkedMultiplayerENet.new()
peer.create_client(SERVER_IP, SERVER_PORT) peer.create_client(SERVER_IP, SERVER_PORT)
get_tree().set_network_peer(peer) get_tree().set_network_peer(peer)
get_node("Client").set_text("Clienting!") get_node("Client").set_text("Clienting!")
func _singleplayer_init(): func _singleplayer_init():
my_info.username = get_node("Username").get_text()
collect_info()
var peer = NetworkedMultiplayerENet.new() var peer = NetworkedMultiplayerENet.new()
peer.create_server(SERVER_PORT, 1) peer.create_server(SERVER_PORT, 1)
get_tree().set_network_peer(peer) get_tree().set_network_peer(peer)
@ -37,6 +37,7 @@ func _singleplayer_init():
pre_configure_game() pre_configure_game()
func _server_init(): func _server_init():
collect_info()
var peer = NetworkedMultiplayerENet.new() var peer = NetworkedMultiplayerENet.new()
peer.create_server(SERVER_PORT, MAX_PLAYERS) peer.create_server(SERVER_PORT, MAX_PLAYERS)
get_tree().set_network_peer(peer) get_tree().set_network_peer(peer)
@ -50,6 +51,10 @@ func _player_connected(id):
func _connected_ok(): func _connected_ok():
rpc("register_player", get_tree().get_network_unique_id(), my_info) rpc("register_player", get_tree().get_network_unique_id(), my_info)
func collect_info():
my_info.username = get_node("Username").get_text()
my_info.hero = get_node("HeroSelect").get_selected_id()
remote func register_player(id, info): remote func register_player(id, info):
player_info[id] = info player_info[id] = info
if (get_tree().is_network_server()): if (get_tree().is_network_server()):
@ -77,10 +82,11 @@ remote func pre_configure_game():
# Load all players (including self) # Load all players (including self)
for p in player_info: for p in player_info:
var player = preload("res://player.tscn").instance()
var hero = player_info[p].hero
var player = load("res://hero_" + str(hero) + ".tscn").instance()
player.set_name(str(p)) player.set_name(str(p))
player.set_network_master(p) player.set_network_master(p)
get_node("/root/world/players").add_child(player)
get_node("/root/world/players").call_deferred("add_child", player)
rpc_id(1, "done_preconfiguring", self_peer_id) rpc_id(1, "done_preconfiguring", self_peer_id)


+ 43
- 13
lobby.tscn View File

@ -1,8 +1,9 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://lobby.gd" type="Script" id=1] [ext_resource path="res://lobby.gd" type="Script" id=1]
[ext_resource path="res://hero_select.gd" type="Script" id=2]
[node name="Control" type="Control" index="0"]
[node name="Control" type="Control"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -23,9 +24,10 @@ anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_top = 6.0
margin_right = 52.0
margin_bottom = 26.0
margin_left = 4.0
margin_top = 12.0
margin_right = 56.0
margin_bottom = 32.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
focus_mode = 2 focus_mode = 2
mouse_filter = 0 mouse_filter = 0
@ -46,10 +48,10 @@ anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_left = 1.0
margin_top = 44.0
margin_right = 50.0
margin_bottom = 64.0
margin_left = 5.0
margin_top = 45.0
margin_right = 54.0
margin_bottom = 65.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
focus_mode = 2 focus_mode = 2
mouse_filter = 0 mouse_filter = 0
@ -70,10 +72,10 @@ anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_left = 3.0
margin_top = 88.0
margin_right = 182.0
margin_bottom = 108.0
margin_left = 6.0
margin_top = 87.0
margin_right = 185.0
margin_bottom = 107.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
focus_mode = 2 focus_mode = 2
mouse_filter = 0 mouse_filter = 0
@ -121,4 +123,32 @@ text = "Singleplayer"
flat = false flat = false
align = 1 align = 1
[node name="HeroSelect" type="OptionButton" parent="." index="4"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 238.0
margin_top = 9.0
margin_right = 426.0
margin_bottom = 29.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( 2 )

Loading…
Cancel
Save