Пример #1
0
        public GalaxyCell GetCell(int x, int y)
        {
            if (x < 0 || y < 0 || x >= galaxySize || y >= galaxySize)
            {
                return(null);
            }

            for (int n = 0; n < cachedCells.Count; n++)
            {
                if (cachedCells[n].cellX == x && cachedCells[n].cellY == y)
                {
                    GalaxyCell result = cachedCells[n];
                    cachedCells.RemoveAt(n);
                    cachedCells.Add(result);
                    return(result);
                }
            }

            GalaxyCell newCell = new GalaxyCell(this, x, y);

            cachedCells.Add(newCell);
            if (cachedCells.Count > maxCacheSize)
            {
                cachedCells.RemoveAt(0);
            }

            return(newCell);
        }
Пример #2
0
        private void View_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                float pickX = (float)(e.X + renderer.scrollX) / renderer.cellSize;
                float pickY = (float)(e.Y + renderer.scrollY) / renderer.cellSize;

                GalaxyCell cell = galaxyGenerator.GetCell((int)pickX, (int)pickY);

                if (cell != null)
                {
                    pickX -= (int)pickX;
                    pickY -= (int)pickY;

                    foreach (StarSystem system in cell.starSystems)
                    {
                        if (Math.Abs(system.x - pickX) < 0.05f && Math.Abs(system.y - pickY) < 0.05f)
                        {
                            SelectSystem(system);
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        public Form1()
        {
            InitializeComponent();

            MainPictureBox.Paint += MainPictureBox_Paint;

            MainPictureBox.Refresh();

            hScrollBar1.Maximum = (GalaxyGenerator.galaxySize * renderer.cellSize);
            vScrollBar1.Maximum = (GalaxyGenerator.galaxySize * renderer.cellSize);

            vScrollBar1.Scroll += (sender, e) => { MainPictureBox.Invalidate(); };
            hScrollBar1.Scroll += (sender, e) => { MainPictureBox.Invalidate(); };

            KeyPress += Form1_KeyPress;

            MainPictureBox.MouseClick += View_MouseClick;
            MainPictureBox.MouseDown  += View_MouseDown;
            MainPictureBox.MouseUp    += View_MouseUp;
            MainPictureBox.MouseMove  += View_MouseMove;
            MainPictureBox.MouseWheel += View_MouseWheel;


            Rand64     rand  = new Rand64((ulong)new Random().Next());
            int        cellX = rand.Range(0, GalaxyGenerator.galaxySize);
            int        cellY = rand.Range(0, GalaxyGenerator.galaxySize);
            GalaxyCell cell  = galaxyGenerator.GetCell(cellX, cellY);

            if (cell != null)
            {
                StarSystem chosenSystem = cell.starSystems[rand.Range(0, cell.starSystems.Count)];
                SelectSystem(chosenSystem);
                CenterOnSystem(chosenSystem);
            }
        }
Пример #4
0
        public StarSystem GetStarSystem(StarSystemId id)
        {
            GalaxyCell cell = GetCell(id.cellX, id.cellY);

            if (cell != null)
            {
                return(cell.starSystems[id.systemIndex]);
            }
            return(null);
        }
Пример #5
0
        void RenderCell(Graphics gfx, int cellX, int cellY)
        {
            Pen pen = new Pen(Color.White, 1.0f);

            GalaxyCell cell = galaxyGenerator.GetCell(cellX, cellY);

            if (cell == null)
            {
                return;
            }

            int startX = (int)cellX * cellSize - scrollX;
            int startY = (int)cellY * cellSize - scrollY;

            foreach (JumpGateLink jump in cell.jumpGates)
            {
                DrawJump(gfx, jump);
            }

            foreach (StarSystem star in cell.starSystems)
            {
                float x = startX + star.x * cellSize;
                float y = startY + star.y * cellSize;

                Region region = galaxyGenerator.GetRegion(star.regionId);

                Brush systemColor = Brushes.White;

                switch (region.colorIndex % 23)
                {
                case 0: systemColor = Brushes.Red; break;

                case 1: systemColor = Brushes.Gold; break;

                case 2: systemColor = Brushes.Blue; break;

                case 3: systemColor = Brushes.Yellow; break;

                case 4: systemColor = Brushes.Orange; break;

                case 5: systemColor = Brushes.Magenta; break;

                case 6: systemColor = Brushes.Cyan; break;

                case 7: systemColor = Brushes.LightCyan; break;

                case 8: systemColor = Brushes.LightPink; break;

                case 9: systemColor = Brushes.LightGreen; break;

                case 10: systemColor = Brushes.LightBlue; break;

                case 11: systemColor = Brushes.DarkCyan; break;

                case 12: systemColor = Brushes.DarkBlue; break;

                case 13: systemColor = Brushes.DarkRed; break;

                case 14: systemColor = Brushes.IndianRed; break;

                case 15: systemColor = Brushes.DarkOrange; break;

                case 16: systemColor = Brushes.DarkSalmon; break;

                case 17: systemColor = Brushes.DarkSlateBlue; break;

                case 18: systemColor = Brushes.DarkTurquoise; break;

                case 19: systemColor = Brushes.DarkViolet; break;

                case 20: systemColor = Brushes.DeepPink; break;

                case 21: systemColor = Brushes.DeepSkyBlue; break;

                case 22: systemColor = Brushes.DodgerBlue; break;
                }

                if ((star.attributes & StarSystem.Attributes.Capital) != 0)
                {
                    gfx.FillRectangle(Brushes.White, x - 4, y - 4, 8, 8);
                    gfx.FillRectangle(systemColor, x - 3, y - 3, 6, 6);
                }
                else
                {
                    gfx.FillRectangle(systemColor, x - 1, y - 1, 3, 3);
                }

                if (star.id == selectedSystem)
                {
                    gfx.DrawRectangle(Pens.White, x - 10, y - 10, 20, 20);
                }

                if (zoom > 0.6f)
                {
                    gfx.DrawString(star.name, Label.DefaultFont, Brushes.White, x + 5, y - 5);
                }

                //if((star.attributes & StarSystem.Attributes.NorthConnector) != 0)
                //{
                //    DrawJump(gfx, star, galaxyGenerator.GetCell(cellX, cellY - 1).GetSystemWithAttribute(StarSystem.Attributes.SouthConnector));
                //}
                //if ((star.attributes & StarSystem.Attributes.EastConnector) != 0)
                //{
                //    DrawJump(gfx, star, galaxyGenerator.GetCell(cellX + 1, cellY).GetSystemWithAttribute(StarSystem.Attributes.WestConnector));
                //}
                //if ((star.attributes & StarSystem.Attributes.SouthConnector) != 0)
                //{
                //    DrawJump(gfx, star, galaxyGenerator.GetCell(cellX, cellY - 1).GetSystemWithAttribute(StarSystem.Attributes.NorthConnector));
                //}
                //if ((star.attributes & StarSystem.Attributes.WestConnector) != 0)
                //{
                //    DrawJump(gfx, star, galaxyGenerator.GetCell(cellX, cellY - 1).GetSystemWithAttribute(StarSystem.Attributes.EastConnector));
                //}
            }
        }
Пример #6
0
 public void GetRelativePosition(GalaxyCell relativeCell, out float outX, out float outY)
 {
     outX = (float)(id.cellX - relativeCell.cellX) + x;
     outY = (float)(id.cellY - relativeCell.cellY) + y;
 }
Пример #7
0
 public void GetRelativePosition(GalaxyCell relativeCell, out float outX, out float outY)
 {
     outX = (float)(id.cellX * RegionCell.galaxyCellsPerRegion - relativeCell.cellX) + x * RegionCell.galaxyCellsPerRegion;
     outY = (float)(id.cellY * RegionCell.galaxyCellsPerRegion - relativeCell.cellY) + y * RegionCell.galaxyCellsPerRegion;
 }