Example #1
0
    void AddPlayingField(List <string> gridRows, int gridWidth, int gridHeight)
    {
        // create a parent object for everything
        GameObjectList playingField = new GameObjectList();

        // this playing field should be roughly centered on the screen
        Vector2 gridSize = new Vector2(gridWidth * TileWidth, gridHeight * TileHeight);

        playingField.LocalPosition = new Vector2(600, 420) - gridSize / 2.0f;

        // prepare the grid arrays
        tiles          = new Tile[gridWidth, gridHeight];
        animalsOnTiles = new Animal[gridWidth, gridHeight];

        // load the tiles and animals
        for (int y = 0; y < gridHeight; y++)
        {
            string row = gridRows[y];
            for (int x = 0; x < gridWidth; x++)
            {
                // the row could be too short; if so, pretend there is an empty tile
                char symbol = ' ';
                if (x < row.Length)
                {
                    symbol = row[x];
                }

                // load the non-changing part of the tile
                AddTile(x, y, symbol);

                // load the animal part of the tile, if it exists
                AddAnimal(x, y, symbol);
            }
        }

        // add the tiles to the playing field
        for (int y = 0; y < gridHeight; y++)
        {
            for (int x = 0; x < gridWidth; x++)
            {
                playingField.AddChild(tiles[x, y]);
            }
        }

        // add the animals after that, so that they will be drawn on top
        for (int y = 0; y < gridHeight; y++)
        {
            for (int x = 0; x < gridWidth; x++)
            {
                if (animalsOnTiles[x, y] != null)
                {
                    playingField.AddChild(animalsOnTiles[x, y]);
                }
            }
        }

        // add the hint arrow (so that it will be drawn on top), but make it invisible for now
        hintArrow.Visible = false;
        playingField.AddChild(hintArrow);

        // add the animal selector
        selector = new MovableAnimalSelector();
        playingField.AddChild(selector);

        // finally, add the playing field to the level
        AddChild(playingField);
    }
Example #2
0
    public JewelJamGameWorld(JewelJam game)
    {
        // store a reference to the game
        this.game = game;

        // add the background
        SpriteGameObject background = new SpriteGameObject("spr_background");

        Size = new Point(background.Width, background.Height);
        AddChild(background);

        // add a "playing field" parent object for the grid and all related objects
        GameObjectList playingField = new GameObjectList();

        playingField.LocalPosition = new Vector2(85, 150);
        AddChild(playingField);

        // add the grid to the playing field
        JewelGrid grid = new JewelGrid(GridWidth, GridHeight, CellSize);

        playingField.AddChild(grid);

        // add the row selector to the playing field
        playingField.AddChild(new RowSelector(grid));

        // add a background sprite for the score object
        SpriteGameObject scoreFrame = new SpriteGameObject("spr_scoreframe");

        scoreFrame.LocalPosition = new Vector2(20, 20);
        AddChild(scoreFrame);

        // add the object that displays the score
        ScoreGameObject scoreObject = new ScoreGameObject();

        scoreObject.LocalPosition = new Vector2(270, 30);
        AddChild(scoreObject);

        // add the moving jewel cart
        jewelCart = new JewelCart(new Vector2(410, 230));
        AddChild(jewelCart);

        // add the help button
        helpButton = new SpriteGameObject("spr_button_help");
        helpButton.LocalPosition = new Vector2(1270, 20);
        AddChild(helpButton);

        // add combo images with visibility timers attached to them
        timer_double = AddComboImageWithTimer("spr_double");
        timer_triple = AddComboImageWithTimer("spr_triple");

        // add the various overlays
        titleScreen    = AddOverlay("spr_title");
        gameOverScreen = AddOverlay("spr_gameover");
        helpScreen     = AddOverlay("spr_frame_help");

        // start at the title screen
        GoToState(GameState.TitleScreen);

        // play background music
        ExtendedGame.AssetManager.PlaySong("snd_music", true);
    }