Exemplo n.º 1
0
        public virtual void Draw(Effect effect, bool enable_lighting = false, DrawModes mode = DrawModes.Mesh | DrawModes.Outline)
        {
            //effect.LightingEnabled = false;
            if (OutlineLocation > 0 && (mode & DrawModes.Outline) != 0)
            {
                effect.CurrentTechnique.Passes[0].Apply();
                Device.SetVertexBuffer(OutlineBuffer);
                Device.DrawPrimitives(PrimitiveType.LineList, 0, OutlineLocation / 2);
            }

            if ((IsIndexed && IndexCount == 0) || (!IsIndexed && VertexCount == 0) || ((mode & DrawModes.Mesh) == 0))
            {
                Device.SetVertexBuffer(null);
                return;
            }

            if (enable_lighting)
            {
                /*effect.LightingEnabled = true;
                 * effect.PreferPerPixelLighting = true;
                 * effect.SpecularPower = 64;
                 * effect.SpecularColor = Color.Black.ToVector3();
                 * effect.CurrentTechnique.Passes[0].Apply();
                 * effect.AmbientLightColor = Color.Gray.ToVector3();*/
            }

            if (effect != null)
            {
                effect.CurrentTechnique.Passes[0].Apply();
            }
            Device.SetVertexBuffer(VertexBuffer);
            if (IsIndexed)
            {
                Device.Indices = IndexBuffer;
                if (Is3D)
                {
                    Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, VertexCount, 0, Math.Min(1048575, IndexCount / 3));
                }
                else
                {
                    Device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, VertexCount, 0, IndexCount / 2);
                }
                Device.Indices = null;
            }
            else
            {
                if (Is3D)
                {
                    Device.DrawPrimitives(PrimitiveType.TriangleList, 0, VertexCount / 3);
                }
                else
                {
                    Device.DrawPrimitives(PrimitiveType.LineList, 0, VertexCount / 2);
                }
            }
            Device.SetVertexBuffer(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Конструктор. Инициализирует экземпляр отрисовщика
        /// </summary>
        public LogoDrawer()
        {
            // Инициализация
#if LDDEBUG
            extended = 1;
#else
            extended = (uint)((rnd.Next(10) == 0) ? 1 : 0);
#endif
            mode = DrawModes.Mode1;

            InitializeComponent();
        }
Exemplo n.º 3
0
        public MathGraphic(Color PenColor, DrawModes drawMode,
                           DoubleFunction f, float x1, float x2, float StepX)
        {
            this.penColor = PenColor;
            this.penWidth = 1f;

            this.drawingMode = drawMode;

            graphic = Tabulate(f, x1, x2, StepX);

            tabulated = true;
        }
Exemplo n.º 4
0
        public MathGraphic(Color PenColor, DrawModes drawMode,
                           DoubleFunction fx, DoubleFunction fy, float T1, float T2, float StepT)
        {
            this.penColor = PenColor;
            this.penWidth = 1f;

            this.drawingMode = drawMode;

            graphic = Tabulate(fx, fy, T1, T2, StepT);

            tabulated = true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// adds graph of parametrically defined 2D function
        /// </summary>
        /// <param name="f">Real function of DoubleFunction</param>
        /// <param name="drawMode">Whether to join nodes with lines</param>
        /// <returns>Zero-based index (ID) of newly added graphic</returns>
        public int AddGraphic(DoubleFunction fx, DoubleFunction fy, float t1, float t2,
                              DrawModes drawMode, Color penColor)
        {
            if (grs == null)
            {
                grs = new List <MathGraphic>(100);
            }
            MathGraphic newGraphic = new MathGraphic(penColor, drawMode,
                                                     fx, fy, t1, t2, 0.01f);

            grs.Add(newGraphic);

            return(grs.Count - 1);
        }
Exemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="penWidth">Is zooming with graphics of not zero :(</param>
        public int AddPolygon(Color penColor, float penWidth,
                              DrawModes drawMode, params PointF[] pts)
        {
            if (grs == null)
            {
                grs = new List <MathGraphic>(100);
            }

            MathGraphic newGraphic = new MathGraphic(pts);

            newGraphic.DrawingMode = drawMode;
            newGraphic.PenColor    = penColor;
            newGraphic.PenWidth    = penWidth;

            grs.Add(newGraphic);

            return(grs.Count - 1);
        }
Exemplo n.º 7
0
        public override void Draw(Effect effect, bool enable_lighting = false, DrawModes mode = DrawModes.Mesh | DrawModes.Outline)
        {
            //effect.LightingEnabled = false;
            if (OutlineLocation > 0 && (mode & DrawModes.Outline) != 0)
            {
                effect.CurrentTechnique.Passes[0].Apply();
                Device.SetVertexBuffer(OutlineBuffer);
                Device.DrawPrimitives(PrimitiveType.LineList, 0, OutlineLocation / 2);
                Device.SetVertexBuffer(null);
            }

            if (DualGridCount > 0 && IndexCount > 0 && (mode & DrawModes.Outline) != 0)
            {
                effect.CurrentTechnique.Passes[0].Apply();
                Device.SetVertexBuffer(DualGridBuffer);

                Device.Indices = IndexBuffer;
                Device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, DualGridCount, 0, IndexCount / 2);
                Device.Indices = null;
            }

            if (VertexCount == 0 || ((mode & DrawModes.Mesh) == 0))
            {
                return;
            }

            if (enable_lighting)
            {
                /*effect.LightingEnabled = true;
                 * effect.PreferPerPixelLighting = true;
                 * effect.SpecularPower = 64;
                 * effect.SpecularColor = Color.Black.ToVector3();
                 * effect.CurrentTechnique.Passes[0].Apply();
                 * effect.AmbientLightColor = Color.Gray.ToVector3();*/
            }

            effect.CurrentTechnique.Passes[0].Apply();
            Device.SetVertexBuffer(VertexBuffer);

            Device.DrawPrimitives(PrimitiveType.LineList, 0, VertexCount / 2);

            Device.SetVertexBuffer(null);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns ID of added grapgic
        /// </summary>
        /// <param name="f">Real function of DoubleFunction</param>
        /// <param name="x1">Left tabulation bound</param>
        /// <param name="x2">Right tabulation bound</param>
        /// <param name="drawMode">Weather to join nodes with lines</param>
        /// <returns></returns>
        public int AddGraphic(DoubleFunction f, float x1, float x2, DrawModes drawMode,
                              Color penColor)
        {
            if (grs == null)
            {
                grs = new List <MathGraphic>(100);
            }
            MathGraphic newGraphic = new MathGraphic(f);

            newGraphic.LeftBound  = x1;
            newGraphic.RightBound = x2;
            newGraphic.Step       = 0.01f;
            newGraphic.DrawMode   = drawMode;
            newGraphic.PenColor   = penColor;

            newGraphic.Tabulate();

            grs.Add(newGraphic);

            return(grs.IndexOf(newGraphic));
        }
Exemplo n.º 9
0
 private void SetWhiteboardToolImage(DrawModes drawMode)
 {
     if (drawMode == DrawModes.Selection)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.PointerHS;
     }
     else if (drawMode == DrawModes.Arrow)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.arrow.ToBitmap();
     }
     else if (drawMode == DrawModes.Circle)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.circle.ToBitmap();
     }
     else if (drawMode == DrawModes.Line)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.line.ToBitmap();
     }
     else if (drawMode == DrawModes.Text)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.Text;
     }
 }
Exemplo n.º 10
0
        // Таймер расширенного режима отображения, вариант 1
        private void ExtendedTimer1_Tick(object sender, EventArgs e)
        {
            switch (phase1)
            {
            // Начальное затенение
            case 1:
                HideScreen(false);
                break;

            // Отрисовка начальных элементов
            case 2:
                DrawMarker(1);
                break;

            case 3:
            case 14:
                DrawMarker(2);
                break;

            case 4:
            case 15:
                if (steps++ == 0)
                {
                    g.DrawImage(new Bitmap(logo1, new Size((int)((double)logo1.Width / ((double)logo1.Height / 24)),
                                                           (int)((double)logo1.Height / ((double)logo1.Height / 24)))), 110, lineFeed * 2);
                }
                else if (steps > 20)
                {
                    steps = 0;
                    phase1++;
                }
                break;

            case 5:
                if (steps++ == 0)
                {
                    g.DrawString("ESHQ", headerFont, foreBrush, 80, lineFeed);
                }
                else if (steps > 20)
                {
                    steps    = 0;
                    point1.X = lineLeft;
                    point1.Y = lineFeed;
                    phase1++;
                }
                break;

            case 6:
                DrawSplitter();
                break;

            // Отрисовка текста
            case 7:
            case 9:
            case 11:
            case 13:
            case 17:
            case 19:
                DrawText(extendedStrings1);
                break;

            // Интермиссии
            case 8:
                HideMarker(2);
                break;

            case 16:
                HideMarker(1);
                break;

            // Обновление экрана
            case 10:
            case 12:
            case 18:
                point1.Y = lineFeed;
                phase1   = 100;
                break;

            case 100:
                HideText();
                break;

            // Завершение
            case 20:
                HideScreen(true);
                break;

            case 21:
                ExtendedTimer.Enabled = false;
                extended           = 0;
                mode               = DrawModes.Mode2;
                DrawingTimer.Tick -= DrawingTimer_Mode1;
                LogoDrawer_Shown(null, null);
                break;
            }

#if LDDEXPORT
            logo4b.Save("C:\\1\\" + (moves++).ToString("D8") + ".png", ImageFormat.Png);
#endif
        }
 public SpriteBatch this[DrawModes drawMode]
 {
     get { return(batches[drawMode].Item1); }
 }
 public SpriteBatchSettings Settings(DrawModes drawMode)
 {
     return(batches[drawMode].Item2);
 }
Exemplo n.º 13
0
 private void SetWhiteboardToolImage(DrawModes drawMode)
 {
     if (drawMode == DrawModes.Selection)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.PointerHS;
     }
     else if (drawMode == DrawModes.Arrow)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.arrow.ToBitmap();
     }
     else if (drawMode == DrawModes.Circle)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.circle.ToBitmap();
     }
     else if (drawMode == DrawModes.Line)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.line.ToBitmap();
     }
     else if (drawMode == DrawModes.Text)
     {
         toolStripDropDownButton1.Image = global::Aptima.Asim.DDD.Client.Properties.Resources.Text;
     }
 }
Exemplo n.º 14
0
 private void Handler_DrawModeChanged(object drawMode)
 {
     _DrawMode = (DrawModes)drawMode;
     UpdateMaterials();
 }
Exemplo n.º 15
0
        public bool AddLine(string objectID, DrawModes mode, LocationValue start, LocationValue end, double width, double oringinalScale, int color, string text)
        {
            LineObject line = new LineObject();

            line.Mode            = mode;
            line.Start           = start;
            line.End             = end;
            line.Width           = width;
            line.OriginalScale   = oringinalScale;
            line.Color           = color;
            line.Text            = text;
            line.ObjectID        = objectID;
            line.BoundingPolygon = null;
            line.ObjectSelected  = false;
            line.InnerRadius     = 0.0f;
            line.OutterRadius    = 0.0f;

            string user_id;

            if (objectID.LastIndexOf('_') >= 0)
            {
                user_id = objectID.Substring(0, objectID.LastIndexOf('_'));
            }
            else
            {
                return(false);
            }

            // If this is not a circle, create a bounding polygon for this object
            Polygon newBoundingPoly = null;

            if ((line.Mode == DrawModes.Line) || (line.Mode == DrawModes.Arrow))
            {
                GetLineBoundingPoly((float)line.Start.X, (float)line.Start.Y, (float)line.End.X, (float)line.End.Y,
                                    (float)line.Width, (float)line.OriginalScale, out newBoundingPoly);
                line.BoundingPolygon = newBoundingPoly;
            }
            else if (line.Mode == DrawModes.Circle)
            {
                float innerRadius;
                float outterRadius;

                GetCircleBoundingPoly((float)line.Start.X, (float)line.Start.Y, (float)line.End.X, (float)line.End.Y,
                                      (float)line.Width, (float)line.OriginalScale, out newBoundingPoly,
                                      out outterRadius, out innerRadius);
                line.BoundingPolygon = newBoundingPoly;
                line.InnerRadius     = innerRadius;
                line.OutterRadius    = outterRadius;
            }

            if (string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0)
            {
                lock (drawingCommandLock)
                {
                    drawingCommands.Add(line);
                }
            }
            else
            {
                drawingCommands.Add(line);
            }

            return(true);
        }
Exemplo n.º 16
0
 public int AddPolygon(Color penColor,
                       DrawModes drawMode, params PointF[] pts)
 {
     return(AddPolygon(penColor, 1f, drawMode, pts));
 }
Exemplo n.º 17
0
        public bool AddLine(string objectID, DrawModes mode, LocationValue start, LocationValue end, double width, double oringinalScale, int color, string text)
        {
            LineObject line = new LineObject();
            line.Mode = mode;
            line.Start = start;
            line.End = end;
            line.Width = width;
            line.OriginalScale = oringinalScale;
            line.Color = color;
            line.Text = text;
            line.ObjectID = objectID;
            line.BoundingPolygon = null;
            line.ObjectSelected = false;
            line.InnerRadius = 0.0f;
            line.OutterRadius = 0.0f;

            string user_id;

            if (objectID.LastIndexOf('_') >= 0)
            {
                user_id = objectID.Substring(0, objectID.LastIndexOf('_'));
            }
            else
            {
                return false;
            }

            // If this is not a circle, create a bounding polygon for this object
            Polygon newBoundingPoly = null;
            if ((line.Mode == DrawModes.Line) || (line.Mode == DrawModes.Arrow))
            {
                GetLineBoundingPoly((float) line.Start.X, (float) line.Start.Y, (float) line.End.X, (float) line.End.Y,
                    (float) line.Width, (float) line.OriginalScale, out newBoundingPoly);
                line.BoundingPolygon = newBoundingPoly;
            }
            else if (line.Mode == DrawModes.Circle)
            {
                float innerRadius;
                float outterRadius;

                GetCircleBoundingPoly((float)line.Start.X, (float)line.Start.Y, (float)line.End.X, (float)line.End.Y,
                    (float)line.Width, (float)line.OriginalScale, out newBoundingPoly,
                    out outterRadius, out innerRadius);
                line.BoundingPolygon = newBoundingPoly;
                line.InnerRadius = innerRadius;
                line.OutterRadius = outterRadius;
            }

            if (string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0)
            {
                lock (drawingCommandLock)
                {
                    drawingCommands.Add(line);
                }
            }
            else
            {
                drawingCommands.Add(line);
            }

            return true;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState ks = Keyboard.GetState();
            MouseState ms = Mouse.GetState();
            // Allows the game to exit
            if (ks.IsKeyDown(Keys.Escape))
                this.Exit();

            int dx = 0, dy = 0;

            if (ks.IsKeyDown(Keys.Left))
            {
                dx = -camSpeed;
            }
            if (ks.IsKeyDown(Keys.Right))
            {
                dx = camSpeed;
            }
            if (ks.IsKeyDown(Keys.Up))
            {
                dy = -camSpeed;
            }
            if (ks.IsKeyDown(Keys.Down))
            {
                dy = camSpeed;
            }

            if (ks.IsKeyDown(Keys.D1))
            {
                if (mode == DrawModes.NPC)
                {
                    npcType = NPC.Type.Civilian;
                    mouseNPC.type = NPC.Type.Civilian;
                }
                if (mode == DrawModes.Consumable)
                {
                    consType = Consumable.Type.TURN;
                    mouseConsumable.type = Consumable.Type.TURN;
                }
            }
            if (ks.IsKeyDown(Keys.D2))
            {
                if (mode == DrawModes.NPC)
                {
                    npcType = NPC.Type.DumbCop;
                    mouseNPC.type = NPC.Type.DumbCop;
                }
                if (mode == DrawModes.Consumable)
                {
                    consType = Consumable.Type.MASS;
                    mouseConsumable.type = Consumable.Type.MASS;
                }
            }
            if (ks.IsKeyDown(Keys.D3))
            {
                if (mode == DrawModes.NPC)
                {
                    npcType = NPC.Type.SmartCop;
                    mouseNPC.type = NPC.Type.SmartCop;
                }
                if (mode == DrawModes.Consumable)
                {
                    consType = Consumable.Type.SLIP;
                    mouseConsumable.type = Consumable.Type.SLIP;
                }
            }
            if (ks.IsKeyDown(Keys.D4))
            {
                if (mode == DrawModes.NPC)
                {
                    npcType = NPC.Type.RoboCop;
                    mouseNPC.type = NPC.Type.RoboCop;
                }
                if (mode == DrawModes.Consumable)
                {
                    consType = Consumable.Type.SPEED;
                    mouseConsumable.type = Consumable.Type.SPEED;
                }
            }

            if (ks.IsKeyDown(Keys.L) && !lpressed)
            {
                load("level.txt");
                lpressed = true;
            }

            if (ks.IsKeyDown(Keys.M) && !mpressed)
            {
                if (mode == DrawModes.Box)
                    mode = DrawModes.Node;
                else if (mode == DrawModes.Node)
                    mode = DrawModes.NPC;
                else if (mode == DrawModes.NPC)
                    mode = DrawModes.Trigger;
                else if (mode == DrawModes.Trigger)
                    mode = DrawModes.Consumable;
                else if (mode == DrawModes.Consumable)
                    mode = DrawModes.Player;
                else if (mode == DrawModes.Player)
                    mode = DrawModes.Box;
                mpressed = true;
            }

            if (ks.IsKeyDown(Keys.S) && !saving)
            {
                save();
                saving = true;
            }

            if (ks.IsKeyDown(Keys.W) && !wpressed)
            {
                if (mode == DrawModes.Box)
                {
                    mouseBox.seeThrough = !mouseBox.seeThrough;
                }
                else if (mode == DrawModes.Node)
                {
                    mouseNode.isKey = !mouseNode.isKey;
                    nodeType = mouseNode.isKey;
                }
                else if (mode == DrawModes.NPC)
                {
                    if (npcMode == NPC.Mode.Static)
                        npcMode = NPC.Mode.Wander;
                    else if (npcMode == NPC.Mode.Wander)
                        npcMode = NPC.Mode.Patrol;
                    else if (npcMode == NPC.Mode.Patrol)
                        npcMode = NPC.Mode.Static;
                    mouseNPC.mode = npcMode;
                }
                wpressed = true;
            }

            if (ks.IsKeyUp(Keys.L))
                lpressed = false;
            if (ks.IsKeyUp(Keys.M))
                mpressed = false;
            if (ks.IsKeyUp(Keys.S))
                saving = false;
            if (ks.IsKeyUp(Keys.W))
                wpressed = false;

            if (ms.LeftButton == ButtonState.Pressed)
            {
                if (mode == DrawModes.Box || mode == DrawModes.Trigger)
                {
                    if (!drawing)
                    {
                        drawing = true;
                        startPos.X = ms.X + Camera.X;
                        startPos.Y = ms.Y + Camera.Y;
                    }
                    endPos.X = ms.X + Camera.X;
                    endPos.Y = ms.Y + Camera.Y;
                    mouseBox.rect.X = (int)Math.Min(startPos.X, endPos.X);
                    mouseBox.rect.Y = (int)Math.Min(startPos.Y, endPos.Y);
                    mouseBox.rect.Width = (int)Math.Abs(startPos.X - endPos.X);
                    mouseBox.rect.Height = (int)Math.Abs(startPos.Y - endPos.Y);
                }
                else if (mode == DrawModes.Node)
                {
                    mouseNode.position = new Vector2(ms.X + Camera.X, ms.Y + Camera.Y);
                    if (!drawing)
                    {
                        foreach (Node node in nodes.Values)
                        {
                            if (node.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                selected = node;
                                break;
                            }
                        }
                        drawing = true;
                    }
                    else if (selected != null)
                    {
                        mouseEdge.start = selected;
                        mouseEdge.end = mouseNode;
                    }

                }
                else if (mode == DrawModes.NPC)
                {
                    mouseNPC.position = new Vector2(ms.X + Camera.X, ms.Y + Camera.Y);
                    if (!drawing)
                    {
                        foreach (NPC npc in NPCs)
                        {
                            if (npc.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                selectedNPC = npc;
                                break;
                            }
                        }
                        drawing = true;
                    }
                    else if (selectedNPC != null)
                    {

                        foreach (Node node in nodes.Values)
                        {
                            if (node.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                selectedStart = node;
                                break;
                            }
                        }
                    }
                }
                else if (mode == DrawModes.Consumable)
                {
                    mouseConsumable.rect.X = ms.X + Camera.X;
                    mouseConsumable.rect.Y =  ms.Y + Camera.Y;
                    if (!drawing)
                    {
                        drawing = true;
                    }
                }
                else if (mode == DrawModes.Player)
                {
                    mousePlayer.position = new Vector2(ms.X + Camera.X, ms.Y + Camera.Y);
                    if (!drawing)
                    {
                        drawing = true;
                    }
                }
            }

            if (ms.LeftButton == ButtonState.Released && drawing)
            {
                if (mode == DrawModes.Box)
                {
                    drawing = false;
                    if (mouseBox.rect.Width > 0 && mouseBox.rect.Height > 0)
                        boxes.Add(new Box(mouseBox.rect.X, mouseBox.rect.Y, mouseBox.rect.Width, mouseBox.rect.Height, mouseBox.seeThrough));
                }
                else if (mode == DrawModes.Node)
                {
                    drawing = false;
                    if (selected != null)
                    {
                        foreach (Node node in nodes.Values)
                        {
                            if (node != selected && node.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                mouseEdge.end = node;
                                edges.Add(mouseEdge);
                                mouseEdge = new Edge(null, null);
                                selected = null;
                                break;
                            }
                        }
                        selected = null;
                        mouseEdge = new Edge(null, null);
                    }
                    else
                    {
                        if (nodes.Keys.Contains(mouseNode.ID)){
                            mouseNode.ID = nodes.Keys.Max() + 1;
                            Node.FixID(mouseNode.ID + 1);
                        }
                        nodes.Add(mouseNode.ID, mouseNode);
                        mouseNode = new Node(ms.X + Camera.X, ms.Y + Camera.Y);
                        mouseNode.isKey = nodeType;
                    }
                }
                else if (mode == DrawModes.NPC && ms.RightButton == ButtonState.Released)
                {
                    drawing = false;
                    if (ms.RightButton == ButtonState.Released && selectedEnd == null)
                    {
                        if (selectedNPC != null)
                        {
                            foreach (Node node in nodes.Values)
                            {
                                if (node == selectedStart && node.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                                {
                                    selectedNPC.patrolStart = node;
                                    break;
                                }
                            }
                            selectedStart = null;
                            mouseEdge = new Edge(null, null);
                        }
                        else
                        {
                            NPCs.Add(mouseNPC);
                            mouseNPC = new NPC(ms.X + Camera.X, ms.Y + Camera.Y, npcType, npcMode);
                        }
                    }

                }
                else if (mode == DrawModes.Consumable)
                {
                    drawing = false;
                    consumables.Add(mouseConsumable);
                    mouseConsumable = new Consumable(ms.X + Camera.X, ms.Y + Camera.Y, consType);
                }
                else if (mode == DrawModes.Trigger)
                {
                    drawing = false;
                    if (mouseBox.rect.Width > 0 && mouseBox.rect.Height > 0)
                        triggers.Add(new Trigger(mouseBox.rect.X, mouseBox.rect.Y, mouseBox.rect.Width, mouseBox.rect.Height));
                }
                else if (mode == DrawModes.Player)
                {
                    drawing = false;
                    player = mousePlayer;
                    mousePlayer = new NPC(ms.X + Camera.X, ms.Y + Camera.Y, NPC.Type.Streaker, NPC.Mode.Static);

                }
            }

            if (ms.RightButton == ButtonState.Pressed)
            {
                if (mode == DrawModes.NPC)
                {
                    mouseNPC.position = new Vector2(ms.X + Camera.X, ms.Y + Camera.Y);
                    if (!drawing)
                    {
                        foreach (NPC npc in NPCs)
                        {
                            if (npc.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                selectedNPC = npc;
                                break;
                            }
                        }
                        drawing = true;
                    }
                    else if (selectedNPC != null)
                    {
                        foreach (Node node in nodes.Values)
                        {
                            if (node.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                selectedEnd = node;
                                break;
                            }
                        }
                    }
                }
                else if (!drawing)
                {
                    if (mode == DrawModes.Box)
                    {
                        for (int i = 0; i != boxes.Count; i++)
                        {
                            Box r = boxes[i];
                            if (r.rect.Contains(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                boxes.Remove(r);
                                i--;
                            }
                        }
                    }
                    else if (mode == DrawModes.Node)
                    {
                        for (int i = 0; i != nodes.Keys.Count; i++)
                        {
                            int ind = nodes.Keys.ElementAt(i);
                            Node n = nodes[ind];
                            if (n.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                nodes.Remove(n.ID);
                                for (int j = 0; j != edges.Count; j++)
                                {
                                    Edge e = edges[j];
                                    if (e.start == n || e.end == n)
                                    {
                                        edges.Remove(e);
                                        j--;
                                    }
                                }
                                i--;
                            }
                        }
                    }
                    //else if (mode == DrawModes.NPC)
                    //{
                    //    for (int i = 0; i != NPCs.Count; i++)
                    //    {
                    //        NPC n = NPCs[i];
                    //        if (n.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                    //        {
                    //            NPCs.Remove(n);
                    //            i--;
                    //        }
                    //    }
                    //}
                    else if (mode == DrawModes.Consumable){
                        for (int i = 0; i != consumables.Count; i++)
                        {
                            Consumable c = consumables[i];
                            if (c.rect.Contains(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                consumables.Remove(c);
                                i--;
                            }
                        }
                    }
                    else if (mode == DrawModes.Trigger)
                    {
                        for (int i = 0; i != triggers.Count; i++)
                        {
                            Trigger t = triggers[i];
                            if (t.rect.Contains(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                triggers.Remove(t);
                                i--;
                            }
                        }
                    }
                    else if (mode == DrawModes.Player)
                    {
                        if (player != null && player.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                        {
                            player = null;
                        }
                    }
                }
            }

            if (ms.RightButton == ButtonState.Released)
            {
                if (mode == DrawModes.NPC && ms.LeftButton == ButtonState.Released)
                {
                    if (selectedNPC != null)
                    {
                        for (int i = 0; i != NPCs.Count; i++)
                        {
                            NPC n = NPCs[i];
                            if (n.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                NPCs.Remove(n);
                                i--;
                            }
                        }
                        foreach (Node node in nodes.Values)
                        {
                            if (node == selectedEnd && node.pointInside(ms.X + Camera.X, ms.Y + Camera.Y))
                            {
                                selectedNPC.patrolEnd = node;
                                break;
                            }
                        }
                        selectedEnd = null;
                        selectedNPC = null;
                        mouseEdge = new Edge(null, null);
                    }
                }
            }

            Camera.X += dx;
            Camera.Y += dy;

            //if (Camera.X < 0)
            //    Camera.X = 0;
            //if (Camera.Y < 0)
            //    Camera.Y = 0;
            //if (Camera.X + Camera.Width > maxW)
            //    Camera.X = maxW - Camera.Width;
            //if (Camera.Y + Camera.Height > maxH)
            //    Camera.Y = maxH - Camera.Height;

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Exemplo n.º 19
0
        protected void load(string filename)
        {
            boxes.Clear();
            nodes.Clear();
            edges.Clear();
            NPCs.Clear();
            player = null;

            StreamReader reader = new StreamReader(filename);
            try
            {
                string line = reader.ReadLine();
                if (line.StartsWith("RECTANGLES"))
                    line = reader.ReadLine();
                do
                {
                    int x, y, w, h;
                    bool seeThrough;
                    int spacei = line.IndexOf(' ');
                    x = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    y = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    w = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    h = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    seeThrough = bool.Parse(line);
                    boxes.Add(new Box(x, y, w, h, seeThrough));
                    line = reader.ReadLine();
                } while (reader.Peek() != -1
                    && !line.StartsWith("NODES")
                    && !line.StartsWith("EDGES")
                    && !line.StartsWith("NPCS")
                    && !line.StartsWith("TRIGGER")
                    && !line.StartsWith("CONSUMABLE")
                    && !line.StartsWith("PLAYER")
                    );

                if (line.StartsWith("NODES"))
                    line = reader.ReadLine();
                do
                {
                    int id, x, y;
                    bool key;
                    int spacei = line.IndexOf(' ');
                    id = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    x = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    y = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    key = bool.Parse(line);
                    Node n = new Node(x, y, id);
                    n.isKey = key;
                    nodes.Add(id, n);
                    line = reader.ReadLine();
                } while (reader.Peek() != -1
                    && !line.StartsWith("EDGES")
                    && !line.StartsWith("NPCS")
                    && !line.StartsWith("TRIGGER")
                    && !line.StartsWith("CONSUMABLE")
                    && !line.StartsWith("PLAYER")
                    );

                if (line.StartsWith("EDGES"))
                    line = reader.ReadLine();
                do
                {
                    int sid, eid;
                    int spacei = line.IndexOf(' ');
                    sid = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    eid = int.Parse(line);
                    edges.Add(new Edge(nodes[sid], nodes[eid]));
                    line = reader.ReadLine();
                } while (reader.Peek() != -1
                    && !line.StartsWith("NPCS")
                    && !line.StartsWith("TRIGGER")
                    && !line.StartsWith("CONSUMABLE")
                    && !line.StartsWith("PLAYER")
                    );

                if (line.StartsWith("NPCS"))
                    line = reader.ReadLine();
                do
                {
                    int x, y, sid, eid;
                    NPC.Type type;
                    NPC.Mode mode;
                    int spacei = line.IndexOf(' ');
                    x = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    y = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    type = (NPC.Type)Enum.Parse(typeof(NPC.Type), line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    mode = (NPC.Mode)Enum.Parse(typeof(NPC.Mode), line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    sid = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    eid = int.Parse(line);
                    NPC npc = new NPC(x, y, type, mode);
                    if (sid > 0 && eid > 0)
                    {
                        npc.patrolStart = nodes[sid];
                        npc.patrolEnd = nodes[eid];
                    }
                    NPCs.Add(npc);
                    line = reader.ReadLine();
                }
                while (reader.Peek() != -1
                    && !line.StartsWith("CONSUMABLE")
                    && !line.StartsWith("TRIGGER")
                    && !line.StartsWith("PLAYER")
                    );

                if (line.StartsWith("TRIGGER"))
                    line = reader.ReadLine();
                do
                {
                    int x, y, w, h, id;
                    int spacei = line.IndexOf(' ');
                    x = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    y = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    w = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    h = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    id = int.Parse(line);
                    triggers.Add(new Trigger(x, y, w, h, id));
                    line = reader.ReadLine();
                } while (reader.Peek() != -1
                    && !line.StartsWith("CONSUMABLE")
                    && !line.StartsWith("PLAYER")
                    );

                if (line.StartsWith("CONSUMABLE"))
                    line = reader.ReadLine();
                do
                {
                    int x, y;
                    Consumable.Type t;
                    int spacei = line.IndexOf(' ');
                    x = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    y = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    t = (Consumable.Type)Enum.Parse(typeof(Consumable.Type), line);
                    consumables.Add(new Consumable(x, y, t));
                    line = reader.ReadLine();
                } while (reader.Peek() != -1
                    && !line.StartsWith("NODES")
                    && !line.StartsWith("EDGES")
                    && !line.StartsWith("NPCS")
                    && !line.StartsWith("TRIGGER")
                    && !line.StartsWith("PLAYER"));

                if (line.StartsWith("PLAYER"))
                    line = reader.ReadLine();
                do
                {
                    int x, y;
                    int spacei = line.IndexOf(' ');
                    x = int.Parse(line.Substring(0, spacei));
                    line = line.Substring(spacei + 1);
                    spacei = line.IndexOf(' ');
                    y = int.Parse(line);
                    player = new NPC(x, y, NPC.Type.Streaker, NPC.Mode.Static);
                    line = reader.ReadLine();
                } while (reader.Peek() != -1);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemplo n.º 20
0
        public virtual void Draw(Effect effect, bool enable_lighting = false, DrawModes mode = DrawModes.Mesh | DrawModes.Outline)
        {
            //effect.LightingEnabled = false;
            if (OutlineLocation > 0 && (mode & DrawModes.Outline) != 0)
            {
                effect.CurrentTechnique.Passes[0].Apply();
                Device.SetVertexBuffer(OutlineBuffer);
                Device.DrawPrimitives(PrimitiveType.LineList, 0, OutlineLocation / 2);
            }

            if ((IsIndexed && IndexCount == 0) || (!IsIndexed && VertexCount == 0) || ((mode & DrawModes.Mesh) == 0))
            {
                Device.SetVertexBuffer(null);
                return;
            }

            if (enable_lighting)
            {
                /*effect.LightingEnabled = true;
                effect.PreferPerPixelLighting = true;
                effect.SpecularPower = 64;
                effect.SpecularColor = Color.Black.ToVector3();
                effect.CurrentTechnique.Passes[0].Apply();
                effect.AmbientLightColor = Color.Gray.ToVector3();*/
            }

            if (effect != null)
                effect.CurrentTechnique.Passes[0].Apply();
            Device.SetVertexBuffer(VertexBuffer);
            if (IsIndexed)
            {
                Device.Indices = IndexBuffer;
                if (Is3D)
                    Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, VertexCount, 0, Math.Min(1048575, IndexCount / 3));
                else
                    Device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, VertexCount, 0, IndexCount / 2);
                Device.Indices = null;
            }
            else
            {
                if (Is3D)
                    Device.DrawPrimitives(PrimitiveType.TriangleList, 0, VertexCount / 3);
                else
                    Device.DrawPrimitives(PrimitiveType.LineList, 0, VertexCount / 2);
            }
            Device.SetVertexBuffer(null);
        }
Exemplo n.º 21
0
        public override void Draw(BasicEffect effect, bool enable_lighting = false, DrawModes mode = DrawModes.Mesh | DrawModes.Outline)
        {
            effect.LightingEnabled = false;
            if (OutlineLocation > 0 && (mode & DrawModes.Outline) != 0)
            {
                effect.CurrentTechnique.Passes[0].Apply();
                Device.SetVertexBuffer(OutlineBuffer);
                Device.DrawPrimitives(PrimitiveType.LineList, 0, OutlineLocation / 2);
                Device.SetVertexBuffer(null);
            }

            if (DualGridCount > 0 && IndexCount > 0 && (mode & DrawModes.Outline) != 0)
            {
                effect.CurrentTechnique.Passes[0].Apply();
                Device.SetVertexBuffer(DualGridBuffer);

                Device.Indices = IndexBuffer;
                Device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, DualGridCount, 0, IndexCount / 2);
                Device.Indices = null;
            }

            if (VertexCount == 0 || ((mode & DrawModes.Mesh) == 0))
                return;

            if (enable_lighting)
            {
                effect.LightingEnabled = true;
                effect.PreferPerPixelLighting = true;
                effect.SpecularPower = 64;
                effect.SpecularColor = Color.Black.ToVector3();
                effect.CurrentTechnique.Passes[0].Apply();
                effect.AmbientLightColor = Color.Gray.ToVector3();
            }

            effect.CurrentTechnique.Passes[0].Apply();
            Device.SetVertexBuffer(VertexBuffer);

            Device.DrawPrimitives(PrimitiveType.LineList, 0, VertexCount / 2);

            Device.SetVertexBuffer(null);
        }