Compare commits
6 Commits
a7118b3d77
...
2023.01.01
| Author | SHA1 | Date | |
|---|---|---|---|
| ce7b74c832 | |||
| 9893bc45b4 | |||
| 1ef5d54d6c | |||
| 5cfc0839f7 | |||
| 2e4c378991 | |||
| 40d73f2590 |
34
.exr.import
Normal file
34
.exr.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bpsjhyhlis3ov"
|
||||
path="res://.godot/imported/.exr-a7725c7e971a9679cf60303f5fa7defa.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://.exr"
|
||||
dest_files=["res://.godot/imported/.exr-a7725c7e971a9679cf60303f5fa7defa.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
32
Game.gd
32
Game.gd
@@ -1,35 +1,32 @@
|
||||
extends Node3D
|
||||
class_name Game
|
||||
|
||||
@onready var label : Label = $CanvasLayer/Label
|
||||
@onready var player : CharacterBody3D = $PlayerQ3
|
||||
signal game_loaded
|
||||
|
||||
var init_config
|
||||
var weapon_config
|
||||
|
||||
func _ready():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
var config = Runtimeloader.loadConfig("init.cfg") as ConfigFile
|
||||
weapon_config = Runtimeloader.loadConfig("weapons.cfg") as ConfigFile
|
||||
init_config = Runtimeloader.loadConfig("init.cfg") as ConfigFile
|
||||
|
||||
print("Loading PCK...")
|
||||
for map_list in config.get_section_keys("MAPS"):
|
||||
for map in config.get_value("MAPS", map_list):
|
||||
for map_list in init_config.get_section_keys("MAPS"):
|
||||
for map in init_config.get_value("MAPS", map_list):
|
||||
Runtimeloader.loadPCK(map)
|
||||
|
||||
for weapons_list in config.get_section_keys("WEAPONS"):
|
||||
for weapon in config.get_value("WEAPONS", weapons_list):
|
||||
for weapons_list in init_config.get_section_keys("WEAPONS"):
|
||||
for weapon in init_config.get_value("WEAPONS", weapons_list):
|
||||
Runtimeloader.loadPCK(weapon)
|
||||
|
||||
print("Loading Resources Done.")
|
||||
|
||||
|
||||
func load_map():
|
||||
Runtimeloader.loadScene("maps/test_map.tscn", self)
|
||||
#Runtimeloader.get_all_entities(node)
|
||||
game_loaded.emit()
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
label.text = "H Velocity: %3.2f" % [Vector2(player.velocity.x, player.velocity.z).length()]
|
||||
label.text += "\nV Velocity: %3.2f" % [player.velocity.y]
|
||||
label.text += "\nOn floor: %s" % player.is_on_floor()
|
||||
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_F:
|
||||
@@ -39,3 +36,4 @@ func _input(event):
|
||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||
elif event.keycode == KEY_ESCAPE:
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
shader_type spatial;
|
||||
render_mode cull_back;
|
||||
|
||||
uniform float z_offset : hint_range(-1, 1);
|
||||
|
||||
void fragment() {
|
||||
// Place fragment code here.
|
||||
}
|
||||
// write the final depth value to the depth buffer
|
||||
DEPTH = 0.9;
|
||||
}
|
||||
14
assets/shader/test.tscn
Normal file
14
assets/shader/test.tscn
Normal file
@@ -0,0 +1,14 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://tojfiub8y1f6"]
|
||||
|
||||
[ext_resource type="Shader" path="res://assets/shader/no_depth.gdshader" id="2_lklwv"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5pubw"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("2_lklwv")
|
||||
shader_parameter/z_offset = null
|
||||
|
||||
[node name="Chainsaw_test"]
|
||||
|
||||
[node name="Cube014" parent="." index="0"]
|
||||
material_override = SubResource("ShaderMaterial_5pubw")
|
||||
transparency = 0.02
|
||||
@@ -1,12 +1,20 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bl7jynld7s25o"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://bl7jynld7s25o"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/player/PlayerQ3.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://scripts/player/Weapons.gd" id="2_dl1i1"]
|
||||
[ext_resource type="Texture2D" uid="uid://17b1nu8spjfi" path="res://textures/icon.png" id="2_mxb5i"]
|
||||
[ext_resource type="Shader" path="res://assets/shader/crosshair.gdshader" id="3_3vnqi"]
|
||||
[ext_resource type="Script" path="res://entities/PlayerSync.gd" id="5_828co"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="1"]
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_6d8kk"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mqdp4"]
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ikq67"]
|
||||
albedo_texture = ExtResource("2_mxb5i")
|
||||
uv1_scale = Vector3(3, 2, 1)
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_4e7dm"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_08bwh"]
|
||||
shader = ExtResource("3_3vnqi")
|
||||
shader_parameter/center_enabled = null
|
||||
shader_parameter/legs_enabled = null
|
||||
@@ -21,15 +29,38 @@ shader_parameter/len = null
|
||||
shader_parameter/spacing = null
|
||||
shader_parameter/spread = null
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rfdcv"]
|
||||
properties/0/path = NodePath("Body/Head:rotation")
|
||||
properties/0/spawn = true
|
||||
properties/0/sync = true
|
||||
properties/1/path = NodePath("Body:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/sync = true
|
||||
properties/2/path = NodePath("Networking:player_state")
|
||||
properties/2/spawn = false
|
||||
properties/2/sync = true
|
||||
properties/3/path = NodePath("Networking:sync_position")
|
||||
properties/3/spawn = true
|
||||
properties/3/sync = false
|
||||
properties/4/path = NodePath("Networking:sync_velocity")
|
||||
properties/4/spawn = true
|
||||
properties/4/sync = false
|
||||
|
||||
[node name="PlayerQ3" type="CharacterBody3D"]
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = SubResource("1")
|
||||
shape = SubResource("CylinderShape3D_6d8kk")
|
||||
|
||||
[node name="Body" type="Node3D" parent="."]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Body"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
material_override = SubResource("StandardMaterial3D_ikq67")
|
||||
mesh = SubResource("CylinderMesh_4e7dm")
|
||||
skeleton = NodePath("../../CollisionShape3D")
|
||||
|
||||
[node name="Head" type="Node3D" parent="Body"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
|
||||
|
||||
@@ -37,12 +68,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
|
||||
script = ExtResource("2_dl1i1")
|
||||
|
||||
[node name="Crosshair" type="ColorRect" parent="Body/Head/Hand"]
|
||||
material = SubResource("ShaderMaterial_mqdp4")
|
||||
material = SubResource("ShaderMaterial_08bwh")
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Body/Head"]
|
||||
cull_mask = 1048573
|
||||
@@ -51,3 +84,17 @@ current = true
|
||||
[node name="AimCast" type="RayCast3D" parent="Body/Head/Camera3D"]
|
||||
target_position = Vector3(0, 0, -1)
|
||||
collision_mask = 512
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Label" type="Label" parent="CanvasLayer"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 14.0
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="Networking" type="Node" parent="."]
|
||||
script = ExtResource("5_828co")
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="Networking"]
|
||||
root_path = NodePath("../..")
|
||||
replication_config = SubResource("SceneReplicationConfig_rfdcv")
|
||||
|
||||
31
entities/PlayerSync.gd
Normal file
31
entities/PlayerSync.gd
Normal file
@@ -0,0 +1,31 @@
|
||||
extends Node
|
||||
|
||||
###SYNC PLAYER###
|
||||
const PLAYER_STATE_SIZE = 13
|
||||
var player_state:
|
||||
get:
|
||||
var buf = PackedByteArray()
|
||||
buf.resize(PLAYER_STATE_SIZE)
|
||||
buf.encode_half(0, sync_position.x)
|
||||
buf.encode_half(2, sync_position.y)
|
||||
buf.encode_half(4, sync_position.z)
|
||||
buf.encode_half(6, sync_velocity.x)
|
||||
buf.encode_half(8, sync_velocity.y)
|
||||
buf.encode_half(10, sync_velocity.z)
|
||||
return buf
|
||||
set(value):
|
||||
assert(typeof(value) == TYPE_PACKED_BYTE_ARRAY and value.size() == PLAYER_STATE_SIZE,
|
||||
"Invalid `player_state` array type or size (must be TYPE_PACKED_BYTE_ARRAY of size 11).")
|
||||
sync_position = Vector3(value.decode_half(0), value.decode_half(2), value.decode_half(4))
|
||||
sync_velocity = Vector3(value.decode_half(6), value.decode_half(8), value.decode_half(10))
|
||||
|
||||
var sync_position : Vector3:
|
||||
set(value):
|
||||
sync_position = value
|
||||
processed_position = false
|
||||
var sync_velocity : Vector3
|
||||
var sync_is_jumping : bool
|
||||
|
||||
var processed_position : bool
|
||||
|
||||
|
||||
BIN
entities/Weapon.scn
Normal file
BIN
entities/Weapon.scn
Normal file
Binary file not shown.
@@ -9,6 +9,11 @@
|
||||
config_version=5
|
||||
|
||||
_global_script_classes=[{
|
||||
"base": "Node3D",
|
||||
"class": &"Game",
|
||||
"language": &"GDScript",
|
||||
"path": "res://Game.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": &"Hitable",
|
||||
"language": &"GDScript",
|
||||
@@ -25,6 +30,7 @@ _global_script_classes=[{
|
||||
"path": "res://scripts/player/Weapon.gd"
|
||||
}]
|
||||
_global_script_class_icons={
|
||||
"Game": "",
|
||||
"Hitable": "",
|
||||
"TBPlugin": "",
|
||||
"Weapon": ""
|
||||
@@ -40,6 +46,7 @@ config/icon="res://textures/icon.png"
|
||||
[autoload]
|
||||
|
||||
Runtimeloader="*res://scripts/utils/runtimeloader.gd"
|
||||
Network="*res://scripts/utils/network.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
||||
57
scenes/GUI/MAIN.tscn
Normal file
57
scenes/GUI/MAIN.tscn
Normal file
@@ -0,0 +1,57 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://3o430r2kys4k"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/GUI/main.gd" id="1_i8nr4"]
|
||||
|
||||
[node name="MAIN" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
script = ExtResource("1_i8nr4")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -198.0
|
||||
offset_top = -104.0
|
||||
offset_right = 199.0
|
||||
offset_bottom = 64.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="Start" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Start Game"
|
||||
|
||||
[node name="ModsMenu" type="MenuButton" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Select Mod"
|
||||
flat = false
|
||||
item_count = 2
|
||||
popup/item_0/text = "test1"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "test2"
|
||||
popup/item_1/id = 1
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 10
|
||||
|
||||
[node name="SettingsButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "Game Settings"
|
||||
icon_alignment = 1
|
||||
|
||||
[node name="ExitButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "Exit"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Start" to="." method="_on_start_pressed"]
|
||||
@@ -1,4 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://dsnlwjofq6psf"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dsnlwjofq6psf"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/GUI/MainMenu.gd" id="1_23sw7"]
|
||||
[ext_resource type="PackedScene" uid="uid://3o430r2kys4k" path="res://scenes/GUI/MAIN.tscn" id="1_sojs8"]
|
||||
[ext_resource type="PackedScene" uid="uid://d0kkhtesg83g" path="res://scenes/GUI/START_GAME.tscn" id="2_ipoll"]
|
||||
|
||||
[node name="Main Menu" type="Control"]
|
||||
layout_mode = 3
|
||||
@@ -9,61 +13,14 @@ anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_23sw7")
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -198.0
|
||||
offset_top = -104.0
|
||||
offset_right = 199.0
|
||||
offset_bottom = 64.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
[node name="MAIN" parent="." instance=ExtResource("1_sojs8")]
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
offset_left = 102.0
|
||||
offset_right = 295.0
|
||||
offset_bottom = 31.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 2
|
||||
[node name="START GAME" parent="." instance=ExtResource("2_ipoll")]
|
||||
visible = false
|
||||
|
||||
[node name="Start" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
offset_right = 96.0
|
||||
offset_bottom = 31.0
|
||||
text = "Start Game"
|
||||
|
||||
[node name="ModsMenu" type="MenuButton" parent="VBoxContainer/HBoxContainer"]
|
||||
offset_left = 100.0
|
||||
offset_right = 193.0
|
||||
offset_bottom = 31.0
|
||||
text = "Select Mod"
|
||||
flat = false
|
||||
item_count = 2
|
||||
popup/item_0/text = "test1"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "test2"
|
||||
popup/item_1/id = 1
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer"]
|
||||
offset_left = 138.0
|
||||
offset_top = 102.0
|
||||
offset_right = 258.0
|
||||
offset_bottom = 168.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 10
|
||||
|
||||
[node name="SettingsButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
|
||||
offset_right = 120.0
|
||||
offset_bottom = 31.0
|
||||
text = "Game Settings"
|
||||
icon_alignment = 1
|
||||
|
||||
[node name="ExitButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
|
||||
offset_top = 35.0
|
||||
offset_right = 120.0
|
||||
offset_bottom = 66.0
|
||||
text = "Exit"
|
||||
[connection signal="start_game" from="MAIN" to="." method="_on_main_start_game"]
|
||||
[connection signal="back" from="START GAME" to="." method="_on_start_game_back"]
|
||||
[connection signal="start_game" from="START GAME" to="." method="_on_start_game_start_game"]
|
||||
|
||||
25
scenes/GUI/MainMenu.gd
Normal file
25
scenes/GUI/MainMenu.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends Control
|
||||
|
||||
@onready var game = get_tree().get_current_scene() as Game
|
||||
@onready var previous = $MAIN
|
||||
@onready var current = $MAIN
|
||||
|
||||
func _on_main_start_game():
|
||||
previous = current
|
||||
current = $"START GAME"
|
||||
$"START GAME".show()
|
||||
|
||||
func back():
|
||||
current.hide()
|
||||
previous.show()
|
||||
var tmp = current
|
||||
current = previous
|
||||
previous = tmp
|
||||
|
||||
func _on_start_game_start_game():
|
||||
game.load_map()
|
||||
self.hide()
|
||||
|
||||
func _on_start_game_back():
|
||||
previous = $MAIN
|
||||
back()
|
||||
62
scenes/GUI/START_GAME.tscn
Normal file
62
scenes/GUI/START_GAME.tscn
Normal file
@@ -0,0 +1,62 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://d0kkhtesg83g"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/GUI/start_game.gd" id="1_amknd"]
|
||||
|
||||
[node name="START GAME" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
script = ExtResource("1_amknd")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -198.0
|
||||
offset_top = -104.0
|
||||
offset_right = 199.0
|
||||
offset_bottom = 64.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="HostContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="HostButton" type="Button" parent="VBoxContainer/HostContainer"]
|
||||
layout_mode = 2
|
||||
text = "Host"
|
||||
|
||||
[node name="JoinContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 2
|
||||
|
||||
[node name="IPAdress" type="TextEdit" parent="VBoxContainer/JoinContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_font_sizes/font_size = 13
|
||||
placeholder_text = "localhost"
|
||||
|
||||
[node name="JoinButton" type="Button" parent="VBoxContainer/JoinContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
text = "Join
|
||||
"
|
||||
|
||||
[node name="BackContainer" type="VBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
|
||||
[node name="BackButton" type="Button" parent="VBoxContainer/BackContainer"]
|
||||
layout_mode = 2
|
||||
text = "Back"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/HostContainer/HostButton" to="." method="_on_host_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/JoinContainer/JoinButton" to="." method="_on_join_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/BackContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||
7
scenes/GUI/main.gd
Normal file
7
scenes/GUI/main.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
extends Control
|
||||
|
||||
signal start_game;
|
||||
|
||||
func _on_start_pressed():
|
||||
start_game.emit()
|
||||
hide()
|
||||
27
scenes/GUI/start_game.gd
Normal file
27
scenes/GUI/start_game.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends Control
|
||||
|
||||
@onready var IPAdress_Field = $VBoxContainer/JoinContainer/IPAdress as TextEdit
|
||||
signal start_game
|
||||
signal back
|
||||
|
||||
func _on_join_button_pressed():
|
||||
if not try_connection():
|
||||
return
|
||||
Network.start_network(false, IPAdress_Field.text)
|
||||
start_game.emit()
|
||||
|
||||
|
||||
func try_connection():
|
||||
if IPAdress_Field.text.is_empty():
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func _on_host_button_pressed():
|
||||
Network.start_network(true)
|
||||
start_game.emit()
|
||||
|
||||
|
||||
func _on_back_button_pressed():
|
||||
hide()
|
||||
back.emit()
|
||||
5
scenes/map/EntitySpawner.gd
Normal file
5
scenes/map/EntitySpawner.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends MultiplayerSpawner
|
||||
|
||||
|
||||
func _spawn_custom(data):
|
||||
return
|
||||
@@ -1,8 +1,7 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://8g7w4uv2xsck"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://8g7w4uv2xsck"]
|
||||
|
||||
[ext_resource type="Script" path="res://Game.gd" id="1_71dcv"]
|
||||
[ext_resource type="PackedScene" uid="uid://bp5ekvan8qsmc" path="res://entities/enemy/dummy.tscn" id="2_13e86"]
|
||||
[ext_resource type="PackedScene" uid="uid://bl7jynld7s25o" path="res://entities/Player.tscn" id="3_ngdfc"]
|
||||
[ext_resource type="PackedScene" uid="uid://dsnlwjofq6psf" path="res://scenes/GUI/Main Menu.tscn" id="2_448f8"]
|
||||
|
||||
[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_2n8qo"]
|
||||
|
||||
@@ -31,15 +30,10 @@ shadow_enabled = true
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_oqaam")
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
[node name="Main Menu" parent="." instance=ExtResource("2_448f8")]
|
||||
|
||||
[node name="Label" type="Label" parent="CanvasLayer"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 14.0
|
||||
metadata/_edit_use_anchors_ = true
|
||||
[node name="Networking" type="Node" parent="."]
|
||||
|
||||
[node name="Enemy" parent="." instance=ExtResource("2_13e86")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 23.8087, 0.346554, -28.3203)
|
||||
|
||||
[node name="PlayerQ3" parent="." instance=ExtResource("3_ngdfc")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 3.52828, 2.64918, -22.0849)
|
||||
[node name="PlayerSpawner" type="MultiplayerSpawner" parent="Networking"]
|
||||
_spawnable_scenes = PackedStringArray("res://entities/Player.tscn")
|
||||
spawn_path = NodePath("..")
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://bq7p576e7a17i"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://bq7p576e7a17i"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bx4pdgghucl4k" path="res://textures/concrete_15.jpg" id="1_os4mo"]
|
||||
[ext_resource type="Texture2D" uid="uid://bj2qm3joiywso" path="res://textures/dark.png" id="2_53atb"]
|
||||
[ext_resource type="Texture2D" uid="uid://bt671xkej3a2s" path="res://textures/shipping_container_01_side.jpg" id="3_am21j"]
|
||||
[ext_resource type="Texture2D" uid="uid://c52qu6ad3taix" path="res://textures/shipping_container_01_front.jpg" id="4_tpukd"]
|
||||
[ext_resource type="Texture2D" uid="uid://bx4pdgghucl4k" path="res://textures/concrete_15.jpg" id="1_37wdm"]
|
||||
[ext_resource type="Texture2D" uid="uid://bj2qm3joiywso" path="res://textures/dark.png" id="2_f8syx"]
|
||||
[ext_resource type="Texture2D" uid="uid://bt671xkej3a2s" path="res://textures/shipping_container_01_side.jpg" id="3_vf5qg"]
|
||||
[ext_resource type="Texture2D" uid="uid://c52qu6ad3taix" path="res://textures/shipping_container_01_front.jpg" id="4_70w0l"]
|
||||
[ext_resource type="PackedScene" uid="uid://bp5ekvan8qsmc" path="res://entities/enemy/dummy.tscn" id="5_1x24o"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_yhpph"]
|
||||
albedo_texture = ExtResource("1_os4mo")
|
||||
albedo_texture = ExtResource("1_37wdm")
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_plg37"]
|
||||
albedo_texture = ExtResource("2_53atb")
|
||||
albedo_texture = ExtResource("2_f8syx")
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8xybu"]
|
||||
albedo_texture = ExtResource("3_am21j")
|
||||
albedo_texture = ExtResource("3_vf5qg")
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rri1d"]
|
||||
albedo_texture = ExtResource("4_tpukd")
|
||||
albedo_texture = ExtResource("4_70w0l")
|
||||
|
||||
[sub_resource type="ArrayMesh" id="ArrayMesh_bdgr3"]
|
||||
lightmap_size_hint = Vector2i(2802, 2814)
|
||||
@@ -67,10 +68,16 @@ data = PackedVector3Array(-31.1636, -2.5938, -36.3203, -31.1636, -4.5938, -36.32
|
||||
[node name="Map" type="Node3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 22.8341, -0.0932, -2.1058)
|
||||
|
||||
[node name="entity_0_geometry" type="MeshInstance3D" parent="."]
|
||||
[node name="0_geometry" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("ArrayMesh_bdgr3")
|
||||
|
||||
[node name="entity_0_geometry_col" type="StaticBody3D" parent="."]
|
||||
[node name="0_geometry_col" type="StaticBody3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="entity_0_geometry_col"]
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="0_geometry_col"]
|
||||
shape = SubResource("ConcavePolygonShape3D_2ub2n")
|
||||
|
||||
[node name="entity_test" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.7493, -0.748922, -3.17036)
|
||||
|
||||
[node name="Enemy" parent="." instance=ExtResource("5_1x24o")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.47822, -2.5938, -7.02456)
|
||||
2
scoom
2
scoom
Submodule scoom updated: e921609c47...81bf2c532a
@@ -2,6 +2,9 @@ extends CharacterBody3D
|
||||
|
||||
const DIST_FLOOR_SNAP := Vector3.DOWN * 0.2
|
||||
|
||||
@onready var label : Label = $CanvasLayer/Label
|
||||
@onready var networking = $Networking
|
||||
|
||||
@onready var body : Node3D = $Body
|
||||
@onready var head : Node3D = $Body/Head
|
||||
@onready var cam : Camera3D = $Body/Head/Camera3D
|
||||
@@ -26,9 +29,27 @@ const DIST_FLOOR_SNAP := Vector3.DOWN * 0.2
|
||||
|
||||
var floor_snap := Vector3.ZERO
|
||||
|
||||
func _enter_tree():
|
||||
$Networking/MultiplayerSynchronizer.set_multiplayer_authority(str(name).to_int())
|
||||
$Body/Head/Camera3D.current = is_local_authority()
|
||||
if is_local_authority():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func init():
|
||||
$Body/Head/Hand.set_weapons()
|
||||
|
||||
func is_local_authority():
|
||||
return $Networking/MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id()
|
||||
|
||||
func _process(_delta):
|
||||
if not is_local_authority():
|
||||
return
|
||||
label.text = "H Velocity: %3.2f" % [Vector2(velocity.x, velocity.z).length()]
|
||||
label.text += "\nV Velocity: %3.2f" % [velocity.y]
|
||||
label.text += "\nOn floor: %s" % is_on_floor()
|
||||
label.text += "\nNetwork ID: %d" % multiplayer.get_unique_id()
|
||||
|
||||
func get_move_direction() -> Vector3:
|
||||
|
||||
var input_dir := Vector2(
|
||||
Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward"),
|
||||
Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
||||
@@ -36,18 +57,24 @@ func get_move_direction() -> Vector3:
|
||||
|
||||
return input_dir.x * body.global_transform.basis.z + input_dir.y * body.global_transform.basis.x
|
||||
|
||||
|
||||
func _input(event):
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and event is InputEventMouseMotion:
|
||||
rotate_look(event.relative * 0.001 * mouse_sensitivity)
|
||||
|
||||
if is_local_authority():
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and event is InputEventMouseMotion:
|
||||
rotate_look(event.relative * 0.001 * mouse_sensitivity)
|
||||
|
||||
func rotate_look(amount : Vector2) -> void:
|
||||
body.rotation.y -= amount.x
|
||||
head.rotation.x = clamp(head.rotation.x - amount.y, -PI * 0.5, PI * 0.5)
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
if !is_local_authority():
|
||||
if not networking.processed_position:
|
||||
position = networking.sync_position
|
||||
networking.processed_position = true
|
||||
velocity = networking.sync_velocity
|
||||
move_and_slide()
|
||||
return
|
||||
|
||||
|
||||
var was_on_floor : bool = is_on_floor()
|
||||
var h_target_dir : Vector3 = get_move_direction()
|
||||
@@ -78,7 +105,9 @@ func _physics_process(delta):
|
||||
floor_snap = DIST_FLOOR_SNAP
|
||||
elif was_on_floor and !is_on_floor():
|
||||
floor_snap = Vector3.ZERO
|
||||
|
||||
|
||||
networking.sync_position = position
|
||||
networking.sync_velocity = velocity
|
||||
|
||||
func accelerate(delta : float, p_target_dir : Vector3, p_target_speed : float, p_accel : float):
|
||||
var current_speed : float = velocity.dot(p_target_dir)
|
||||
@@ -87,7 +116,6 @@ func accelerate(delta : float, p_target_dir : Vector3, p_target_speed : float, p
|
||||
var accel_speed : float = min(add_speed, p_accel * delta * p_target_speed)
|
||||
velocity += p_target_dir * accel_speed
|
||||
|
||||
|
||||
func apply_friction(delta : float):
|
||||
|
||||
#var vec : Vector3 = velocity
|
||||
|
||||
@@ -47,7 +47,7 @@ func init():
|
||||
can_shoot = true
|
||||
InitialPos(DRAW_TIME, DRAW_TIME)
|
||||
|
||||
|
||||
|
||||
|
||||
func InitialPos(draw_time, ready_time):
|
||||
tween = create_tween()
|
||||
@@ -58,32 +58,39 @@ func InitialPos(draw_time, ready_time):
|
||||
tween.tween_property(MODEL, "rotation", Vector3.ZERO, draw_time)
|
||||
tween.tween_callback(func(): state = INITIAL).set_delay(ready_time)
|
||||
|
||||
|
||||
|
||||
@rpc
|
||||
func Shoot():
|
||||
if CanShoot():
|
||||
if not FIREMODE:
|
||||
can_shoot = false
|
||||
if not MELEE:
|
||||
clip -= 1
|
||||
|
||||
state = SHOOT;
|
||||
tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_ELASTIC)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(MODEL, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2)
|
||||
var rand_rot_y = randf_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
|
||||
var rand_rot_z = randf_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
|
||||
tween.tween_property(MODEL, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2)
|
||||
tween.tween_callback(func(): InitialPos(RECOIL_COOLDOWN / 2, SHOOTING_SPEED / 2)).set_delay(SHOOTING_SPEED / 2)
|
||||
rpc("rpc_AnimShoot")
|
||||
return true
|
||||
return false
|
||||
|
||||
@rpc(call_local, any_peer)
|
||||
func rpc_AnimShoot():
|
||||
state = SHOOT;
|
||||
tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_ELASTIC)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(MODEL, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2)
|
||||
var rand_rot_y = randf_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
|
||||
var rand_rot_z = randf_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
|
||||
tween.tween_property(MODEL, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2)
|
||||
tween.tween_callback(func(): InitialPos(RECOIL_COOLDOWN / 2, SHOOTING_SPEED / 2)).set_delay(SHOOTING_SPEED / 2)
|
||||
|
||||
func CanShoot():
|
||||
return clip > 0 && state == INITIAL && can_shoot
|
||||
|
||||
|
||||
@rpc
|
||||
func Release():
|
||||
rpc("rpc_Release")
|
||||
|
||||
@rpc(call_local, any_peer)
|
||||
func rpc_Release():
|
||||
if !FIREMODE:
|
||||
can_shoot = true
|
||||
|
||||
|
||||
@@ -1,36 +1,145 @@
|
||||
extends Node3D
|
||||
|
||||
const CONFIG_PATH = "weapons.cfg"
|
||||
signal shoot
|
||||
const WEAPON_SCENE = preload("res://entities/Weapon.scn")
|
||||
|
||||
var state = 0
|
||||
@onready var player_root = get_node("../../../../PlayerQ3") as CharacterBody3D
|
||||
@onready var player_root = get_node("../../..")
|
||||
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
|
||||
#@onready var crosshair = $Crosshair
|
||||
|
||||
|
||||
var ALL_WEAPONS = []
|
||||
var weapons = []
|
||||
var current_weapon = 0
|
||||
|
||||
var current_weapon_index = 0
|
||||
var current_weapon = null
|
||||
|
||||
var mouse_mov : Vector3
|
||||
var sway_lerp = 5
|
||||
@onready var game = get_node("/root/Game") as Game
|
||||
|
||||
func _ready():
|
||||
get_tree().get_current_scene().ready.connect(init)
|
||||
Init_Config(game.weapon_config)
|
||||
if not player_root.is_local_authority():
|
||||
for w_name in game.init_config.get_value("PLAYER", "starting_weapons"):
|
||||
GiveWeapon(w_name)
|
||||
|
||||
func init():
|
||||
var config = Runtimeloader.loadConfig(CONFIG_PATH) as ConfigFile
|
||||
if(config == null):
|
||||
func set_weapons():
|
||||
for w_name in game.init_config.get_value("PLAYER", "starting_weapons"):
|
||||
rpc("GiveWeapon",w_name)
|
||||
|
||||
@rpc(call_local, any_peer)
|
||||
func GiveWeapon(weapon_name):
|
||||
for i in ALL_WEAPONS.size():
|
||||
if(ALL_WEAPONS[i].name != weapon_name):
|
||||
continue
|
||||
if(weapons.has(i)):
|
||||
return
|
||||
|
||||
weapons.append(i)
|
||||
if(current_weapon == null):
|
||||
rpc("ChangeWeapon", ((posmod(current_weapon_index, weapons.size()))))
|
||||
return
|
||||
|
||||
@rpc(call_local, any_peer)
|
||||
func TakeWeapon(weapon_name):
|
||||
for i in ALL_WEAPONS.size():
|
||||
if(ALL_WEAPONS[i].name != weapon_name):
|
||||
continue
|
||||
weapons.erase(i)
|
||||
if(current_weapon == ALL_WEAPONS[i]):
|
||||
rpc("ChangeWeapon", ((posmod(current_weapon_index, weapons.size()))))
|
||||
|
||||
func _input(event):
|
||||
if not player_root.is_local_authority():
|
||||
return
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_mov.y = clampf(-event.relative.x, -0.1, 0.1)
|
||||
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
|
||||
if event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_T:
|
||||
rpc("GiveWeapon","CHAINSAW")
|
||||
|
||||
func _unhandled_input(_event):
|
||||
if not player_root.is_local_authority():
|
||||
return
|
||||
|
||||
if(weapons.size() == 0):
|
||||
return
|
||||
|
||||
Init_Config(config)
|
||||
ChangeWeapon(0)
|
||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
|
||||
rpc("ChangeWeapon", (posmod((current_weapon_index + 1),weapons.size())))
|
||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
|
||||
rpc("ChangeWeapon", (posmod((current_weapon_index - 1),weapons.size())))
|
||||
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
current_weapon.Reload()
|
||||
@rpc(call_local, any_peer)
|
||||
func ChangeWeapon(i):
|
||||
if(current_weapon):
|
||||
current_weapon.hide()
|
||||
|
||||
if(weapons.size() == 0):
|
||||
current_weapon = null
|
||||
return
|
||||
|
||||
current_weapon_index = i
|
||||
var w_index = weapons[current_weapon_index]
|
||||
current_weapon = ALL_WEAPONS[w_index]
|
||||
current_weapon.show()
|
||||
current_weapon.init()
|
||||
raycast.target_position.z = -current_weapon.RAY_LEN
|
||||
|
||||
var time = 0
|
||||
|
||||
func _process(delta):
|
||||
if not player_root.is_local_authority():
|
||||
return
|
||||
if(current_weapon == null):
|
||||
return
|
||||
|
||||
if Input.is_action_pressed("shoot") && current_weapon.Shoot():
|
||||
if(current_weapon.HITSCAN):
|
||||
HitScan()
|
||||
else:
|
||||
Projectile()
|
||||
|
||||
if Input.is_action_just_released("shoot"):
|
||||
current_weapon.Release()
|
||||
|
||||
|
||||
#SWAY
|
||||
if mouse_mov != null && mouse_mov.length() > 0:
|
||||
current_weapon.MODEL.rotation = current_weapon.MODEL.rotation.lerp(mouse_mov, sway_lerp * delta)
|
||||
mouse_mov = Vector3.ZERO
|
||||
else:
|
||||
current_weapon.MODEL.rotation = current_weapon.MODEL.rotation.lerp(Vector3.ZERO, sway_lerp * delta)
|
||||
|
||||
#BOB
|
||||
if player_root.velocity.length() > 0:
|
||||
time += delta
|
||||
var bobOscillate = sin(time * 4 * (2 * PI)) * 0.01
|
||||
position.y = bobOscillate
|
||||
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
|
||||
position.x = bobOscillate
|
||||
|
||||
@rpc(call_local, any_peer)
|
||||
func HitScan():
|
||||
if(raycast.is_colliding()):
|
||||
var target = raycast.get_collider()
|
||||
print_debug("Hit target ", target.name, " with ", current_weapon.name, " ",current_weapon_index, ". Dealt damage ", current_weapon.DAMAGE)
|
||||
if(raycast.get_collision_mask_value(10)):
|
||||
if(target is Hitable):
|
||||
target.Hit(current_weapon.DAMAGE)
|
||||
|
||||
|
||||
func Projectile():
|
||||
pass
|
||||
|
||||
|
||||
func Init_Config(config):
|
||||
for weapon in config.get_sections():
|
||||
var root = Weapon.new()
|
||||
var root = WEAPON_SCENE.instantiate()
|
||||
root.name = weapon
|
||||
|
||||
|
||||
var model_path = config.get_value(weapon, "MODEL") as String
|
||||
var weapon_model
|
||||
if(model_path.ends_with(".glb") or model_path.ends_with(".gltf")):
|
||||
@@ -70,72 +179,5 @@ func Init_Config(config):
|
||||
root.RELOAD_MOMENTUM = config.get_value(weapon, "RELOAD_MOMENTUM")
|
||||
root.RELOAD_ANGULAR_MOMENTUM = config.get_value(weapon, "RELOAD_ANGULAR_MOMENTUM")
|
||||
root.RELOAD_TIME = config.get_value(weapon, "RELOAD_TIME")
|
||||
|
||||
weapons.append(root)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_mov.y = clampf(-event.relative.x, -0.1, 0.1)
|
||||
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
|
||||
|
||||
|
||||
|
||||
func _unhandled_input(_event):
|
||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
|
||||
ChangeWeapon((current_weapon + 1) % weapons.size())
|
||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
|
||||
ChangeWeapon((current_weapon - 1) % weapons.size())
|
||||
|
||||
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
weapons[current_weapon].Reload()
|
||||
|
||||
func ChangeWeapon(i):
|
||||
weapons[current_weapon].hide()
|
||||
current_weapon = i
|
||||
weapons[current_weapon].show()
|
||||
weapons[current_weapon].init()
|
||||
raycast.target_position.z = -weapons[current_weapon].RAY_LEN
|
||||
|
||||
var time = 0
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("shoot") && weapons[current_weapon].Shoot():
|
||||
shoot.emit(0.20, 0.15)
|
||||
if(weapons[current_weapon].HITSCAN):
|
||||
HitScan()
|
||||
else:
|
||||
Projectile()
|
||||
|
||||
if Input.is_action_just_released("shoot"):
|
||||
weapons[current_weapon].Release()
|
||||
|
||||
|
||||
#SWAY
|
||||
if mouse_mov != null && mouse_mov.length() > 0:
|
||||
weapons[current_weapon].MODEL.rotation = weapons[current_weapon].MODEL.rotation.lerp(mouse_mov, sway_lerp * delta)
|
||||
mouse_mov = Vector3.ZERO
|
||||
else:
|
||||
weapons[current_weapon].MODEL.rotation = weapons[current_weapon].MODEL.rotation.lerp(Vector3.ZERO, sway_lerp * delta)
|
||||
|
||||
#BOB
|
||||
if player_root.velocity.length() > 0:
|
||||
time += delta
|
||||
var bobOscillate = sin(time * 4 * (2 * PI)) * 0.01
|
||||
position.y = bobOscillate
|
||||
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
|
||||
position.x = bobOscillate
|
||||
|
||||
|
||||
func HitScan():
|
||||
if(raycast.is_colliding()):
|
||||
var target = raycast.get_collider()
|
||||
print_debug("Hit target ", target.name, " with ", weapons[current_weapon].MODEL.name, " ",current_weapon, ". Dealt damage ", weapons[current_weapon].DAMAGE)
|
||||
if(raycast.get_collision_mask_value(10)):
|
||||
if(target is Hitable):
|
||||
target.Hit(weapons[current_weapon].DAMAGE)
|
||||
|
||||
|
||||
func Projectile():
|
||||
pass
|
||||
|
||||
|
||||
ALL_WEAPONS.append(root)
|
||||
|
||||
45
scripts/utils/network.gd
Normal file
45
scripts/utils/network.gd
Normal file
@@ -0,0 +1,45 @@
|
||||
extends Node
|
||||
|
||||
|
||||
signal player_spawn
|
||||
# The player scene (which we want to configure for replication).
|
||||
const Player = preload("res://entities/Player.tscn")
|
||||
@onready var NetworkingRoot = get_node("/root/Game/Networking")
|
||||
|
||||
|
||||
func start_network(server: bool, ip="localhost"):
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
if server:
|
||||
peer.create_server(27015)
|
||||
# Listen to peer connections, and create new player for them
|
||||
multiplayer.peer_connected.connect(create_player)
|
||||
# Listen to peer disconnections, and destroy their players
|
||||
multiplayer.peer_disconnected.connect(destroy_player)
|
||||
multiplayer.set_multiplayer_peer(peer)
|
||||
create_player()
|
||||
else:
|
||||
peer.create_client(ip, 27015)
|
||||
multiplayer.set_multiplayer_peer(peer)
|
||||
|
||||
func add_network_entity(path):
|
||||
var spawner = NetworkingRoot.get_node("Networking") as MultiplayerSpawner
|
||||
spawner.add_spawnable_scene(path)
|
||||
|
||||
|
||||
func create_player(id=1):
|
||||
# Instantiate a new player for this client.
|
||||
var p = Player.instantiate()
|
||||
# Sets the player name (only sent during spawn).
|
||||
#p.player_name = "Player %d" % id
|
||||
# Set a random position (sent on every replicator update).
|
||||
#p.position = Vector2(randi() % 500, randi() % 500)
|
||||
# Add it to the "Players" node.
|
||||
# We give the new Node a name for easy retrieval, but that's not necessary.
|
||||
p.name = str(id)
|
||||
#p.set_multiplayer_authority(id)
|
||||
NetworkingRoot.add_child(p)
|
||||
p.init()
|
||||
|
||||
func destroy_player(id):
|
||||
# Delete this peer's node.
|
||||
NetworkingRoot.get_node(str(id)).queue_free()
|
||||
@@ -7,10 +7,6 @@ func _ready():
|
||||
if(not OS.has_feature("editor")):
|
||||
EXTERNAL_PATH = OS.get_executable_path().get_base_dir() + "/scoom/"
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_T:
|
||||
load_gltf("models/runtime_loader_test.glb")
|
||||
|
||||
func get_all_children(in_node, arr = []):
|
||||
arr.push_back(in_node)
|
||||
@@ -32,30 +28,29 @@ func load_gltf(file, parent = self, hasCollision = false, trimesh = false):
|
||||
fileBytes = snd_file.get_buffer(snd_file.get_length())
|
||||
|
||||
gltf.append_from_buffer(fileBytes, "", gltf_state)
|
||||
|
||||
|
||||
print("Loading ", EXTERNAL_PATH + file)
|
||||
var node = gltf.generate_scene(gltf_state)
|
||||
var entity_count = 0;
|
||||
for o in get_all_children(node):
|
||||
if o.name.begins_with("entity_") && not o.name.ends_with("_geometry"):
|
||||
print("Loading entity ", o.name)
|
||||
if loadEntity(o):
|
||||
entity_count += 1;
|
||||
elif o is MeshInstance3D:
|
||||
if hasCollision:
|
||||
if(trimesh):
|
||||
o.create_trimesh_collision()
|
||||
else:
|
||||
o.create_convex_collision()
|
||||
var node = gltf.generate_scene(gltf_state) as Node
|
||||
|
||||
parent.add_child(node)
|
||||
if(entity_count > 0):
|
||||
print("Loaded ", entity_count, " entities.")
|
||||
get_all_entities(node)
|
||||
|
||||
|
||||
if not hasCollision:
|
||||
return node
|
||||
|
||||
for o in get_all_children(node):
|
||||
if o is MeshInstance3D:
|
||||
if(trimesh):
|
||||
o.create_trimesh_collision()
|
||||
else:
|
||||
o.create_convex_collision()
|
||||
return node
|
||||
|
||||
func get_all_entities(at_node):
|
||||
var entity_count = 0
|
||||
for o in get_all_children(at_node):
|
||||
if o.name.begins_with("entity_") && not o.name.ends_with("_geometry"):
|
||||
if o.name.begins_with("entity_"):
|
||||
print("Loading entity ", o.name)
|
||||
if loadEntity(o):
|
||||
entity_count += 1;
|
||||
@@ -73,8 +68,13 @@ func loadEntity(node):
|
||||
if(not config.has_section(node.name)):
|
||||
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
|
||||
return false
|
||||
|
||||
var model = config.get_value(node.name, "model")
|
||||
var has_collision = config.get_value(node.name, "has_collision")
|
||||
var has_trimesh_col = config.get_value(node.name, "has_trimesh_col")
|
||||
|
||||
var entity = load_gltf(model, node.get_parent(), has_collision, has_trimesh_col) as Node3D
|
||||
|
||||
var entity = load_gltf(config.get_value(node.name, "model"), node.get_parent()) as Node3D
|
||||
if(entity == null):
|
||||
printerr("ENTITY COULD NOT BE CREATED : ", node.name)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user