Implement basic networking
This commit is contained in:
parent
c320d9ddcb
commit
994823a9c3
25 changed files with 643 additions and 217 deletions
|
|
@ -4,6 +4,39 @@ public class Character(Sector sector, Vector3 localCoordinates) : GameObject(sec
|
|||
{
|
||||
private Player player;
|
||||
|
||||
public bool SheduledUpdateNode = false;
|
||||
|
||||
public override void AssignSector(Sector sector)
|
||||
{
|
||||
CurrentSector = sector;
|
||||
|
||||
ResetLocalCoordinates();
|
||||
UpdateSectorOffsetToMainPlayer();
|
||||
UpdateNodePosition();
|
||||
|
||||
if (IsMainPlayer())
|
||||
{
|
||||
GameManager.Singleton.ApplyOrigin();
|
||||
|
||||
if (!Global.IsGameHost)
|
||||
{
|
||||
GameManager.Singleton.RpcId(
|
||||
1,
|
||||
nameof(GameManager.Singleton.RpcSendNearbySectors),
|
||||
CurrentSector.Coordinates,
|
||||
NetworkManager.Singleton.LocalNetId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
reassigning = false;
|
||||
}
|
||||
|
||||
public bool IsMainPlayer()
|
||||
{
|
||||
return player == GameManager.Singleton.MainPlayer;
|
||||
}
|
||||
|
||||
public Player InstantiatePlayer()
|
||||
{
|
||||
PackedScene prefab = ResourceLoader.Load<PackedScene>("res://prefabs/gameObjects/player.tscn");
|
||||
|
|
@ -17,6 +50,13 @@ public class Character(Sector sector, Vector3 localCoordinates) : GameObject(sec
|
|||
|
||||
public override void UpdateNodePosition()
|
||||
{
|
||||
player.GlobalPosition = LocalCoordinates;
|
||||
if (IsMainPlayer())
|
||||
{
|
||||
player.GlobalPosition = LocalCoordinates;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.GlobalPosition = LocalCoordinates + SectorOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ public class Star(Sector sector, Vector3 localCoordinates) : GameObject(sector,
|
|||
{
|
||||
base.Simulate(delta);
|
||||
|
||||
SetCoordinatesFromGlobal(new(GlobalCoordinates.X, GlobalCoordinates.Y, GlobalCoordinates.Z + 1 * (decimal)delta));
|
||||
//SetCoordinatesFromGlobal(new(GlobalCoordinates.X, GlobalCoordinates.Y, GlobalCoordinates.Z + 1 * (decimal)delta));
|
||||
}
|
||||
|
||||
public override Node3D Instantiate(Sector sector)
|
||||
|
|
@ -14,8 +14,9 @@ public class Star(Sector sector, Vector3 localCoordinates) : GameObject(sector,
|
|||
PackedScene prefab = ResourceLoader.Load<PackedScene>("res://prefabs/gameObjects/star.tscn");
|
||||
StarNode instance = prefab.Instantiate<StarNode>();
|
||||
|
||||
instance.Name = $"Star-{UUID}";
|
||||
instance.StarData = this;
|
||||
SectorOffset = GetSectorOffset(sector);
|
||||
UpdateSectorOffsetToMainPlayer();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue