Beispiel #1
0
        public void Draw(RTSWorld world, GameContext context, XnaGraphics graphics)
        {
            this.Update(world, context);

            graphics.DrawStringLeft(0, 0, world.ActiveLevel.GetType().Name);
            graphics.DrawStringLeft(0, 32, this.m_Tick.ToString());

            if (this.m_LastMousePoint.HasValue && this.m_CurrentMousePoint.HasValue)
            {
                graphics.DrawRectangle(this.m_LastMousePoint.Value, this.m_CurrentMousePoint.Value, Color.LimeGreen);
            }

            foreach (Unit u in this.Selected)
            {
                Rectangle bb = new Rectangle((int)u.X, (int)u.Y - 1, u.Width + 1, u.Height + 1);
                if (u.Team != null)
                {
                    graphics.DrawRectangle(bb, u.Team.Color);
                }
                else
                {
                    graphics.DrawRectangle(bb, Color.LimeGreen);
                }
            }

            // Draw chat.
            int a = 16;

            for (int i = this.m_ChatMessages.Count - 1; i >= Math.Max(this.m_ChatMessages.Count - 11, 0); i--)
            {
                if (i < this.m_ChatMessages.Count)
                {
                    graphics.DrawStringLeft(0, context.Graphics.GraphicsDevice.Viewport.Height - a, this.m_ChatMessages[i]);
                }
                a += 16;
            }

            // Draw graph.
            if (this.m_GraphFrames.Count > 1)
            {
                for (int i = 1; i < this.m_GraphFrames.Count; i++)
                {
                    graphics.DrawLine(i - 1, (float)this.m_GraphFrames[i - 1], i, (float)this.m_GraphFrames[i], 1, Color.Lime);
                }
            }

            // Add frame information.
            if (this.m_GraphFrames.Count > 200)
            {
                this.m_GraphFrames.RemoveAt(0);
            }
            this.m_GraphFrames.Add(context.GameTime.ElapsedGameTime.TotalMilliseconds);

            this.m_Tick++;
        }
Beispiel #2
0
        public override bool RightAction(RTSWorld world)
        {
            MouseState mouse = Mouse.GetState();

            // Cancel existing attack target.
            this.AttackTarget = null;

            // Handle enemy unit detection under mouse cursor here.
            foreach (IEntity e in world.Entities)
            {
                if (e is Unit)
                {
                    Unit u = e as Unit;

                    // Check to see if the unit is under the mouse cursor.
                    if (u.CollidesAt <Unit>(world, mouse.X, mouse.Y) != u)
                    {
                        continue;
                    }

                    // Check to see if this unit is on our team.
                    if (u.Team == this.Team)
                    {
                        continue;
                    }

                    // Check to make sure unit is synchronised across machines.
                    if (u.SynchronisationData == null)
                    {
                        throw new InvalidOperationException("Attack requested against unit that is not synchronised on network.  Ensure it was spawned correctly.");
                    }

                    // Set this unit as our target.
                    this.AttackTarget = u;
                    if (this is MovableUnit)
                    {
                        (this as MovableUnit).MoveCancel();
                    }
                    if (this.SynchronisationData != null && u.SynchronisationData != null && this.LocallyOwned)
                    {
                        this.SynchronisationData.BroadcastAttack(u.SynchronisationData);
                    }

                    // We are attacking this unit.
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        public override bool RightAction(RTSWorld world)
        {
            if (base.RightAction(world))
            {
                return(true);
            }

            MouseState mouse = Mouse.GetState();

            if (!this.MoveTo(new Vector2(mouse.X, mouse.Y)))
            {
                (world as RTSWorld).UiManager.Log("unit can't find path to target.");
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #4
0
        public void Draw(RTSWorld world, GameContext context, XnaGraphics graphics)
        {
            this.Update(world, context);

            graphics.DrawStringLeft(0, 0, world.ActiveLevel.GetType().Name);
            graphics.DrawStringLeft(0, 32, this.m_Tick.ToString());

            if (this.m_LastMousePoint.HasValue && this.m_CurrentMousePoint.HasValue)
                graphics.DrawRectangle(this.m_LastMousePoint.Value, this.m_CurrentMousePoint.Value, Color.LimeGreen);

            foreach (Unit u in this.Selected)
            {
                Rectangle bb = new Rectangle((int)u.X, (int)u.Y - 1, u.Width + 1, u.Height + 1);
                if (u.Team != null)
                    graphics.DrawRectangle(bb, u.Team.Color);
                else
                    graphics.DrawRectangle(bb, Color.LimeGreen);
            }

            // Draw chat.
            int a = 16;
            for (int i = this.m_ChatMessages.Count - 1; i >= Math.Max(this.m_ChatMessages.Count - 11, 0); i--)
            {
                if (i < this.m_ChatMessages.Count)
                    graphics.DrawStringLeft(0, context.Graphics.GraphicsDevice.Viewport.Height - a, this.m_ChatMessages[i]);
                a += 16;
            }

            // Draw graph.
            if (this.m_GraphFrames.Count > 1)
            {
                for (int i = 1; i < this.m_GraphFrames.Count; i++)
                    graphics.DrawLine(i - 1, (float)this.m_GraphFrames[i - 1], i, (float)this.m_GraphFrames[i], 1, Color.Lime);
            }

            // Add frame information.
            if (this.m_GraphFrames.Count > 200)
                this.m_GraphFrames.RemoveAt(0);
            this.m_GraphFrames.Add(context.GameTime.ElapsedGameTime.TotalMilliseconds);

            this.m_Tick++;
        }
Beispiel #5
0
        public override bool RightAction(RTSWorld world)
        {
            MouseState mouse = Mouse.GetState();

            // Cancel existing attack target.
            this.AttackTarget = null;

            // Handle enemy unit detection under mouse cursor here.
            foreach (IEntity e in world.Entities)
            {
                if (e is Unit)
                {
                    Unit u = e as Unit;

                    // Check to see if the unit is under the mouse cursor.
                    if (u.CollidesAt<Unit>(world, mouse.X, mouse.Y) != u)
                        continue;

                    // Check to see if this unit is on our team.
                    if (u.Team == this.Team)
                        continue;

                    // Check to make sure unit is synchronised across machines.
                    if (u.SynchronisationData == null)
                        throw new InvalidOperationException("Attack requested against unit that is not synchronised on network.  Ensure it was spawned correctly.");

                    // Set this unit as our target.
                    this.AttackTarget = u;
                    if (this is MovableUnit)
                        (this as MovableUnit).MoveCancel();
                    if (this.SynchronisationData != null && u.SynchronisationData != null && this.LocallyOwned)
                        this.SynchronisationData.BroadcastAttack(u.SynchronisationData);

                    // We are attacking this unit.
                    return true;
                }
            }

            return false;
        }
Beispiel #6
0
 public override bool LeftAction(RTSWorld world)
 {
     return false;
 }
Beispiel #7
0
 public override bool LeftAction(RTSWorld world)
 {
     return base.LeftAction(world);
 }
Beispiel #8
0
        public override bool RightAction(RTSWorld world)
        {
            if (base.RightAction(world))
                return true;

            MouseState mouse = Mouse.GetState();
            if (!this.MoveTo(new Vector2(mouse.X, mouse.Y)))
            {
                (world as RTSWorld).UiManager.Log("unit can't find path to target.");
                return false;
            } else
                return true;
        }
Beispiel #9
0
 /// <summary>
 /// Called when the "right" action occurs in the UI manager.  Usually
 /// reserved for attack or movement.
 /// </summary>
 /// <returns>Whether the action has been handled.</returns>
 public abstract bool RightAction(RTSWorld world);
Beispiel #10
0
 /// <summary>
 /// Called when the "left" action occurs in the UI manager.  Usually
 /// reserved for selection.
 /// </summary>
 /// <returns>Whether the action has been handled.</returns>
 public abstract bool LeftAction(RTSWorld world);
Beispiel #11
0
        private void Update(RTSWorld world, GameContext context)
        {
            MouseState mouse = Mouse.GetState();

            // Left mouse action.
            if (mouse.LeftButton == ButtonState.Pressed)
            {
                if (!this.m_LastMousePoint.HasValue)
                {
                    this.m_LastMousePoint = new Vector2(mouse.X, mouse.Y);
                }
                else
                {
                    this.m_CurrentMousePoint = new Vector2(mouse.X, mouse.Y);

                    // Determine selected objects.
                    Rectangle coverage = new Rectangle(
                        (int)this.m_LastMousePoint.Value.X,
                        (int)this.m_LastMousePoint.Value.Y,
                        (int)this.m_CurrentMousePoint.Value.X - (int)this.m_LastMousePoint.Value.X,
                        (int)this.m_CurrentMousePoint.Value.Y - (int)this.m_LastMousePoint.Value.Y
                        ).Normalize();
                    this.Selected.Clear();
                    foreach (IMultiLevelEntity e in world.ActiveLevel.Entities)
                    {
                        if (e is Unit)
                        {
                            Unit      u  = e as Unit;
                            Rectangle bb = new Rectangle((int)u.X, (int)u.Y, u.Width, u.Height);
                            if (coverage.Intersects(bb))
                            {
                                this.Selected.Add(u);
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.m_LastMousePoint != null && this.m_CurrentMousePoint != null)
                {
                    if (this.m_LastMousePoint.Value == this.m_CurrentMousePoint.Value)
                    {
                        // Left mouse action.
                        foreach (Unit u in this.Selected)
                        {
                            if (u.LocallyOwned)
                            {
                                u.LeftAction(world);
                            }
                        }
                    }
                }
                this.m_LastMousePoint    = null;
                this.m_CurrentMousePoint = null;
            }

            // Right mouse action.
            if (mouse.RightButton == ButtonState.Pressed)
            {
                this.m_JustRightClicked = true;
            }
            else if (mouse.RightButton == ButtonState.Released && this.m_JustRightClicked)
            {
                this.Log("right action triggered on " + this.Selected.Count + " selected units.");
                foreach (Unit u in this.Selected)
                {
                    if (u.LocallyOwned)
                    {
                        u.RightAction(world);
                    }
                }
                this.m_JustRightClicked = false;
            }
        }
Beispiel #12
0
 /// <summary>
 /// Called when the "right" action occurs in the UI manager.  Usually
 /// reserved for attack or movement.
 /// </summary>
 /// <returns>Whether the action has been handled.</returns>
 public abstract bool RightAction(RTSWorld world);
Beispiel #13
0
 /// <summary>
 /// Called when the "left" action occurs in the UI manager.  Usually
 /// reserved for selection.
 /// </summary>
 /// <returns>Whether the action has been handled.</returns>
 public abstract bool LeftAction(RTSWorld world);
Beispiel #14
0
        private void Update(RTSWorld world, GameContext context)
        {
            MouseState mouse = Mouse.GetState();

            // Left mouse action.
            if (mouse.LeftButton == ButtonState.Pressed)
            {
                if (!this.m_LastMousePoint.HasValue)
                    this.m_LastMousePoint = new Vector2(mouse.X, mouse.Y);
                else
                {
                    this.m_CurrentMousePoint = new Vector2(mouse.X, mouse.Y);

                    // Determine selected objects.
                    Rectangle coverage = new Rectangle(
                        (int)this.m_LastMousePoint.Value.X,
                        (int)this.m_LastMousePoint.Value.Y,
                        (int)this.m_CurrentMousePoint.Value.X - (int)this.m_LastMousePoint.Value.X,
                        (int)this.m_CurrentMousePoint.Value.Y - (int)this.m_LastMousePoint.Value.Y
                        ).Normalize();
                    this.Selected.Clear();
                    foreach (IMultiLevelEntity e in world.ActiveLevel.Entities)
                        if (e is Unit)
                        {
                            Unit u = e as Unit;
                            Rectangle bb = new Rectangle((int)u.X, (int)u.Y, u.Width, u.Height);
                            if (coverage.Intersects(bb))
                                this.Selected.Add(u);
                        }
                }
            }
            else
            {
                if (this.m_LastMousePoint != null && this.m_CurrentMousePoint != null)
                {
                    if (this.m_LastMousePoint.Value == this.m_CurrentMousePoint.Value)
                    {
                        // Left mouse action.
                        foreach (Unit u in this.Selected)
                        {
                            if (u.LocallyOwned)
                                u.LeftAction(world);
                        }
                    }
                }
                this.m_LastMousePoint = null;
                this.m_CurrentMousePoint = null;
            }

            // Right mouse action.
            if (mouse.RightButton == ButtonState.Pressed)
            {
                this.m_JustRightClicked = true;
            }
            else if (mouse.RightButton == ButtonState.Released && this.m_JustRightClicked)
            {
                this.Log("right action triggered on " + this.Selected.Count + " selected units.");
                foreach (Unit u in this.Selected)
                {
                    if (u.LocallyOwned)
                        u.RightAction(world);
                }
                this.m_JustRightClicked = false;
            }
        }
Beispiel #15
0
 public override bool LeftAction(RTSWorld world)
 {
     return(false);
 }
Beispiel #16
0
 public override bool LeftAction(RTSWorld world)
 {
     return(base.LeftAction(world));
 }