Пример #1
0
        public void Render(Graphics g, Vector2D translation)
        {
            Pen pen = new Pen(new SolidBrush(color));
            Vector2D z = new Vector2D((float)Math.Sqrt(RADIUS * RADIUS - RADIUS * Math.Sin(ToRadians(60))), (float)(RADIUS * Math.Sin(ToRadians(60))));

            Vector2D upRight = new Vector2D(z.X, 2 * -z.Y);
            Vector2D horRight = new Vector2D(2 * z.X, 0);
            Vector2D botRight = new Vector2D(z.X, 2 * z.Y);
            Vector2D botLeft = new Vector2D(-z.X, 2 * z.Y);
            Vector2D horLeft = new Vector2D(-2 * z.X, 0);
            Vector2D upLeft = new Vector2D(-z.X, 2 * -z.Y);

            Vector2D posUpRight = center + upRight + translation;
            Vector2D posHorRight = center + horRight + translation;
            Vector2D posBotRight = center + botRight + translation;
            Vector2D posBotLeft = center + botLeft + translation;
            Vector2D posHorLeft = center + horLeft + translation;
            Vector2D posUpLeft = center + upLeft + translation;

            PointF[] points = new PointF[]
            {
                new PointF(posUpRight.X, posUpRight.Y),
                new PointF(posHorRight.X, posHorRight.Y),
                new PointF(posBotRight.X, posBotRight.Y),
                new PointF(posBotLeft.X, posBotLeft.Y),
                new PointF(posHorLeft.X, posHorLeft.Y),
                new PointF(posUpLeft.X, posUpLeft.Y)
            };

            g.DrawPolygon(pen, points);
        }
Пример #2
0
        public Cell(Vector2D center, Vector2D translation)
        {
            this.center = new Vector2D(center.X * DIAMETER, center.Y * DIAMETER);
            this.center += translation;

            this.color = PickRandomColor();
        }
Пример #3
0
        public bool Collides(Vector2D hitterPosition)
        {
            Vector2D worldPosition = CoordinateSystemConverter.PixelsToWorld(hitterPosition);
            LayeredWorld world = (LayeredWorld)WorldManager.Worlds["first_world"];

            return world.Collides(worldPosition, 0);
        }
Пример #4
0
        public HexagonalGrid(Vector2D size, HexagonalCell[] cells, int iteration)
        {
            this.size = new Point((int)size.X, (int)size.Y);

            this.cells = cells;
            this.iteration = iteration;

            this.copy = new HexagonalCell[Width * Height];
        }
Пример #5
0
        public Player(Vector2D position)
        {
            this.speed = new Vector2D(3, 3);
            this.position = CoordinateSystemConverter.WorldToPixels(position);

            this.sprite = AnimationManager.GetAnimation("character");

            Program.RenderWindow.KeyPressed += RenderWindow_KeyPressed;
            Program.RenderWindow.KeyReleased += RenderWindow_KeyReleased;
        }
Пример #6
0
 public static Vector2D GetDirectionVector(Direction direction, Vector2D extra)
 {
     if (direction == Direction.Up)
         return new Vector2D(0, -extra.Y);
     if (direction == Direction.Down)
         return new Vector2D(0, extra.Y);
     if (direction == Direction.Left)
         return new Vector2D(-extra.X, 0);
     return new Vector2D(extra.X, 0);
 }
Пример #7
0
        public HexagonalCell(Vector2D position, Vector2D translation, bool alive)
        {
            this.alive = alive;

            this.gridCenter = position;
            this.center = new Vector2D(position.X * DIAMETER, position.Y * DIAMETER);
            this.center += translation;

            this.color = PickRandomColor();
            DetermineColorFromLifeState();
        }
Пример #8
0
        public Player()
        {
            this.speed = new Vector2D(3, 3);
            this.position = new Vector2D(10, 10);

            animation = AnimationGroupManager.GetAnimationGroup("player_animation");
            animation.SetCurrentAnimation("player_up");

            Program.RenderWindow.KeyPressed += RenderWindow_KeyPressed;
            Program.RenderWindow.KeyReleased += RenderWindow_KeyReleased;
        }
        ///--------------------------\
        //|     p(x,y) = p(i)         |
        //|     p(i) = wy + x         |
        //\--------------------------/
        public static int PlaneToLine(Vector2D worldCoords, int width)
        {
            int y = (int)worldCoords.Y;
            int x = (int)worldCoords.X;

            if (x < 0 || x > width)
                return -1;        // If x is not in the grid, return
                                 // a negative value that won't be
                                // processed downward. ;-)

            int line = width * y + x;
            return line;
        }
Пример #10
0
        private void RenderWindow_KeyPressed(object sender, KeyEventArgs e)
        {
            Vector2D position = new Vector2D(view.Center.X, view.Center.Y);

            if (e.Code == Keyboard.Key.Q)
                position.X -= 10;
            if (e.Code == Keyboard.Key.D)
                position.X += 10;
            if (e.Code == Keyboard.Key.Z)
                position.Y -= 10;
            if (e.Code == Keyboard.Key.S)
                position.Y += 10;

            view.Center = position.InternalVector;
        }
Пример #11
0
        public static IntRect CreateHitbox(Vector2D position, bool useTextureSize = false)
        {
            int w = (int)TextureManager.TextureSize.X;
            int h = (int)TextureManager.TextureSize.Y;
            int x = (int)position.X;
            int y = (int)position.Y;

            if (useTextureSize)
            {
                x *= (int)TextureManager.TextureSize.X;
                y *= (int)TextureManager.TextureSize.Y;
            }

            IntRect hitbox = new IntRect(x, y, w, h);
            return hitbox;
        }
Пример #12
0
        private void InitializeLifeGame(bool hasBitmap = true, bool hasGrid = false)
        {
            working = false;

            mouseDown = false;
            lastDrawnPosition = Vector2D.Zero;
            view = new Rectangle(0, 0, pb_Ozone.Width, pb_Ozone.Height);

            if (!hasGrid)
                CreateGrid();

            if (!hasBitmap)
                CreateBitmap();

            SetScrollBarsMaximums();
        }
Пример #13
0
 public static Vector2D GetDirectionVector(Direction direction)
 {
     Vector2D extra = new Vector2D(1, 1);
     return GetDirectionVector(direction, extra);
 }
 public static Vector2D WorldToPixels(Vector2D worldCoords)
 {
     int x = (int)(worldCoords.X * Textures.TextureManager.TextureSize.X);
     int y = (int)(worldCoords.Y * Textures.TextureManager.TextureSize.Y);
     return new Vector2D(x, y);
 }
Пример #15
0
        public void Render(Graphics graphics, Vector2D translation)
        {
            Pen pen = new Pen(new SolidBrush(color));

            Vector2D posUpRight = center + upRight + translation;
            Vector2D posHorRight = center + horRight + translation;
            Vector2D posBotRight = center + botRight + translation;
            Vector2D posBotLeft = center + botLeft + translation;
            Vector2D posHorLeft = center + horLeft + translation;
            Vector2D posUpLeft = center + upLeft + translation;

            PointF[] points = new PointF[]
            {
                new PointF(posUpRight.X, posUpRight.Y),
                new PointF(posHorRight.X, posHorRight.Y),
                new PointF(posBotRight.X, posBotRight.Y),
                new PointF(posBotLeft.X, posBotLeft.Y),
                new PointF(posHorLeft.X, posHorLeft.Y),
                new PointF(posUpLeft.X, posUpLeft.Y)
            };

            graphics.DrawPolygon(pen, points);
        }
Пример #16
0
        private void DrawRow(Graphics g, int y, Vector2D translation)
        {
            for (int x = 0; x < Width; x++)
            {
                int i = CoordinateSystemConverter.PlaneToLine(new Vector2D(x, y), Width);

                if (x % 2 != 0)
                {
                    Vector2D totalTranslation = new Vector2D(x * Cell.RADIUS, -Cell.DIAMETER);
                    totalTranslation += translation;
                    cells[i].Render(g, totalTranslation);
                }
                else
                {
                    Vector2D totalTranslation = new Vector2D(x * Cell.RADIUS, 0);
                    totalTranslation += translation;
                    cells[i].Render(g, totalTranslation);
                }
            }
        }
Пример #17
0
 private void pb_Ozone_MouseMove(object sender, MouseEventArgs e)
 {
     if (grid != null && mouseDown)
         lastDrawnPosition = ReverseCellStateAndRender(e);
 }
Пример #18
0
        public virtual void ReverseCellLifeState(Vector2D position)
        {
            int i = CoordinateSystemConverter.PlaneToLine(position, Width);

            if (IsInBounds(i))
                cells[i].ReverseLife();
        }
Пример #19
0
        private Vector2D ReverseCellStateAndRender(MouseEventArgs e)
        {
            Vector2D position = new Vector2D(e.X / Cell.CELL_SIZE, e.Y / Cell.CELL_SIZE);

            if (!lastDrawnPosition.Equals(position))
            {
                grid.ReverseCellLifeState(position);
                Render();
            }

            return position;
        }
Пример #20
0
 public HexagonalGrid(Vector2D size)
 {
     this.size = new Point((int)size.X, (int)size.Y);
     CreateCells();
 }
Пример #21
0
 public bool Equals(Vector2D b)
 {
     return b.X == X && b.Y == Y;
 }
 public static Vector2D PixelsToWorld(Vector2D pixelCoords)
 {
     int x = (int)(pixelCoords.X / Textures.TextureManager.TextureSize.X);
     int y = (int)(pixelCoords.Y / Textures.TextureManager.TextureSize.Y);
     return new Vector2D(x, y);
 }