bool IsThisSkidAGoodIdea() { CGPoint nowPos = myPig.position; CGPoint nowSpeed = skidDirection; float prevNumThings = 0.0f; float frame = 5.0f; for (int i = 0; i < 9; i++) { float numThings = (frame * (frame + 1.0f)) * 0.5f; float nowNumThings = numThings; numThings -= prevNumThings; prevNumThings = nowNumThings; nowPos.x += (nowSpeed.x * 5.0f); nowPos.y += (nowSpeed.y * 5.0f); nowPos.x += (numThings * skidAcceleration.x); nowPos.y += (numThings * skidAcceleration.y); frame += 5.0f; int whichTargetPoint = this.GetTargetPointAt(nowPos.y); CGPoint nearestPoint = Utilities.CGPointMake((float)racingLine.GetPoint(whichTargetPoint).x, (float)racingLine.GetPoint(whichTargetPoint).y); float sqrDistance = Utilities.GetSqrDistanceP1(nowPos, nearestPoint); float kMinSqrDistanceForPoint = 2500.0f; if (sqrDistance > kMinSqrDistanceForPoint) { return(false); } } return(true); }
public bool CheckPop(CGPoint playerPosition) { const float kDistanceToPopSqr = 225.0f; float sqrDistance = Utilities.GetSqrDistanceP1(playerPosition, position); if (sqrDistance <= kDistanceToPopSqr) { this.Pop(); return(true); } return(false); }
public void CheckRunAwayP1(CGPoint playerPosition, CGPoint playerSpeed) { if (state != (int)ChickenState.e_Pecking) { return; } float distToRun = 100.0f + (playerSpeed.y * 10.0f); float kSqrDistanceToRun = (distToRun * distToRun); float sqrDistance = Utilities.GetSqrDistanceP1(playerPosition, position); if (sqrDistance <= kSqrDistanceToRun) { this.RunAway(playerSpeed); } }
public void UpdateGoRoundTractors_Dodging() { dodgingTractorPos = ((Globals.g_world.game).GetTractor(dodgingTractor)).position; dodgingTractorPos.x += dodgingTractorOffset.x; dodgingTractorPos.y += dodgingTractorOffset.y; if (dodgingTractorPos.x < 0.0f) { dodgingTractorPos.x = 0.0f; } float distSqr = Utilities.GetSqrDistanceP1(myPig.position, dodgingTractorPos); if (distSqr < 6400.0f) { dodgingTractor = -1; this.SetTargetPointFromHere(220.0f); } }
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 } } }
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); }
public float GetBumpPowerSqr(CGPoint newVelocity) { CGPoint diff = Utilities.CGPointMake(newVelocity.x - xSpeed, newVelocity.y); return(Utilities.GetSqrDistanceP1(Utilities.CGPointMake(0, 0), diff)); }
public float BumpP1(CGPoint newVelocity, Player whoBy) { #if RACE_AS_PIGGY return(false); #endif CGPoint bumpVelocity = Utilities.CGPointMake(newVelocity.x, newVelocity.y - myFlock.speed); float powerSqr = Utilities.GetSqrDistanceP1(Utilities.CGPointMake(0.0f, myFlock.speed), newVelocity); if (flockAnimalType == FlockAnimalType.kFlockAnimalShirley) { if (powerSqr > 120.0f) { if (whoBy == (Globals.g_world.game).player) { ((Globals.g_world.frontEnd).profile).QueueAchievement(Profile.Enum2.kAchievement_ShirleyThump); ((Globals.g_world.frontEnd).profile).FlushPendingAchievements(); } } if (powerSqr > 24.0f) { if (bumpTimer <= 0.25f) { (SoundEngine.Instance()).PlayFinchSound((int)Audio.Enum1.kSoundEffect_HitShirley); } } } if (bumpTimer > 0.0f) { return(0.0f); } if (flockAnimalType == FlockAnimalType.kFlockAnimalCow) { bumpMaxDistance = 2.0f * Utilities.GetDistanceP1(Utilities.CGPointMake(0.0f, 0.0f), bumpVelocity); } else if (flockAnimalType == FlockAnimalType.kFlockAnimalSheep) { bumpMaxDistance = 2.0f * Utilities.GetDistanceP1(Utilities.CGPointMake(0.0f, 0.0f), bumpVelocity); } else if (flockAnimalType == FlockAnimalType.kFlockAnimalZebra) { bumpMaxDistance = 3.2f * Utilities.GetDistanceP1(Utilities.CGPointMake(0.0f, 0.0f), bumpVelocity); } else if (flockAnimalType == FlockAnimalType.kFlockAnimalShirley) { bumpMaxDistance = 2.0f * Utilities.GetDistanceP1(Utilities.CGPointMake(0.0f, 0.0f), bumpVelocity); } else { bumpMaxDistance = 5.0f * Utilities.GetDistanceP1(Utilities.CGPointMake(0.0f, 0.0f), bumpVelocity); } bumpDirection = Utilities.Normalise(bumpVelocity); bumpTimer = kBumpTime; return(powerSqr); }