Exemple #1
0
    private void DrawEndless(int part, GameTime gameTime, SpriteBatch spriteBatch)
    {
        level        = new Level();
        level.player = new Player(new Vector3(200, 200f, 200));

        GameObjectGrid grid = new GameObjectGrid(20, 20, "grid");

        for (int i = 0; i < grid.Rows; i++)
        {
            grid.Add(new WallTile("01"), 0, i);
            grid.Add(new WallTile("01"), 2, i);
            grid.Add(new PathTile("01"), 1, i);
        }

        for (int x = 0; x < grid.Objects.GetLength(0); x++)
        {
            for (int y = 0; y < grid.Objects.GetLength(1); y++)
            {
                if (grid.Objects[x, y] != null)
                {
                    grid.Objects[x, y].Position -= new Vector3(0, 0, GameObjectGrid.CellWidth * part / 60);
                    if (grid.Objects[x, y] is WallTile)
                    {
                        grid.Objects[x, y].Position += new Vector3(0, 200, 0);
                    }
                }
            }
        }

        level.Add(grid);

        level.Parent = this;

        foreach (GameObject obj in level.Objects)
        {
            obj.Parent = level;
        }
    }
Exemple #2
0
        public GameObjectGridState()
        {
            GOGrid = new GameObjectGrid(5, 5, 0);
            Add(GOGrid);
            GOGrid.CellHeight = 50;
            GOGrid.CellWidth  = 50;
            for (int i = 0; i < GOGrid.Rows; i++)
            {
                for (int x = 0; x < GOGrid.Columns; x++)
                {
                    GOGrid.Add(new SpriteGameObject("spr_player"), i, x);
                }
            }

            DH = new DrawingHelper();
        }
Exemple #3
0
    /// <summary>
    /// Method that loads all tiles into the tilefield
    /// </summary>
    /// <param name="tileStringList">string list with tile information given from the main method</param>
    /// <returns></returns>
    protected GameObjectGrid LoadTiles(List <string> tileStringList)
    {
        // Throw an exception if the given Tile string list is null
        if (tileStringList == null)
        {
            throw new NullReferenceException("The given Tile list was null");
        }
        string[] lineArray = tileStringList[0].Split(',');
        // Make a new tile field with x being the length of a line (the length) and the amount of lines the y direction
        GameObjectGrid tileField = new GameObjectGrid(tileStringList.Count, lineArray.Length - 1, 3, "TileField")
        {
            //values for the cell width and height, these are predetermined in the Tiled Map Editor, so are constants.
            CellWidth  = 50,
            CellHeight = 50
        };

        // Go through all given lines in the file, it is assumed here that it is in the correct form.
        int[,] IDlist = new int[tileField.Columns, tileField.Rows];

        for (int y = 0; y < tileField.Rows; y++)
        {
            lineArray = tileStringList[y].Split(',');
            for (int x = 0; x < tileField.Columns; x++)
            {
                IDlist[x, y] = int.Parse(lineArray[x]);
            }
        }

        // Go through each position in the ID list and give the correct tile for each ID, and in the end return the tileField to the invoker of this method
        for (int x = 0; x < tileField.Columns; x++)
        {
            for (int y = 0; y < tileField.Rows; y++)
            {
                Tile newtile;
                switch (IDlist[x, y])
                {
                case 1:
                    newtile = new Tile(TileType.BasicTile, "Assets/Sprites/Tiles/BasicTile1");     // add the correct id here later this is just an example
                    break;

                case 2:
                    newtile = new Tile(TileType.Brick, "Assets/Sprites/Tiles/TileBrick");
                    break;

                case 3:
                    newtile = new Tile(TileType.Ice, "Assets/Sprites/Tiles/TileIce1");
                    break;

                case 4:
                    newtile = new Tile(TileType.RockIce, "Assets/Sprites/Tiles/RockIce");
                    break;

                case 5:
                    newtile = new Tile(TileType.Water, "Assets/Sprites/Tiles/TileWater1");
                    break;

                case 6:
                    newtile = new Tile(TileType.CobbleStone, "Assets/Sprites/Tiles/TileCobbleStone1");
                    break;

                case 7:
                    newtile = new Tile(TileType.Wood, "Assets/Sprites/Tiles/TileWood1");
                    break;

                case 8:
                    newtile = new Tile(TileType.Grass, "Assets/Sprites/Tiles/TileGrass1");
                    break;

                case 99:
                    newtile = new Tile(TileType.BasicTile, "Assets/Sprites/Tiles/BasicTile1");
                    break;

                default: throw new NullReferenceException("the given ID " + IDlist[x, y] + " was not found in the preprogrammed IDs");
                }

                tileField.Add(newtile, x, y);
            }
        }
        return(tileField);
    }
    private void DrawEndless(int part,GameTime gameTime, SpriteBatch spriteBatch)
    {
        level = new Level();
        level.player = new Player(new Vector3(200, 200f, 200));

        GameObjectGrid grid = new GameObjectGrid(20,20,"grid");

        for (int i = 0; i < grid.Rows; i++)
        {
            grid.Add(new WallTile("01"), 0, i);
            grid.Add(new WallTile("01"), 2, i);
            grid.Add(new PathTile("01"), 1, i);
        }

        for (int x = 0; x < grid.Objects.GetLength(0); x++)
        {
            for (int y = 0; y < grid.Objects.GetLength(1); y++)
            {
                if (grid.Objects[x, y] != null)
                {
                    grid.Objects[x, y].Position -= new Vector3(0, 0, GameObjectGrid.CellWidth * part / 60);
                    if (grid.Objects[x, y] is WallTile)
                    {
                        grid.Objects[x, y].Position += new Vector3(0, 200, 0);
                    }
                }
            }
        }

        level.Add(grid);

        level.Parent = this;

        foreach (GameObject obj in level.Objects)
        {
            obj.Parent = level;
        }
    }
Exemple #5
0
        public Level(int levelIndex, StreamReader reader, int layer = 0, string id = "") : base(layer, id)
        {
            animals = new List <Animal>();
            sharks  = new List <SpriteGameObject>();

            Add(new SpriteGameObject("Sprites/spr_background_level"));

            string levelTitle = reader.ReadLine();
            string levelHelp  = reader.ReadLine();
            int    nrPairs    = int.Parse(reader.ReadLine());

            string[] stringList = reader.ReadLine().Split();
            int      width      = int.Parse(stringList[0]);
            int      height     = int.Parse(stringList[1]);

            GameObjectList playingField = new GameObjectList(1, "playingField")
            {
                Position = new Vector2((PenguinPairs.Screen.X - width * 73) / 2, 100)
            };

            Add(playingField);

            stringList = reader.ReadLine().Split();
            int hintX             = int.Parse(stringList[0]) - 1;
            int hintY             = int.Parse(stringList[1]) - 1;
            int hintDirection     = int.Parse(stringList[2]);
            SpriteGameObject hint = new SpriteGameObject("Sprites/spr_arrow_hint@4", 2, "hint", hintDirection)
            {
                Position = new Vector2(hintX, hintY) * new Vector2(73, 72)
            };

            playingField.Add(hint);

            GameObjectGrid tileField = new GameObjectGrid(height, width, 1, "tileField")
            {
                CellWidth = 73, CellHeight = 72
            };

            for (int row = 0; row < height; row++)
            {
                string currRow = reader.ReadLine();
                for (int col = 0; col < currRow.Length; col++)
                {
                    Tile t;
                    switch (currRow[col])
                    {
                    case '.':
                        tileField.Add(new Tile("Sprites/spr_field@2", 0, "", (row + col) % 2), col, row);
                        break;

                    case ' ':
                        tileField.Add(new Tile("Sprites/spr_wall")
                        {
                            Type = TileType.Background
                        }, col, row);
                        break;

                    case 'r':
                    case 'b':
                    case 'g':
                    case 'o':
                    case 'p':
                    case 'y':
                    case 'm':
                    case 'x':
                    case 'R':
                    case 'B':
                    case 'G':
                    case 'O':
                    case 'P':
                    case 'Y':
                    case 'M':
                    case 'X':
                        t = new Tile("Sprites/spr_field@2", 0, "", (row + col) % 2);
                        tileField.Add(t, col, row);
                        string assetName = "Sprites/spr_penguin@8";
                        if (char.IsUpper(currRow[col]))
                        {
                            assetName = "Sprites/spr_penguin_boxed@8";
                        }
                        Animal a = new Animal(assetName, 2, "", currRow[col]);
                        a.Position        = t.Position;
                        a.InitialPosition = t.Position;
                        playingField.Add(a);
                        animals.Add(a);
                        break;

                    case '@':
                        t = new Tile("Sprites/spr_field@2", 0, "", (row + col) % 2);
                        tileField.Add(t, col, row);
                        SpriteGameObject s = new SpriteGameObject("Sprites/spr_shark", 2)
                        {
                            Position = t.Position
                        };
                        playingField.Add(s);
                        sharks.Add(s);
                        break;

                    default:
                        tileField.Add(new Tile("Sprites/spr_wall")
                        {
                            Type = TileType.Wall
                        }, col, row);
                        break;
                    }
                }
            }

            playingField.Add(tileField);

            playingField.Add(new AnimalSelector(2, "animalSelector")
            {
                Visible = false
            });

            Add(new PairList(nrPairs, 1, "pairList")
            {
                Position = new Vector2(20, 15)
            });

            quitButton = new Button("Sprites/spr_button_quit", 1)
            {
                Position = new Vector2(1058, 20)
            };
            Add(quitButton);

            playingField.Add(new VisibilityTimer(hint, 0, "hintVisible"));
            hintButton = new Button("Sprites/spr_button_hint", 1, "hintButton")
            {
                Position = new Vector2(916, 20)
            };
            FirstMoveMade = false;
            Add(hintButton);
            retryButton = new Button("Sprites/spr_button_retry", 1, "retryButton")
            {
                Position = new Vector2(916, 20), Visible = false
            };
            Add(retryButton);

            SpriteGameObject helpField = new SpriteGameObject("Sprites/spr_help", 1);

            helpField.Position = new Vector2((PenguinPairs.Screen.X - helpField.Width) / 2, 780);
            Add(helpField);
            TextGameObject helpText = new TextGameObject("Fonts/HelpFont", 2)
            {
                Text = levelHelp.Replace('#', '\n'), Color = Color.DarkBlue
            };

            helpText.Position = new Vector2((PenguinPairs.Screen.X - helpText.Size.X) / 2, (90 - helpText.Size.Y) / 2 + 780);
            Add(helpText);
        }