Add initial game code

This commit is contained in:
Aslan 2025-09-12 08:34:06 -04:00
parent f80a60e208
commit 1383997ebf
55 changed files with 1355 additions and 0 deletions

View file

@ -0,0 +1,22 @@
using System.Collections.Generic;
public partial class Galaxy : GameObject
{
public List<GameObject> GameObjects { get; private set; }
public Galaxy(string name, CoordinateVector position, CoordinateVector size)
: base(name, position, size, null)
{
this.GameObjects = new List<GameObject>();
}
public override void Simulate()
{
base.Simulate();
foreach (GameObject gameObject in this.GameObjects)
{
gameObject.Simulate();
}
}
}

View file

@ -0,0 +1 @@
uid://ciroqbky68llv

View file

@ -0,0 +1,13 @@
public partial class Item : GameObject
{
public Item(string name, GameObject parent)
: base(name, new CoordinateVector(0, 0), new CoordinateVector(0, 0), parent)
{
}
public override void Simulate()
{
base.Simulate();
}
}

View file

@ -0,0 +1 @@
uid://26tpqqdo7kfi

View file

@ -0,0 +1,13 @@
public partial class Component : Item
{
public Component(string name, GameObject parent)
: base(name, parent)
{
}
public override void Simulate()
{
base.Simulate();
}
}

View file

@ -0,0 +1 @@
uid://crsm66sgsoax2

View file

@ -0,0 +1,13 @@
public partial class Life : GameObject
{
public Life(string name, GameObject parent)
: base(name, new CoordinateVector(0, 0), new CoordinateVector(0, 0), parent)
{
}
public override void Simulate()
{
base.Simulate();
}
}

View file

@ -0,0 +1 @@
uid://eybn0icmypql

View file

@ -0,0 +1,22 @@
using System.Collections.Generic;
public partial class Nebula : GameObject
{
public List<GameObject> GameObjects { get; private set; }
public Nebula(string name, CoordinateVector position, CoordinateVector size, GameObject parent)
: base(name, position, size, parent)
{
this.GameObjects = new List<GameObject>();
}
public override void Simulate()
{
base.Simulate();
foreach (GameObject gameObject in this.GameObjects)
{
gameObject.Simulate();
}
}
}

View file

@ -0,0 +1 @@
uid://cyo7pd66loqvy

View file

@ -0,0 +1,35 @@
using System.Collections.Generic;
public partial class Planet : GameObject
{
public bool IsMoon { get; private set; }
public long Diameter { get; private set; }
public List<GameObject> OrbitingGameObjects { get; private set; }
public List<GameObject> PlanetGameObjects { get; private set; }
public Planet(string name, CoordinateVector position, GameObject parent, bool isMoon, long diameter)
: base(name, position, new CoordinateVector(0, 0), parent)
{
this.IsMoon = isMoon;
this.Diameter = diameter;
this.OrbitingGameObjects = new List<GameObject>();
this.PlanetGameObjects = new List<GameObject>();
}
public override void Simulate()
{
base.Simulate();
foreach (GameObject gameObject in this.OrbitingGameObjects)
{
gameObject.Simulate();
}
foreach (GameObject gameObject in this.PlanetGameObjects)
{
gameObject.Simulate();
}
}
}

View file

@ -0,0 +1 @@
uid://bgeb47vjo08xs

View file

@ -0,0 +1,23 @@
public partial class Ship : Structure
{
public Ship(string name, CoordinateVector position, GameObject parent, long diameter, bool isPlayer)
: base(name, position, parent, diameter, isPlayer)
{
this.IsMobile = true;
}
public override void Simulate()
{
base.Simulate();
if (this.IsPlayer)
{
SimulatePlayer();
}
}
protected void SimulatePlayer()
{
}
}

View file

@ -0,0 +1 @@
uid://cna2w4aqci13s

View file

@ -0,0 +1,33 @@
using System.Collections.Generic;
public partial class Star : GameObject
{
public enum SpectralClassType
{
O = 0, B = 1, A = 2, F = 3, G = 4, K = 5, M = 6
}
public SpectralClassType SpectralClass { get; private set; }
public long Diameter { get; private set; }
public List<GameObject> GameObjects { get; private set; }
public Star(string name, CoordinateVector position, GameObject parent, SpectralClassType spectralClass, long diameter)
: base(name, position, new CoordinateVector(0, 0), parent)
{
this.SpectralClass = spectralClass;
this.Diameter = diameter;
this.GameObjects = new List<GameObject>();
}
public override void Simulate()
{
base.Simulate();
foreach (GameObject gameObject in this.GameObjects)
{
gameObject.Simulate();
}
}
}

View file

@ -0,0 +1 @@
uid://clu6fkj61p62a

View file

@ -0,0 +1,136 @@
using System.Collections.Generic;
public partial class Structure : GameObject
{
public Order CurrentOrder { get; protected set; }
public bool IsPlayer { get; private set; }
public bool IsMobile { get; protected set; }
public bool IsLanded { get; protected set; }
public bool IsOrbiting { get; protected set; }
public long Diameter { get; protected set; }
public AI AI { get; protected set; }
public List<Component> Components { get; protected set; }
public List<GameObject> Cargo { get; protected set; }
public List<Life> Crew { get; protected set; }
public Structure(string name, CoordinateVector position, GameObject parent, long diameter, bool isPlayer)
: base(name, position, new CoordinateVector(0, 0), parent)
{
this.IsPlayer = isPlayer;
this.IsMobile = false;
this.IsLanded = false;
this.IsOrbiting = false;
this.Diameter = diameter;
this.AI = isPlayer ? null : new AI(this);
this.Components = new List<Component>();
this.Cargo = new List<GameObject>();
this.Crew = new List<Life>();
}
public override void Simulate()
{
base.Simulate();
foreach (GameObject component in this.Components)
{
component.Simulate();
}
foreach (GameObject cargoItem in this.Cargo)
{
cargoItem.Simulate();
}
foreach (GameObject crewMember in this.Crew)
{
crewMember.Simulate();
}
ExecuteOrder();
}
public bool SetNewPlayerOrder(Order newOrder)
{
if (!this.IsPlayer)
{
return false;
}
this.CurrentOrder = newOrder;
return true;
}
protected bool ExecuteOrder()
{
bool finished = false;
if (this.CurrentOrder == null)
{
if (!this.IsPlayer && this.AI != null)
{
this.CurrentOrder = this.AI.Think();
}
return false;
}
if (this.CurrentOrder.Category == Order.OrderCategory.TICK)
{
finished = ExecuteTickOrder(this.CurrentOrder as TickOrder);
}
if (this.CurrentOrder.Category == Order.OrderCategory.DESTINATION)
{
finished = ExecuteDestinationOrder(this.CurrentOrder as DestinationOrder);
}
if (finished)
{
this.CurrentOrder = null;
}
return finished;
}
protected bool ExecuteTickOrder(TickOrder tickOrder)
{
bool finished = false;
switch (tickOrder.Type)
{
case Order.OrderType.IDLE:
break;
case Order.OrderType.ORBIT:
break;
case Order.OrderType.LAND:
break;
}
return finished;
}
protected bool ExecuteDestinationOrder(DestinationOrder destinationOrder)
{
bool finished = false;
switch (destinationOrder.Type)
{
case Order.OrderType.MOVE_THRUSTERS:
finished = this.TravelTo(destinationOrder.Destination, false);
break;
case Order.OrderType.MOVE_WARP:
finished = this.TravelTo(destinationOrder.Destination, true);
break;
}
return finished;
}
}

View file

@ -0,0 +1 @@
uid://jpr7mwxec56

View file

@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Threading.Tasks;
public partial class Universe
{
public decimal CurrentTick { get; private set; }
public List<GameObject> GameObjects { get; private set; }
public Ship PlayerShip { get; private set; }
public Universe()
{
this.GameObjects = new List<GameObject>();
}
public decimal SimulateTick()
{
this.CurrentTick++;
List<Task> galaxySimulationTasks = new List<Task>();
foreach (GameObject gameObject in this.GameObjects)
{
if (gameObject.GetType().Name == "Galaxy")
{
Task galaxySimulation = new Task(() => gameObject.Simulate());
galaxySimulation.Start();
galaxySimulationTasks.Add(galaxySimulation);
continue;
}
gameObject.Simulate();
}
Task.WaitAll(galaxySimulationTasks.ToArray());
return this.CurrentTick;
}
}

View file

@ -0,0 +1 @@
uid://bwhcw860ysbpm