Beispiel #1
0
 public Block(Resources.BlockRegistry.BlockTypes type,Block[,] grid,short x,short y)
 {
     this.Type = type;
     Grid = grid;
     X = x;
     Y = y;
 }
Beispiel #2
0
 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 void SetMachine(ref TechnicalBlock techBlock,Block childBlock,bool activated = true)
 {
     switch(childBlock.Type)
     {
         case Resources.BlockRegistry.BlockTypes.ThrusterIon:
             {
                 techBlock = new TechnicalBlock(childBlock, new TechnicalBlock.Machine(Rocket), activated);
                 break;
             }
         case Resources.BlockRegistry.BlockTypes.SolarPanel:
             {
                 techBlock = new TechnicalBlock(childBlock, new TechnicalBlock.Machine(SolarPanel), activated);
                 break;
             }
         case Resources.BlockRegistry.BlockTypes.Collector:
             {
                 techBlock = new TechnicalBlock(childBlock, new TechnicalBlock.Machine(HydrogenCollecter), activated);
                 break;
             }
         default:
             {
                 techBlock = new TechnicalBlock(childBlock, new TechnicalBlock.Machine(Generic), false);
                 break;
             }
     }
 }
 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 RightClick(Block block)
        {
            Console.WriteLine("Active = " + TechGrid[block.X,block.Y].Activated + "\n Enter: t/f");
            char ret = Console.ReadKey().KeyChar;
            if (ret == 't' || ret == 'T')
                TechGrid[block.X, block.Y].Activated = true;
            else TechGrid[block.X, block.Y].Activated = false;

        }
        public static void Draw(Block[,] grid, Vector2 positionTopLeft,ref RectangleF windowFrame,View view, float rotation = 0.0f,bool ForceRender = false)
        {
            short width = (short)grid.GetLength(0);
            short height = (short)grid.GetLength(1);
            //origin = zero
            Vector2[] vertices = new Vector2[4]
            {
                new Vector2(0,0),
                new Vector2(1,0),
                new Vector2(1,1),
                new Vector2(0,1),
            };
            GL.MatrixMode(MatrixMode.Texture);
            GL.LoadIdentity();
            if (rotation != 0)
            {
                var matrix = Matrix4.CreateTranslation(-0.5f, -0.5f, 0.0f) *
                          Matrix4.CreateFromAxisAngle(new Vector3(0, 0, 1), rotation) *
                          Matrix4.CreateTranslation(0.5f, 0.5f, 0.0f);
                GL.LoadMatrix(ref matrix);
            }
            GL.MatrixMode(MatrixMode.Modelview);
            byte h;
            RectangleF checking;
            for (short i = 0; i < width; i++)
            {
                for (short j = 0; j < height; j++)
                {
                    if (!ForceRender)
                    {
                        if ((i % view.TextureDensity == 0 && j % view.TextureDensity == 0))
                        {
                            //checking = new RectangleF((grid[i, j].PreciseLocation.X + positionTopLeft.X), (grid[i, j].PreciseLocation.Y + positionTopLeft.Y), 1.5f, 1.5f);
                            checking = new RectangleF(
                                (grid[i, j].PreciseLocation.X + positionTopLeft.X), (grid[i, j].PreciseLocation.Y + positionTopLeft.Y),
                                1f * view.Zoom, 1f * view.Zoom);
                            if (!windowFrame.IntersectsWith(checking))
                                continue;

                        }
                    }
                    GL.BindTexture(TextureTarget.Texture2D, grid[i,j].Texture(view.TextureSize).ID);
                    GL.Begin(PrimitiveType.Quads);
                    for (h = 0; h < 4; h++)
                    {
                        GL.TexCoord2(vertices[h]);
                        GL.Vertex2((vertices[h] + positionTopLeft + grid[i,j].PreciseLocation)*view.TextureSize);
                    }
                    GL.End();
                }
            }
        }
Beispiel #7
0
 public Cluster(Block[,] grid,Vector2 positionTopLeft, Vector2 velocity, float rotation,ushort[] sectorBlock,Galaxy gal)
 {
     
     Grid = grid;
     Rotation = rotation;
     this.Velocity = velocity;
     this.positionTopLeft = positionTopLeft;
     short[] centerCoords = new short[2];
     RefreshMass();
     RefreshCenterOfMass();
     RefreshRenderFrame(1,16);
     Radius = (float)Math.Sqrt(Math.Pow(Height, 2) + Math.Pow(Width, 2));
     CurrentSectorBlock = sectorBlock;
     CurrentSector = SectorBlock.GetNearestSectorCoords(ref positionTopLeft);
     gal.SetSectorBlock(this);
 }
 public TechnicalBlock(Block childBlock,Machine action,bool activated = true)
 {
     ChildBlock = childBlock;
     Action = action;
     Activated = activated;
 }