public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { if (needsTrialPitch && !showingTrialPitch && gameTime.TotalGameTime > trialDuration) { needsTrialPitch = false; gameOverlay.TrialExpired(); } if (!firstUpdate && gameOverlay.hasActivePanel) { base.ManageInput(gameTime); gameOverlay.Update(gameTime); } else if (isActive) { base.Update(gameTime); firstUpdate = false; for (int i = 0; i < lanes.Length; i++) { lanes[i].Update(gameTime, this); } for (int i = 0; i < players.Count; i++) { SmuckPlayer p = players[i]; if (p != null) { if (p.LivingState == LivingState.Alive) { int curLane = GetLaneFromY((int)(p.Y + p.Height / 2)); if (curLane != p.Lane.laneIndex) { p.snapLaneY = lanes[curLane].yLocation + lanes[curLane].laneHeight / 2; gameOverlay.SetScore(p); p.Lane = lanes[curLane]; // make it harder and harder after success level of points if (p.roundScore >= pointsToWinRound) { if (winningPlayer == -1) { winningPlayer = i; p.CreateFlameEffect(); if (defaultShader != null) { ((DesaturationShader)defaultShader).level = .2f;// (70f - starParticles.NumChildren) / 70f; } } if (endOnLastLane) { isLevelOver = true; } if (p.Lane.LaneKind != LaneKind.Sidewalk) { p.Lane.minCreationDelay = (int)(p.Lane.minCreationDelay * .9); p.Lane.maxCreationDelay = (int)(p.Lane.maxCreationDelay * .9); p.Lane.vehicleSpeed += 3; } } } } else if (p.IsOnStage && !p.skipDeathMarker && p.LivingState == LivingState.Dying) { float vel = p.body.GetLinearVelocity().LengthSquared(); if (p.body.GetLinearVelocity().LengthSquared() < 100) { p.DestroyAfterUpdate(); } } } } } stage.audio.Update(); }
public override void BeginContact(Contact contact) { collisionObjA = (V2DSprite)contact.GetFixtureA().GetBody().GetUserData(); collisionObjB = (V2DSprite)contact.GetFixtureB().GetBody().GetUserData(); SmuckPlayer p = null; V2DSprite nonPlayerObj = null; if (collisionObjA is SmuckPlayer) { p = (SmuckPlayer)collisionObjA; nonPlayerObj = collisionObjB; } else if (collisionObjB is SmuckPlayer) { p = (SmuckPlayer)collisionObjB; nonPlayerObj = collisionObjA; } if (p != null) { LaneVehicle v = nonPlayerObj is LaneVehicle ? (LaneVehicle)nonPlayerObj : null; if (v != null) { if (v.Lane.LaneKind == LaneKind.DrownWater && !collideWithBoats) { if (p.LivingState == LivingState.Alive) { p.aboardVehicle = v; } else { p.DestroyAfterUpdate(); // dont want drowning amin over boats } } else { Manifold m; contact.GetManifold(out m); Vector2 dir = m._localNormal * (p == collisionObjA ? 20 : -20) + v.body.GetLinearVelocity() * 10; if (Math.Abs(dir.Y) < 60) { dir.Y += rnd.Next(-400, 400); } p.isExploding = false; p.body.ApplyLinearImpulse(dir, p.body.GetPosition()); float torque = dir.Y > 0 ? 1 : -1; p.body.ApplyTorque(torque); p.body.SetAngularVelocity(rnd.Next(15) * torque); if (p.LivingState == LivingState.Alive) // first hit a whack { stage.audio.PlaySound(Sfx.whack); } stage.audio.PlaySound(Sfx.secondWhack); this.KillPlayer(p); } } else { if (nonPlayerObj.InstanceName.StartsWith("water")) { p.IsOnWater = true; if (p.aboardVehicle == null) { p.Lane = lanes[GetLaneFromY((int)nonPlayerObj.Y)]; p.LivingState = LivingState.Dying; stage.audio.PlaySound(Sfx.bigSplash); } } else if (p.LivingState == LivingState.Dying && nonPlayerObj.InstanceName.StartsWith("border")) { // no death icon when flying off left or right side of highway if (nonPlayerObj.Index == 0 || nonPlayerObj.Index == 2) { p.skipDeathMarker = true; } p.DestroyAfterUpdate(); } } } else if (collisionObjA is LaneVehicle && collisionObjB is LaneVehicle) { LaneVehicle vA = (LaneVehicle)collisionObjA; LaneVehicle vB = (LaneVehicle)collisionObjB; const float boost = 15; if (vA.Lane.movesRight && vB.Lane.movesRight) { if (vA.Position.X > vB.Position.X) { vA.MaxSpeed = vA.Lane.vehicleSpeed + boost; vB.MaxSpeed = vA.MaxSpeed - boost; } else { vB.MaxSpeed = vB.Lane.vehicleSpeed + boost; vA.MaxSpeed = vB.MaxSpeed - boost; } } else if (!vA.Lane.movesRight && !vB.Lane.movesRight) { if (vA.Position.X > vB.Position.X) { vB.MaxSpeed = vB.Lane.vehicleSpeed + boost; vA.MaxSpeed = vB.MaxSpeed - boost; } else { vA.MaxSpeed = vA.Lane.vehicleSpeed + boost; vB.MaxSpeed = vA.MaxSpeed - boost; } } } }