Added dynamic spawning and despawning of objects
This commit is contained in:
parent
adbb208436
commit
e0cf8d9755
23 changed files with 794 additions and 350 deletions
22
scripts/GameObjects/Character.cs
Normal file
22
scripts/GameObjects/Character.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Godot;
|
||||
|
||||
public class Character(Sector sector, Vector3 localCoordinates) : GameObject(sector, localCoordinates)
|
||||
{
|
||||
private Player player;
|
||||
|
||||
public Player InstantiatePlayer()
|
||||
{
|
||||
PackedScene prefab = ResourceLoader.Load<PackedScene>("res://prefabs/gameObjects/player.tscn");
|
||||
Player instance = prefab.Instantiate<Player>();
|
||||
|
||||
instance.PlayerData = this;
|
||||
player = instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public override void UpdateNodePosition()
|
||||
{
|
||||
player.GlobalPosition = LocalCoordinates;
|
||||
}
|
||||
}
|
||||
1
scripts/GameObjects/Character.cs.uid
Normal file
1
scripts/GameObjects/Character.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dbl3bjk8yp3eb
|
||||
|
|
@ -1,5 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
public partial class StarNode : Node
|
||||
public partial class StarNode : StaticBody3D
|
||||
{
|
||||
public Star StarData { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
GlobalPosition = StarData.LocalCoordinates + StarData.SectorOffset;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
GlobalPosition = StarData.LocalCoordinates + StarData.SectorOffset;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,18 @@ public class Star(Sector sector, Vector3 localCoordinates) : GameObject(sector,
|
|||
public override void Simulate(double delta)
|
||||
{
|
||||
base.Simulate(delta);
|
||||
|
||||
SetCoordinatesFromGlobal(new(GlobalCoordinates.X, GlobalCoordinates.Y, GlobalCoordinates.Z + 1 * (decimal)delta));
|
||||
}
|
||||
|
||||
public override Node3D Instantiate(Sector sector)
|
||||
{
|
||||
PackedScene prefab = ResourceLoader.Load<PackedScene>("res://prefabs/gameObjects/star.tscn");
|
||||
StarNode instance = prefab.Instantiate<StarNode>();
|
||||
|
||||
instance.StarData = this;
|
||||
SectorOffset = GetSectorOffset(sector);
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue