abracadabra

This commit is contained in:
Valera
2025-06-12 22:51:36 +07:00
parent 9cacb9ee37
commit 1ed47cc6e9
11 changed files with 6746 additions and 0 deletions

3
code/Assembly.cs Normal file
View File

@@ -0,0 +1,3 @@
global using Sandbox;
global using System.Collections.Generic;
global using System.Linq;

53
code/LocalCar.cs Normal file
View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using VeloX;
namespace Sandbox
{
internal class LocalCar : Component, Component.INetworkListener
{
void INetworkListener.OnDisconnected( Connection channel )
{
if ( Car?.ConnectionID == channel.Id )
DestroyGameObject();
}
[Property] VeloXCar Car { get; set; }
[Property] public Vector3 CameraOffset { get; set; }
private Angles EyeAngles { get; set; }
protected override void OnUpdate()
{
if ( !Car.IsDriver )
return;
UpdateEyeAngles();
CameraSetup();
}
private void UpdateEyeAngles()
{
Angles input = Input.AnalogLook;
Angles eyeAngles = EyeAngles;
eyeAngles += input;
eyeAngles.roll = 0f;
eyeAngles.pitch = eyeAngles.pitch.Clamp( 0f - 89, 89 );
EyeAngles = eyeAngles;
}
protected void CameraSetup()
{
var cam = Scene.Camera;
cam.WorldRotation = EyeAngles;
cam.WorldPosition = WorldPosition + Vector3.Up * CameraOffset.z + cam.WorldRotation.Backward * CameraOffset.x;
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeloX;
namespace Sandbox;
public sealed class VeloXNetworkManager : Component, Component.INetworkListener
{
/// <summary>
/// The prefab to spawn for the player to control.
/// </summary>
[Property] public GameObject PlayerPrefab { get; set; }
protected override async Task OnLoad()
{
if ( Scene.IsEditor )
return;
if ( !Networking.IsActive )
{
LoadingScreen.Title = "Creating Lobby";
await Task.DelayRealtimeSeconds( 0.1f );
Networking.CreateLobby( new() );
}
}
/// <summary>
/// A client is fully connected to the server. This is called on the host.
/// </summary>
public void OnActive( Connection channel )
{
Log.Info( $"Player '{channel.DisplayName}' has joined the game" );
if ( !PlayerPrefab.IsValid() )
return;
var player = PlayerPrefab.Clone( WorldTransform, name: $"Player - {channel.DisplayName}" );
player.NetworkSpawn( channel );
player.Components.Get<VeloXCar>().ConnectionID = channel.Id;
}
}