예제 #1
0
        void UserControl()
        {
            if (isSelected && !isInGroup)
            {
                isSquishing = true;

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

                //calculate aim angle
                float angleToMouse = GameMath.GetAngleBetweenPoints(x * Renderer.cam.scale, y * Renderer.cam.scale, InputManager.mouseX, InputManager.mouseY);
                aimAngle = angleToMouse + (float)Math.PI;

                //calculate mouse pull
                pullDistance = GameMath.GetDistanceBetweenPoints((x + 4) * Renderer.cam.scale, (y + 4) * Renderer.cam.scale, InputManager.mouseX, InputManager.mouseY);

                pullPercentage = (float)(pullDistance / maxPullDistance);
                if (pullPercentage > 1)
                {
                    pullPercentage = 1;
                }
                if (pullPercentage < 0.3f)
                {
                    pullPercentage = 0.5f;
                }

                //calculate target positioning
                float targetDist = maxJumpDistance * pullPercentage;

                currentJumpForce = jumpForce * pullPercentage;
            }
            else
            {
                if (wasSelected == isSelected) //only reset if the mouse wasn't JUST released
                {
                    isSquishing    = false;
                    squishCooldown = maxSquishCooldown;
                }
            }

            //jump is ready! (mouse has been released, no longer squishing
            if (isSquishing && wasSelected && !isSelected)
            {
                isSquishing    = false;
                squishCooldown = maxSquishCooldown;

                //Jump(aimAngle);

                AddForce(currentJumpForce, aimAngle);

                //Game.debugOutput = currentJumpForce.ToString();

                currentJumpForce = jumpForce; //reset jump force

                //Jump(CalculateJumpAngle());
            }
        }
예제 #2
0
        public void MoveToTarget()
        {
            Vector2 lPos = GameMath.LerpVectors(new Vector2(x, y), target, 0.2f);

            x = lPos.X;
            y = lPos.Y;

            float distToTarget = GameMath.GetDistanceBetweenPoints(x, y, target.X, target.Y);

            //stop if in close proximity
            if (distToTarget < 3)
            {
                if (!returningToParent)
                {
                    //destroy target
                    if (targetEntity != null)
                    {
                        targetEntity.forRemoval = true;
                    }
                    //report back to frog
                    if (parent.GetType() == typeof(Frog))
                    {
                        ((Frog)parent).ToungeGrabbed(targetEntity);
                    }
                    if (parent.GetType() == typeof(BadFrog))
                    {
                        ((BadFrog)parent).ToungeGrabbed(targetEntity);
                    }

                    //return to parent
                    targetEntity      = null;
                    target            = new Vector2(parent.x, parent.y);
                    returningToParent = true;
                }
                else
                {
                    isOut             = false;
                    returningToParent = false;
                }
            }
        }
예제 #3
0
        Entity GetNearestGoal()
        {
            List <Entity> entityList  = EntityManager.GetEntities();
            float         nearestDist = 99999;
            Entity        nearestGoal = null;

            foreach (Entity e in entityList)
            {
                if (e.GetType() == typeof(BadFrog) || e.GetType() == typeof(Pickup))
                {
                    float distToGoal = GameMath.GetDistanceBetweenPoints(x, y, e.x, e.y);
                    if (distToGoal < nearestDist)
                    {
                        nearestDist = distToGoal;
                        nearestGoal = e;
                    }
                }
            }

            return(nearestGoal);
        }
예제 #4
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();
        }
예제 #5
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();
        }