diff --git a/project.godot b/project.godot index ae0f0be..3e3b303 100644 --- a/project.godot +++ b/project.godot @@ -28,6 +28,10 @@ jump=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":""," ] quit=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null) ] +hero_1_place_wall=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":46,"unicode":0,"echo":false,"script":null) + ] +hero_1_confirm_wall=[ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) + ] [rendering] diff --git a/scenes/heroes/0.tscn b/scenes/heroes/0.tscn index d9567f4..6fd42f4 100644 --- a/scenes/heroes/0.tscn +++ b/scenes/heroes/0.tscn @@ -77,9 +77,9 @@ _sections_unfolded = [ "Transform", "Visibility" ] [node name="Yaw" type="Spatial" parent="." index="3"] -_sections_unfolded = [ "Transform", "Visibility" ] +[node name="Pitch" type="Spatial" parent="Yaw" index="0"] -[node name="Camera" type="Camera" parent="Yaw" index="0"] +[node name="Camera" type="Camera" parent="Yaw/Pitch" index="0"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4, 0 ) keep_aspect = 0 diff --git a/scenes/heroes/1.tscn b/scenes/heroes/1.tscn new file mode 100644 index 0000000..5f2ceb1 --- /dev/null +++ b/scenes/heroes/1.tscn @@ -0,0 +1,146 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://scripts/heroes/1.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" groups=[ +"player", +]] + +input_ray_pickable = true +input_capture_on_drag = false +collision_layer = 1 +collision_mask = 1 +mode = 2 +mass = 200.0 +friction = 1.0 +bounce = 0.0 +gravity_scale = 1.0 +custom_integrator = false +continuous_cd = true +contacts_reported = 0 +contact_monitor = false +sleeping = false +can_sleep = true +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", "Axis Lock", "Collision", "Linear", "Transform", "Visibility", "collision" ] + +[node name="Crosshair" type="Label" parent="." index="0"] + +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 +text = "+" +align = 1 +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="Body" type="CollisionShape" parent="." index="1"] + +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="2"] + +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="3"] + +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="4"] + +[node name="Pitch" type="Spatial" parent="Yaw" index="0"] + +[node name="Camera" type="Camera" parent="Yaw/Pitch" 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="Ray" type="RayCast" parent="Yaw/Pitch" index="1"] + +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4, 0 ) +enabled = true +exclude_parent = true +cast_to = Vector3( 0, 0, -100 ) +collision_mask = 1 +_sections_unfolded = [ "Transform" ] + +[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" ] + + diff --git a/scenes/lobby.tscn b/scenes/lobby.tscn index 1e16552..b8a952d 100644 --- a/scenes/lobby.tscn +++ b/scenes/lobby.tscn @@ -3,7 +3,7 @@ [ext_resource path="res://scripts/lobby.gd" type="Script" id=1] [ext_resource path="res://scripts/hero_select.gd" type="Script" id=2] -[node name="Control" type="Control" index="0"] +[node name="Control" type="Control"] anchor_left = 0.0 anchor_top = 0.0 @@ -273,16 +273,36 @@ caret_blink = false caret_blink_speed = 0.65 caret_moving_by_right_click = true -[node name="HeroSelect" type="OptionButton" parent="." index="11"] +[node name="HeroSelectLabel" type="Label" parent="." index="11"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 460.0 +margin_top = 66.0 +margin_right = 538.0 +margin_bottom = 80.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +text = "Hero Select:" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="HeroSelect" type="OptionButton" parent="." index="12"] anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 457.0 -margin_top = 67.0 +margin_top = 94.0 margin_right = 645.0 -margin_bottom = 87.0 +margin_bottom = 114.0 rect_rotation = -0.0115615 rect_pivot_offset = Vector2( 0, 0 ) focus_mode = 2 diff --git a/scenes/player.tscn b/scenes/player.tscn index 984d0fe..8642a2a 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -20,7 +20,7 @@ radial_segments = 64 rings = 8 _sections_unfolded = [ "Resource" ] -[node name="RigidBody" type="RigidBody" index="0" groups=[ +[node name="RigidBody" type="RigidBody" groups=[ "player", ]] @@ -77,9 +77,9 @@ _sections_unfolded = [ "Transform", "Visibility" ] [node name="Yaw" type="Spatial" parent="." index="3"] -_sections_unfolded = [ "Transform", "Visibility" ] +[node name="Pitch" type="Spatial" parent="Yaw" index="0"] -[node name="Camera" type="Camera" parent="Yaw" index="0"] +[node name="Camera" type="Camera" parent="Yaw/Pitch" index="0"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4, 0 ) keep_aspect = 0 diff --git a/scenes/wall.tscn b/scenes/wall.tscn new file mode 100644 index 0000000..9200360 --- /dev/null +++ b/scenes/wall.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=3 format=2] + +[sub_resource type="CubeMesh" id=1] + +size = Vector3( 2, 2, 0.2 ) +subdivide_width = 0 +subdivide_height = 0 +subdivide_depth = 0 + +[sub_resource type="BoxShape" id=2] + +extents = Vector3( 1, 1, 0.1 ) + +[node name="StaticBody" type="StaticBody"] + +input_ray_pickable = true +input_capture_on_drag = false +collision_layer = 1 +collision_mask = 1 +friction = 1.0 +bounce = 0.0 +constant_linear_velocity = Vector3( 0, 0, 0 ) +constant_angular_velocity = Vector3( 0, 0, 0 ) + +[node name="MeshInstance" type="MeshInstance" parent="." index="0"] + +transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, -1.05 ) +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( 1 ) +skeleton = NodePath("..") +material/0 = null +_sections_unfolded = [ "Transform" ] + +[node name="CollisionShape" type="CollisionShape" parent="." index="1"] + +transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, -1.05 ) +shape = SubResource( 2 ) +disabled = true +_sections_unfolded = [ "Transform" ] + + diff --git a/scripts/hero_select.gd b/scripts/hero_select.gd index 1696908..379a04a 100644 --- a/scripts/hero_select.gd +++ b/scripts/hero_select.gd @@ -2,3 +2,4 @@ extends OptionButton func _ready(): add_item("Wallriding mfer", 0) + add_item("WallMAKING mfer", 1) diff --git a/scripts/heroes/1.gd b/scripts/heroes/1.gd new file mode 100644 index 0000000..27af723 --- /dev/null +++ b/scripts/heroes/1.gd @@ -0,0 +1,63 @@ +extends "res://scripts/player.gd" + +var walls = [] +var placing_wall_node +var is_placing_wall = false + +const max_walls = 3 + +func _process(delta): + if is_network_master(): + + if Input.is_action_just_pressed("hero_1_place_wall"): + # Press button twice to cancel + if is_placing_wall: + # We changed our mind, delete the placing wall + placing_wall_node.queue_free() + is_placing_wall = false + else: + # Make a floating placement wall + placing_wall_node = add_wall() + is_placing_wall = true + if Input.is_action_just_pressed("hero_1_confirm_wall"): + finalize_wall(placing_wall_node) + rpc("place_wall", placing_wall_node.get_transform()) + placing_wall_node = null + is_placing_wall = false + + if is_placing_wall: + # Find the point we're looking at, and put the wall there + var aim = get_node("Yaw/Pitch").get_global_transform().basis + var look_ray = get_node("Yaw/Pitch/Ray") + var pos = look_ray.get_collision_point() + placing_wall_node.set_translation(pos) + var towards = look_ray.get_collision_normal() + pos + var up = -aim[2] # Wall should be horizontal to my view + placing_wall_node.look_at(towards, up) + +slave func place_wall(tf): + var wall = add_wall() + finalize_wall(wall, tf) + check_wall_count() + +# Creates wall, adds to world, and returns the node +func add_wall(): + var wall = preload("res://scenes/wall.tscn").instance() + get_node("/root/world").add_child(wall) + return wall + +func finalize_wall(wall, tf=null): + if tf: + wall.set_transform(tf) + # Originally, the wall is disabled to avoid weird physics + wall.get_node("CollisionShape").disabled = false + # Remember this wall, and return to non-placing state + # We need to do this even as slave, because we keep track of the count + walls.append(wall) + check_wall_count() + +func check_wall_count(): + # If we've made max_walls, remove the first we made + if walls.size() > max_walls: + walls[0].queue_free() + walls.pop_front() \ No newline at end of file diff --git a/scripts/player.gd b/scripts/player.gd index c08da7a..96a8d82 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -35,7 +35,7 @@ func _ready(): debug_node = get_node("/root/world/Debug") if is_network_master(): - get_node("Yaw/Camera").make_current() + get_node("Yaw/Pitch/Camera").make_current() func _input(event): if is_network_master(): @@ -44,7 +44,7 @@ func _input(event): yaw = fmod(yaw - event.relative.x * view_sensitivity, 360) pitch = max(min(pitch - event.relative.y * view_sensitivity, 85), -85) get_node("Yaw").set_rotation(Vector3(0, deg2rad(yaw), 0)) - get_node("Yaw/Camera").set_rotation(Vector3(deg2rad(pitch), 0, 0)) + get_node("Yaw/Pitch").set_rotation(Vector3(deg2rad(pitch), 0, 0)) # Toggle mouse capture: if Input.is_action_pressed("toggle_mouse_capture"): @@ -127,10 +127,7 @@ func control_player(state): lin_v.z *= air_friction state.set_linear_velocity(lin_v) - # print(state.get_linear_velocity()) - var vel = get_linear_velocity() - debug_node.set_text("%8.f,%8.f,%8.f" % [vel.x, vel.y, vel.z]) state.integrate_forces()