Esempio n. 1
0
        public BoxCollider(FixedVector2 _position, FixedVector2 _positionOffset, FixedVector2 _size)
        {
            positionOffset = _positionOffset;
            bounds         = new BoundingBox(_position + positionOffset, _size);

            edges = new FixedLine2[] {
                new FixedLine2(
                    bounds.min,
                    new FixedVector2(bounds.max.x, bounds.min.y)
                    ),

                new FixedLine2(
                    new FixedVector2(bounds.min.x, bounds.max.y),
                    bounds.max
                    ),

                new FixedLine2(
                    bounds.min,
                    new FixedVector2(bounds.min.x, bounds.max.y)
                    ),

                new FixedLine2(
                    new FixedVector2(bounds.max.x, bounds.min.y),
                    bounds.max
                    )
            };
        }
Esempio n. 2
0
    public static bool Check(FixedVector2 origin, FixedVector2 end, out FixedVector2 intersection, int id, Mask check, out int otherID)
    {
        _allColliders = Contexts.sharedInstance.logic.GetGroup(LogicMatcher.Collider);
        intersection  = FixedVector2.NAN;
        otherID       = -1;

        foreach (LogicEntity e in _allColliders)
        {
            if (!check.HasFlag(e.collider.value.mask))
            {
                continue;
            }
            if (id == e.id.value)
            {
                continue;
            }

            if (RayCast.CheckIntersection(origin, end, out intersection, e.collider.value))
            {
                otherID = e.id.value;
                return(true);
            }
        }

        return(false);
    }
Esempio n. 3
0
 /// <summary>
 ///   <para>Creates a rectangle given a size and position.</para>
 /// </summary>
 /// <param name="position">The position of the minimum corner of the rect.</param>
 /// <param name="size">The width and height of the rect.</param>
 public FixedRect(FixedVector2 position, FixedVector2 size)
 {
     this.m_XMin   = position.x;
     this.m_YMin   = position.y;
     this.m_Width  = size.x;
     this.m_Height = size.y;
 }
Esempio n. 4
0
    protected override void Execute(List <LogicEntity> entities)
    {
        foreach (LogicEntity e in entities)
        {
            foreach (Passenger p  in e.pusher.passengers)
            {
                LogicEntity passenger = Contexts.sharedInstance.logic.GetEntityWithId(p.id);

                if (passenger.isMovable && !passenger.isStunned && (!passenger.hasWeight || !e.hasWeight || passenger.weight.value >= e.weight.value))
                {
                    FixedVector2 currentMovement = FixedVector2.ZERO;
                    if (passenger.hasMove)
                    {
                        currentMovement = passenger.move.target;
                    }

                    if (p.h)
                    {
                        passenger.ReplaceMove(currentMovement + new FixedVector2(e.velocity.value.x / 50, 0));
                        passenger.ReplaceDirection(passenger.move.target.x.Sign());
                    }

                    if (p.v)
                    {
                        passenger.ReplaceMove(currentMovement + new FixedVector2(0, e.velocity.value.y / 50));
                    }
                }
            }

            e.pusher.passengers.Clear();
        }
    }
    private void CreateBlock(FixedVector2 position, FixedVector2 scale)
    {
//		LogicEntity block = Contexts.sharedInstance.logic.CreateEntity ();
//		block.AddPosition (position);
//		block.AddScale (scale);
//		block.AddCollider (new Determinism.BoxCollider (block.position.value, block.scale.value));
//		block.AddSprite ("Sprites/Crate");
//
//		block.AddLastPosition (FixedVector2.ZERO);
//		block.AddLastVelocity (FixedVector2.ZERO);
//		block.AddVelocity (FixedVector2.ZERO);
//		block.AddAcceleration (FixedVector2.ZERO);
//		block.AddDirection (1);
//
//		block.isMovable = true;
//		block.isPusheable = true;
//		block.isFalling = true;
//		block.isHitable = true;
//		block.AddGravity (FixedMath.Create (30));
//
//		block.AddCurrentMovementX (0, 0, 0);
//		block.AddGroundMovement (0, 0);
//		block.AddStunMovement (0, FixedMath.Create (33, 100));
//
//		block.AddOnRayCastCollision (new CommandInput.RayCastCollisionCommand(block.id.value));
//
//		block.collider.value.mask = Mask.DEFAULT;
//		block.collider.value.tag = Tag.DEFAULT;
//
//		block.collider.value.check =
//			block.collider.value.check.AddFlags (Mask.DEFAULT, Mask.P1, Mask.P2, Mask.P3, Mask.P4, Mask.P5, Mask.P6, Mask.P7, Mask.P8);
    }
Esempio n. 6
0
    protected override void Execute(List <LogicEntity> entities)
    {
        foreach (LogicEntity e in entities)
        {
            if (_context.spawnPoints.list.Length == 0)
            {
                spawnPosition = FixedVector2.ZERO;
            }
            else
            {
                spawnPosition = _context.spawnPoints.list[Random.Range(0, _context.spawnPoints.list.Length)];
            }

            if (!e.isDead)
            {
                e.ReplacePosition(spawnPosition);
                e.ReplaceLastPosition(spawnPosition);

                if (e.hasHat)
                {
                    LogicEntity hat = Contexts.sharedInstance.logic.GetEntityWithId(e.hat.entityID);

                    hat.ReplacePosition(spawnPosition);
                    hat.ReplaceLastPosition(spawnPosition);
                }

                e.isRespawn = false;
            }
        }
    }
Esempio n. 7
0
 public FixedTriangle2D RotateZAxe(Fixed sin, Fixed cos, FixedVector2 pivotPoint)
 {
     a.RotateZAxe(sin, cos, pivotPoint);
     b.RotateZAxe(sin, cos, pivotPoint);
     c.RotateZAxe(sin, cos, pivotPoint);
     return(this);
 }
Esempio n. 8
0
 private void RecalculateDirection()
 {
     if (directionRecalculationRequired)
     {
         this.direction = new FixedVector2(end.X - begin.X, end.Y - begin.X);
     }
 }
Esempio n. 9
0
        private void RecalculateEqualationCoef()
        {
            if (!equationCoefRecalculationRequired)
            {
                return;
            }
            RecalculateDirection();
            if (direction.x.IsZero())
            {
                xFromYEqualationCoef = new FixedVector2(FixedConstants.FIXED_ZERO, begin.X);
                yFromXEqualationCoef = FixedVector2.CreateZeroVector();
                return;
            }
            if (direction.y.IsZero())
            {
                yFromXEqualationCoef = new FixedVector2(FixedConstants.FIXED_ZERO, begin.Y);
                xFromYEqualationCoef = FixedVector2.CreateZeroVector();
                return;
            }
//			Fixed yc = begin.Y / direction.y;
//			Fixed xc = begin.X / direction.x;
            Fixed dx_div_dy = direction.x / direction.y;
            Fixed dy_div_dx = direction.y / direction.x;

            xFromYEqualationCoef = new FixedVector2(dy_div_dx, begin.Y - begin.X * dy_div_dx);
            yFromXEqualationCoef = new FixedVector2(dx_div_dy, begin.X - begin.Y * dx_div_dy);
            return;
        }
Esempio n. 10
0
 public FixedSegment2D RotateZ(Fixed sin, Fixed cos, FixedVector2 pivotPoint)
 {
     begin.RotateZAxe(sin, cos, pivotPoint);
     end.RotateZAxe(sin, cos, pivotPoint);
     ActivateRecalculationFlags();
     return(this);
 }
 public Edge(FixedVector2 _p1, FixedVector2 _p2)
 {
     if (_p1.y == _p2.y)
     {
         if (_p1.x < _p2.x)
         {
             start = _p1;
             end   = _p2;
         }
         else
         {
             start = _p2;
             end   = _p1;
         }
     }
     else
     {
         if (_p1.y < _p2.y)
         {
             start = _p1;
             end   = _p2;
         }
         else
         {
             start = _p2;
             end   = _p1;
         }
     }
 }
Esempio n. 12
0
        public BoxCollider(FixedVector2 position, FixedVector2 halfExtents)
        {
            bounds = new BoundingBox(position, halfExtents);

            edges = new FixedLine2[] {
                new FixedLine2(
                    bounds.min,
                    new FixedVector2(bounds.max.x, bounds.min.y)
                    ),

                new FixedLine2(
                    new FixedVector2(bounds.min.x, bounds.max.y),
                    bounds.max
                    ),

                new FixedLine2(
                    bounds.min,
                    new FixedVector2(bounds.min.x, bounds.max.y)
                    ),

                new FixedLine2(
                    new FixedVector2(bounds.max.x, bounds.min.y),
                    bounds.max
                    )
            };
        }
Esempio n. 13
0
 public FixedRectangle2D Scale(FixedVector2 scale)
 {
     a.Scale(scale);
     b.Scale(scale);
     c.Scale(scale);
     d.Scale(scale);
     return(this);
 }
Esempio n. 14
0
 public FixedRectangle2D Translate(FixedVector2 translation)
 {
     a.Translate(translation);
     b.Translate(translation);
     c.Translate(translation);
     d.Translate(translation);
     return(this);
 }
Esempio n. 15
0
 public FixedVertex2D Scale(FixedVector2 scale, FixedVector2 pivot)
 {
     this.coordinates = coordinates - pivot;
     this.coordinates = new FixedVector2(coordinates.x * scale.x, coordinates.y * scale.y);
     this.coordinates = coordinates + pivot;
     InvokeOwnerChangeMethod();
     return(this);
 }
Esempio n. 16
0
        public FixedVector2 RotateZAxe(Fixed sin, Fixed cos, FixedVector2 pivotPoint)
        {
            Fixed nx = (x - pivotPoint.x) * cos - (y - pivotPoint.y) * sin + pivotPoint.x;
            Fixed ny = (x - pivotPoint.x) * sin + (y - pivotPoint.y) * cos + pivotPoint.y;

            x = nx;
            y = ny;
            return(this);
        }
Esempio n. 17
0
    public static FixedVector2 ContrainTo16Angles(this FixedVector2 normalizedVector)
    {
        return(new FixedVector2(

                   normalizedVector.x.ContrainAxisTo16Angles(),
                   normalizedVector.y.ContrainAxisTo16Angles()

                   ));
    }
Esempio n. 18
0
        public BoundingBox(FixedVector2 _position, FixedVector2 _size)
        {
            this.width  = _size.x;
            this.height = _size.y;

            this.position    = _position;
            this.halfExtents = _size / 2;
            this.size        = _size;
        }
Esempio n. 19
0
        public bool IsCrossingWith(FixedSegment2D s)
        {
            RecalculateDirection();
            FixedVector2 dirToBeginS   = s.begin.Coordinates - this.begin.Coordinates;
            FixedVector2 dirToEndS     = s.end.Coordinates - this.begin.Coordinates;
            Fixed        angleToBeginS = this.direction.x * dirToBeginS.y - this.direction.y * dirToBeginS.x;
            Fixed        angleToEndS   = this.direction.x * dirToEndS.y - this.direction.y * dirToEndS.x;

            return(angleToBeginS.IsPositiveOrZero() != angleToEndS.IsPositiveOrZero());
        }
Esempio n. 20
0
 private void RecalculateDirectionalVectors()
 {
     if (directionalVectorsRecalculationRequired)
     {
         ab = a.GetDirectionTo(b);
         bc = b.GetDirectionTo(c);
         ca = c.GetDirectionTo(a);
         directionalVectorsRecalculationRequired = false;
     }
 }
Esempio n. 21
0
        //TODO: I can use CheckNotTriangleException but i don't know is it neccessary
        private void CheckNotTriangleException(FixedVertex2D a, FixedVertex2D b, FixedVertex2D c)
        {
            FixedVector2 ab = a.GetDirectionTo(b);
            FixedVector2 ac = a.GetDirectionTo(c);

            if ((ab.x * ac.y - ab.y * ac.x).IsZero())
            {
                throw new System.ArgumentException("This set of vertices can't form the triangle");
            }
        }
Esempio n. 22
0
    private void CreateWall(FixedVector2 position, FixedVector2 scale)
    {
//		LogicEntity wall = Contexts.sharedInstance.logic.CreateEntity ();
//		wall.AddPosition (position);
//		wall.AddScale (scale);
//		wall.AddCollider (new Determinism.BoxCollider (wall.position.value, wall.scale.value));
//		wall.AddSprite ("Sprites/1");
//
//		wall.collider.value.mask = Mask.DEFAULT;
//		wall.collider.value.tag = Tag.DEFAULT;
    }
Esempio n. 23
0
    protected override void Execute(List <LogicEntity> entities)
    {
        foreach (LogicEntity e in entities)
        {
            FixedVector2 newPosition = e.position.value + e.move.target;

            e.ReplaceLastPosition(e.position.value);
            e.ReplacePosition(newPosition);

            e.RemoveMove();
        }
    }
Esempio n. 24
0
        public override void Execute()
        {
            LogicEntity e   = Contexts.sharedInstance.logic.GetEntityWithId(entityID);
            LogicEntity hat = Contexts.sharedInstance.logic.GetEntityWithId(e.hat.entityID);

            if (hat == null)
            {
                return;
            }

            if (hat.isAttached)
            {
                hat.isAttached  = false;
                hat.isDangerous = true;
                hat.isFalling   = true;

                FixedVector2 throwdirection = axes.normalized;
                throwdirection = throwdirection.ContrainTo16Angles();
                throwdirection = throwdirection.normalized;

                if (axes == FixedVector2.ZERO)
                {
                    if (e.isWallRiding)
                    {
                        throwdirection = FixedVector2.LEFT * e.direction.value;
                    }
                    else
                    {
                        throwdirection = FixedVector2.RIGHT * e.direction.value;
                    }
                }

                long extraPower = 0;
                if (e.velocity.value.y < 0 && axes.y < 0)
                {
                    extraPower = e.velocity.value.y / 200;
                }

                hat.ReplaceVelocity(new FixedVector2(

                                        (hat.throwMovement.power + extraPower).Mul(throwdirection.x),
                                        (hat.throwMovement.power + extraPower).Mul(throwdirection.y)

                                        ));

                hat.throwMovement.throwPositionY = e.position.value.y;
                hat.ReplaceThrowTimer(FixedMath.Create(3, 10));

                hat.ReplaceLastRotation(0);
                hat.ReplaceRotation(0);
            }
        }
Esempio n. 25
0
        public FixedRectangle2D(Fixed leftX, Fixed bottomY, Fixed width, Fixed height)
        {
            FixedVector2 a = new FixedVector2(leftX, bottomY);
            FixedVector2 b = new FixedVector2(leftX + width, bottomY);
            FixedVector2 c = new FixedVector2(leftX + width, bottomY + height);
            FixedVector2 d = new FixedVector2(leftX, bottomY + height);

            this.a = new FixedVertex2D(a);
            this.b = new FixedVertex2D(b);
            this.c = new FixedVertex2D(c);
            this.d = new FixedVertex2D(d);
            abc    = new FixedTriangle2D(this.a, this.b, this.c);
            acd    = new FixedTriangle2D(this.a, this.c, this.d);
        }
Esempio n. 26
0
    public void GetHatCollider()
    {
        LowLevelHatView hatView = hat.GetComponent <LowLevelHatView> ();

        if (hatView != null)
        {
            Debug.Log(hat.name + " follow data updated.");

            hatColOffsetPosition = hatView.offset;
            hatColScale          = hatView.size;
        }
        else
        {
            Debug.LogError(hat.name + " could not be found.");
        }
    }
Esempio n. 27
0
        public bool IsInTriangle(FixedVector2 p)
        {
            RecalculateDirectionalVectors();
            FixedVector2 ap    = a.GetDirectionTo(p);
            FixedVector2 bp    = b.GetDirectionTo(p);
            FixedVector2 cp    = b.GetDirectionTo(p);
            Fixed        bpXab = FixedVector2.PseudoscalarMultiplication(bp, ab);
            Fixed        cpXbc = FixedVector2.PseudoscalarMultiplication(cp, bc);
            Fixed        apXca = FixedVector2.PseudoscalarMultiplication(ap, ca);

            //this return means that sign of the pseudoscalar multiplications is equal
            return
                (apXca.IsZero() || bpXab.IsZero() || cpXbc.IsZero()
                 ||
                 (apXca.IsNegative() == bpXab.IsNegative() && apXca.IsNegative() == cpXbc.IsNegative()));
        }
Esempio n. 28
0
    public virtual void OnScale(LogicEntity entity, FixedVector2 value)
    {
        if (isSquishy)
        {
            SquashAndStretch s = GetComponent <SquashAndStretch> ();
            if (s == null)
            {
                s = gameObject.AddComponent <SquashAndStretch> ();
            }

            s.ChangeReferenceScale(value.ToVector3());
        }
        else
        {
            transform.localScale = value.ToVector3();
        }
    }
Esempio n. 29
0
    public static bool CheckIntersection(FixedVector2 origin, FixedVector2 length, out FixedVector2 intersection, Determinism.BoxCollider collider)
    {
        intersection = FixedVector2.NAN;
        FixedLine2 l = new FixedLine2(origin, origin + length);

        if (l.isHorizontal)
        {
            for (int i = 2; i < 4; i++)
            {
//				if (FixedMath.Min (l.start.y, l.end.y) > collider.edges[i].start.y) continue;
//				if (FixedMath.Max (l.start.y, l.end.y) < collider.edges[i].start.y) continue;

//				if (FixedLine2.LineIntersection (l, collider.edges[i], out intersection))
//					return true;

                if (FixedLine2.AAOrthogonalLineIntersection(l, collider.edges[i], out intersection))
                {
                    return(true);
                }
            }
        }

        if (l.isVertical)
        {
            for (int i = 0; i < 2; i++)
            {
                //if (edge.isVertical) continue;
//				if (FixedMath.Min (l.start.x, l.end.x) > collider.edges[i].start.x) continue;
//				if (FixedMath.Max (l.start.x, l.end.x) < collider.edges[i].start.x) continue;

//				if (FixedLine2.LineIntersection (l, collider.edges[i], out intersection))
//					return true;

                if (FixedLine2.AAOrthogonalLineIntersection(collider.edges[i], l, out intersection))
                {
                    return(true);
                }
            }
        }

        return(false);

        intersection = FixedVector2.NAN;
        return(FixedVector2.LineBoxIntersection(collider.broadBounds, origin, length, out intersection));
    }
Esempio n. 30
0
    public static bool CheckIntersection(FixedVector2 origin, FixedVector2 length, out FixedVector2 intersection, Determinism.Collider collider)
    {
        if (collider is BoxCollider)
        {
            return(CheckIntersection(origin, length, out intersection, (BoxCollider)collider));
        }
        if (collider is RectilinearCollider)
        {
            return(CheckIntersection(origin, length, out intersection, (RectilinearCollider)collider));
        }
        if (collider is PolygonCollider)
        {
            return(CheckIntersection(origin, length, out intersection, (PolygonCollider)collider));
        }

        intersection = FixedVector2.NAN;
        return(false);
    }