Example #1
0
 public void MoveObject(int x, int y, int newX, int newY, GameObject obj)
 {
     if (isInitialized)
     {
         if (mapBlockData != null)
         {
             if (newX >= 0 && newX < mapBlockData.getRows() &&
                 newY >= 0 && newY < mapBlockData.getCols())
             {
                 AddObject(newX, newY, obj);
                 RemoveObject(x, y, obj);
             }
             else
             {
                 // move object to a different BlockView
                 this.asciiMapScript.MoveObject(newX, newY, obj);
                 RemoveObject(x, y, obj);
             }
         }
     }
 }
Example #2
0
        public IEnumerator Initialize(int blockX, int blockY, MapBlockData mapBlockData, String mapPath, YieldDirection yieldDirection, ResourceManager resourceManager, AsciiMapScript asciiMapScript)
        {
            this.blockX          = blockX;
            this.blockY          = blockY;
            this.mapBlockData    = mapBlockData;
            this.mapPath         = mapPath;
            this.resourceManager = resourceManager;
            this.asciiMapScript  = asciiMapScript;
            this.mapfile         = new MapFile();
            if (this.prefabWall == null)
            {
                this.prefabWall = resourceManager.getGameObject("Main/Wall");
            }
            if (this.prefabWorldWall == null)
            {
                this.prefabWorldWall = resourceManager.getGameObject("Main/worldwall");
            }

            if (mapBlockData == null)
            {
                // Empty map blocks will display as walls
                CreateMapObject((MapRows / 2), (MapCols / 2), prefabWorldWall, this.gameObject, "Main/WorldWall", 6, MapLayer.Floor);
            }
            else
            {
                if (yieldDirection == YieldDirection.YieldRight)
                {
                    for (int x = 0; x < mapBlockData.getRows(); x++)
                    {
                        if (this != null)
                        {
                            for (int y = 0; y < mapBlockData.getCols(); y++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else if (yieldDirection == YieldDirection.YieldLeft)
                {
                    for (int x = mapBlockData.getRows() - 1; x >= 0; x--)
                    {
                        if (this != null)
                        {
                            for (int y = 0; y < mapBlockData.getCols(); y++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else if (yieldDirection == YieldDirection.YieldDown)
                {
                    if (this != null)
                    {
                        for (int y = 0; y < mapBlockData.getCols(); y++)
                        {
                            for (int x = 0; x < mapBlockData.getRows(); x++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else if (yieldDirection == YieldDirection.YieldUp)
                {
                    for (int y = mapBlockData.getCols() - 1; y >= 0; y--)
                    {
                        if (this != null)
                        {
                            for (int x = 0; x < mapBlockData.getRows(); x++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else
                {
                    for (int x = 0; x < mapBlockData.getRows(); x++)
                    {
                        if (this != null)
                        {
                            for (int y = 0; y < mapBlockData.getCols(); y++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
            }
            isInitialized = true;
            // Spawn a zombie
            if (blockX == 3 && blockY == 3 && this != null)
            {
                CreateMapObject(5, 10, resourceManager.getGameObject("main/zombie"), this.gameObject, "main/zombie", 7, MapLayer.Main);
                //	CreateMapObject (5, 5, resourceManager.getGameObject ("main/npc"), this.gameObject, "main/npc", 7, MapLayer.Main);
            }
        }