Ejemplo n.º 1
0
        public void UpdateHoofBeats()
        {
            if ((int)crossingThingType != (int)CrossingThingType.kCrossingThing_Sheep)
            {
                return;
            }

            const float kDistanceForAllHoofs = 200.0f;

            float[] hoofDistanceRatio = new float[4]
            {
                0.1f, 0.2f, 0.6f, 0.7f
            };
            distanceBetweenHoofSounds += Utilities.GetABS(xSpeed);
            if (distanceBetweenHoofSounds >= kDistanceForAllHoofs)
            {
                whichHoof = 0;
                distanceBetweenHoofSounds -= kDistanceForAllHoofs;
            }

            if (whichHoof < 4)
            {
                float ratio = distanceBetweenHoofSounds / kDistanceForAllHoofs;
                if (ratio >= hoofDistanceRatio[whichHoof])
                {
                    this.PlayHoofSound();
                    whichHoof++;
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateDustCloud()
        {
            if (Globals.g_world.artLevel == 0)
            {
                return;
            }

            const float kDistBetweenClouds = 115.0f;

            distSinceCloud += Utilities.GetABS(xSpeed);
            if (distSinceCloud >= kDistBetweenClouds)
            {
                distSinceCloud -= kDistBetweenClouds;
                ParticleSystemRoss.EffectInfo info = new ParticleSystemRoss.EffectInfo();
                info.type          = EffectType.kEffect_DustCloudTrailWithoutPlayer;
                info.startPosition = position;
                CGPoint normalDirection = Utilities.CGPointMake(0.0f, 1.0f);
                info.startPosition.y -= (normalDirection.y * 15.0f);
                info.startPosition.x -= (normalDirection.x * 15.0f);
                info.velocity         = Utilities.CGPointMake(0.0f, xSpeed * 0.5f);
                if ((int)crossingThingType == (int)CrossingThingType.kCrossingThing_Sheep)
                {
                    info.velocity = Utilities.CGPointMake(0.0f, 1.5f);
                }

                info.player = null;
                (ParticleSystemRoss.Instance()).AddParticleEffect(info);
            }
        }
Ejemplo n.º 3
0
        public static float GetAngleFromXYNewP1(float inX, float inY)
        {
            float angle    = Utilities.GetABS(inX) / Utilities.GetABS(inY);
            float outAngle = (float)Math.Atan(angle);

            if (inX > 0.0f)
            {
                if (inY > 0.0f)
                {
                    outAngle = Constants.PI_ - outAngle;
                }
            }
            else
            {
                if (inY > 0.0f)
                {
                    outAngle = Constants.PI_ + outAngle;
                }
                else
                {
                    outAngle = (2.0f * Constants.PI_) - outAngle;
                }
            }

            return(outAngle);
        }
Ejemplo n.º 4
0
        static float GetFastestRotationDirectionP1(float prevAngle, float angle)
        {
            float clockWiseDist;
            float antiClockWiseDist;

            if (angle < prevAngle)
            {
                clockWiseDist     = Utilities.GetABS((prevAngle - (angle + (2.0f * Constants.PI_))));
                antiClockWiseDist = Utilities.GetABS((prevAngle - angle));
            }
            else
            {
                antiClockWiseDist = Utilities.GetABS(((prevAngle + (2.0f * Constants.PI_)) - angle));
                clockWiseDist     = Utilities.GetABS((prevAngle - angle));
            }

            if (clockWiseDist < antiClockWiseDist)
            {
                return(1.0f);

                ;
            }

            return(-1.0f);
        }
Ejemplo n.º 5
0
        public static float GetAngleDiffP1(float inVal1, float inVal2)
        {
            if (inVal1 < 0.0f)
            {
                inVal1 += Constants.TWO_PI;
            }

            if (inVal1 > Constants.TWO_PI)
            {
                inVal1 -= Constants.TWO_PI;
            }

            if (inVal2 < 0.0f)
            {
                inVal2 += Constants.TWO_PI;
            }

            if (inVal2 > Constants.TWO_PI)
            {
                inVal2 -= Constants.TWO_PI;
            }

            float diff1 = Utilities.GetABS((inVal1 - inVal2));

            inVal1 -= Constants.PI_;
            if (inVal1 < 0.0f)
            {
                inVal1 += Constants.TWO_PI;
            }

            float diff2 = Utilities.GetABS((inVal1 - inVal2));

            return(GetMinP1(diff1, diff2));
        }
Ejemplo n.º 6
0
        public void UpdateSpeed()
        {
            if (boostTimer > 0.0f)
            {
                boostTimer -= Constants.kFrameRate;
                if (boostTimer <= 0.0f)
                {
                    boostPower = 0.0f;
                }
            }

            this.UpdateCurrentElasticity();
            currentSpeed  = baseSpeed + elasticity + myPig.GetWhiteStarExtraSpeed() + boostPower;
            currentSpeed *= myPig.GetSpeedMultiplier();
            const float kMinTurnSizeForSpeedReduction  = 0.02f;
            const float kMaxTurnSizeForSpeedReduction  = 0.08f;
            const float kMaxSpeedReductionForCornering = 0.9f;
            float       turnSize = Utilities.GetABS(myPig.moveAngle - myPig.prevMoveAngle);

            if (turnSize > kMinTurnSizeForSpeedReduction)
            {
                const float kMinCurrentSpeedForSpeedReduction = 8.0f;
                const float kMaxCurrentSpeedForSpeedReduction = 16.0f;
                float       currentSpeedMultiplier            = Utilities.GetRatioP1P2(myPig.GetDistanceLastFrame(), kMinCurrentSpeedForSpeedReduction,
                                                                                       kMaxCurrentSpeedForSpeedReduction);
                float reductionMultiplier = Utilities.GetRatioP1P2(turnSize, kMinTurnSizeForSpeedReduction, kMaxTurnSizeForSpeedReduction);
                currentSpeed -= (currentSpeed * kMaxSpeedReductionForCornering * reductionMultiplier * currentSpeedMultiplier);
            }
        }
Ejemplo n.º 7
0
        public int GetTargetPointAtBackwards(float inY)
        {
            if (targetPoint < 10)
            {
                return(-1);
            }

            int yDistMin      = 10000;
            int closestTarget = -1;

            for (int i = 0; i < 50; i++)
            {
                int yDist = (int)Utilities.GetABS((float)(racingLine.GetPoint(targetPoint - i).y - inY));
                if ((yDist < yDistMin) || (i == 0))
                {
                    yDistMin      = yDist;
                    closestTarget = targetPoint - i;
                }
                else
                {
                    return(closestTarget);
                }
            }

            return(closestTarget);
        }
Ejemplo n.º 8
0
        public float GetValue()
        {
            switch ((InterpolationRange)range)
            {
            case InterpolationRange.kInterp_ZeroToOne:
                return(value);

            case InterpolationRange.kInterp_OneToZero:
                return(1 - value);

            case InterpolationRange.kInterp_ZeroToOneToZero:
                return(1 - (Utilities.GetABS((2 * value - 1))));
            }

            Globals.Assert(false);
            return(-1);
        }
Ejemplo n.º 9
0
        public void UpdateMoveAnim()
        {
            if (numAnims <= 1)
            {
                return;
            }

            animateRoll += Utilities.GetABS(xSpeed);
            if (animateRoll > kRollAnimSpeed)
            {
                animateIndex += 1;
                if (animateIndex >= numAnims)
                {
                    animateIndex = 0;
                }

                mapObject.SetSubTextureId(animMinSubTexture + animateIndex);
                animateRoll -= kRollAnimSpeed;
            }
        }
Ejemplo n.º 10
0
        public void PlayHoofSound()
        {
            float distanceToPlayer = Utilities.GetABS(((Globals.g_world.game).player).position.y - position.y);
            float volume           = 0.3f + (0.3f * (1.0f - Utilities.GetRatioP1P2(distanceToPlayer, 0.0f, 300.0f)));
            bool  playIt           = true;

            if (((Globals.g_world.game).gameState == GameState.e_ShowResultsWin) || ((Globals.g_world.game).gameState == GameState.e_ShowResultsLoseToPiggy
                                                                                     ))
            {
                if ((Globals.g_world.game).stateTimer > 2.4f)
                {
                    playIt = false;
                }
            }

            if (playIt)
            {
                Globals.g_world.PlayFinchSoundWithPositionP1P2(hoofSoundId + whichHoof, volume, position);
            }
        }
Ejemplo n.º 11
0
        public void UpdateSplashingInWater()
        {
            timer += player.GetDistanceLastFrame() + 1;
            const float kTimeBetweenSplashes = 20;

            if (timer >= kTimeBetweenSplashes)
            {
                ParticleList inList;
                if (player.positionZ < -5.0f)
                {
                    inList = ParticleList.t_DownInRiver;
                }
                else
                {
                    inList = ParticleList.t_BeforePlayer;
                }

                Particle particle = (ParticleSystemRoss.Instance()).GetNextFreeParticleP1(inList, "scal_rip");
                if (particle != null)
                {
                    CGPoint pos   = player.position;
                    CGPoint speed = player.GetActualSpeed();
                    if ((Utilities.GetABS(speed.x) < 0.01f) && (Utilities.GetABS(speed.y) < 0.01f))
                    {
                        speed = Utilities.CGPointMake(0.0f, 0.0f);
                    }
                    else
                    {
                        speed = Utilities.Normalise(speed);
                    }

                    pos.x = pos.x + (speed.x * 20);
                    pos.y = pos.y + (speed.y * 20);
                    particle.Launch_ScalingRipple(pos);
                    particle.SetAtlasAndSubTextureId(Globals.g_world.GetAtlas(AtlasType.kAtlas_ParticlesScene), 9);
                }

                timer -= kTimeBetweenSplashes;
            }
        }
Ejemplo n.º 12
0
        public void Update(Player inPlayer)
        {
            CGPoint     playerPosition  = inPlayer.position;
            const float kSqrHitDistance = 33 * 33;
            float       heightDiff      = Utilities.GetABS(inPlayer.positionZ - groundLevel);

            if (heightDiff > 20.0f)
            {
                return;
            }

            for (int y = 0; y < (int)Enum.kNumBoostPoints; y++)
            {
                if (pointHit [inPlayer.playerId, y])
                {
                    continue;
                }

                float distSqr = Utilities.GetSqrDistanceP1(playerPosition, boostPointPosition [y]);
                if (distSqr <= kSqrHitDistance)
                {
                    pointHit [inPlayer.playerId, y] = true;
                    if (inPlayer == (Globals.g_world.game).player)
                    {
                        ParticleSystemRoss.EffectInfo info = new ParticleSystemRoss.EffectInfo();
                        info.type          = EffectType.kEffect_BoostGlow;
                        info.startPosition = boostPointPosition[y];
                        info.velocity.x    = (float)y;
                        (ParticleSystemRoss.Instance()).AddParticleEffect(info);
                    }

                    CGPoint boostDir = Utilities.CGPointMake(0, 1);
                    inPlayer.AddBoost(boostDir);

                    #if NOT_FINAL_VERSION
                    #endif
                }
            }
        }
Ejemplo n.º 13
0
        public static float GetAngleDifferenceP1(float angle, float prevAngle)
        {
            float clockWiseDist;
            float antiClockWiseDist;

            if (angle < prevAngle)
            {
                clockWiseDist     = Utilities.GetABS((prevAngle - (angle + (2.0f * Constants.PI_))));
                antiClockWiseDist = Utilities.GetABS((prevAngle - angle));
            }
            else
            {
                antiClockWiseDist = Utilities.GetABS(((prevAngle + (2.0f * Constants.PI_)) - angle));
                clockWiseDist     = Utilities.GetABS((prevAngle - angle));
            }

            if (clockWiseDist < antiClockWiseDist)
            {
                return(clockWiseDist);
            }

            return(-antiClockWiseDist);
        }
Ejemplo n.º 14
0
        int GetTargetPointBackP1P2(int fromTargetPoint, float inY, int iteration)
        {
            int yDistMin         = 100000;
            int closestTarget    = -1;
            int whichTargetPoint = fromTargetPoint;

            for (int i = 0; i < 80; i++)
            {
                int yDist = (int)Utilities.GetABS((float)racingLine.GetPoint(whichTargetPoint).y - inY);
                if (yDist < yDistMin)
                {
                    yDistMin      = yDist;
                    closestTarget = whichTargetPoint;
                }
                else
                {
                    return(closestTarget);
                }

                whichTargetPoint -= iteration;
            }

            return(closestTarget);
        }
Ejemplo n.º 15
0
        public void UpdateActive()
        {
            if (knockedOver)
            {
                const float kHitSlowDown = 0.05f;
                velocity.y -= kHitSlowDown;
                if (velocity.y > 0)
                {
                    position.y += velocity.y;
                }
            }
            else
            {
                if (((int)movement != (int)CowMovement.kCowStandingStillRight) && ((int)movement != (int)CowMovement.kCowStandingStillLeft))
                {
                    this.UpdateWalkWobble();
                    position.x -= velocity.x;
                    position.y += velocity.y;
                    nowAnim.UpdateWithDistance(Utilities.GetABS(velocity.x));
                }
            }

            this.UpdateBlinking();
            ((Globals.g_world.game).GetNoGoZone(noGoZoneId)).SetMapPosition(Utilities.CGPointMake(position.x, position.y - 5.0f));
            screenPosition = Utilities.GetScreenPositionP1(position, (Globals.g_world.GetGame()).GetScrollPosition());
            if (screenPosition.y < -40)
            {
                this.SetState(CowState.e_Inactive);
            }

            if (stillHasMapObject)
            {
                mapObject.SetTexture(nowAnim.GetTexture());
                mapObject.SetPosition(position);
            }
        }
Ejemplo n.º 16
0
        bool CheckStartSkid()
        {
            if (inFlock)
            {
                return(false);
            }

            if (timeTilCanSkidAgain > 0.0f)
            {
                timeTilCanSkidAgain -= Constants.kFrameRate;
                return(false);
            }

            const float kExtrapFrames        = 50.0f;
            CGPoint     nowSpeed             = myPig.GetActualSpeed();
            CGPoint     extrapolatedPosition = Utilities.CGPointMake(myPig.position.x + (nowSpeed.x * kExtrapFrames), myPig.position.y + (nowSpeed.y * kExtrapFrames));
            float       yDistInFront         = extrapolatedPosition.y - myPig.position.y;

            if (yDistInFront < 700.0f)
            {
                return(false);
            }

            int whichTargetPoint = this.GetTargetPointAtBackwards(myPig.position.y);

            if (whichTargetPoint == -1)
            {
                return(false);
            }

            CGPoint     nowTargetPos        = Utilities.CGPointMake((float)racingLine.GetPoint(whichTargetPoint).x, (float)racingLine.GetPoint(whichTargetPoint).y);
            float       distSqr             = Utilities.GetSqrDistanceP1(myPig.position, nowTargetPos);
            const float kMinSqrDistForStart = 700.0f;

            if (distSqr > kMinSqrDistForStart)
            {
                return(false);
            }

            CGPoint targetDirection = Utilities.CGPointMake((float)racingLine.GetPoint(whichTargetPoint + 1).x - nowTargetPos.x, (float)racingLine.GetPoint(
                                                                whichTargetPoint + 1).y - nowTargetPos.y);
            float targetAngle    = Utilities.GetAngleFromXYNewP1(targetDirection.x, targetDirection.y);
            float playerAngleNow = myPig.moveAngle;

            if (Utilities.GetABS(targetAngle - playerAngleNow) > 0.18f)
            {
                return(false);
            }

            whichTargetPoint = this.GetTargetPointAt(extrapolatedPosition.y);
            if (whichTargetPoint == -1)
            {
                return(false);
            }

            CGPoint diff = Utilities.CGPointMake((float)racingLine.GetPoint(whichTargetPoint).x - extrapolatedPosition.x, (float)racingLine.GetPoint(
                                                     whichTargetPoint).y - extrapolatedPosition.y);

            skidDirection = Utilities.CGPointMake(nowSpeed.x, nowSpeed.y);
            float numAccelerationAdditions = (kExtrapFrames * (kExtrapFrames + 1.0f)) * 0.5f;

            skidAcceleration = Utilities.CGPointMake(diff.x / numAccelerationAdditions, diff.y / numAccelerationAdditions);
            float   xAtEnd      = nowSpeed.x + (skidAcceleration.x * kExtrapFrames);
            float   yAtEnd      = nowSpeed.y + (skidAcceleration.y * kExtrapFrames);
            float   angleAtEnd  = Utilities.GetAngleFromXYNewP1(xAtEnd, yAtEnd);
            CGPoint endPointDir = Utilities.CGPointMake(((float)racingLine.GetPoint(whichTargetPoint).x - (float)racingLine.GetPoint(whichTargetPoint - 1).x), ((
                                                                                                                                                                    float)racingLine.GetPoint(whichTargetPoint).y - (float)racingLine.GetPoint(whichTargetPoint - 1).y));
            float angleAtEndPoint = Utilities.GetAngleFromXYNewP1(endPointDir.x, endPointDir.y);

            if (Utilities.GetABS(angleAtEnd - angleAtEndPoint) > 0.18f)
            {
                return(false);
            }

            float yDisplay;

            if (skidAcceleration.y >= 0.0f)
            {
                yDisplay = skidAcceleration.y;
            }
            else
            {
                yDisplay = 0.0f;
            }

            skidTarget = Utilities.CGPointMake((float)racingLine.GetPoint(whichTargetPoint).x, (float)racingLine.GetPoint(whichTargetPoint).y);
            if (!this.IsThisSkidAGoodIdea())
            {
                return(false);
            }

            skidDisplayAngle = Utilities.CGPointMake(skidAcceleration.x, yDisplay);
            skidding         = true;
            skidFrames       = (int)kExtrapFrames;
            return(true);
        }
Ejemplo n.º 17
0
        public void StartEffect_SplashRingP1(ParticleSystemRoss.EffectInfo info, bool isMud)
        {
            const int kNumSplashesInRing = 10;

            Particle.ParticleInfo pInfo = new Particle.ParticleInfo();
            pInfo.type                  = ParticleType.kParticle_SingleSplash;
            pInfo.hasGravity            = false;
            pInfo.isAnimated            = true;
            pInfo.numAnimFrames         = 4;
            pInfo.texture[0]            = (ParticleSystemRoss.Instance()).GetTexture(ParticleTextureType.kParticleTexture_Splash1);
            pInfo.texture[1]            = (ParticleSystemRoss.Instance()).GetTexture(ParticleTextureType.kParticleTexture_Splash2);
            pInfo.texture[2]            = (ParticleSystemRoss.Instance()).GetTexture(ParticleTextureType.kParticleTexture_Splash3);
            pInfo.texture[3]            = (ParticleSystemRoss.Instance()).GetTexture(ParticleTextureType.kParticleTexture_Splash4);
            pInfo.animatedSubtexture[0] = 5;
            pInfo.animatedSubtexture[1] = 6;
            pInfo.animatedSubtexture[2] = 7;
            pInfo.animatedSubtexture[3] = 8;
            if (isMud)
            {
                pInfo.animatedSubtexture[0] = 18;
                pInfo.animatedSubtexture[1] = 19;
                pInfo.animatedSubtexture[2] = 20;
                pInfo.animatedSubtexture[3] = 21;
            }

            pInfo.timeBetweenAnimFrames[0] = 0.1f;
            pInfo.timeBetweenAnimFrames[1] = 0.1f;
            pInfo.timeBetweenAnimFrames[2] = 0.1f;
            pInfo.timeBetweenAnimFrames[3] = 0.1f;
            pInfo.alphaStart = 1;
            int   randSplash     = 1 + Utilities.GetRand(8);
            float circleSize     = Constants.PI_ + Constants.HALF_PI;
            float perThing       = circleSize / ((float)kNumSplashesInRing);
            float outSpeed       = 3.2f;
            float playerSpeedInf = 0.8f;
            float dirMultip      = 1.0f;

            if (isMud)
            {
                outSpeed       = 2.6f;
                playerSpeedInf = 0.9f;
                dirMultip      = 0.8f;
            }

            pInfo.scaleStart = 1;
            for (int i = 0; i < kNumSplashesInRing; i++)
            {
                if (isMud)
                {
                    if (i != randSplash)
                    {
                        continue;
                    }
                }

                float directionMulti = Utilities.GetABS(4.5f - ((float)i));
                float angle          = (info.rotation - Constants.HALF_PI) - (circleSize / 2) + (perThing * ((float)i));
                pInfo.rotationStart = -angle + (Constants.HALF_PI);
                pInfo.velocity      = Utilities.GetVectorFromAngleP1(angle, outSpeed);
                pInfo.velocity.x   += (playerSpeedInf * info.velocity.x);
                pInfo.velocity.y   += (playerSpeedInf * info.velocity.y);
                pInfo.startPosition = Utilities.CGPointMake(info.startPosition.x + (pInfo.velocity.x * (directionMulti * dirMultip)), info.startPosition.y + (pInfo.
                                                                                                                                                              velocity.y * (directionMulti * dirMultip)));
                Particle particle = (ParticleSystemRoss.Instance()).GetNextFreeParticleP1(info.inList, "splashring");
                if (particle != null)
                {
                    particle.Launch_AnimatedParticle(pInfo);
                    particle.SetAtlasAndSubTextureId(Globals.g_world.GetAtlas(AtlasType.kAtlas_ParticlesScene), pInfo.animatedSubtexture[0]);
                    particle.SetRotationScale(Globals.g_world.GetRotationScaleForShorts(22.6274f));
                    if (Globals.deviceIPad)
                    {
                        float rotScale = (Globals.g_world.GetAtlas(AtlasType.kAtlas_ParticlesScene)).GetSubTextureRotationScale(particle.subTextureId);
                        particle.SetRotationScale(rotScale);
                    }
                }
            }

            state = EffectState.e_Inactive;
        }
Ejemplo n.º 18
0
        public bool Update()
        {
            if (!active)
            {
                return(false);
            }

            if (startTimer < waitToBegin)
            {
                startTimer += Constants.kFrameRate;
            }

            switch (type)
            {
            case InterpolationType.kInterp_Accelerate:
                value    += velocity;
                velocity += acceleration;
                break;

            case InterpolationType.kInterp_Lag:
                value = value + ((1 - value) * lag);
                break;

            case InterpolationType.kInterp_Linear:
                break;

            case InterpolationType.kInterp_Cos:
                timer += Constants.kFrameRate;
                value  = Utilities.GetCosInterpolationHalfP1P2(timer, 0, time);
                break;

            case InterpolationType.kInterp_Boing:
                if (phase == (int)Enum.kInterp_Phase1)
                {
                    value += velocity;
                    if (value >= 1)
                    {
                        acceleration = (-velocity * 0.1f);
                        phase        = (int)Enum.kInterp_Phase2;
                    }
                }
                else
                {
                    velocity += acceleration;
                    value    += velocity;
                    velocity *= 0.95f;
                    if (((acceleration > 0) && (value >= 1)) || ((acceleration < 0) && (value <= 1)))
                    {
                        acceleration = (-acceleration * 1.05f);
                        if (Utilities.GetABS(acceleration) >= Utilities.GetABS((velocity)))
                        {
                            value  = 1;
                            active = false;
                            return(true);
                        }
                    }
                }

                break;
            }

            switch (endParameter)
            {
            case InterpolationEndParameter.kInterpEnd_Time:
                if (timer >= time)
                {
                    active = false;
                    return(true);
                }

                break;

            case InterpolationEndParameter.kInterpEnd_Value:
                if (value >= endValue)
                {
                    value  = endValue;
                    active = false;
                    return(true);
                }

                break;

            default:
                break;
            }

            return(false);
        }