static void Main(string[] args) { Galaxy gal = new Galaxy(20000,15000); Game game = new Game(1000, 1000,gal); //Cluster shuttle = new Cluster(Resources.IO.LoadMultiBlock(@"\Shuttle.TMX"), new OpenTK.Vector2(0, 0), new OpenTK.Vector2(-0.00f, -0.00f), 0.00f); Block[,] grid = new Block[1, 3]; grid[0, 0] = new Block(Resources.BlockRegistry.BlockTypes.Collector, grid, 0, 0); grid[0, 1] = new Block(Resources.BlockRegistry.BlockTypes.SolarPanel, grid, 0, 1); grid[0, 2] = new Block(Resources.BlockRegistry.BlockTypes.ThrusterIon, grid, 0, 2); float value = 0; Cluster Probe = new Cluster(grid, new OpenTK.Vector2(value,value),OpenTK.Vector2.Zero,0,new ushort[] {2,2 },gal); Controller player = new Controller(Controller.ControlType.Human); ShipLogistics ship = new ShipLogistics(Probe,grid, player); game.ObjHandler.AddCluster(Probe); game.ObjHandler.AddShipLogistics(ship); //game.ObjHandler.AddCluster(new Cluster(Cluster.Shape.Rectangle, Resources.BlockRegistry.BlockTypes.WingMid, new OpenTK.Vector2(0, -1000), new OpenTK.Vector2(0,0),(float)Math.PI/(60*10), 50,250)); new Task(() => { while (1 == 1 ) { System.Threading.Thread.Sleep(2000); Console.WriteLine("FramesPerSec = " + game.TICK/2.0); game.TICK = 0; } }).Start(); game.Run(); Console.ReadLine(); }
public ShipLogistics(Cluster outside,Block[,] grid,Controller ctrl) { External = outside; CargoHold = new Inventory(); TechGrid = new TechnicalBlock[outside.Width, outside.Height]; DoToAll(new Action((int x,int y) => { SetMachine(ref TechGrid[x, y],grid[x,y]); })); Parent = ctrl; }
public void RefreshCurrentSector(Cluster cluster,ref Vector2 positionTopLeft) { if (!SectorBlock.OutOfSectorBounds(ref cluster.CurrentSector[0], ref cluster.CurrentSector[1], ref positionTopLeft)) return; List<Cluster> sector = GetSectorBlock(cluster.CurrentSectorBlock).Sector(cluster.CurrentSector); sector.Remove(cluster); if (sector.Count == 0) sector = null; for (byte i = 0; i < 2; i++) { if (cluster.PositionTopLeft[i] < 0) { cluster.CurrentSectorBlock[i]--; positionTopLeft[i] += SectorBlock.SectorBlockSize; } else if(cluster.PositionTopLeft[i] >= SectorBlock.SectorBlockSize) { cluster.CurrentSectorBlock[i]++; positionTopLeft[i] -= SectorBlock.SectorBlockSize; } } SetSectorBlock(cluster); }
/// <summary> /// set /// </summary> /// <param name="location"></param> /// <param name="cluster"></param> public void SetSectorBlock(Cluster cluster) { if (GetSectorBlock(cluster.CurrentSectorBlock) == null) area[cluster.CurrentSectorBlock[0], cluster.CurrentSectorBlock[1]] = new SectorBlock(); GetSectorBlock(cluster.CurrentSectorBlock).Sector(cluster.CurrentSector); }
public static long[] GetGalacticCoords(Cluster cluster) => new long[2] { (long)cluster.PositionTopLeft.X + (cluster.CurrentSectorBlock[0]*SectorBlock.SectorBlockSize), (long)cluster.PositionTopLeft.Y + (cluster.CurrentSectorBlock[1]*SectorBlock.SectorBlockSize), };
public void AddCluster(Cluster cluster) => Clusters.Add(cluster);
private bool SetHeadingTo(float theta,Cluster cluster) { if (Math.Round(theta, Precision) == Math.Round(cluster.CurrentRotation, Precision)) return true; theta -= cluster.CurrentRotation; if (theta > Math.PI) theta -= (float)(Math.PI*3); else if (theta < -Math.PI) theta += (float)(Math.PI); cluster.AccelerateTorque(Resources.Helper.GetSign(theta)); return false; }
public void Update(Cluster cluster,View view) { if (AutoPilot) { Console.WriteLine("Coords = " + cluster.PositionTopLeft); if (SetHeadingTo(FixTheta(Math.Abs(Resources.Helper.GetPolarCoords(cluster.Velocity).Y)), cluster)) Accelerate = true; else Accelerate = false; if (cluster.Velocity.LengthSquared < 0.01) AutoPilot = false; } switch(Master) { case ControlType.Human: { if(Input.KeyRelease(OpenTK.Input.Key.O)) { if(AutoPilot) { AutoPilot = false; Console.WriteLine("AutoPilot:Off"); } else { AutoPilot = true; Console.WriteLine("AutoPilot:On"); } } sbyte[] input = Input.GetKeyInputVector2(); if (-input[1] > 0) Accelerate = true; else if(!AutoPilot) Accelerate = false; cluster.AccelerateTorque(input[0]); view.SetPosition( cluster.PositionTopLeft + new OpenTK.Vector2(cluster.Width / 2, cluster.Height / 2) + cluster.Velocity); if (Input.KeysDown.Contains(OpenTK.Input.Key.KeypadPlus)) { view.Zoom *= 1.0625f; } if (Input.KeysDown.Contains(OpenTK.Input.Key.KeypadMinus)) { view.Zoom /= 1.0625f; } OpenTK.Vector2 velocity = new OpenTK.Vector2((float)Math.Round(cluster.Velocity.X,2), (float)Math.Round(cluster.Velocity.Y, 2)); if (velocity != velocityLast) { //Console.WriteLine("Velocity = " + velocity); Console.WriteLine("Kilometers Per Second = " + velocity.Length*60*60/1000); velocityLast = velocity; } break; } case ControlType.Runner: { break; } case ControlType.Charger: { break; } default: { break; } } }