/// <summary>
 /// Initializes a new instance of the <see cref="MoveManyTransBox"/> class.
 /// </summary>
 /// <param name="owner">The <see cref="TransBoxManager"/>.</param>
 /// <param name="spatials">The <see cref="ISpatial"/>s.</param>
 /// <param name="position">The position.</param>
 /// <param name="camera">The camera.</param>
 public MoveManyTransBox(TransBoxManager owner, IEnumerable<ISpatial> spatials, Vector2 position, ICamera2D camera)
 {
     _owner = owner;
     _camera = camera;
     _position = position;
     _spatials = spatials.ToImmutable();
 }
示例#2
0
        /// <summary>
        /// Checks if the <see cref="ISpatial"/> contains a point.
        /// </summary>
        /// <param name="spatial">The spatial.</param>
        /// <param name="p">Point to check if the <paramref name="spatial"/> contains.</param>
        /// <returns>True if the <paramref name="spatial"/> contains <paramref name="p"/>; otherwise false.</returns>
        public static bool Contains(this ISpatial spatial, Vector2 p)
        {
            var min = spatial.Position;
            var max = spatial.Max;

            return (min.X <= p.X && max.X >= p.X && min.Y <= p.Y && max.Y >= p.Y);
        }
示例#3
0
        /// <summary>
        /// Finds the Minimal Translational Distance between two <see cref="ISpatial"/>s.
        /// </summary>
        /// <param name="srcMin">Top-left of the source (dynamic) <see cref="ISpatial"/> that will be the one moving.</param>
        /// <param name="srcMax">Bottom-right of the source (dynamic) <see cref="ISpatial"/> that will be the one moving.</param>
        /// <param name="tarMin">Top-left of the target (static) <see cref="ISpatial"/> that will not move.</param>
        /// <param name="tarMax">Bottom-right of the target (static) <see cref="ISpatial"/> that will not move.</param>
        /// <returns>The MTD for the source to no longer intersect the target.</returns>
        public static Vector2 MTD(Vector2 srcMin, Vector2 srcMax, Vector2 tarMin, Vector2 tarMax)
        {
            // Down
            float mtd = srcMax.Y - tarMin.Y;
            BoxSide side = BoxSide.Bottom;

            // Left
            float diff = srcMax.X - tarMin.X;
            if (diff < mtd)
            {
                mtd = diff;
                side = BoxSide.Left;
            }

            // Right
            diff = tarMax.X - srcMin.X;
            if (diff < mtd)
            {
                mtd = diff;
                side = BoxSide.Right;
            }

            // Up
            diff = tarMax.Y - srcMin.Y;
            if (diff < mtd)
            {
                mtd = diff;
                side = BoxSide.Top;
            }

            if (mtd < 0.0f)
                return Vector2.Zero;

            return CreateMTDVector(side, mtd + 1);
        }
 /// <summary>
 /// Checks if this <see cref="ITransBox"/> contains the given world point.
 /// </summary>
 /// <param name="worldPos">The world point.</param>
 /// <returns>True if this <see cref="ITransBox"/> contains the <paramref name="worldPos"/>; otherwise false.</returns>
 public bool ContainsPoint(Vector2 worldPos)
 {
     var w = worldPos;
     var lo = Position;
     var hi = Max;
     return (lo.X <= w.X) && (lo.Y <= w.Y) && (hi.X >= w.X) && (hi.Y >= w.Y);
 }
            Vector2 Align(Vector2 v)
            {
                if (_owner == null || _owner.GridAligner == null)
                    return v;

                return _owner.GridAligner.Align(v);
            }
示例#6
0
文件: ChatForm.cs 项目: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatForm"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="pos">The pos.</param>
        public ChatForm(Control parent, Vector2 pos) : base(parent, pos, new Vector2(300, 150))
        {
            // Create the input and output TextBoxes
            _input = new TextBox(this, Vector2.Zero, new Vector2(32, 32))
            {
                IsMultiLine = false,
                IsEnabled = true,
                Font = GameScreenHelper.DefaultChatFont,
                MaxInputTextLength = GameData.MaxClientSayLength,
                BorderColor = new Color(255, 255, 255, 100)
            };

            _output = new TextBox(this, Vector2.Zero, new Vector2(32, 32))
            {
                IsMultiLine = true,
                IsEnabled = false,
                Font = GameScreenHelper.DefaultChatFont,
                BorderColor = new Color(255, 255, 255, 100)
            };

            _input.KeyPressed -= Input_KeyPressed;
            _input.KeyPressed += Input_KeyPressed;
           
            // Force the initial repositioning
            RepositionTextBoxes();
        }
示例#7
0
        /// <summary>
        /// Draws the <see cref="SkeletonBodyItem"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Position to draw at.</param>
        /// <param name="scale">Amount to scale the Grh in percent (1.0f for no scaling).</param>
        /// <param name="color">The color.</param>
        /// <param name="effect">SpriteEffects to use when drawing.</param>
        internal void Draw(ISpriteBatch sb, Vector2 position, float scale, Color color, SpriteEffects effect)
        {
            // Validate
            if (Source == null)
                return;

            // Find the effect
            Vector2 m;
            switch (effect)
            {
                case SpriteEffects.FlipHorizontally:
                    m = new Vector2(-1, 1);
                    break;

                case SpriteEffects.FlipVertically:
                    m = new Vector2(1, -1);
                    break;

                default:
                    m = new Vector2(1, 1);
                    break;
            }

            // Calculate the angle
            float angle;
            if (Dest == null)
                angle = 0.0f;
            else
                angle = SkeletonNode.GetAngle(Source.Position * m, Dest.Position * m) - MathHelper.PiOver2;

            // Draw
            var v = Source.Position + ItemInfo.Offset;
            Grh.Draw(sb, (v * m) + position, color, effect, angle, ItemInfo.Origin, scale);
        }
示例#8
0
 /// <summary>
 /// Finds the <see cref="Direction"/> from a <see cref="Vector2"/>.
 /// </summary>
 /// <param name="v">The <see cref="Vector2"/> containing the relative direction, where
 /// (0,0) is the center.</param>
 /// <returns>The <see cref="Direction"/> for the <paramref name="v"/>, or null if
 /// <paramref name="v"/> is equal to <see cref="Vector2.Zero"/>.</returns>
 public static Direction? FromVector(Vector2 v)
 {
     if (v.Y < 0)
     {
         if (v.X < 0)
             return Direction.NorthWest;
         else if (v.X == 0)
             return Direction.North;
         else
             return Direction.NorthEast;
     }
     else if (v.Y == 0)
     {
         if (v.X < 0)
             return Direction.West;
         else if (v.X == 0)
             return null;
         else
             return Direction.East;
     }
     else
     {
         if (v.X < 0)
             return Direction.SouthWest;
         else if (v.X == 0)
             return Direction.South;
         else
             return Direction.SouthEast;
     }
 }
示例#9
0
        /// <summary>
        /// Plays a sound.
        /// </summary>
        /// <param name="soundManager">The sound manager.</param>
        /// <param name="name">The name of the sound to play.</param>
        /// <param name="source">The source of the sound.</param>
        /// <returns>
        /// True if the sound was successfully played; otherwise false.
        /// </returns>
        public static bool Play(this ISoundManager soundManager, string name, Vector2 source)
        {
            var info = soundManager.GetSoundInfo(name);
            if (info == null)
                return false;

            return soundManager.Play(info.ID, source);
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonBodyItemInfo"/> class.
 /// </summary>
 /// <param name="grhIndex">The <see cref="GrhIndex"/> for the sprite to draw for the body item.</param>
 /// <param name="sourceName">Name of the source node.</param>
 /// <param name="destName">Name of the destination node (String.Empty for no destination).</param>
 /// <param name="offset">Grh drawing offset.</param>
 /// <param name="origin">Grh drawing origin.</param>
 public SkeletonBodyItemInfo(GrhIndex grhIndex, string sourceName, string destName, Vector2 offset, Vector2 origin)
 {
     GrhIndex = grhIndex;
     _sourceName = sourceName;
     _destName = destName;
     Offset = offset;
     Origin = origin;
 }
示例#11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Toolbar"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="pos">The pos.</param>
        public Toolbar(Control parent, Vector2 pos) : base(parent, pos, Vector2.One)
        {
            ResizeToChildren = true;
            ResizeToChildrenPadding = _padding;

            _items = CreateToolbarItems();

            Position = pos;
        }
示例#12
0
        static IEnumerable<Entity> CreateEntities(int amount, Vector2 minPos, Vector2 maxPos)
        {
            var ret = new Entity[amount];
            for (var i = 0; i < amount; i++)
            {
                ret[i] = new TestEntity { Position = RandomHelper.NextVector2(minPos, maxPos) };
            }

            return ret;
        }
示例#13
0
            /// <summary>
            /// Initializes a new instance of the <see cref="TransBox"/> class.
            /// </summary>
            /// <param name="owner">The <see cref="TransBoxManager"/>.</param>
            /// <param name="type">The <see cref="TransBoxType"/>.</param>
            /// <param name="spatial">The <see cref="ISpatial"/>.</param>
            TransBox(TransBoxManager owner, TransBoxType type, ISpatial spatial)
            {
                _owner = owner;

                _type = type;
                _spatial = spatial;

                _size = GetTransBoxSize(type);
                _position = GetPosition();
            }
示例#14
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the rectangle.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color)
        {
            var drawRect = _drawRectBorder;

            drawRect.Size = size;
            drawRect.Position = position;
            drawRect.FillColor = color;

            sb.Draw(drawRect);
        }
示例#15
0
        public ThralledNPC(World parent, CharacterTemplate template, Map map, Vector2 position)
            : base(parent, template, map, position)
        {
            // This NPC should never respawn. Once it's dead, that should be it!
            RespawnMapID = null;
            RespawnPosition = Vector2.Zero;

            if (log.IsDebugEnabled)
                log.DebugFormat("Created ThralledNPC `{0}` on map `{1}` at `{2}` with template `{3}`.", this, Map, Position,
                    template);
        }
示例#16
0
        /// <summary>
        /// Gets the selectable object currently under the cursor.
        /// </summary>
        /// <param name="map">The <see cref="EditorMap"/>.</param>
        /// <param name="worldPos">The world position.</param>
        /// <returns>The selectable object currently under the cursor, or null if none.</returns>
        protected override object GetObjUnderCursor(EditorMap map, Vector2 worldPos)
        {
            var closestLight = map.Lights.MinElementOrDefault(x => worldPos.QuickDistance(x.Center));
            if (closestLight == null)
                return null;

            if (worldPos.QuickDistance(closestLight.Center) > 10)
                return null;

            return closestLight;
        }
示例#17
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the box.</param>
        /// <param name="borderColor">Color of the border to draw around the rectangle.</param>
        /// <param name="borderThickness">The thickness of the border in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color, Color borderColor, float borderThickness = 1f)
        {
            var drawRect = _drawRectNoBorder;

            drawRect.Size = size;
            drawRect.Position = position;
            drawRect.FillColor = color;
            drawRect.OutlineColor = borderColor;
            drawRect.OutlineThickness = borderThickness;

            sb.Draw(drawRect);
        }
        /// <summary>
        /// Draws a string with shading.
        /// </summary>
        /// <param name="spriteBatch"><see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="font"><see cref="Font"/> to draw the string with.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="position">The position of the top-left corner of the string to draw.</param>
        /// <param name="fontColor">The font color.</param>
        /// <param name="borderColor">The shading color.</param>
        public static void DrawStringShaded(this ISpriteBatch spriteBatch, Font font, string text, Vector2 position,
                                            Color fontColor, Color borderColor)
        {
            position = position.Round();

            spriteBatch.DrawString(font, text, position - new Vector2(0, 1), borderColor);
            spriteBatch.DrawString(font, text, position - new Vector2(1, 0), borderColor);
            spriteBatch.DrawString(font, text, position + new Vector2(0, 1), borderColor);
            spriteBatch.DrawString(font, text, position + new Vector2(1, 0), borderColor);

            spriteBatch.DrawString(font, text, position, fontColor);
        }
示例#19
0
        /// <summary>
        /// Finds the mean for a collection of values of the specified type.
        /// </summary>
        /// <param name="values">Values to find the mean of.</param>
        /// <param name="offset">Array offset to start at.</param>
        /// <param name="count">Number of elements in the array to use.</param>
        /// <returns>Mean of the values in the <paramref name="values"/> array.</returns>
        public static Vector2 Mean(Vector2[] values, int offset, int count)
        {
            if (count == 0)
                return Vector2.Zero;

            var sum = Vector2.Zero;

            for (var i = offset; i < offset + count; i++)
            {
                sum += values[i];
            }

            return sum / count;
        }
示例#20
0
        public Particle(Vector2 position, Vector2 direction, float decayTime, Vector2 size, Color color)
        {
            _position = position;
            _direction = direction;
            _decayTime = decayTime;
            _startTime = Game.ElapsedTime;

            _shape = new RectangleShape
            {
                Size = size,
                Rotation = RandomHelper.RandomFloat(360),
                FillColor = color,
                Origin = size / 2
            };
        }
示例#21
0
        void FocusCameraAtScreenPoint(MouseEventArgs e)
        {
            if (Camera == null || Camera.Map == null)
                return;

            if (e.Button == MouseButtons.Left)
            {
                var percent = new Vector2(e.X, e.Y) / new Vector2(Size.Width, Size.Height);
                var min = Vector2.Zero;
                var max = Vector2.One;
                Vector2.Clamp(ref percent, ref min, ref max, out percent);

                var worldPos = Camera.Map.Size * percent;
                Camera.CenterOn(worldPos);
            }
        }
示例#22
0
        /// <summary>
        /// Activates the DamageText.
        /// </summary>
        /// <param name="damage">Damage value to display.</param>
        /// <param name="entity">Entity the damage was done to.</param>
        /// <param name="currTime">Current time.</param>
        public void Activate(int damage, Entity entity, TickCount currTime)
        {
            if (entity == null)
            {
                Debug.Fail("entity is null.");
                return;
            }

            // Set the starting values
            _alpha = 255;
            _pos = entity.Position;
            _lastUpdate = currTime;
            _text = damage.ToString();

            // Get a random velocity
            _velocity = new Vector2(-1.0f + (float)_random.NextDouble() * 2.0f, -2.0f - (float)_random.NextDouble() * 0.25f);
        }
示例#23
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="p1">First point of the line.</param>
        /// <param name="p2">Second point of the line.</param>
        /// <param name="color">Color of the line.</param>
        /// <param name="thickness">The thickness of the line in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 p1, Vector2 p2, Color color, float thickness = 1f)
        {
            if (sb == null)
            {
                Debug.Fail("sb is null.");
                return;
            }

            if (sb.IsDisposed)
            {
                Debug.Fail("sb is disposed.");
                return;
            }

            using (var s = Shape.Line(p1, p2, thickness, color))
            {
                sb.Draw(s);
            }
        }
示例#24
0
        public FireballProjectile(IProjectileOwner owner, Vector2 direction)
            : base(owner, 0)
        {
            _direction = direction;
            Position = owner.Position;
            fireballAge = Game.ElapsedTime + 10;

            _centerShapes = new List<RectangleShape>();
            _particles = new List<Particle>();
            for (int i = 0; i < 3; i++)
            {
                _centerShapes.Add(new RectangleShape
                {
                    Size = new Vector2(15, 15),
                    Origin = new Vector2(7.5f, 7.5f),
                    Rotation = RandomHelper.RandomFloat(360),
                    FillColor = Color.Red
                });
            }
        }
示例#25
0
        /// <summary>
        /// Handles initialization of the GameScreen. This will be invoked after the GameScreen has been
        /// completely and successfully added to the ScreenManager. It is highly recommended that you
        /// use this instead of the constructor. This is invoked only once.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            var cScreen = new Panel(GUIManager, Vector2.Zero, ScreenManager.ScreenSize);

            // Create the menu buttons
            _menuButtons = GameScreenHelper.CreateMenuButtons(ScreenManager, cScreen, "Accept", "Cancel");
            _menuButtons["Accept"].Clicked += accept_Clicked;
            _menuButtons["Cancel"].Clicked += cancel_Clicked;

            // Create the options
            var pos = new Vector2(60, 180);
            var lblSound = GameScreenHelper.CreateMenuLabel(cScreen, pos, "Sound (0 to 100):");
            _txtSound = new TextBox(cScreen, pos + new Vector2(lblSound.Size.X + 10, -6), 
                new Vector2(128, lblSound.ClientSize.Y + 4)) { AllowKeysHandler = TextEventArgsFilters.IsDigitFunc };

            pos.Y += _txtSound.Size.Y + 16;
            var lblMusic = GameScreenHelper.CreateMenuLabel(cScreen, pos, "Music (0 to 100):");
            _txtMusic = new TextBox(cScreen, pos + new Vector2(lblMusic.Size.X + 10, -6), 
                new Vector2(128, lblMusic.ClientSize.Y + 4)) { AllowKeysHandler = TextEventArgsFilters.IsDigitFunc };
        }
示例#26
0
 public TestEntity(Vector2 pos, Vector2 size) : base(pos, size)
 {
 }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffectTimed"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="life">How long the effect will last in milliseconds.</param>
 public MapGrhEffectTimed(Grh grh, Vector2 position, int life) : base(grh, position)
 {
     _expireTime = (TickCount)(TickCount.Now + life);
 }
示例#28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CharacterEntity"/> class.
 /// </summary>
 /// <param name="position">The initial world position.</param>
 /// <param name="size">The initial size.</param>
 protected CharacterEntity(Vector2 position, Vector2 size) : base(position, size)
 {
 }
示例#29
0
 /// <summary>
 /// Moves the character to the new location. Unlike Teleport(), this will not set the
 /// velocity to zero, and is intended for position corrections / resynchronization.
 /// </summary>
 /// <param name="position">Correct position.</param>
 public virtual void UpdatePosition(Vector2 position)
 {
     base.Teleport(position);
 }
示例#30
0
        /// <summary>
        /// Moves the character to a new location instantly. The character's velocity will
        /// also be set to zero upon teleporting.
        /// </summary>
        /// <param name="position">New position</param>
        protected override void Teleport(Vector2 position)
        {
            // Force the character to stop moving
#if !TOPDOWN
            _state = CharacterState.Falling;
#endif
            SetVelocity(Vector2.Zero);
            StopMoving();

            // Teleport
            base.Teleport(position);
        }