public void Append(Checkpoint cp) { Checkpoints.Add(cp); if (finishForced) { return; } var position = positions.GetOrAdd(cp.RiderId, x => RoundPosition.FromStartTime(x, RoundStartTime)); if (position.Finished) { return; } position.Append(cp); if (Track.Count < position.LapCount) { Track.Add(new List <Checkpoint>()); } Track[position.LapCount - 1].Add(cp); if (FinishCriteria?.HasFinished(position, GetSequence(), false) == true) { position.Finish(); } rating = null; }
private void CreateCheckPoints() { Checkpoints.Clear(); for (int i = 0; i < centerTrack.Lines.Count * 0.90f; i += 4) { Checkpoints.Add(new Boundary(outsideTrack.Lines[i].X, outsideTrack.Lines[i].Y, insideTrack.Lines[i].X, insideTrack.Lines[i].Y)); } }
/// <summary> /// Recursively find all checkpoints that are children of the transform /// </summary> /// <param name="parent">Parent transform of the children to check</param> private void FindChildCheckpoints(Transform parent) { for (int i = 0; i < parent.childCount; i++) { Transform child = parent.GetChild(i); // Not the checkpoint manager, look for Checkpoint component Checkpoint cp = child.GetComponent <Checkpoint>(); if (cp != null) { // Found a checkpoint add it to the Checkpoints list Checkpoints.Add(cp); // Add collider to dictionary checkpointDictionary.Add(cp.checkpointCollider, cp); // A checkpoint should not have any children checkpoints } else { // Checkpoint not found, checking children FindChildCheckpoints(child); } } }
private void BuildLevel(List <string[]> levelData) { // iterate through lines for (int i = 0; i < levelData.Count(); i++) { switch (levelData[i][0]) { case "00": // mario Mario.Instance.PlayableObjectState = new SmallRightIdleMario(Mario.Instance); Mario.Instance.Position = new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize); break; case "01": // floor tiles StaticObjects.Add(new FloorTile(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), new Vector2(StringToInt(i, 3), StringToInt(i, 4)), levelData[i][5])); break; case "02": // blocks Blocks.Add(new Block(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), levelData[i][3], levelData[i][4])); break; case "03": // floating coins Coins.Add(new Item(new Vector2((StringToInt(i, 1) * levelCellSize) + (levelCellSize / 4), StringToInt(i, 2) * levelCellSize), "FloatingCoin")); break; case "04": // pipes Pipes.Add(new Pipe(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3), Convert.ToBoolean(levelData[i][4]), levelData[i][5])); break; case "05": // enemies Enemies.Add(new Enemy(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize - 10), levelData[i][3])); break; case "06": // hills BackgroundItems.Add(new Hill(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3))); break; case "07": // bushes BackgroundItems.Add(new Bush(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3))); break; case "08": // clouds BackgroundItems.Add(new Cloud(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3))); break; case "09": // castle Castle = new Castle(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize)); break; case "10": // flag pole Flagpoles.Add(new Flagpole(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), levelCellSize)); break; case "11": // check point Checkpoints.Add(new CheckPoint(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize))); break; case "12": // coin room CoinRoomPosition = new Vector2(StringToInt(i, 1) * levelCellSize + (levelCellSize / 8), StringToInt(i, 2) * levelCellSize); break; } } DynamicObjects.Add(Mario.Instance); foreach (Block block in Blocks) { DynamicObjects.Add(block); DynamicObjects.Add(block.Item); // Add items in each block too. } foreach (Item coin in Coins) { DynamicObjects.Add(coin); } foreach (Enemy enemy in Enemies) { // Added such that the Koopa spawns in a correct position before any updates are made, otherwise he spawns in the floor to start. if (enemy.EnemyState.ToString() == "SuperMario.EnemyStates.LeftWalkingKoopa" || enemy.EnemyState.ToString() == "SuperMario.EnemyStates.RightWalkingKoopa") { enemy.Position = new Vector2(enemy.Position.X, enemy.Position.Y - GameValues.KoopaPositionOffset); } DynamicObjects.Add(enemy); } foreach (Pipe pipe in Pipes) { StaticObjects.Add(pipe); } foreach (Flagpole flagpole in Flagpoles) { StaticObjects.Add(flagpole); } if (Flagpoles.Count > 0) { Flag.Position = new Vector2(Flagpoles[0].CollisionRectangle.X - GameValues.FlagPositionOffsetVector.X, Flagpoles[0].CollisionRectangle.Y + GameValues.FlagPositionOffsetVector.Y); } }
private Level(BinaryReader reader) : this() { ID = reader.ReadInt32(); var nameLength = reader.ReadInt32(); Name = Encoding.UTF8.GetString(reader.ReadBytes(nameLength)); SPlusTime = reader.ReadUInt16(); STime = reader.ReadUInt16(); ATime = reader.ReadUInt16(); BTime = reader.ReadUInt16(); CTime = reader.ReadUInt16(); CheckTime(); var prismsCount = reader.ReadInt16(); Size = new Size3D(reader); #region Boring verifying var temp = reader.ReadUInt16(); if (Temp1 != temp) { Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, Temp1, "unknown_ushort_1")); } temp = reader.ReadUInt16(); if (Temp2 != temp) { Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, Temp2, "unknown_ushort_2")); } ushort width = reader.ReadUInt16(), length = reader.ReadUInt16(); var legacyMinimapValid = true; if (LegacyMinimapSize.Width != width) { Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, width, LegacyMinimapSize.Width, "unknown_ushort_3")); legacyMinimapValid = false; } if (LegacyMinimapSize.Length != length) { Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, width, LegacyMinimapSize.Length, "unknown_ushort_4")); legacyMinimapValid = false; } if (!legacyMinimapValid) { Warning.WriteLine(Localization.LevelLegacyMinimapMalformed); } var tempByte = reader.ReadByte(); if (tempByte != 10) { Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, 10, "unknown_byte_1")); } temp = reader.ReadUInt16(); if (Size.Length - 1 != temp) { Warning.WriteLine(string.Format (Localization.LevelInvalidArgument, temp, Size.Length - 1, "unknown_ushort_5")); } temp = reader.ReadUInt16(); if (0 != temp) { Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, 0, "unknown_ushort_6")); } #endregion if (legacyMinimapValid) { LegacyMinimap = new Flat(reader, LegacyMinimapSize); } else { LegacyMinimap = new Flat(LegacyMinimapSize); reader.ReadBytes((width * length + 7) / 8); } CollisionMap = new Cube(reader, Size); SpawnPoint = new Point3D16(reader); Zoom = reader.ReadInt16(); if (Zoom < 0) { Value = reader.ReadInt16(); ValueIsAngle = reader.ReadBoolean(); } ExitPoint = new Point3D16(reader); var count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { MovingPlatforms.Add(new MovingPlatform(MovingPlatforms, reader)); } count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { Bumpers.Add(new Bumper(Bumpers, reader)); } count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { FallingPlatforms.Add(new FallingPlatform(this, reader)); } count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { Checkpoints.Add(new Checkpoint(reader)); } count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { CameraTriggers.Add(new CameraTrigger(reader)); } count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { Prisms.Add(new Prism(reader)); } if (count != prismsCount) { Warning.WriteLine(string.Format (Localization.LevelInvalidArgument, prismsCount, count, "prisms_count")); } if ((count = reader.ReadUInt16()) > 0) { Warning.WriteLine(string.Format(Localization.DeprecatedElement, "Fan")); } for (var i = 0; i < count; i++) { Fans.Add(new Fan(reader)); } Buttons = new Buttons(this, reader); count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { OtherCubes.Add(new OtherCube(this, reader)); } count = reader.ReadUInt16(); for (var i = 0; i < count; i++) { Resizers.Add(new Resizer(this, reader)); } if ((count = reader.ReadUInt16()) > 0) { Warning.WriteLine(string.Format(Localization.DeprecatedElement, "MiniBlock")); } for (var i = 0; i < count; i++) { MiniBlocks.Add(new MiniBlock(reader)); } ModelTheme = Theme = reader.ReadByte(); MusicJava = reader.ReadByte(); Music = reader.ReadByte(); foreach (var button in Buttons) { if (button.IsMoving) { button.MovingPlatformID.Name.DoNothing(); } foreach (var e in button.Events) { Buttons.BlockEvents[e].ID.Name.DoNothing(); } } foreach (var cube in OtherCubes) { cube.MovingBlockSync.Name.DoNothing(); cube.DarkCubeMovingBlockSync?.Name.DoNothing(); } }
private Level(string path) : this() { var element = XHelper.Load(path + ".xml").GetElement("Level"); ID = element.GetAttributeValue <int>("ID"); Name = element.GetAttributeValueWithDefault("Name", string.Empty); var thresholds = element.GetAttributeValueWithDefault("TimeThresholds", "1,2,3,4,5").Split(',') .Select(str => ushort.Parse(str.Trim())).ToArray(); SPlusTime = thresholds[0]; STime = thresholds[1]; ATime = thresholds[2]; BTime = thresholds[3]; CTime = thresholds[4]; CheckTime(); Size = element.GetAttributeValue <Size3D>("Size"); LegacyMinimap = new Flat(path + ".png", LegacyMinimapSize); CollisionMap = new Cube(path + ".{0}.png", Size); SpawnPoint = element.GetAttributeValue <Point3D16>("SpawnPoint"); ExitPoint = element.GetAttributeValue <Point3D16>("ExitPoint"); Theme = element.GetAttributeValueWithDefault <byte>("Theme"); ModelTheme = element.GetAttributeValueWithDefault("ModelTheme", Theme); MusicJava = element.GetAttributeValueWithDefault <byte>("MusicJava"); Music = element.GetAttributeValueWithDefault("Music", (byte)6); Zoom = element.GetAttributeValueWithDefault("Zoom", (short)-1); var advanced = true; if (ValueIsAngle = element.AttributeCaseInsensitive("Angle") != null) { Value = element.GetAttributeValueWithDefault <short>("Angle", 22); if (element.AttributeCaseInsensitive("FieldOfView") != null) { Warning.WriteLine(string.Format(Localization.FieldOfViewIgnored, "Level")); } } else if (element.AttributeCaseInsensitive("FieldOfView") != null) { Value = element.GetAttributeValueWithDefault <short>("FieldOfView", 22); } else if (Zoom < 0) { Value = 22; } else { advanced = false; } if (Zoom >= 0 && advanced) { Warning.WriteLine(string.Format(Localization.AdvancedCameraModeDisabled, "Level", "@Angle, @FieldOfView")); } Buttons = new Buttons(this); foreach (var e in element.Elements()) { switch (e.Name.LocalName.ToLower()) { case "movingplatform": MovingPlatforms.Add(new MovingPlatform(MovingPlatforms, e)); break; case "bumper": Bumpers.Add(new Bumper(Bumpers, e)); break; case "fallingplatform": FallingPlatforms.Add(new FallingPlatform(this, e)); break; case "checkpoint": Checkpoints.Add(new Checkpoint(e)); break; case "cameratrigger": CameraTriggers.Add(new CameraTrigger(e)); break; case "prism": Prisms.Add(new Prism(e)); break; case "fan": Fans.Add(new Fan(e)); Warning.WriteLine(string.Format(Localization.DeprecatedElement, "Fan")); break; case "button": case "buttonsequence": // ReSharper disable once ObjectCreationAsStatement new Button(Buttons, e); break; case "othercube": case "darkcube": OtherCubes.Add(new OtherCube(this, e)); break; case "resizergrow": case "resizershrink": Resizers.Add(new Resizer(this, e)); break; case "miniblock": MiniBlocks.Add(new MiniBlock(e)); Warning.WriteLine(string.Format(Localization.DeprecatedElement, "MiniBlock")); break; default: Warning.WriteLine(string.Format(Localization.UnrecognizedChildElement, e.Name, "Level")); break; } } }
public void Read(string path) { SaveEmpty = false; Checkpoints.Clear(); EpisodePlayed.Clear(); // read and decode Data byte[] file = File.ReadAllBytes(path); byte[] decoded = DecodeEncode.Decode(file); // decoded is - dexored content only (since file starts with header) Raw = Encoding.UTF8.GetString(decoded); try { m_Data = Json.Decode(Raw); //this is the save file, NOT initialdata } catch { SaveEmpty = true; return; } // add normal checkpoints foreach (var checkpoint in m_Data.checkpoints) { List <string> flags = new List <string>(); var vars = ReadVarsForCheckpoint(checkpoint); foreach (var fl in checkpoint.flags) { flags.Add(fl); } Checkpoints.Add(new Checkpoint(checkpoint, vars, flags)); } // add currentcheckpoint (seems to be identical to latest checkpoint...) Dictionary <string, VariableState> variables; try { List <string> flags = new List <string>(); foreach (var fl in m_Data.currentCheckpoint.stateCheckPoint.flags) { flags.Add(fl); } variables = ReadVarsForCheckpoint(m_Data.currentCheckpoint.stateCheckPoint); Checkpoints.Add(new Checkpoint(m_Data.currentCheckpoint.stateCheckPoint, variables, flags)); } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) { SaveEmpty = true; return; } // add global variables as a last checkpoint.. // hack... variables = ReadVarsForCheckpoint(m_Data); Checkpoints.Add(new Checkpoint(new { pointIdentifier = "Global Vars", currentObjective = "" }, variables)); // fill episodeState (?) foreach (var episode in m_Data.episodes) { string name = episode.name; string stateStr = episode.episodeState; bool played = false; if (stateStr == "kFinished" || stateStr == "kInProgress") { played = true; } EpisodePlayed[name] = played; } if (File.Exists(Path.GetDirectoryName(path) + @"\Header.Save")) { ReadHeader(Path.GetDirectoryName(path) + @"\Header.Save"); } else { m_Header = null; } }
public void ReadSaveFromFile(string savePath) { SaveIsEmpty = false; Checkpoints.Clear(); PlayedEpisodes.Clear(); // Read and decode Data var fileContent = File.ReadAllBytes(savePath); try { Data = JsonConverter.DecodeFileContentToJson(fileContent); RawSave = Data.ToString(); } catch { SaveIsEmpty = true; return; } Dictionary <string, VariableState> variables; Dictionary <string, FloatState> floats; // Add regular checkpoints foreach (var checkpoint in Data.checkpoints) { var cpFlags = new List <string>(); variables = GetCheckpointVariables(checkpoint); floats = GetCheckpointFloats(checkpoint); foreach (var flag in checkpoint.flags) { cpFlags.Add(flag.Value); } Checkpoints.Add(new Checkpoint(checkpoint, variables, cpFlags, floats)); } // Add currentcheckpoint (seems to be identical to latest checkpoint...) try { var currentCpFlags = new List <string>(); foreach (var fl in Data.currentCheckpoint.stateCheckpoint.flags) { currentCpFlags.Add(fl.Value); } variables = GetCheckpointVariables(Data.currentCheckpoint.stateCheckpoint); floats = GetCheckpointFloats(Data.currentCheckpoint.stateCheckpoint); Checkpoints.Add(new Checkpoint(Data.currentCheckpoint.stateCheckpoint, variables, currentCpFlags, floats)); } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) { SaveIsEmpty = true; return; } // Add global variables as a last checkpoint.. // hack... variables = GetCheckpointVariables(Data); floats = GetCheckpointFloats(Data); Checkpoints.Add(new Checkpoint(new { pointIdentifier = "Global Vars", currentObjective = Data.currentObjective }, variables, null, floats)); // Fill episodeState (?) foreach (var episode in Data.episodes) { string episodeName = episode.name; string episodeState = episode.episodeState; var isPlayed = episodeState == Consts.EpisodeStates.Finished || episodeState == Consts.EpisodeStates.InProgress; PlayedEpisodes[episodeName] = isPlayed; } if (File.Exists(Path.GetDirectoryName(savePath) + @"\Header.Save")) { ReadHeaderFromFile(Path.GetDirectoryName(savePath) + @"\Header.Save"); } else { Header = null; } }
void InitializeDepartureProcess() { Process departure = new Process() { ProcessType = ProcessType.DepartingProcess.ToString() }; Processes.Add(departure); SaveChanges(); Checkpoint parkingBoarding_terminal1 = new Checkpoint() { Serial = 71, Control = "txtblckFlightTerminal1", CheckpointType = CheckpointType.ParkingBoarding_terminal1.ToString(), Duration = 5000, Process = departure, Flights = new List <Flight>(1) }; Checkpoints.Add(parkingBoarding_terminal1); departure.Checkpoints.Add(parkingBoarding_terminal1); SaveChanges(); Checkpoint parkingBoarding_terminal2 = new Checkpoint() { Serial = 72, Control = "txtblckFlightTerminal2", CheckpointType = CheckpointType.ParkingBoarding_terminal2.ToString(), Duration = 5000, Process = departure, Flights = new List <Flight>(1) }; Checkpoints.Add(parkingBoarding_terminal2); departure.Checkpoints.Add(parkingBoarding_terminal2); SaveChanges(); Checkpoint standbyDeparting = new Checkpoint() { Serial = 8, Control = "lstvwParkDepart", CheckpointType = CheckpointType.StandbyDeparting.ToString(), Duration = 2000, Process = departure, Flights = new List <Flight>(100) }; Checkpoints.Add(standbyDeparting); departure.Checkpoints.Add(standbyDeparting); SaveChanges(); Checkpoint runwayDeparting = new Checkpoint() { Serial = 42, Control = "txtblckFlightRunway", CheckpointType = CheckpointType.RunwayDeparting.ToString(), Duration = 3000, Process = departure, Flights = new List <Flight>(1) }; Checkpoints.Add(runwayDeparting); departure.Checkpoints.Add(runwayDeparting); SaveChanges(); Checkpoint departed = new Checkpoint() { Serial = 9, Control = "txtblckFlightDepart", CheckpointType = CheckpointType.Departed.ToString(), Duration = 2000, Process = departure, Flights = new List <Flight>(1) }; Checkpoints.Add(departed); departure.Checkpoints.Add(departed); SaveChanges(); }
void InitializeLandingProcess() { Process landing = new Process() { ProcessType = ProcessType.LandingProcess.ToString() }; Processes.Add(landing); SaveChanges(); Checkpoint arrival1 = new Checkpoint() { Serial = 1, Control = "txtblckFlightArr1", CheckpointType = CheckpointType.Landing.ToString(), Duration = 2000, Process = landing, Flights = new List <Flight>(1) }; Checkpoints.Add(arrival1); landing.Checkpoints.Add(arrival1); SaveChanges(); Checkpoint arrival2 = new Checkpoint() { Serial = 2, Control = "txtblckFlightArr2", CheckpointType = CheckpointType.Landing.ToString(), Duration = 2000, Process = landing, Flights = new List <Flight>(1) }; Checkpoints.Add(arrival2); landing.Checkpoints.Add(arrival2); SaveChanges(); Checkpoint arrival3 = new Checkpoint() { Serial = 3, Control = "txtblckFlightArr3", CheckpointType = CheckpointType.Landing.ToString(), Duration = 2000, Process = landing, Flights = new List <Flight>(1) }; Checkpoints.Add(arrival3); landing.Checkpoints.Add(arrival3); SaveChanges(); Checkpoint runwayLanded = new Checkpoint() { Serial = 41, Control = "txtblckFlightRunway", CheckpointType = CheckpointType.RunwayLanded.ToString(), Duration = 3000, Process = landing, Flights = new List <Flight>(1) }; Checkpoints.Add(runwayLanded); landing.Checkpoints.Add(runwayLanded); SaveChanges(); Checkpoint standbyLanded = new Checkpoint() { Serial = 5, Control = "lstvwParkUnload", CheckpointType = CheckpointType.StandbyLanded.ToString(), Duration = 2000, Process = landing, Flights = new List <Flight>(100) }; Checkpoints.Add(standbyLanded); landing.Checkpoints.Add(standbyLanded); SaveChanges(); Checkpoint parkingUnloading_terminal1 = new Checkpoint() { Serial = 61, Control = "txtblckFlightTerminal1", CheckpointType = CheckpointType.ParkingUnloading_terminal1.ToString(), Duration = 5000, Process = landing, Flights = new List <Flight>(1) }; Checkpoints.Add(parkingUnloading_terminal1); landing.Checkpoints.Add(parkingUnloading_terminal1); SaveChanges(); Checkpoint parkingUnloading_terminal2 = new Checkpoint() { Serial = 62, Control = "txtblckFlightTerminal2", CheckpointType = CheckpointType.ParkingUnloading_terminal2.ToString(), Duration = 5000, Process = landing, Flights = new List <Flight>(1) }; Checkpoints.Add(parkingUnloading_terminal2); landing.Checkpoints.Add(parkingUnloading_terminal2); SaveChanges(); }