Ejemplo n.º 1
0
        static void MapInitialize(ref Map map)
        {
            map.Clear();

            for (int m = 0; m < map.Dimension.Y; m++)
            {
                Row row = new Row();

                for (int c = 0; c < map.Dimension.X; c++)
                {
                    row.Add(new Tile());
                }

                map.Add(row);
            }

            Generate(GetGameObject("tree"), ref map, 5);
            Generate(GetGameObject("boulder"), ref map, 3);
            Generate(GetGameObject("chest"), ref map, 0.5f);


            //spawn the player
            playerPos = new VectorTwoInt(random.Next(map.Dimension.X), random.Next(map.Dimension.Y));


            //mapList[playerY] = mapList[playerY].Substring(0, playerX) + "p" + mapList[playerY].Substring(playerX + 1);
            PlaceGameObject(ref map, GetGameObject("player"), playerPos);
        }
Ejemplo n.º 2
0
        static List <GameObject> ReturnObjsAtPos(VectorTwoInt pos, Map map)
        {
            List <GameObject> list = new List <GameObject>();

            list.AddRange(map[pos.Y][pos.X]);

            return(list);
        }
Ejemplo n.º 3
0
        static bool IsObjectAtPos(VectorTwoInt pos, Map map)
        {
            if (ReturnObjsAtPos(pos, map) == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        static bool IsObjectAtPos(GameObject gameObject, VectorTwoInt pos, Map map)
        {
            if (ReturnObjsAtPos(pos, map).Contains(gameObject))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        static void Generate(GameObject gameObject, ref Map map, float precentOfTiles)
        {
            for (int i = 0; i < map.Dimension.X * map.Dimension.Y / 100 * precentOfTiles; i++)
            {
                VectorTwoInt randomPos = RandPos(map);

                if (!IsObjectAtPos(gameObject, randomPos, map))
                {
                    PlaceGameObject(ref map, gameObject, randomPos);
                }

                else
                {
                    i--;
                }
            }
        }
Ejemplo n.º 6
0
 static void PlaceGameObject(ref Map map, GameObject gameObject, VectorTwoInt pos)
 {
     map[pos.Y][pos.X].Add(gameObject);
 }