public void Reset(float x, float y, float rot) { this.roundScore = 0; this.lane = null; this.playerSkin = PlayerSkin.None; this.isExploding = false; this.skipDeathMarker = false; this.autoCenterOnLane = true; this.dampingRatio = .7f; this.impulseScale = 50f; this.X = x; this.Y = y; this.Rotation = rot; this.SpeedLevel = SpeedLevel.Normal; lastStepPos = body.GetPosition(); goalIsTop = !(lastStepPos.Y < this.screen.ClientSize.Y / 2); this.SpeedLevel = SpeedLevel.Normal; aboardVehicle = null; this.LivingState = LivingState.Alive; }
public bool CreateVehicle(V2DScreen screen, TimeSpan totalGameTime) { bool result = false; if (laneKind == LaneKind.Empty) { return(result); } if (!((BaseScreen)screen).WaitingOnPanel) { if (firstVehicle) { firstVehicle = false; laneWidth = (int)screen.ClientSize.X; if (!createVehicleOnStartup || rnd.Next(maxCreationDelay) < minCreationDelay) { SetNextVehicleTime(totalGameTime); return(result); } } if (CanCreateVehicle()) { // todo: move this into vehicles V2DInstance vInst; switch (laneKind) { case LaneKind.Sidewalk: vehicleStyleIndex = rnd.Next(4); vInst = screen.CreateInstanceDefinition("sidewalker" + vehicleStyleIndex, "vehicle" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.Car: if (rnd.Next(20) == 0) { // special vehicles vehicleStyleIndex = rnd.Next(2) + 11; } else { vehicleStyleIndex = rnd.Next(11); } vInst = screen.CreateInstanceDefinition("vehicle" + vehicleStyleIndex, "vehicle" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.Train: vehicleStyleIndex = 0; vInst = screen.CreateInstanceDefinition("trainFull" + vehicleStyleIndex, "vehicle" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.Shinkansen: vehicleStyleIndex = 1; vInst = screen.CreateInstanceDefinition("trainFull" + vehicleStyleIndex, "vehicle" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.Spaceship: vehicleStyleIndex = rnd.Next(8); vInst = screen.CreateInstanceDefinition("spaceship" + vehicleStyleIndex, "vehicle" + nextDepth); vInst.Rotation = movesRight ? rightAngle + (float)rnd.Next(1000) / 2000f - .25f : leftAngle + (float)rnd.Next(1000) / 2000f - .25f; break; case LaneKind.DrownWater: vehicleStyleIndex = rnd.Next(3); vInst = screen.CreateInstanceDefinition("boat" + vehicleStyleIndex, "boat" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.SwimWater: vehicleStyleIndex = FindBoatIndex(screen); if (vehicleStyleIndex == -1) { return(result); } if (vehicleStyleIndex == 5) { vInst = screen.CreateInstanceDefinition("boat" + vehicleStyleIndex, "carrier" + nextDepth); } else { vInst = screen.CreateInstanceDefinition("boat" + vehicleStyleIndex, "boat" + nextDepth); } vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.WideCar: vehicleStyleIndex = 0; vInst = screen.CreateInstanceDefinition("wideVehicle" + vehicleStyleIndex, "vehicle" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; case LaneKind.SteamRoller: vInst = screen.CreateInstanceDefinition("steamRoller", "steamRoller" + nextDepth); vInst.Rotation = movesRight ? rightAngle : leftAngle; break; default: throw new Exception("Unsupported vehicle: " + laneKind); } vInst.Depth = nextDepth++; vInst.Y = yLocation; Vector4 shapeRect = vInst.Definition.GetShapeRectangle(); float h = shapeRect.W; if (movesRight) { vInst.X = 10; vInst.Y += laneHeight - (laneHeight - h - shapeRect.Y) / 2f;// vInst.Definition.Height) / 2f; } else { vInst.X = laneWidth - 10; vInst.Y += (laneHeight - h - shapeRect.Y) / 2f;//vInst.Definition.Height) / 2f; } if (firstVehicle && !oneTimeVehicle) { vInst.X = rnd.Next(0, laneWidth); firstVehicle = false; } LaneVehicle v = (LaneVehicle)screen.AddInstance(vInst, screen); v.vehicleStyleIndex = vehicleStyleIndex; // trains shouldn't move off track if (v.VisibleWidth > 500) { v.body.SetFixedRotation(true); } v.Lane = this; v.laneY = v.Y; v.direction = new Vector2((float)System.Math.Cos(vInst.Rotation), (float)System.Math.Sin(vInst.Rotation)); v.MaxSpeed = vehicleSpeed; vehicles.Add(v); if (laneKind == LaneKind.WideCar || laneKind == LaneKind.DrownWater || laneKind == LaneKind.SwimWater || laneKind == LaneKind.Sidewalk) { v.PlayAll(); if ((laneKind == LaneKind.DrownWater) && vehicleStyleIndex == 1) { v.MaxSpeed = 5; } } else if (laneKind == LaneKind.Car && vehicleStyleIndex >= 11) { v.PlayAll(); } SetNextVehicleTime(totalGameTime); result = true; } } return(result); }
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; }