Beispiel #1
0
        /// <summary>
        /// Instantiates a player, puts him in the level, and remembers where to put him when he is resurrected.
        /// </summary>
        private Tile LoadStartTile(int x, int y)
        {
            start = RectangleExtensions.GetBottomCenter(GetBounds(x, y));
            if (Player == null)
            {
                Player = new Player(this, start);
            }
            else
            {
                Player.Reset(start);
            }

            return new Tile(null, TileCollision.Passable);
        }
Beispiel #2
0
        /// <summary>
        /// Loads objects from the files for each stage of the level.
        /// </summary>
        private void LoadObjects(Stream fileStream)
        {
            using (StreamReader reader = new StreamReader(fileStream))
            {
                string objectID = reader.ReadLine();
                while (objectID != null)
                {
                    string typeLine = reader.ReadLine();
                    List<string> objectInfo = new List<string>(ObjectManager.getObjectInfo(typeLine));
                    string[] positionLine = reader.ReadLine().Split(' ');
                    Vector2 position = new Vector2(float.Parse(positionLine[0]), float.Parse(positionLine[1]));
                    if (objectInfo[0] == "Trigger")
                    {
                        Objects.Add(new TriggerObject(typeLine, position, int.Parse(objectID),
                                    objectInfo.Contains("Reversible"), objectInfo.Contains("Front")));
                    }
                    else if (objectInfo[0] == "ProximityTrigger")
                    {
                        Objects.Add(new ProximityTriggerObject(typeLine, position, float.Parse(objectInfo[1]),
                                    int.Parse(objectID), objectInfo.Contains("Front")));
                    }
                    else if (objectInfo[0] == "Start")
                    {
                        Objects.Add(new Start(typeLine, position, float.Parse(objectInfo[1]),
                                    int.Parse(objectID), objectInfo.Contains("Front")));
                        start = ((Start)Objects[Objects.Count - 1]).StartPoint;

                        // If the player exists from a previous stage, then we just reset the player's position.
                        if (Player != null)
                        {
                            Player.Reset(start);
                        }
                        else
                        {
                            Player = new Player(this, start);
                        }
                    }
                    else if (objectInfo[0] == "Exit")
                    {
                        Objects.Add(new Exit(typeLine, position, float.Parse(objectInfo[1]),
                                    int.Parse(objectID), objectInfo.Contains("Front")));
                        ((Exit)Objects[Objects.Count - 1]).ExitReached += OnExitReached;
                    }
                    else if (objectInfo[0] == "Sign")
                    {
                        string fact = reader.ReadLine();
                        Objects.Add(new Sign(typeLine, position, fact, int.Parse(objectID)));
                    }
                    else if (objectInfo[0] == "Activating")
                    {
                        string[] objectIDs = reader.ReadLine().Split(' ');
                        Objects.Add(new ActivatingObject(typeLine, position, int.Parse(objectID), objectIDs,
                                    objectInfo.Contains("Front")));
                    }
                    else if (objectInfo[0] == "Dynamic")
                    {
                        Vector2 displacement = new Vector2(int.Parse(objectInfo[1]), int.Parse(objectInfo[2]));
                        Objects.Add(new DynamicObject(typeLine, position, displacement, int.Parse(objectID),
                                    objectInfo.Contains("Reversible"), objectInfo.Contains("Looping")));
                    }
                    else if (objectInfo[0] == "CyclicDynamic")
                    {
                        Vector2 displacement = new Vector2(int.Parse(objectInfo[1]), int.Parse(objectInfo[2]));
                        Objects.Add(new CyclicDynamicObject(typeLine, position, position, displacement, int.Parse(objectID),
                                    objectInfo.Contains("Break"), objectInfo.Contains("Reversible"), objectInfo.Contains("Looping")));
                    }
                    else if (objectInfo[0] == "Conveyor")
                    {
                        Objects.Add(new ConveyorObject(typeLine, position, float.Parse(objectInfo[1]), int.Parse(objectID),
                                    objectInfo.Contains("Reversible"), objectInfo.Contains("Looping")));
                    }
                    else
                    {
                        Objects.Add(new Object(typeLine, position, int.Parse(objectID), objectInfo.Contains("Front"),
                                    objectInfo.Contains("Looping")));
                    }
                    objectID = reader.ReadLine();
                }
            }
        }