Beispiel #1
0
    void FixedUpdate()
    {
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundedRadius, GroundLayer);
        gravity.Apply(rigidbody2D);

        Vector2 dir = Vector2.zero;

        if (facingRight)
        {
            dir = new Vector2(1, 0);
        }
        else
        {
            dir = new Vector2(-1, 0);
        }

        RaycastHit2D hit  = Physics2D.Raycast(transform.position, dir, LookDistance, 1 << LayerMask.NameToLayer("Player"));
        RaycastHit2D hit2 = Physics2D.Raycast(transform.position, dir, LookDistance, 1 << LayerMask.NameToLayer("WayPoint"));


        if (hit.collider != null && hit.collider.tag.Equals("Player"))
        {
            StopCoroutine("SeePlayer");
            StartCoroutine("SeePlayer");
            player = hit.collider.gameObject.GetComponent <Player>();
        }

        AnimatorStateInfo currentBaseState = animator.GetCurrentAnimatorStateInfo(0);

        if (currentBaseState.nameHash == DeadState)
        {
            DestroySelf();
        }
    }
Beispiel #2
0
        protected void OnLayoutChildren()
        {
            for (int i = 0; i < ChildCount; i++)
            {
                View child = GetChildAt(i);
                if (child.Visibility == ViewStates.Gone)
                {
                    continue;
                }
                var lp      = (ViewLayoutParams)child.LayoutParameters;
                var gravity = lp.Gravity;
                if (gravity == GravityFlags.NoGravity)
                {
                    gravity = GravityFlags.Left | GravityFlags.Top;
                }
                int widthSpace  = child.MeasuredWidth + lp.LeftMargin + lp.RightMargin;
                int heightSpace = child.MeasuredHeight + lp.TopMargin + lp.BottomMargin;
                switch (lp.Layer)
                {
                case ViewLayoutParams.LAYER_CENTER:
                    ContainerRect.Set(CenterRect);
                    ContainerRect.Offset(-LayerScrollX, -LayerScrollY);
                    break;

                case ViewLayoutParams.LAYER_LEFT:
                    ContainerRect.Set(CenterRect.Left - EdgeSize.Left, CenterRect.Top, CenterRect.Left, CenterRect.Bottom);
                    ContainerRect.Offset(-LayerScrollX, -LayerScrollY);
                    break;

                case ViewLayoutParams.LAYER_TOP:
                    ContainerRect.Set(CenterRect.Left, CenterRect.Top - EdgeSize.Top, CenterRect.Right, CenterRect.Top);
                    ContainerRect.Offset(-LayerScrollX, -LayerScrollY);
                    break;

                case ViewLayoutParams.LAYER_RIGHT:
                    ContainerRect.Set(CenterRect.Right, CenterRect.Top, CenterRect.Right + EdgeSize.Right, CenterRect.Bottom);
                    ContainerRect.Offset(-LayerScrollX, -LayerScrollY);
                    break;

                case ViewLayoutParams.LAYER_BOTTOM:
                    ContainerRect.Set(CenterRect.Left, CenterRect.Bottom, CenterRect.Right, CenterRect.Bottom + EdgeSize.Bottom);
                    ContainerRect.Offset(-LayerScrollX, -LayerScrollY);
                    break;

                case ViewLayoutParams.LAYER_NONE:
                default:
                    ContainerRect.Set(CenterRect);
                    break;
                }
                Gravity.Apply(gravity, widthSpace, heightSpace, ContainerRect, OutRect);
                OutRect.Left   += lp.LeftMargin;
                OutRect.Top    += lp.TopMargin;
                OutRect.Right  -= lp.RightMargin;
                OutRect.Bottom -= lp.BottomMargin;
                child.Layout(OutRect.Left, OutRect.Top, OutRect.Right, OutRect.Bottom);
            }
        }
Beispiel #3
0
        public override void FixedProcess()
        {
            base.FixedProcess();

            ApplyMove();
            ApplyY();

            Gravity.Apply();
        }
        protected override void OnDraw(Canvas canvas)
        {
            var d = _dotDrawable;

            if (d != null)
            {
                var count = _dotType == DotTypes.Single ? _dotCount : _activeDot;

                if (count <= 0)
                {
                    return;
                }

                int h = d.IntrinsicHeight;
                int w = Math.Max(0, count * (d.IntrinsicWidth + _dotSpacing) - _dotSpacing);

                int pRight  = PaddingRight;
                int pLeft   = PaddingLeft;
                int pTop    = PaddingTop;
                int pBottom = PaddingBottom;

                _inRect.Set(pLeft, pTop, Width - pRight, Height - pBottom);
                Gravity.Apply(_gravityFlag, w, h, _inRect, _outRect);

                canvas.Save();
                canvas.Translate(_outRect.Left, _outRect.Top);
                for (int i = 0; i < count; i++)
                {
                    if (d.IsStateful)
                    {
                        int[] state = GetDrawableState();
                        if (_dotType == DotTypes.Multiple || i == _activeDot)
                        {
                            state = _extraState;
                        }
                        d.SetCallback(null);
                        d.SetState(state);
                        d.SetCallback(this);
                    }
                    d.Draw(canvas);
                    canvas.Translate(_dotSpacing + d.IntrinsicWidth, 0);
                }
                canvas.Restore();
            }
        }
Beispiel #5
0
        public override void FixedProcess()
        {
            base.FixedProcess();

            Vector3 velocity;

            if (GroundCheck.Slope <= GroundCheck.MaxSlope)
            {
                velocity = Direction.Forward * Speed.Value.y +
                           Direction.Right * Speed.Value.x;
            }
            else
            {
                velocity = rigidbody.velocity;
            }

            velocity   = Vector3.ClampMagnitude(velocity, Speed.MaxValue);
            velocity.y = rigidbody.velocity.y;

            SetVelocity(velocity);

            Gravity.Apply();
        }
Beispiel #6
0
 void FixedUpdate()
 {
     grounded = Physics2D.OverlapCircle(groundCheck.position, groundedRadius, GroundLayer);
     gravity.Apply(rigidbody2D);
 }
Beispiel #7
0
 void FixedUpdate()
 {
     gravity.Apply(rigidbody2D);
 }
Beispiel #8
0
        public virtual void Update(GameTime gameTime)
        {
            // readjust objects according to viewport settings
            int pinnedOffsetX = 0;
            int pinnedOffsetY = 0;

            if (pinnedGameObjectActive &&
                pinnedGameObject != null)
            {
                int originalX = pinnedGameObject.PositionRectangle.X;
                int originalY = pinnedGameObject.PositionRectangle.Y;

                // gravity and update
                Gravity.Apply(gameTime);
                pinnedGameObject.Update(gameTime);

                // check for unpinning
                pinnedGameObjectActive = (XScroll && !((pinnedObjectAbsolutePositionX <= ViewportWidthOneHalf || pinnedObjectAbsolutePositionX + pinnedGameObject.Width >= TotalWidth - 100)));

                // calculate offset
                // put the object back to its original position
                if (XScroll)
                {
                    pinnedOffsetX = (pinnedGameObject.PositionRectangle.X - originalX) * -1;
                    if (!pinnedGameObjectActive)
                    {
                        // adjust offset
                    }

                    pinnedGameObject.X            += pinnedOffsetX;
                    pinnedObjectAbsolutePositionX -= pinnedOffsetX;
                }
                if (YScroll)
                {
                    pinnedOffsetY = (pinnedGameObject.PositionRectangle.Y - originalY) * -1;
                    if (!pinnedGameObjectActive)
                    {
                        // adjust offset
                    }

                    pinnedGameObject.Y            += pinnedOffsetY;
                    pinnedObjectAbsolutePositionY -= pinnedOffsetY;
                }
            }
            else
            {
                // gravity
                Gravity.Apply(gameTime);

                // check for pinning
                if (pinnedGameObject != null)
                {
                    // check if we need to pin or unpin the player
                    pinnedGameObjectActive = (XScroll && (pinnedGameObject.PositionRectangle.X > 100 && pinnedGameObject.PositionRectangle.X + pinnedGameObject.Width < 200));
                    if (pinnedGameObjectActive)
                    {
                        if (pinnedObjectAbsolutePositionX == 0)
                        {
                            pinnedObjectAbsolutePositionX = pinnedGameObject.PositionRectangle.X;
                        }
                        if (pinnedObjectAbsolutePositionY == 0)
                        {
                            pinnedObjectAbsolutePositionY = pinnedGameObject.PositionRectangle.Y;
                        }
                    }
                }
            }

            // move objects / user input
            for (int i = activeObjects.Count - 1; i >= 0; i--)
            {
                if (pinnedGameObject == null || !pinnedGameObjectActive)
                {
                    activeObjects[i].Update(gameTime);
                }
                else if (pinnedGameObject != activeObjects[i])
                {
                    // if an object is pinned, don't process it
                    activeObjects[i].Update(gameTime);

                    if (XScroll)
                    {
                        activeObjects[i].X += pinnedOffsetX;
                    }
                    if (YScroll)
                    {
                        activeObjects[i].Y += pinnedOffsetY;
                    }
                }

                // GameArea Edge processing
            }

            // handle collisions
            Collision.HandleCollisions();

            // background processing

            // register next update
            EventClock.AddGameEvent(new EventClock.GameEvent(Update), NextFrameTimeSpan);
        }