Пример #1
0
 public virtual void Move(GameTime gameTime)
 {
     foreach (Polygon ActivePolygon in ListCollisionPolygon)
     {
         ActivePolygon.Offset(Speed.X, Speed.Y);
     }
 }
Пример #2
0
        private void MouseMoveCollisions(MouseEventArgs e, int RealX, int RealY)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (SelectionChoice == SelectionChoices.Move)
                {
                    LayerViewer.SelectedPolygonTriangle.Move(e.X - MouseEventOld.X, e.Y - MouseEventOld.Y);
                }
            }
            else
            {
                LayerViewer.SelectedPolygonTriangle = null;
                SelectionChoice = SelectionChoices.None;

                foreach (Polygon ActivePolygon in ActiveLayer.ListWorldCollisionPolygon)
                {
                    PolygonTriangle Result = ActivePolygon.PolygonCollisionWithMouse(RealX, RealY);

                    if (Result.ActivePolygon != null)
                    {
                        LayerViewer.SelectedPolygonTriangle = Result;
                        SelectionChoice = SelectionChoices.Move;
                        break;
                    }
                }

                if (Control.ModifierKeys == Keys.Control && LayerViewer.SelectedPolygonTriangle != null)
                {
                    LayerViewer.SelectedPolygonTriangle.SelectionType = PolygonTriangle.SelectionTypes.Polygon;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Draws the control.
        /// </summary>
        protected override void Draw()
        {
            // Clear to the default control background color.
            Color backColor = new Color(BackColor.R, BackColor.G, BackColor.B);

            GraphicsDevice.Clear(backColor);

            if (OldWidth != ClientSize.Width || OldHeight != ClientSize.Height)
            {
                Matrix Projection      = Matrix.CreateOrthographicOffCenter(0, ClientSize.Width, ClientSize.Height, 0, 0, 1);
                Matrix HalfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

                PolygonEffect.Projection = HalfPixelOffset * Projection;

                OldWidth  = ClientSize.Width;
                OldHeight = ClientSize.Height;
            }

            g.Begin();

            if (EditOrigin && sprSource != null)
            {
                g.Draw(sprSource, new Vector2(0, 0), Color.White);
            }
            else
            {
                PolygonEffect.Texture = sprSource;
                PolygonEffect.CurrentTechnique.Passes[0].Apply();
                GraphicsDevice.RasterizerState = RasterizerState.CullNone;

                foreach (Polygon ActivePolygon in ListPolygon)
                {
                    ActivePolygon.Draw(GraphicsDevice);
                }
            }

            //Draw selected polygons.
            PolygonEffect.Texture = sprRedTexture;
            PolygonEffect.CurrentTechnique.Passes[0].Apply();
            GraphicsDevice.RasterizerState = RasterizerState.CullNone;
            foreach (Polygon ActivePolygon in ListSelectedPolygon)
            {
                ActivePolygon.Draw(GraphicsDevice);
            }

            DrawPolygons(g);

            if (SplittingPoint1 != SplittingPoint2)
            {
                DrawLine(g, SplittingPoint1, SplittingPoint2, Color.Black);
            }

            g.End();
        }
Пример #4
0
        public void Save(BinaryWriter BW)
        {
            BW.Write(ListWorldCollisionPolygon.Count);
            foreach (WorldPolygon ActivePolygon in ListWorldCollisionPolygon)
            {
                ActivePolygon.Save(BW);
            }

            BW.Write(GroundLevelCollision.ArrayVertex.Length);
            for (int V = 0; V < GroundLevelCollision.ArrayVertex.Length; V++)
            {
                BW.Write(GroundLevelCollision.ArrayVertex[V].X);
                BW.Write(GroundLevelCollision.ArrayVertex[V].Y);
            }

            BW.Write(ListImages.Count);
            for (int B = 0; B < ListImages.Count; B++)
            {
                ListImages[B].Save(BW);
                BW.Write(ListImages[B].Position.X);
                BW.Write(ListImages[B].Position.Y);
                BW.Write(ListImages[B].Depth);
            }

            BW.Write(ListProp.Count);
            for (int P = 0; P < ListProp.Count; P++)
            {
                BW.Write(ListProp[P].Name);
                ListProp[P].Save(BW);
            }

            BW.Write(ListSpawnPointTeam.Count);
            for (int S = 0; S < ListSpawnPointTeam.Count; S++)
            {
                ListSpawnPointTeam[S].Save(BW);
            }

            BW.Write(ListSpawnPointNoTeam.Count);
            for (int S = 0; S < ListSpawnPointNoTeam.Count; S++)
            {
                ListSpawnPointNoTeam[S].Save(BW);
            }
        }
Пример #5
0
        public override void OnUpdatePosition(Vector2 Translation)
        {
            foreach (Polygon ActivePolygon in ListPolygon)
            {
                ActivePolygon.UpdateWorldPosition(Translation, Angle);
            }

            float MinX = float.MaxValue;
            float MaxX = float.MinValue;
            float MinY = float.MaxValue;
            float MaxY = float.MinValue;

            foreach (Polygon ActivePolygon in ListPolygon)
            {
                for (int V = 0; V < ActivePolygon.VertexCount; V++)
                {
                    int VertexX = (int)ActivePolygon.ArrayVertex[V].X;
                    int VertexY = (int)ActivePolygon.ArrayVertex[V].Y;

                    if (VertexX < MinX)
                    {
                        MinX = VertexX;
                    }
                    if (VertexX > MaxX)
                    {
                        MaxX = VertexX;
                    }

                    if (VertexY < MinY)
                    {
                        MinY = VertexY;
                    }
                    if (VertexY > MaxY)
                    {
                        MaxY = VertexY;
                    }
                }
            }

            SourceRectangle = new Rectangle((int)MinX, (int)MinY, (int)(MaxX - MinX), (int)(MaxY - MinY));
        }
Пример #6
0
        /// <summary>
        /// Handles keypresses on the map
        /// </summary>
        protected internal override bool OnKeyDownCore(MapKeyEventArgs e)
        {
            if (ActivePolygon != null)
            {
                if (e.KeyEventArgs.KeyCode == Keys.Delete)
                {
                    Delete(ActivePolygon);
                    return(true);
                }

                if (!ActivePolygon.Drawing)
                {
                    var polygonMove = new KeyboardInputToMovementConverter(e.KeyEventArgs.KeyData, 1, 5).GetKeyMove();
                    if (polygonMove.HasValue)
                    {
                        ActivePolygon.Move(polygonMove.Value);
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #7
0
        public override void Draw(CustomSpriteBatch g, bool IsInEditMode)
        {
            foreach (Polygon ActivePolygon in ListPolygon)
            {
                ActivePolygon.Draw(g.GraphicsDevice);
            }

            if (IsInEditMode)
            {
                foreach (Polygon ActivePolygon in ListPolygon)
                {
                    for (int I = 0; I < ActivePolygon.ArrayIndex.Length; I += 3)
                    {
                        Vector2 Vertex1 = ActivePolygon.ArrayVertex[ActivePolygon.ArrayIndex[I]];
                        Vector2 Vertex2 = ActivePolygon.ArrayVertex[ActivePolygon.ArrayIndex[I + 1]];
                        Vector2 Vertex3 = ActivePolygon.ArrayVertex[ActivePolygon.ArrayIndex[I + 2]];

                        g.DrawLine(GameScreen.sprPixel, Vertex1, Vertex2, Color.Black, 1);
                        g.DrawLine(GameScreen.sprPixel, Vertex2, Vertex3, Color.Black, 1);
                        g.DrawLine(GameScreen.sprPixel, Vertex3, Vertex1, Color.Black, 1);
                    }
                }
            }
        }