Split client and server

This commit is contained in:
2024-01-24 00:09:50 +01:00
parent 532a1faa21
commit 26c52a00b3
59 changed files with 335 additions and 142 deletions

View File

@ -0,0 +1,3 @@
class_name Attack
var damage: float

View File

@ -0,0 +1,44 @@
class_name Character
extends CharacterBody3D
@export var model: Node3D
@export var move_speed: float = 4.5
@export var rotation_speed: float = 20.0
const JUMP_VELOCITY := 4.5
const DECELERATE := 0.75
var direction: Vector3
var angle: float
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
func _process(delta):
if direction:
angle = atan2(direction.x, direction.z)
model.rotation.y = lerp_angle(model.rotation.y, angle, rotation_speed * delta)
func _physics_process(delta):
if direction:
velocity.x = direction.x * move_speed
velocity.z = direction.z * move_speed
else:
velocity.x *= DECELERATE
velocity.z *= DECELERATE
if !is_on_floor():
velocity.y -= gravity * delta
move_and_slide()
func jump():
if !is_on_floor():
return
velocity.y = JUMP_VELOCITY
func dash():
print("dash")
func attack():
print("attack")

View File

@ -0,0 +1,14 @@
class_name HealthComponent
extends Node
@export var max_health: float
var health: float
func _ready():
pass
func take_damage(attack: Attack):
health -= attack.damage
if health <= 0:
get_parent().queue_free()

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://2bbycjulf00g"]
[ext_resource type="Script" path="res://character/HealthComponent.gd" id="1_403dm"]
[node name="HealthComponent" type="Node"]
script = ExtResource("1_403dm")

2
client/enemy/Enemy.gd Normal file
View File

@ -0,0 +1,2 @@
class_name Enemy
extends Character

View File

@ -0,0 +1,2 @@
class_name EnemyController
extends Node

View File

@ -0,0 +1,50 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://b358op5h1y83m"
path="res://.godot/imported/Slime.blend-8da460d18e3c1f7085d49df94a74fec6.scn"
[deps]
source_file="res://enemy/Slime.blend"
dest_files=["res://.godot/imported/Slime.blend-8da460d18e3c1f7085d49df94a74fec6.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1
blender/nodes/visible=0
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true

55
client/enemy/Slime.tscn Normal file
View File

@ -0,0 +1,55 @@
[gd_scene load_steps=8 format=3 uid="uid://cb2t7bvvf3gwh"]
[ext_resource type="PackedScene" uid="uid://b358op5h1y83m" path="res://enemy/Slime.blend" id="1_1h1hj"]
[ext_resource type="Script" path="res://enemy/Enemy.gd" id="1_r5888"]
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/HealthComponent.tscn" id="2_fsqxc"]
[sub_resource type="BoxShape3D" id="BoxShape3D_x1ppt"]
size = Vector3(0.7, 0.6, 0.7)
[sub_resource type="Animation" id="Animation_qls31"]
resource_name = "slime_fall"
tracks/0/type = "scale_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Slime")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = PackedFloat32Array(0, 1, 0.5, 1.2, 0.5, 0.5, 1, 0.6, 1, 0.6, 1, 1, 0.5, 1.2, 0.5)
[sub_resource type="Animation" id="Animation_mdtm7"]
resource_name = "slime_idle"
length = 2.0
loop_mode = 1
tracks/0/type = "scale_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Slime")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = PackedFloat32Array(0, 1, 1, 1, 1, 0.5, 1, 0.9, 1.1, 0.9, 1, 1, 1, 1, 1, 1.5, 1, 1.1, 0.9, 1.1, 2, 1, 1, 1, 1)
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1bw8m"]
_data = {
"slime_fall": SubResource("Animation_qls31"),
"slime_idle": SubResource("Animation_mdtm7")
}
[node name="Slime" type="CharacterBody3D" node_paths=PackedStringArray("model") groups=["enemy"]]
script = ExtResource("1_r5888")
model = NodePath("Model")
[node name="Model" parent="." instance=ExtResource("1_1h1hj")]
[node name="Collision" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0452515, 0.3, 0)
shape = SubResource("BoxShape3D_x1ppt")
[node name="Animation" type="AnimationPlayer" parent="."]
root_node = NodePath("../Model")
libraries = {
"": SubResource("AnimationLibrary_1bw8m")
}
autoplay = "slime_idle"
[node name="Health" parent="." instance=ExtResource("2_fsqxc")]

15
client/network/Client.gd Normal file
View File

@ -0,0 +1,15 @@
extends NetworkNode
@export var ip := "127.0.0.1"
@export var port := 4242
var socket := PacketPeerUDP.new()
func _init():
super._init()
socket.connect_to_host(ip, port)
func _process(_delta):
while socket.get_available_packet_count() > 0:
var packet := socket.get_packet()
handle_packet(packet, socket)

29
client/network/Login.gd Normal file
View File

@ -0,0 +1,29 @@
extends PacketHandler
var auth_token: String
func _ready():
%Client.set_handler(Packet.LOGIN, self)
send_login()
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
if data[0] != 0:
print("[Client] Login failed.")
return
print("[Client] Login succeeded.")
auth_token = data.slice(1).get_string_from_ascii()
print("[Client] Auth token: %s" % auth_token)
func send_login():
if is_logged_in():
return
var buffer := StreamPeerBuffer.new()
buffer.put_8(Packet.LOGIN)
buffer.put_data(JSON.stringify(["user1", "password"]).to_utf8_buffer())
%Client.socket.put_packet(buffer.data_array)
print("[Client] Connecting...")
func is_logged_in() -> bool:
return auth_token != ""

32
client/network/Ping.gd Normal file
View File

@ -0,0 +1,32 @@
extends PacketHandler
signal changed(ping: float)
const HISTORY_SIZE = 8
var count := 0
var history: Array[float] = []
func _init():
history.resize(HISTORY_SIZE)
func _ready():
%Client.set_handler(Packet.PING, self)
func send_ping():
var buffer := StreamPeerBuffer.new()
buffer.put_8(Packet.PING)
buffer.put_8(count)
%Client.socket.put_packet(buffer.data_array)
history[count] = Time.get_unix_time_from_system()
count += 1
if count >= HISTORY_SIZE:
count = 0
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
var id := data[0]
var ping := Time.get_unix_time_from_system() - history[id]
changed.emit(ping)

14
client/network/Spawn.gd Normal file
View File

@ -0,0 +1,14 @@
extends PacketHandler
@export var player_scene: PackedScene
func _ready():
%Client.set_handler(Packet.SPAWN, self)
func handle_packet(_data: PackedByteArray, _peer: PacketPeer):
Global.player = spawn_player()
func spawn_player() -> Player:
var player = player_scene.instantiate()
%Players.add_child(player)
return player

7
client/player/Player.gd Normal file
View File

@ -0,0 +1,7 @@
class_name Player
extends Character
func _ready():
var controller := PlayerController.new()
controller.character = self
add_child(controller)

34
client/player/Player.tscn Normal file
View File

@ -0,0 +1,34 @@
[gd_scene load_steps=6 format=3 uid="uid://2lcnu3dy54lx"]
[ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"]
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/HealthComponent.tscn" id="2_np5ag"]
[ext_resource type="Script" path="res://player/PlayerController.gd" id="3_oox5k"]
[sub_resource type="PrismMesh" id="PrismMesh_y7abh"]
size = Vector3(0.5, 1.6, 0.5)
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"]
radius = 0.25
height = 1.6
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("model") groups=["player"]]
script = ExtResource("1_8gebs")
model = NodePath("Model")
[node name="Model" type="Node3D" parent="."]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Model"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
mesh = SubResource("PrismMesh_y7abh")
[node name="Collision" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
shape = SubResource("CapsuleShape3D_2f50n")
[node name="Animation" type="AnimationPlayer" parent="."]
[node name="Health" parent="." instance=ExtResource("2_np5ag")]
[node name="Controller" type="Node" parent="." node_paths=PackedStringArray("character")]
script = ExtResource("3_oox5k")
character = NodePath("..")

View File

@ -0,0 +1,22 @@
class_name PlayerController
extends Node
## The character that we're controlling.
@export var character: Character
var move: Vector2
func _input(_event):
move = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
character.direction = (Global.camera.transform.basis * Vector3(move.x, 0, move.y))
character.direction.y = 0
character.direction = character.direction.normalized()
if Input.is_action_just_pressed("jump"):
character.jump()
if Input.is_action_just_pressed("dash"):
character.dash()
if Input.is_action_just_pressed("attack"):
character.attack()

99
client/project.godot Normal file
View File

@ -0,0 +1,99 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Client"
run/main_scene="res://world/Client.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://ui/icon.svg"
[autoload]
Global="*res://world/Global.gd"
[display]
window/vsync/vsync_mode=0
[gui]
theme/custom="res://ui/theme.tres"
[input]
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
]
}
move_forward={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_backward={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
]
}
jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}
dash={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
toggle_fullscreen={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":true,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194342,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
attack={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":false,"script":null)
]
}
aim={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":false,"script":null)
]
}
menu={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null)
]
}
[physics]
3d/run_on_separate_thread=true
common/physics_ticks_per_second=100

View File

@ -0,0 +1,76 @@
shader_type spatial;
render_mode unshaded;
uniform sampler2D screen_texture : source_color, hint_screen_texture, filter_nearest;
uniform sampler2D depth_texture : source_color, hint_depth_texture, filter_nearest;
uniform sampler2D normal_texture : source_color, hint_normal_roughness_texture, filter_nearest;
uniform bool depth_layer = true;
uniform bool normal_layer = true;
uniform bool original_layer = true;
uniform float depth_edge_strength : hint_range(-1, 1, 0.01) = -0.5;
uniform float normal_edge_strength : hint_range(-1, 1, 0.01) = 0.5;
uniform float depth_edge_threshold : hint_range(0, 1) = 0.2;
uniform float normal_edge_threshold : hint_range(0, 1) = 0.6;
uniform vec3 normal_edge_bias = vec3(1, 1, 1);
float get_depth(vec2 screen_uv, mat4 inv_projection_matrix) {
float depth = texture(depth_texture, screen_uv).r;
vec3 ndc = vec3(screen_uv * 2.0 - 1.0, depth);
vec4 view = inv_projection_matrix * vec4(ndc, 1.0);
view.xyz /= view.w;
return -view.z;
}
vec2[4] create_uvs(vec2 screen_uv, vec2 texel_size) {
vec2 uvs[4];
uvs[0] = vec2(screen_uv.x, min(1.0 - texel_size.y, screen_uv.y + texel_size.y));
uvs[1] = vec2(screen_uv.x, max(0.0, screen_uv.y - texel_size.y));
uvs[2] = vec2(min(1.0 - texel_size.x, screen_uv.x + texel_size.x), screen_uv.y);
uvs[3] = vec2(max(0.0, screen_uv.x - texel_size.x), screen_uv.y);
return uvs;
}
float normal_detection(vec2 uv, vec3 normal) {
vec3 neighbor_normal = texture(normal_texture, uv).xyz * 2.0 - 1.0;
vec3 normal_diff = normal - neighbor_normal;
float normal_bias_diff = dot(normal_diff, normal_edge_bias);
float normal_indicator = smoothstep(0.01, -0.01, normal_bias_diff);
return dot(normal_diff, normal_diff) * normal_indicator;
}
void vertex() {
POSITION = vec4(VERTEX, 1.0);
}
void fragment() {
vec3 original = texture(screen_texture, SCREEN_UV).rgb;
vec3 normal = texture(normal_texture, SCREEN_UV).xyz * 2.0 - 1.0;
float depth = get_depth(SCREEN_UV, INV_PROJECTION_MATRIX);
vec2 texel_size = 1.0 / VIEWPORT_SIZE.xy;
vec2 neighbors[4] = create_uvs(SCREEN_UV, texel_size);
float depth_diff = 0.0;
float normal_diff = 0.0;
for (int i = 0; i < 4; i++) {
float neighbor_depth = get_depth(neighbors[i], INV_PROJECTION_MATRIX);
depth_diff += neighbor_depth - depth;
normal_diff += normal_detection(neighbors[i], normal);
}
float strength = 0.0;
if (depth_layer && depth_diff > depth_edge_threshold) {
strength = 1.0 + depth_edge_strength;
} else if (normal_layer && normal_diff > normal_edge_threshold && depth_diff > 0.0) {
strength = 1.0 + normal_edge_strength;
} else if(original_layer) {
strength = 1.0;
}
ALBEDO = original * strength;
}

View File

@ -0,0 +1,15 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://ddy5gkw0k16dq"]
[ext_resource type="Shader" path="res://shader/Outline.gdshader" id="1_fmkjv"]
[resource]
render_priority = 0
shader = ExtResource("1_fmkjv")
shader_parameter/depth_layer = true
shader_parameter/normal_layer = true
shader_parameter/original_layer = true
shader_parameter/depth_edge_strength = -0.5
shader_parameter/normal_edge_strength = 0.5
shader_parameter/depth_edge_threshold = 0.2
shader_parameter/normal_edge_threshold = 0.6
shader_parameter/normal_edge_bias = Vector3(1, 1, 1)

9
client/shared/Account.gd Normal file
View File

@ -0,0 +1,9 @@
class_name Account
var username: String
var password: String
var position: Vector3
func _init(name: String, pw: String):
username = name
password = pw

View File

@ -0,0 +1,23 @@
class_name NetworkNode
extends Node
var handlers: Array[Node] = []
func _init():
handlers.resize(256)
func get_handler(index: int) -> PacketHandler:
return handlers[index]
func set_handler(index: int, node: PacketHandler):
handlers[index] = node
func handle_packet(packet: PackedByteArray, peer: PacketPeer):
var type := packet.decode_u8(0)
var handler := get_handler(type)
if handler == null:
push_warning("Unknown packet type %d" % type)
return
handler.handle_packet(packet.slice(1), peer)

9
client/shared/Packet.gd Normal file
View File

@ -0,0 +1,9 @@
class_name Packet
enum {
PING = 1,
LOGIN = 2,
LOGOUT = 3,
STATE = 10,
MOVE = 11,
}

View File

@ -0,0 +1,5 @@
class_name PacketHandler
extends Node
func handle_packet(_data: PackedByteArray, _peer: PacketPeer):
pass

View File

@ -0,0 +1,8 @@
class_name DebugLabel
extends Control
var text : String :
get:
return get_child(1).text
set(value):
get_child(1).text = value

View File

@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=3 uid="uid://cch67vqpsmtej"]
[ext_resource type="Script" path="res://ui/debug/DebugLabel.gd" id="1_xfly0"]
[ext_resource type="Script" path="res://ui/debug/DebugLabelText.gd" id="2_i4ix0"]
[node name="Container" type="HBoxContainer"]
script = ExtResource("1_xfly0")
[node name="Text" type="Label" parent="."]
layout_mode = 2
text = ":"
script = ExtResource("2_i4ix0")
[node name="Value" type="Label" parent="."]
layout_mode = 2

View File

@ -0,0 +1,5 @@
@tool
extends Label
func _ready():
text = get_parent().name + ":"

View File

@ -0,0 +1,4 @@
extends DebugLabel
func _process(_delta):
text = str(Engine.get_frames_per_second())

View File

@ -0,0 +1,6 @@
extends DebugLabel
@export var monitor: Performance.Monitor
func _process(_delta):
text = str(Performance.get_monitor(monitor))

View File

@ -0,0 +1,7 @@
extends DebugLabel
func _ready():
%Ping.connect("changed", on_ping_changed)
func on_ping_changed(ping):
text = str(snapped(ping * 1000, 1)) + " ms"

View File

@ -0,0 +1,7 @@
extends DebugLabel
func _process(_delta):
if Global.player == null:
return
text = str(Global.player.global_position)

View File

@ -0,0 +1,7 @@
extends DebugLabel
func _process(_delta):
if Global.player == null:
return
text = str(Global.player.velocity)

1
client/ui/icon.svg Normal file
View File

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

After

Width:  |  Height:  |  Size: 950 B

37
client/ui/icon.svg.import Normal file
View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://biplb56hj51h7"
path="res://.godot/imported/icon.svg-57a480398ce0db3d1582eb3ec78dffaa.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icon.svg"
dest_files=["res://.godot/imported/icon.svg-57a480398ce0db3d1582eb3ec78dffaa.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

10
client/ui/theme.tres Normal file
View File

@ -0,0 +1,10 @@
[gd_resource type="Theme" load_steps=2 format=3 uid="uid://caqphxkvcu3tb"]
[ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://ui/ubuntu_nf_regular.ttf" id="1_1unma"]
[resource]
default_font = ExtResource("1_1unma")
MarginContainer/constants/margin_bottom = 5
MarginContainer/constants/margin_left = 5
MarginContainer/constants/margin_right = 5
MarginContainer/constants/margin_top = 5

View File

@ -0,0 +1,38 @@
[remap]
importer="font_data_dynamic"
type="FontFile"
uid="uid://b7mov13kwi8u8"
path="res://.godot/imported/ubuntu_nf_regular.ttf-feed7a5a59b6d10a4a32843efe52a9da.fontdata"
[deps]
source_file="res://ui/ubuntu_nf_regular.ttf"
dest_files=["res://.godot/imported/ubuntu_nf_regular.ttf-feed7a5a59b6d10a4a32843efe52a9da.fontdata"]
[params]
Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[{
"chars": [],
"glyphs": [],
"name": "New Configuration",
"size": Vector2i(16, 0)
}]
language_support={}
script_support={}
opentype_features={}

View File

@ -0,0 +1,56 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://tgmbtt7u172g"
path="res://.godot/imported/Arena.blend-c720f6651d38b4cfd30aa3f4d2266924.scn"
[deps]
source_file="res://world/Arena.blend"
dest_files=["res://.godot/imported/Arena.blend-c720f6651d38b4cfd30aa3f4d2266924.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={
"nodes": {
"PATH:Plane": {
"physics/shape_type": 2
}
}
}
gltf/naming_version=1
gltf/embedded_image_handling=1
blender/nodes/visible=0
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true

23
client/world/Camera.gd Normal file
View File

@ -0,0 +1,23 @@
extends Camera3D
@export var center: Node3D
@export var follow_speed: float
func _ready():
Global.camera = self
func _process(delta):
if Global.player == null:
return
center.position = lerp(center.position, Global.player.position, follow_speed * delta)
# @export var shake_strength: float
# var noise = FastNoiseLite.new()
# func shake(time):
# var trauma_sq := 1.0
# var h_offset := noise.get_noise_2d(time, 0) * trauma_sq * shake_strength
# var v_offset := noise.get_noise_2d(time, 1) * trauma_sq * shake_strength
# rotate_x(noise.get_noise_2d(time, 2) * trauma_sq * shake_strength)
# rotate_y(noise.get_noise_2d(time, 3) * trauma_sq * shake_strength)
# rotate_z(noise.get_noise_2d(time, 4) * trauma_sq * shake_strength)

View File

@ -0,0 +1,3 @@
[gd_resource type="CameraAttributesPractical" format=3 uid="uid://b835orxyqq6w5"]
[resource]

139
client/world/Client.tscn Normal file
View File

@ -0,0 +1,139 @@
[gd_scene load_steps=19 format=3 uid="uid://b40y7iuskv1ar"]
[ext_resource type="Script" path="res://world/Game.gd" id="1_pux6q"]
[ext_resource type="Script" path="res://network/Client.gd" id="2_1ofik"]
[ext_resource type="Script" path="res://network/Ping.gd" id="3_4h5la"]
[ext_resource type="Script" path="res://network/Login.gd" id="4_k8n1i"]
[ext_resource type="Script" path="res://network/Spawn.gd" id="5_7n5ie"]
[ext_resource type="PackedScene" uid="uid://2lcnu3dy54lx" path="res://player/Player.tscn" id="5_22pku"]
[ext_resource type="PackedScene" uid="uid://mgyg01l21t0j" path="res://world/World.tscn" id="7_fb4vs"]
[ext_resource type="Environment" uid="uid://dixa0yso2s1u3" path="res://world/Environment.tres" id="8_5uta8"]
[ext_resource type="PackedScene" uid="uid://cch67vqpsmtej" path="res://ui/debug/DebugLabel.tscn" id="8_jr2jn"]
[ext_resource type="Script" path="res://ui/debug/FPSLabel.gd" id="9_0imyg"]
[ext_resource type="CameraAttributesPractical" uid="uid://b835orxyqq6w5" path="res://world/CameraAttributes.tres" id="9_w4cdu"]
[ext_resource type="Script" path="res://world/Sun.gd" id="10_mlmor"]
[ext_resource type="Script" path="res://ui/debug/PingLabel.gd" id="10_pu6sd"]
[ext_resource type="Script" path="res://ui/debug/PositionLabel.gd" id="11_k0017"]
[ext_resource type="Script" path="res://ui/debug/VelocityLabel.gd" id="12_dgr41"]
[ext_resource type="Script" path="res://world/Camera.gd" id="13_y4waa"]
[ext_resource type="Material" uid="uid://ddy5gkw0k16dq" path="res://shader/OutlineMaterial.tres" id="14_hobco"]
[sub_resource type="QuadMesh" id="QuadMesh_7yiqd"]
material = ExtResource("14_hobco")
flip_faces = true
size = Vector2(2, 2)
[node name="Main" type="Node"]
script = ExtResource("1_pux6q")
[node name="Client" type="Node" parent="."]
unique_name_in_owner = true
script = ExtResource("2_1ofik")
[node name="Ping" type="Node" parent="Client"]
unique_name_in_owner = true
script = ExtResource("3_4h5la")
[node name="Timer" type="Timer" parent="Client/Ping"]
autostart = true
[node name="Login" type="Node" parent="Client"]
script = ExtResource("4_k8n1i")
[node name="Timer" type="Timer" parent="Client/Login"]
wait_time = 10.0
autostart = true
[node name="Spawn" type="Node" parent="Client"]
script = ExtResource("5_7n5ie")
player_scene = ExtResource("5_22pku")
[node name="Players" type="Node3D" parent="."]
unique_name_in_owner = true
[node name="World" parent="." instance=ExtResource("7_fb4vs")]
[node name="Sun" type="DirectionalLight3D" parent="World"]
transform = Transform3D(0.984808, 0.122788, -0.122788, 0, 0.707107, 0.707107, 0.173648, -0.696364, 0.696364, 0, 10, 0)
shadow_enabled = true
directional_shadow_mode = 0
script = ExtResource("10_mlmor")
[node name="Environment" type="WorldEnvironment" parent="World"]
environment = ExtResource("8_5uta8")
camera_attributes = ExtResource("9_w4cdu")
[node name="UI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
[node name="CanvasLayer" type="CanvasLayer" parent="UI"]
[node name="TopLeftMargin" type="MarginContainer" parent="UI/CanvasLayer"]
offset_right = 40.0
offset_bottom = 50.0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/CanvasLayer/TopLeftMargin"]
layout_mode = 2
[node name="FPS" parent="UI/CanvasLayer/TopLeftMargin/VBoxContainer" instance=ExtResource("8_jr2jn")]
layout_mode = 2
script = ExtResource("9_0imyg")
[node name="Ping" parent="UI/CanvasLayer/TopLeftMargin/VBoxContainer" instance=ExtResource("8_jr2jn")]
layout_mode = 2
script = ExtResource("10_pu6sd")
[node name="BottomLeftMargin" type="MarginContainer" parent="UI/CanvasLayer"]
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -10.0
offset_right = 10.0
grow_vertical = 0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/CanvasLayer/BottomLeftMargin"]
layout_mode = 2
[node name="Position" parent="UI/CanvasLayer/BottomLeftMargin/VBoxContainer" instance=ExtResource("8_jr2jn")]
layout_mode = 2
script = ExtResource("11_k0017")
[node name="Velocity" parent="UI/CanvasLayer/BottomLeftMargin/VBoxContainer" instance=ExtResource("8_jr2jn")]
layout_mode = 2
script = ExtResource("12_dgr41")
[node name="Viewport" type="SubViewportContainer" parent="."]
texture_filter = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
[node name="SubViewport" type="SubViewport" parent="Viewport"]
handle_input_locally = false
size = Vector2i(1152, 648)
render_target_update_mode = 4
[node name="CameraPivot" type="Node3D" parent="Viewport/SubViewport"]
[node name="Camera" type="Camera3D" parent="Viewport/SubViewport/CameraPivot" node_paths=PackedStringArray("center")]
transform = Transform3D(0.707107, 0.353554, -0.612372, 0, 0.866026, 0.5, 0.707107, -0.353554, 0.612372, -10, 10, 10)
projection = 1
current = true
fov = 90.0
size = 10.0
far = 100.0
script = ExtResource("13_y4waa")
center = NodePath("..")
follow_speed = 5.0
[node name="PostProcessing" type="MeshInstance3D" parent="Viewport/SubViewport/CameraPivot/Camera"]
unique_name_in_owner = true
extra_cull_margin = 16384.0
mesh = SubResource("QuadMesh_7yiqd")
[connection signal="timeout" from="Client/Ping/Timer" to="Client/Ping" method="send_ping"]
[connection signal="timeout" from="Client/Login/Timer" to="Client/Login" method="send_login"]

View File

@ -0,0 +1,10 @@
[gd_resource type="Environment" format=3 uid="uid://dixa0yso2s1u3"]
[resource]
background_mode = 1
background_color = Color(0.317647, 0.541176, 0.713726, 1)
ambient_light_source = 3
ambient_light_color = Color(0.607843, 0.756863, 0.92549, 1)
ambient_light_sky_contribution = 0.17
tonemap_mode = 2
ssao_intensity = 16.0

24
client/world/Game.gd Normal file
View File

@ -0,0 +1,24 @@
extends Node
func _ready():
# Capture mouse
#Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
# Mute audio
var master_sound = AudioServer.get_bus_index("Master")
AudioServer.set_bus_mute(master_sound, true)
func _input(event):
if event.is_action_pressed("toggle_fullscreen"):
toggle_fullscreen()
func toggle_fullscreen():
var mode = DisplayServer.window_get_mode()
match mode:
DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
_:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
return

4
client/world/Global.gd Normal file
View File

@ -0,0 +1,4 @@
extends Node
var camera: Camera3D
var player: Player

6
client/world/RotateY.gd Normal file
View File

@ -0,0 +1,6 @@
extends Node3D
@export var speed: float = 1.0
func _process(delta):
rotate_y(speed * delta)

5
client/world/Sun.gd Normal file
View File

@ -0,0 +1,5 @@
@tool
extends DirectionalLight3D
# func _process(_delta):
# (%PostProcessing as MeshInstance3D).mesh.surface_get_material(0).set_shader_parameter("light_direction", -global_basis.z)

View File

@ -0,0 +1,50 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://hnn0n1xc2qt7"
path="res://.godot/imported/Tree.blend-8edaf7c4bb18f0f1f1c8fa5b8380d9ea.scn"
[deps]
source_file="res://world/Tree.blend"
dest_files=["res://.godot/imported/Tree.blend-8edaf7c4bb18f0f1f1c8fa5b8380d9ea.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1
blender/nodes/visible=0
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true

28
client/world/World.tscn Normal file
View File

@ -0,0 +1,28 @@
[gd_scene load_steps=4 format=3 uid="uid://mgyg01l21t0j"]
[ext_resource type="PackedScene" uid="uid://tgmbtt7u172g" path="res://world/Arena.blend" id="1_1sh4g"]
[ext_resource type="PackedScene" uid="uid://hnn0n1xc2qt7" path="res://world/Tree.blend" id="2_lunhk"]
[ext_resource type="PackedScene" uid="uid://cb2t7bvvf3gwh" path="res://enemy/Slime.tscn" id="3_uuodv"]
[node name="World" type="Node3D"]
[node name="Arena" parent="." instance=ExtResource("1_1sh4g")]
[node name="Trees" type="Node3D" parent="."]
[node name="Tree" parent="Trees" instance=ExtResource("2_lunhk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.11323, 0, -4.64839)
[node name="Tree2" parent="Trees" instance=ExtResource("2_lunhk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.11323, 0, 5.35161)
[node name="Enemies" type="Node3D" parent="."]
[node name="Slime" parent="Enemies" instance=ExtResource("3_uuodv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -3.79687)
[node name="Slime2" parent="Enemies" instance=ExtResource("3_uuodv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.00829, 1.28057, -1.95247)
[node name="Slime3" parent="Enemies" instance=ExtResource("3_uuodv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -0.306177)