Exemple #1
0
        public override void Update()
        {
            //check if moving

            /*
             * if (Math.Abs(v.speed) > 0)
             *  isMoving = true;
             * else
             *  isMoving = false;
             */

            if (GetStrengthOfMotion() == 0)
            {
                isMoving = false;
            }
            else
            {
                isMoving = true;
            }

            if (isMoving)
            {
                movingTime++;
            }

            if (movingTime > maxMovingTime)
            {
                v          = new Velocity(0, 0);
                movingTime = 0;
            }

            if (timeSinceUserControl < maxTimeSinceUserControl)
            {
                timeSinceUserControl++;
            }

            //check if frog is selected
            wasSelected = isSelected;
            if (
                (InputManager.MouseHeld() &&
                 GameMath.GetDistanceBetweenPoints(
                     (x + 4) * Renderer.cam.scale,
                     (y + 4) * Renderer.cam.scale,
                     InputManager.mouseX,
                     InputManager.mouseY
                     ) < 48
                ) ||
                InputManager.MouseHeld() && isSquishing && wasSelected)
            {
                isSelected           = true;
                timeSinceUserControl = 0;
            }
            else if (InputManager.MouseJustReleased())
            {
                isSelected = false;
            }

            if (isInGroup)
            {
                isSelected = true;
            }

            if (timeSinceUserControl >= maxTimeSinceUserControl)
            {
                automatic = true;
            }
            else
            {
                automatic = false;
            }

            //check if should be preparing jump
            if (!isMoving)
            {
                /* DISABLE AUTOMATIC CONTROL
                 * if (!automatic)
                 *  UserControl();
                 * else
                 *  AutoControl();
                 */
                UserControl();
            }

            //handle tounge
            if (!tounge.isOut)
            {
                //update position
                tounge.x = x;
                tounge.y = y;

                //search for something to grab
                foreach (Entity e in EntityManager.GetEntities())
                {
                    if (e.GetType() == typeof(Pickup) && GameMath.GetDistanceBetweenPoints(x, y, e.x, e.y) < toungeRange)
                    {
                        Pickup p = (Pickup)e;

                        tounge.SetTarget(new Vector2(p.x, p.y), p);
                        tounge.isOut = true;
                    }
                }
            }

            //update tounge if out
            if (tounge.isOut)
            {
                tounge.Update();
            }

            CheckCollisions();

            //update sprite based on state
            UpdateSprite();

            base.Update();
        }
Exemple #2
0
        public override void Update()
        {
            if (GetStrengthOfMotion() == 0)
            {
                isMoving = false;
            }
            else
            {
                isMoving = true;
            }

            if (isMoving)
            {
                movingTime++;
            }

            if (movingTime > maxMovingTime)
            {
                v          = new Velocity(0, 0);
                movingTime = 0;
            }

            //execute jump
            if (!isMoving)
            {
                isSquishing = true;

                if (squishCooldown > 0)
                {
                    squishCooldown--;
                }

                if (squishCooldown <= 0) //if cooldown just ran out
                {
                    isMoving       = true;
                    isSquishing    = false;
                    squishCooldown = maxSquishCooldown;

                    Entity nearestGoal = GetNearestGoal();

                    if (nearestGoal == null)
                    {
                        return;
                    }

                    //calculate aim angle
                    aimAngle = GameMath.GetAngleBetweenPoints(x, y, nearestGoal.x, nearestGoal.y);

                    //move towards target
                    AddForce(jumpForce, aimAngle);
                }
            }

            //handle tounge
            if (!tounge.isOut)
            {
                //update position
                tounge.x = x;
                tounge.y = y;

                //search for something to grab
                foreach (Entity e in EntityManager.GetEntities())
                {
                    if (e.GetType() == typeof(Pickup) && GameMath.GetDistanceBetweenPoints(x, y, e.x, e.y) < toungeRange)
                    {
                        Pickup p = (Pickup)e;

                        tounge.SetTarget(new Vector2(p.x, p.y), p);
                        tounge.isOut = true;
                    }
                }
            }

            //update tounge if out
            if (tounge.isOut)
            {
                tounge.Update();
            }

            UpdateSprite();

            base.Update();
        }