public override void BeginContact(Box2D.XNA.Contact contact) { base.BeginContact(contact); LaneVehicle v = null; Sprite ch = null; if (collisionObjA is LaneVehicle && collisionObjA.RootName == "laneChanger") { v = (LaneVehicle)collisionObjA; ch = collisionObjB; } else if (collisionObjB is LaneVehicle && collisionObjA.RootName == "laneChanger") { v = (LaneVehicle)collisionObjB; ch = collisionObjA; } if (v != null) { if (ch.Index == 0) { v.laneY = lanes[v.Lane.laneIndex - 1].yLocation + (lanes[v.Lane.laneIndex - 1].laneHeight - v.VisibleHeight) / 2f; } else { v.laneY = lanes[v.Lane.laneIndex + 1].yLocation + (lanes[v.Lane.laneIndex + 1].laneHeight - v.VisibleHeight) / 2f + v.VisibleHeight; } } }
public override void EndContact(Contact contact) { V2DSprite objA = (V2DSprite)contact.GetFixtureA().GetBody().GetUserData(); V2DSprite objB = (V2DSprite)contact.GetFixtureB().GetBody().GetUserData(); SmuckPlayer p = objA is SmuckPlayer ? (SmuckPlayer)objA : objB is SmuckPlayer ? (SmuckPlayer)objB : null; LaneVehicle v = objA is LaneVehicle ? (LaneVehicle)objA : objB is LaneVehicle ? (LaneVehicle)objB : null; V2DSprite w = objA.InstanceName.StartsWith("water") ? objA : objB.InstanceName.StartsWith("water") ? objB : null; if (p != null) { if (w != null) { p.IsOnWater = false; } else if (v != null) { if (v.Lane.LaneKind == LaneKind.DrownWater) { p.aboardVehicle = null; if (p.IsOnWater) { p.LivingState = LivingState.Dying; stage.audio.PlaySound(Sfx.bigSplash); } } else { this.KillPlayer(p); } } } }
public override void Removed(EventArgs e) { base.RemovedFromStage(e); foreach (SmuckPlayer p in players) { if (p != null) { this.RemoveChild(p); p.body = null; } } for (int i = 0; i < lanes.Length; i++) { for (int j = 0; i < lanes[i].vehicles.Count; j++) { if (lanes[i].vehicles[j] != null && this.Contains(lanes[i].vehicles[j])) { RemoveChild(lanes[i].vehicles[j]); } lanes[i].vehicles[j] = null; lanes[i].vehicles.Clear(); } lanes[i] = null; } lanes = null; vehicle = null; for (int i = 0; i < deadIcons.Count; i++) { RemoveChild(deadIcons[i]); } deadIcons.Clear(); if (starParticles != null) { RemoveChild(starParticles); } gameOverlay = null; }
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; } } } }