示例#1
0
    public Level(int levelIndex)
    {
        // load the backgrounds
        GameObjectList   backgrounds   = new GameObjectList(0, "backgrounds");
        SpriteGameObject backgroundSky = new LockedSpriteGameObject("Backgrounds/spr_sky");

        backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height);
        backgrounds.Add(backgroundSky);

        // add a few random mountains
        for (int i = 10; i > 0; i--)
        {
            newMountainLayer(backgrounds, 3, i * 3 + 7, ((10 - i) * 2));
        }
        Add(backgrounds);

        SpriteGameObject timerBackground = new LockedSpriteGameObject("Sprites/spr_timer", 100);

        timerBackground.Position = new Vector2(10, 10);
        Add(timerBackground);
        timer          = new TimerGameObject(101, "timer");
        timer.Position = new Vector2(25, 30);
        Add(timer);

        quitButton          = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
        Add(quitButton);


        Add(new GameObjectList(1, "waterdrops"));
        Add(new GameObjectList(2, "enemies"));

        LoadTiles("Content/Levels/" + levelIndex + ".txt");
    }
示例#2
0
    public LevelFinishedState()
    {
        playingState = GameEnvironment.GameStateManager.GetGameState("playingState") as PlayingState;
        SpriteGameObject overlay = new LockedSpriteGameObject("Overlays/spr_welldone");

        overlay.Position = new Vector2(GameEnvironment.Screen.X, GameEnvironment.Screen.Y) / 2 - overlay.Center;
        Add(overlay);
        quitButton          = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
    }
示例#3
0
    public void LoadTiles(string path)
    {
        List <string> textLines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine();
        int           width      = line.Length;

        while (line != null)
        {
            textLines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField      tiles     = new TileField(textLines.Count - 1, width, 1, "tiles");
        int            height    = textLines.Count - 1;
        GameObjectList hintField = new GameObjectList(100);

        Add(hintField);
        string           hint      = textLines[textLines.Count - 2];
        SpriteGameObject hintFrame = new LockedSpriteGameObject("Overlays/spr_frame_hint", 1);

        hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10);
        hintField.Add(hintFrame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2);

        hintText.Text     = textLines[textLines.Count - 2];
        hintText.Position = new Vector2(120, 25);
        hintText.Color    = Color.Black;
        hintField.Add(hintText);
        int timerTime = int.Parse(textLines[textLines.Count - 1]);

        timer.SetTime = timerTime;
        VisibilityTimer hintTimer = new VisibilityTimer(hintField, 1, "hintTimer");

        Add(hintTimer);

        Add(tiles);
        tiles.CellWidth  = 72;
        tiles.CellHeight = 55;
        this.width       = width * tiles.CellWidth;
        this.height      = height * tiles.CellHeight;
        for (int x = 0; x < width; x++)
        {
            Tile t = new Tile();
            tiles.Add(t, x, 0);
        }
        for (int x = 0; x < width; ++x)
        {
            for (int y = 1; y < textLines.Count - 1; ++y)
            {
                Tile t = LoadTile(textLines[y - 1][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }