Example #1
0
        public void UpdateWordRotation()
        {
            if (orientationButton != null)
            {
                rotationWholeWord = orientationButton.currentRotation;
            }

            if (rotationWholeWord != 0.0f)
            {
                //Globals.g_main.SetGLMatrixMode(GL_MODELVIEW);
                //glLoadIdentity();
                //glScalef(Constants.kScaleForShorts, Constants.kScaleForShorts, 0.0f);
                //glPushMatrix();
                float roatation = rotationWholeWord;
                float yThing    = Globals.g_world.screenHeight;
                float x         = position.x;
                float y         = position.y;
                if (Globals.deviceIPad)
                {
                    x *= 2.0f;
                    x += 64.0f;
                    y *= 2.0f;
                }

                CGPoint tempWordPos     = Utilities.CGPointMake(x, y);
                CGPoint vectorToBasePos = Utilities.CGPointMake(tempWordPos.x, yThing - tempWordPos.y);
                float   baseAngle       = Constants.PI_ - Utilities.GetAngleFromXYP1(vectorToBasePos.x, vectorToBasePos.y);
                CGPoint positionWas     = tempWordPos;
                float   distance        = Utilities.GetDistanceP1(Utilities.CGPointMake(0, yThing), positionWas);
                CGPoint newPosVec       = Utilities.GetVectorFromAngle(baseAngle + roatation);
                newPosVec.x *= distance;
                newPosVec.y *= distance;
                CGPoint positionNow = newPosVec;
                positionNow.y = -positionNow.y;
                CGPoint diff;
                diff.x = positionNow.x - positionWas.x;
                diff.y = positionNow.y - (yThing - positionWas.y);
                //glRotatef((roatation) * (360.0 / (Constants.TWO_PI)), 0, 0, 1);
                //glTranslatef(diff.x * Constants.kScreenMultiplierForShorts, diff.y * Constants.kScreenMultiplierForShorts, 0.0f);
                CGPoint orientationButtonPos = Utilities.CGPointMake((orientationButton.myButton).position.x, (orientationButton.myButton).position.y);
                if (Globals.deviceIPad)
                {
                    orientationButtonPos.x *= 2.0f;
                    orientationButtonPos.x += 64.0f;
                    orientationButtonPos.y *= 2.0f;
                }

                CGPoint startOffset  = Utilities.CGPointMake(tempWordPos.x - orientationButtonPos.x, tempWordPos.y - orientationButtonPos.y);
                float   startAngle   = Utilities.GetAngleFromXYNewP1(startOffset.x, startOffset.y);
                float   offsetLength = Utilities.GetDistanceP1(Utilities.CGPointMake(0, 0), startOffset);
                CGPoint normalAngle  = Utilities.GetVectorFromAngleNew(startAngle - roatation);
                normalAngle.x *= offsetLength;
                normalAngle.y *= offsetLength;
                CGPoint offset;
                offset.x = startOffset.x - normalAngle.x;
                offset.y = startOffset.y - normalAngle.y;
                //glTranslatef(-offset.x * 20.0f, offset.y * 20.0f, 0.0f);
            }
        }
Example #2
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);
        }