Esempio n. 1
0
    public CollisionState2D CheckProximity(float distance, Direction2D mask)
    {
        var proximityCollision = new CollisionState2D();

        // Check below
        if (FlagsHelper.IsSet(mask, Direction2D.DOWN))
        {
            proximityCollision.Below = CheckBelow(distance, data.skinWidth);
        }

        // Check above
        if (FlagsHelper.IsSet(mask, Direction2D.UP))
        {
            proximityCollision.Above = CheckAbove(distance, data.skinWidth);
        }

        // Check right.
        if (FlagsHelper.IsSet(mask, Direction2D.RIGHT))
        {
            proximityCollision.Right = CheckRight(distance, data.skinWidth);
        }

        // Check left
        if (FlagsHelper.IsSet(mask, Direction2D.LEFT))
        {
            proximityCollision.Left = CheckLeft(distance, data.skinWidth);
        }

        return(proximityCollision);
    }
Esempio n. 2
0
    public CollisionState2D CheckProximity(float distance, Direction2D mask)
    {
        var proximityCollision = new CollisionState2D();

        // Check below
        if (FlagsHelper.IsSet(mask, Direction2D.DOWN))
        {
            proximityCollision.Below = Check(Constants.Directions.DOWN, distance);
        }

        // Check above
        if (FlagsHelper.IsSet(mask, Direction2D.UP))
        {
            proximityCollision.Above = Check(Constants.Directions.UP, distance);
        }

        // Check right.
        if (FlagsHelper.IsSet(mask, Direction2D.RIGHT))
        {
            proximityCollision.Right = Check(Constants.Directions.RIGHT, distance);
        }

        // Check left
        if (FlagsHelper.IsSet(mask, Direction2D.LEFT))
        {
            proximityCollision.Left = Check(Constants.Directions.LEFT, distance);
        }

        return(proximityCollision);
    }
Esempio n. 3
0
    /// <summary>
    /// Sets the rotation.
    /// </summary>
    /// <param name="direction">The direction.</param>
    /// <exception cref="ArgumentOutOfRangeException">direction - null</exception>
    public void SetRotation(Direction2D direction)
    {
        // Set sprite
        switch (direction)
        {
        case Direction2D.Up:
            _currentSprite = Up;
            break;

        case Direction2D.Right:
            _currentSprite = Right;
            break;

        case Direction2D.Down:
            _currentSprite = Down;
            break;

        case Direction2D.Left:
            _currentSprite = Left;
            break;

        default:
            throw new ArgumentOutOfRangeException("direction", direction, null);
        }

        _spriteRenderer.sprite = _currentSprite;
    }
Esempio n. 4
0
 public ItemMovement2D(Vector3Int origin, Direction2D direction, Transform item)
 {
     Origin      = origin;
     Direction   = direction;
     Destination = origin + direction.Vector3Int();
     Item        = item;
 }
Esempio n. 5
0
        public Cannon(Direction2D direction, Vector2i index)
        {
            _direction = direction;
            _worldIndex = index;

            _readOnlyBullets = new ReadOnlyCollection<Bullet>(_bullets);
        }
Esempio n. 6
0
    // Returns the offset resulting from traversing the given number of bands.
    // The offset is affected by the given direction to travel in.
    // A band is formed by a single line of contiguous cells that crosses the entire array.
    // For instance, a row is a horizontal band and a column is a vertical band.
    // A horizontal band is formed by traversing the array horizontally.
    // A vertical band is formed by traversing the array vertically.
    private int GetBandOffsetFromDirection(Direction2D direction, int bands = 1)
    {
        int bandLength = GetEndOffsetFromDirection(direction)
                         - GetStartOffsetFromDirection(direction);

        return(bandLength * bands);
    }
Esempio n. 7
0
        private static void ProcessTerminalVertex(Mesh <WavefrontVertex, EdgeBase, WavefrontFace> wavefrontMesh, IDictionary <VertexBase, List <WavefrontVertex> > wavefrontVertices, TVertex figureVertex)
        {
            // 1. Create two wavefront vertices at ±135° from the incident figure edge
            //  1a. Locate the figure edge
            //  1b. Determine the direction of the figure edge away from the vertex
            Direction2D figureEdgeDirection = new Direction2D(3, 4); // TODO: Temporary - need direction from the terminal vertex along the edge

            Direction2D     direction1       = AffineTransformation2D.Rotation(Angle.DegreesToRadians(+135.0)).Transform(figureEdgeDirection);
            Vector2D        vector1          = new Vector2D(direction1, Constants.Sqrt2);
            WavefrontVertex wavefrontVertex1 = new WavefrontVertex(figureVertex, vector1);

            InsertWavefrontVertex(wavefrontMesh, wavefrontVertices, wavefrontVertex1);

            Direction2D     direction2       = AffineTransformation2D.Rotation(Angle.DegreesToRadians(-135.0)).Transform(figureEdgeDirection);
            Vector2D        vector2          = new Vector2D(direction2, Constants.Sqrt2);
            WavefrontVertex wavefrontVertex2 = new WavefrontVertex(figureVertex, vector2);

            InsertWavefrontVertex(wavefrontMesh, wavefrontVertices, wavefrontVertex2);

            // 2. Label the incoming figureEdge (wavefront precursors) with the two vertices at the correct end
            // 3. Label all of the incoming triangulation edge (spoke precursors) with the first wavefront vertex
            // 4. Create wavefront edge between the two wavefront vertices
            // 5. Identify the quadrilateral based by the edge created in step 4
            // 6. Split this quadrilateral by inserting a new edge from the second
            //    of the two wavefront vertices.

            throw new NotImplementedException();
        }
Esempio n. 8
0
    /// <summary>
    /// Processes vehicle rotation/turning.
    /// </summary>
    private void ProcessRotation()
    {
        // Get the X and Y difference between the current position and the target position

        // Get the direction of travel
        bool posX = _targetPos.x > _currentPos.x;
        bool posY = _targetPos.y > _currentPos.y;

        if (posX && posY)
        {
            _direction = Direction2D.Up;
        }
        else if (!posX && !posY)
        {
            _direction = Direction2D.Down;
        }
        else if (!posX && posY)
        {
            _direction = Direction2D.Left;
        }
        else
        {
            _direction = Direction2D.Right;
        }

        // Change the sprite
        _rotatableSprite2D.SetRotation(_direction);
    }
Esempio n. 9
0
        public static Vector2 GetVector2(this Direction2D d, bool normalized = true)
        {
            Vector2 v = Vector2.zero;

            if (d.HasFlag(Direction2D.Left))
            {
                v += Vector2.left;
            }
            if (d.HasFlag(Direction2D.Right))
            {
                v += Vector2.right;
            }
            if (d.HasFlag(Direction2D.Top))
            {
                v += Vector2.up;
            }
            if (d.HasFlag(Direction2D.Bottom))
            {
                v += Vector2.down;
            }
            if (normalized)
            {
                v.Normalize();
            }
            return(v);
        }
        public void Increment()
        {
            var currentAntCell = _grid[AntCoordinates];
            Cell <LangtonsAntCellMetadata> newAntCell;

            if (currentAntCell.Payload.IsWhite)
            {
                currentAntCell.Payload.IsWhite = false;
                AntDirection = RotateClockwise(AntDirection);
            }
            else
            {
                currentAntCell.Payload.IsWhite = true;
                AntDirection = RotateCounterClockwise(AntDirection);
            }

            newAntCell = ProgressCell(currentAntCell, AntDirection);

            if (newAntCell == null)
            {
                AntDirection = Invert(AntDirection);
                newAntCell   = ProgressCell(currentAntCell, AntDirection);
            }

            AntCoordinates = newAntCell.Coordinates;

            currentAntCell.Payload.AntDirection = null;
            newAntCell.Payload.AntDirection     = AntDirection;

            _gridRenderer.RenderCell(currentAntCell);
            _gridRenderer.RenderCell(newAntCell);
        }
        public virtual void CursorChangeOnMove(BaseEventData data)
        {
            MouseCursor mc = MouseCursor.Instance;
            //Vector3[] corners = new Vector3[4];
            //rt.GetWorldCorners(corners);
            //Vector2 min = corners[1], max = corners[3];
            //Vector2 mousePosition = Input.mousePosition; // data.position;
            //mouseCursorState = CalculateEdgeDirection(mousePosition, min, max, resizeEdgeRadius);
            Vector2 pos = AppInput.MousePosition;

            if (data is PointerEventData ped)
            {
                pos = ped.position;
            }
            mouseCursorState = CalculatePointerOutOfBounds(rt, pos, out Vector2 offset, -resizeEdgeRadius);
            float r2 = resizeEdgeRadius * 2;

            if (Mathf.Abs(offset.x) > resizeEdgeRadius || Mathf.Abs(offset.y) > resizeEdgeRadius)
            {
                mouseCursorState = Direction2D.None;
            }
            if (!dynamicMouseCursor || mc == null)
            {
                return;
            }
            if (mouseCursorState != Direction2D.None)
            {
                mc.SetCursor(this, mouseCursorState);
            }
            else
            {
                mc.SetCursor(this, MouseCursor.CursorType.Cursor);
            }
            data?.Use();
        }
Esempio n. 12
0
 void Awake()
 {
     mainRigidBody      = GetComponent <Rigidbody2D>();
     skinSpriteRenderer = Skin.GetComponent <SpriteRenderer>();
     skinAnimator       = Skin.GetComponent <Animator>();
     direction          = Direction;
 }
Esempio n. 13
0
        /// <summary>
        /// Given a fault segment which is either an InSegment or an OutSegment
        /// of this BranchPoint, determine the next in or out segment in an anticlockwise
        /// direction.
        /// </summary>
        /// <param name="segment">The query segment, must be connected to this BranchPoint</param>
        /// <returns>The next segment anticlockwise from the query segment</returns>
        internal FaultSegment AnticlockwiseSegmentFrom(FaultSegment segment)
        {
            // TODO: Efficiency - re-building the list and re-sorting the segments every time is wasteful
            Debug.Assert(ContainsInSegment(segment) || ContainsOutSegment(segment));
            List <Pair <double, FaultSegment> > segments = new List <Pair <double, FaultSegment> >(inSegments.Count + outSegments.Count);

            foreach (FaultSegment inSegment in inSegments)
            {
                Point2D pointAlongSegment = inSegment.Count == 0 ? inSegment.PreviousBranch.Position : inSegment.Last.Position;
                // TODO: Have reversed sense of arguments in Direction2D constructor call - possibly need reversing here too
                Direction2D direction = new Direction2D(Position, pointAlongSegment);
                segments.Add(new Pair <double, FaultSegment>(direction.Bearing, inSegment));
            }

            foreach (FaultSegment outSegment in outSegments)
            {
                Point2D pointAlongSegment = outSegment.Count == 0 ? outSegment.NextBranch.Position : outSegment.First.Position;
                // TODO: Have reversed sense of arguments in Direction2D constructor call - possibly need reversing here too
                Direction2D direction = new Direction2D(Position, pointAlongSegment);
                segments.Add(new Pair <double, FaultSegment>(direction.Bearing, outSegment));
            }

            segments.Sort();
            int index     = segments.FindIndex(delegate(Pair <double, FaultSegment> bearingSegment) { return(bearingSegment.Second == segment); });
            int nextIndex = (index + 1) % segments.Count;

            return(segments[nextIndex].Second);
        }
Esempio n. 14
0
        // TODO make some kind of FloatRect class, and put this functionality in that?
        public static Direction2D CalculatePointerOutOfBounds(RectTransform rt, Vector3 pointerPosition, out Vector2 offset, float borderExpansion = 0)
        {
            Vector3 p    = rt.InverseTransformPoint(pointerPosition);
            Rect    rect = rt.rect;

            if (borderExpansion != 0)
            {
                Vector2 adjust = Vector2.one * borderExpansion;
                rect.min -= adjust;
                rect.max += adjust;
            }
            float y = p.y, yMin = rect.yMin, yMax = rect.yMax, yDelta = 0;
            float x = p.x, xMin = rect.xMin, xMax = rect.xMax, xDelta = 0;
            //Show.Log("yMin:"+viewport.rect.yMin + "  yMax:" + viewport.rect.yMax+"  y:" + point.y);
            Direction2D dir = Direction2D.None;

            if (y > yMax)
            {
                yDelta += (yMax - y); dir |= Direction2D.Top;
            }
            if (y < yMin)
            {
                yDelta += (yMin - y); dir |= Direction2D.Bottom;
            }
            if (x > xMax)
            {
                xDelta += (xMax - x); dir |= Direction2D.Right;
            }
            if (x < xMin)
            {
                xDelta += (xMin - x); dir |= Direction2D.Left;
            }
            offset = new Vector2(xDelta, yDelta);
            return(dir);
        }
Esempio n. 15
0
        public void TestGetDeltaIncreaseDecrease()
        {
            int[]          directionsX  = { 1, 1, 1, 0, -1, -1, -1, 0 };
            int[]          directionsY  = { 1, 0, -1, -1, -1, 0, 1, 1 };
            DirectionSet2D directionSet = new DirectionSet2D(8, directionsX, directionsY);

            Direction2D direction = new Direction2D(directionSet);

            int deltaX;
            int deltaY;

            direction.GetDelta(out deltaX, out deltaY);
            Assert.AreEqual(deltaX, 1);
            Assert.AreEqual(deltaY, 1);

            direction.Increase();
            direction.Increase();

            direction.GetDelta(out deltaX, out deltaY);
            Assert.AreEqual(deltaX, 1);
            Assert.AreEqual(deltaY, -1);

            direction.Decrease();

            direction.GetDelta(out deltaX, out deltaY);
            Assert.AreEqual(deltaX, 1);
            Assert.AreEqual(deltaY, 0);
        }
Esempio n. 16
0
    private void HandleCollision(Collision2D collision)
    {
        Vector2 moveDirection;

        // If the ice collided with the player, the ice should move away from the player
        if (collision.gameObject.CompareTag("Player") || collision.gameObject.CompareTag("Ice"))
        {
            Direction2D hitFromDir = collision.GetDirectionHitCameFrom();
            moveDirection = hitFromDir.Vector;
        }
        // If the ice collided with something else like a wall
        else
        {
            Direction2D hitFromDir = collision.GetDirectionHitCameFrom();
            //Direction2D curMoveDirection = parentPhys.velocity.GetDirection2D();
            // If the direction changed to the opposite direction we were previously moving in,
            // the ice cube probably had a direct collision and should stop moving
            if (hitFromDir.IsOppositeDirection(previousDirection))
            {
                moveDirection = Vector2.zero;
            }
            // If the direction only changed slightly and is not in the opposite direction,
            // the ice cube probably just brushed against something and should keep moving as it was
            else
            {
                moveDirection = previousDirection.Vector;
            }
        }

        // Set the ice's velocity to be fully in its movement direction
        parentPhys.velocity = moveDirection * slideSpeed;
        // Update the previous direction
        previousDirection = parentPhys.velocity.ToDirection2D();
    }
Esempio n. 17
0
        public static Direction2D FromRotation(float degrees, Direction2D startDirection = Direction2D.Right) //
        {
            degrees = FlaiMath.RealModulus(degrees, 360);

            int step = (int)FlaiMath.Round(degrees / 90);

            return((Direction2D)FlaiMath.RealModulus((int)(step + startDirection), 4));
        }
Esempio n. 18
0
        public void AcuteBisector180()
        {
            Vector2D    v1 = new Vector2D(1.0, 0.0);
            Vector2D    v2 = new Vector2D(-1.0, 0.0);
            Direction2D d  = VectorGeometry.Bisector(ref v1, ref v2);

            Assert.AreEqual(new Direction2D(-1.0, 0.0), d);
        }
Esempio n. 19
0
 /// <summary>
 /// Determines whether this road [can travel to] another.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <param name="direction">The direction.</param>
 /// <returns>
 ///   <c>true</c> if this instance [can travel to] the specified other; otherwise, <c>false</c>.
 /// </returns>
 public bool CanTravelTo(Road other, Direction2D direction)
 {
     // Checks if travel between two roads is possible
     return(direction == Direction2D.Up && TraversableUp && other.TraversableDown ||
            direction == Direction2D.Down && TraversableDown && other.TraversableUp ||
            direction == Direction2D.Left && TraversableLeft && other.TraversableRight ||
            direction == Direction2D.Right && TraversableRight && other.TraversableLeft);
 }
Esempio n. 20
0
 private static void InitalizeBisectors(IEnumerable <Vertex> lav)
 {
     foreach (Vertex vertex in lav)
     {
         Direction2D bisectorDirection = AngularBisector(vertex.inEdge, vertex.outEdge);
         vertex.Bisector = new Ray2D(vertex.Bisector.Source, bisectorDirection);
     }
 }
Esempio n. 21
0
 /// <inheritdoc />
 protected override void OnDirectionInput(GameTime gameTime, InputType inputType, Direction2D direction)
 {
     base.OnDirectionInput(gameTime, inputType, direction);
     if (CanProcessTransferFocusInput &&
         (inputType == InputType.ClickDown ||
          inputType == InputType.Repeat))
         ProcessTransferFocusInput(direction);
 }
 public LangtonsAntIterationCellGenerator(LangtonsAnt game, Grid <LangtonsAntCellMetadata> grid, IGridRenderer <LangtonsAntCellMetadata> gridRenderer, Coordinates2D antCoordinates, Direction2D antDirection)
 {
     _game          = game;
     _grid          = grid;
     _gridRenderer  = gridRenderer;
     AntCoordinates = antCoordinates;
     AntDirection   = antDirection;
 }
Esempio n. 23
0
        public static int Sign(this Direction2D direction)
        {
            if (direction == Direction2D.Left || direction == Direction2D.Up)
            {
                return(-1);
            }

            return(1);
        }
Esempio n. 24
0
 private void DirectionDownRepeat(GameTime gameTime, Direction2D direction, Focusable focusable)
 {
     directionPressedElapsedTime[(int)direction] += (float)gameTime.ElapsedGameTime.TotalSeconds;
     if (directionPressedElapsedTime[(int)direction] <= repeatRate.FirstDelay) return;
     directionPressedElapsedTime2[(int)direction] += (float)gameTime.ElapsedGameTime.TotalSeconds;
     if (directionPressedElapsedTime2[(int)direction] <= repeatRate.RepeatDelay) return;
     directionPressedElapsedTime2[(int)direction] = 0;
     focusable.NotifyDirectionInput(gameTime, InputType.Repeat, direction);
 }
        //public override void OnEndDrag(BaseEventData data) { base.OnEndDrag(data); }

        public override void PointerUp(BaseEventData data)
        {
            base.PointerUp(data);
            pointerDown = false;
            heldDir     = Direction2D.None;
            //if (!disableReize) {
            CursorChangeOnMove(null);
            //}
        }
 public virtual void PointerEnter(BaseEventData data)
 {
     // Show.Log("enter " + this);
     if (disableReize)
     {
         mouseCursorState = Direction2D.None; return;
     }
     //enabled = resizeEdgeRadius != 0;
 }
Esempio n. 27
0
 void Start()
 {
     animWaggle.StartPlay();
     _branch           = transform.parent;
     _branchSpriteSize = _branch.GetComponent <SpriteRenderer> ().bounds.size;
     _direction2D      = _branch.gameObject.name.StartsWith("left")?Direction2D.right:Direction2D.left;
     _startAngulars    = transform.eulerAngles;
     _cor = StartCoroutine(DoMyUpdate());
 }
Esempio n. 28
0
        public static Axis ToAxis(this Direction2D direction)
        {
            if (direction == Direction2D.Left || direction == Direction2D.Right)
            {
                return(Axis.Horizontal);
            }

            return(Axis.Vertical);
        }
Esempio n. 29
0
        public RectangleF GetSideArea(Direction2D side)
        {
            float x      = (side != Direction2D.Right) ? this.Left : this.Right - 1;
            float y      = (side != Direction2D.Down) ? this.Top : this.Bottom - 1;
            float width  = (side == Direction2D.Left || side == Direction2D.Right) ? 1 : this.Width;
            float height = (side == Direction2D.Up || side == Direction2D.Down) ? 1 : this.Height;

            return(new RectangleF(x, y, width, height));
        }
Esempio n. 30
0
    // Returns the total offset resulting from two given coordinates.
    // The directions used are defined by the coordinate order.
    private int GetOffsetFromCoordinates(int coord1, int coord2)
    {
        Direction2D dir1         = order.GetDirectionFirst();
        Direction2D dir2         = order.GetDirectionSecond();
        int         coord1Offset = GetOffsetFromCoordinate(coord1, dir1);
        int         coord2Offset = GetOffsetFromCoordinate(coord2, dir2);

        return(coord1Offset + coord2Offset);
    }
Esempio n. 31
0
 public DamageInfo(GameObject source, int damage, Direction2D direction, bool ignoreInvincibility = false,
                   bool disableKnockback = false)
 {
     Source = source;
     Damage = damage;
     IgnoreInvincibility = ignoreInvincibility;
     DisableKnockback    = disableKnockback;
     Direction           = direction;
 }
Esempio n. 32
0
        private static void AddCurveRule(params int[] npointValues)
        {
            HilbertCurve2D curve = new HilbertCurve2D(npointValues);
            Direction2D    name  = curve.Name();

            if (!_curves.ContainsKey(name))
            {
                _curves[name] = curve;
            }
        }
Esempio n. 33
0
        public Direction2D To2D(Direction direction)
        {
            var result = Direction2D.Create(direction.DotProduct(XAxis), direction.DotProduct(YAxis));

            if (direction != To3D(result))
            {
                throw new ArgumentException("The direction does not lie within the embedded space.");
            }
            return(result);
        }
Esempio n. 34
0
 /// <summary>
 /// Get the state of the given direction button.
 /// </summary>
 public ButtonState GetDirectionState(Direction2D direction, ref GamePadState gamePadState)
 {
     switch (direction)
     {
         case Direction2D.Up: return GetDirectionUpState(ref gamePadState);
         case Direction2D.Down: return GetDirectionDownState(ref gamePadState);
         case Direction2D.Left: return GetDirectionLeftState(ref gamePadState);
         case Direction2D.Right: return GetDirectionRightState(ref gamePadState);
         default: return ButtonState.Released;
     }
 }
Esempio n. 35
0
 private void DirectionInput(GameTime gameTime, Direction2D direction, ButtonState directionButtonState, Focusable focusable)
 {
     if (directionButtonState == ButtonState.Pressed)
     {
         if (isDirectionPressed[(int)direction] != ButtonState.Pressed) focusable.NotifyDirectionInput(gameTime, InputType.ClickDown, direction);
         DirectionDownRepeat(gameTime, direction, focusable);
         focusable.NotifyDirectionInput(gameTime, InputType.Down, direction);
     }
     else if (directionButtonState != ButtonState.Pressed)
     {
         if (isDirectionPressed[(int)direction] == ButtonState.Pressed)
         {
             DirectionUp(direction);
             focusable.NotifyDirectionInput(gameTime, InputType.ClickUp, direction);
         }
         // OPTIMIZATION: this functionality is not worth the speed cost
         //DirectionUpRepeat(gameTime, direction);
         //screen.NotifyDirectionInput(gameTime, InputType.Up, direction);
     }
     isDirectionPressed[(int)direction] = directionButtonState;
 }
Esempio n. 36
0
 public MultipleHits<CollisionResult> CollideEdge(Vector3 position, Vector3 impulse, Vector3 halfSize, Direction2D direction, QueryOptions options, float elasticity, Viewpoint viewpoint)
 {
   MultipleHits<CollisionResult> multipleHits = new MultipleHits<CollisionResult>();
   if (impulse == Vector3.Zero)
     return multipleHits;
   bool flag = (options & QueryOptions.Simple) == QueryOptions.Simple;
   Vector3 vector3_1 = new Vector3((float) Math.Sign(impulse.X), (float) Math.Sign(impulse.Y), (float) Math.Sign(impulse.Z));
   if (!flag)
   {
     Vector3 position1 = position;
     Vector3 position2 = position;
     switch (direction)
     {
       case Direction2D.Horizontal:
         position1 += (vector3_1 + Vector3.Down) * halfSize;
         position2 += (vector3_1 + Vector3.Up) * halfSize;
         break;
       case Direction2D.Vertical:
         Vector3 vector3_2 = FezMath.RightVector(viewpoint) * (float) FezMath.Sign(this.PlayerManager.LookingDirection);
         position1 += (vector3_1 - vector3_2) * halfSize;
         position2 += (vector3_1 + vector3_2) * halfSize;
         break;
     }
     multipleHits.NearLow = this.CollidePoint(position1, impulse, options, elasticity, viewpoint);
     multipleHits.FarHigh = this.CollidePoint(position2, impulse, options, elasticity, viewpoint);
   }
   if (flag || !multipleHits.NearLow.Collided)
   {
     Vector3 position1 = position + vector3_1 * halfSize;
     multipleHits.NearLow = this.CollidePoint(position1, impulse, options, elasticity, viewpoint);
   }
   return multipleHits;
 }
Esempio n. 37
0
 public MultipleHits<CollisionResult> CollideEdge(Vector3 position, Vector3 impulse, Vector3 halfSize, Direction2D direction, QueryOptions options)
 {
   return this.CollideEdge(position, impulse, halfSize, direction, options, 0.0f);
 }
Esempio n. 38
0
 public Bullet(Direction2D direction, Vector2 initialPosition, float speed)
 {
     _direction = direction;
     _position = initialPosition;
     _speed = speed;
 }
Esempio n. 39
0
 private void ProcessTransferFocusInput(Direction2D direction)
 {
     // NOTE: this method is highly imperative so that actor ui lists can be recycled to
     // avoid generating garbage.
     ActorGroup actorGroup = GrabActorGroup<ActorGroup>();
     actorGroup.CollectActors<ActorUI>(cachedActorUIs);
     cachedActorUIs.GetActorUIsThatAcceptFocus(cachedActorUIs2);
     cachedActorUIs.Clear();
     cachedActorUIs2.GetActorUIsInDirection(cachedActorUIs, this, direction);
     cachedActorUIs2.Clear();
     cachedActorUIs.SortActorUIsInDirection(this, direction);
     ActorUI target = cachedActorUIs.FirstOrDefault();
     cachedActorUIs.Clear();
     if (target != null) target.FocusIndex = FocusIndex;
 }
Esempio n. 40
0
 /// <summary>
 /// Notify that directional input has taken place.
 /// </summary>
 public void NotifyDirectionInput(GameTime gameTime, InputType inputType, Direction2D direction)
 {
     OnDirectionInput(gameTime, inputType, direction);
 }
Esempio n. 41
0
 /// <summary>
 /// Handle the fact that directional input took place.
 /// </summary>
 protected virtual void OnDirectionInput(GameTime gameTime, InputType inputType, Direction2D direction) { }
Esempio n. 42
0
 private void DirectionUp(Direction2D direction)
 {
     directionPressedElapsedTime[(int)direction] = 0;
     directionPressedElapsedTime2[(int)direction] = 0;
 }
Esempio n. 43
0
 protected RectangleF GetSideAreaPlusOne(Direction2D side)
 {
     RectangleF fullArea = this.RoundedArea;
     if (side == Direction2D.Left)
     {
         return new RectangleF(fullArea.Left - 1, fullArea.Top, 1, fullArea.Height);
     }
     else if (side == Direction2D.Right)
     {
         return new RectangleF(fullArea.Right, fullArea.Top, 1, fullArea.Height);
     }
     else if (side == Direction2D.Up)
     {
         return new RectangleF(fullArea.Left, fullArea.Top - 1, fullArea.Width, 1);
     }
     else // if(side == Direction2D.Down)
     {
         return new RectangleF(fullArea.Left, fullArea.Bottom, fullArea.Width, 1);
     }
 }
Esempio n. 44
0
        public bool Resize(Direction2D resizeDirection, int difference)
        {
            if(difference == 0)
            {
                return false;
            }

            if (resizeDirection == Direction2D.Right)
            {
                int newWidth = FlaiMath.Max(EditorMap.MinimumWidth, _width + difference);
                if (newWidth == _width)
                {
                    return false;
                }

                this.Resize(_width + difference, _height);
            }
            else if (resizeDirection == Direction2D.Down)
            {
                int newHeight = FlaiMath.Max(EditorMap.MinimumHeight, _height + difference);
                if (newHeight == _height)
                {
                    return false;
                }

                this.Resize(_width, _height + difference);
            }

            if (resizeDirection == Direction2D.Left)
            {
                int newWidth = FlaiMath.Max(EditorMap.MinimumWidth, _width - difference);
                if (newWidth == _width)
                {
                    return false;
                }

                // Make the world smaller
                if (difference > 0)
                {
                    this.MoveTiles(new Rectangle(difference, 0, _width - difference, _height), new Vector2i(-difference, 0));
                    this.Resize(_width - difference, _height);
                }
                // Make the world bigger
                else
                {
                    this.Resize(_width - difference, _height);
                    this.MoveTiles(new Rectangle(0, 0, _width + difference, _height), new Vector2i(-difference, 0));
                }
            }
            else if (resizeDirection == Direction2D.Up)
            {
                int newHeight = FlaiMath.Max(EditorMap.MinimumHeight, _height - difference);
                if (newHeight == _height)
                {
                    return false;
                }

                // Make the world smaller
                if (difference > 0)
                {
                    this.MoveTiles(new Rectangle(0, difference, _width, _height - difference), new Vector2i(0, -difference));
                    this.Resize(_width, _height - difference);
                }
                // Make the world bigger
                else
                {
                    this.Resize(_width, _height - difference);
                    this.MoveTiles(new Rectangle(0, 0, _width, _height + difference), new Vector2i(0, -difference));
                }
            }

            return true;
        }
Esempio n. 45
0
 /// <summary>
 /// �R���X�g���N�^
 /// </summary>
 public ChaseMotion2D()
 {
     fromDirection = new Direction2D(this);
 }
        private void HandleResizeMap(UpdateContext updateContext)
        {
            if (!EditorPlayerController.ScreenInputZone.Contains(updateContext.InputState.MousePosition))
            {
                return;
            }

            if (updateContext.InputState.IsNewMouseButtonPress(MouseButton.Right))
            {
                _isResizing = false;
                _player.EditorMode = EditorMode.Normal;
                return;
            }

            Vector2 mouseWorldCoordinate = _player.Camera.ScreenToWorld(FlaiGame.Current.GraphicsDevice, updateContext.InputState.MousePosition);
            if (_isResizing)
            {
                if (!updateContext.InputState.IsMouseButtonPressed(MouseButton.Left))
                {
                    _isResizing = false;
                    return;
                }

                // To Right and Down, you can resize on per-tile basis
                if (_resizeDirection == Direction2D.Right)
                {
                    int resize = (int)((mouseWorldCoordinate.X - _world.Map.Width * Tile.Size) / Tile.Size / Room.Width) * Room.Width;
                    _world.Map.Resize(Direction2D.Right, resize);
                }
                else if (_resizeDirection == Direction2D.Down)
                {
                    int resize = (int)((mouseWorldCoordinate.Y - _world.Map.Height * Tile.Size) / Tile.Size / Room.Height) * Room.Height;
                    _world.Map.Resize(Direction2D.Down, resize);
                }

                // To Left and Top, you can resize on Room basis
                if (_resizeDirection == Direction2D.Left)
                {
                    int resize = (int)((mouseWorldCoordinate.X / (Room.Width * Tile.Size))) * Room.Width;
                    if (resize != 0)
                    {
                        if (_world.Map.Resize(Direction2D.Left, resize))
                        {
                            _player.Camera.Position -= Vector2.UnitX * resize * Tile.Size;
                        }
                    }
                }
                else if (_resizeDirection == Direction2D.Up)
                {
                    int resize = (int)((mouseWorldCoordinate.Y / (Room.Height * Tile.Size))) * Room.Height;
                    if (resize != 0)
                    {
                        if (_world.Map.Resize(Direction2D.Up, resize))
                        {
                            _player.Camera.Position -= Vector2.UnitY * resize * Tile.Size;
                        }
                    } 
                }
            }
            else
            {
                float MaximumDistance = Tile.Size / _player.Camera.Zoom;
                if (updateContext.InputState.IsMouseButtonPressed(MouseButton.Left))
                {
                    // Left
                    if (FlaiMath.Distance(mouseWorldCoordinate.X, 0) < MaximumDistance)
                    {
                        _isResizing = true;
                        _resizeDirection = Direction2D.Left;
                    }
                    // Right
                    else if (FlaiMath.Distance(mouseWorldCoordinate.X, _world.Map.Width * Tile.Size) < MaximumDistance)
                    {
                        _isResizing = true;
                        _resizeDirection = Direction2D.Right;
                    }
                    // Top
                    else if (FlaiMath.Distance(mouseWorldCoordinate.Y, 0) < MaximumDistance)
                    {
                        _isResizing = true;
                        _resizeDirection = Direction2D.Up;
                    }
                    // Bottom
                    else if (FlaiMath.Distance(mouseWorldCoordinate.Y, _world.Map.Height * Tile.Size) < MaximumDistance)
                    {
                        _isResizing = true;
                        _resizeDirection = Direction2D.Down;
                    }
                }
            }

            _world.IsModified = true;
        }
Esempio n. 47
0
 private bool IsTouchingFromDirection(Direction2D direction, out RectangleF collisionArea)
 {
     return _world.IsOccupied(this.GetSideAreaPlusOne(direction), out collisionArea);
 }
Esempio n. 48
0
 private bool IsTouchingFromDirection(Direction2D direction, bool checkCollisionAgainstCannons = true, bool checkCollisionsAgainstLocks = true)
 {
     return _world.IsOccupied(this.GetSideAreaPlusOne(direction), checkCollisionAgainstCannons, checkCollisionsAgainstLocks);
 }
Esempio n. 49
0
 public MultipleHits<CollisionResult> CollideEdge(Vector3 position, Vector3 impulse, Vector3 halfSize, Direction2D direction, QueryOptions options, float elasticity)
 {
   return this.CollideEdge(position, impulse, halfSize, direction, options, elasticity, this.CameraManager.Viewpoint);
 }
Esempio n. 50
0
 /// <summary>
 /// �R���X�g���N�^
 /// </summary>
 public MoveArc2D()
 {
     fromDirection = new Direction2D(this);
 }
Esempio n. 51
0
 /// <summary>
 /// �R���X�g���N�^
 /// </summary>
 public MoveDirection2D()
 {
     moveDirection = new Direction2D(this);
 }
Esempio n. 52
0
        protected RectangleF GetSideArea(Direction2D side)
        {
            RectangleF fullArea = this.RoundedArea;
            float x = (side != Direction2D.Right) ? fullArea.Left : fullArea.Right - 1;
            float y = (side != Direction2D.Down) ? fullArea.Top : fullArea.Bottom - 1;
            float width = (side == Direction2D.Left || side == Direction2D.Right) ? 1 : fullArea.Width;
            float height = (side == Direction2D.Up || side == Direction2D.Down) ? 1 : fullArea.Height;

            return new RectangleF(x, y, width, height);
        }