private Queue <IAction> ActionToWarp()
        {
            Queue <IAction> actions = new Queue <IAction>();

            if (this._path.Count == 0)
            {
                this.FindPathToNextLocation();
            }

            ILocationParser next = this._path.Dequeue();

            IList <Warp> warps = this._ordered[this._current].GetWarps();

            foreach (Warp warp in warps)
            {
                if (warp.TargetName == next.GetName())
                {
                    IAction action = new ActionTile(null, this._ordered[this._current].WarpToTile(warp), this._ordered[this._current], ActionType.Navigate);
                    actions.Enqueue(action);
                    break;
                }
            }

            return(actions);
        }
示例#2
0
        override protected void Update()
        {
            //code smells bad here
            while (Console.KeyAvailable)
            {
                Console.ReadKey(false);
            }

            ConsoleKeyInfo input = Console.ReadKey();

            Hero h = CurrentLevel.GetHero();

            switch (input.Key)
            {
            case ConsoleKey.LeftArrow:
                Vector2d left = new Vector2d(h.Position.X - 1, h.Position.Y);
                h.Move(left, CurrentLevel.getTileAt((int)left.X, (int)left.Y));
                break;

            case ConsoleKey.RightArrow:
                Vector2d right = new Vector2d(h.Position.X + 1, h.Position.Y);
                h.Move(right, CurrentLevel.getTileAt((int)right.X, (int)right.Y));
                break;

            case ConsoleKey.UpArrow:
                Vector2d up = new Vector2d(h.Position.X, h.Position.Y - 1);
                h.Move(up, CurrentLevel.getTileAt((int)up.X, (int)up.Y));
                break;

            case ConsoleKey.DownArrow:
                Vector2d down = new Vector2d(h.Position.X, h.Position.Y + 1);
                h.Move(down, CurrentLevel.getTileAt((int)down.X, (int)down.Y));
                break;

            case ConsoleKey.Spacebar:
                ActionTile a = h.onTile as ActionTile;
                if (a != null)
                {
                    a.getAction();
                }
                break;

            default:
                break;
            }



            Draw();
        }
示例#3
0
    public void Render(Grid grid)
    {
        Actions = new Dictionary <string, string>();

        for (int l = 0; l < Layers.Count; l++)
        {
            Tilemap map = grid.transform.Find("Tilemap_" + LayerNames[l]).gameObject.GetComponent <Tilemap>();
            map.origin = new Vector3Int(0, 0, 0);
            map.size   = new Vector3Int(0, 0, 0);
            map.ResizeBounds();

            int x, y;
            for (x = 0; x < MapWidth; x++)
            {
                for (y = 0; y < MapHeight; y++)
                {
                    try
                    {
                        int        tileID = Layers[l].Cells[x, y];
                        string     action = Layers[l].Actions[x, y];
                        ActionTile tile   = Resources.Load <ActionTile>("Maps/" + SpriteSheetName + "/" + SpriteSheetName + "_Tile_" + tileID.ToString());
                        if (action != "")
                        {
                            Actions.Add(String.Format("{0}({1}, {2}, 0)", LayerNames[l], x, y), action);
                        }

                        map.SetTile(new Vector3Int(x, y, 0), tile);
                    }
                    catch
                    {
                        Debug.Log(String.Format("Failed to place tile @ {0}, {1} on layer {2}", x, y, LayerNames[l]));
                    }
                }
            }
        }

        // Set Camera Bounds
        GameObject         camgo  = GameObject.FindGameObjectWithTag("MainCamera");
        PixelPerfectCamera camera = camgo.GetComponent <PixelPerfectCamera>();

        float minX = (float)camera.refResolutionX / TileWidth / 2;
        float minY = (float)camera.refResolutionY / TileHeight / 2;
        float maxX = (float)MapWidth - minX;
        float maxY = (float)MapHeight - minY;

        CameraController controller = camgo.GetComponent <CameraController>();

        controller.minPosition = new Vector2(minX, minY);
        controller.maxPosition = new Vector2(maxX, maxY);
    }
示例#4
0
        public override void CreateBoard()
        {
            ITile       tile   = new ActionTile("GO Collect £200", this);
            IGameAction action = new ReceiveMoneyAction("Collect £200", 200, GetGame());

            tile.AddAction(action);
            base.GetTiles().Add(tile);

            ProperityDeed deed      = new ProperityDeed(2, 10, 30, 90, 160, 250, 30, 30, 50);
            Properity     properity = new Properity(200, deed, ColorSets.brown);

            tile   = new ProperityTile("Old Kent", this, properity);
            action = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            deed      = new ProperityDeed(4, 20, 60, 180, 360, 450, 30, 30, 50);
            properity = new Properity(200, deed, ColorSets.brown);
            tile      = new ProperityTile("Whitechapel Road", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            tile   = new SimpleTile("Community Chest", this);
            action = new CommunityChestPickCard("Pick Community Chest Card", GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);

            tile   = new ActionTile("Income Tax (Pay 10% or $200)", this);
            action = new ReceiveMoneyAction("Income Tax (Pay 10% or $200)", -200, GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);

            //TODO: change tile to utility
            tile = new SimpleTile("King's Cross Station", this);
            base.GetTiles().Add(tile);


            deed      = new ProperityDeed(6, 30, 90, 270, 400, 550, 50, 50, 50);
            properity = new Properity(100, deed, ColorSets.lightblue);
            tile      = new ProperityTile("The Angel Islington", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);



            tile   = new SimpleTile("Chance", this);
            action = new ChancePickACard("Pick Chance Card", GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);


            deed      = new ProperityDeed(6, 30, 90, 270, 400, 550, 50, 50, 50);
            properity = new Properity(100, deed, ColorSets.lightblue);
            tile      = new ProperityTile("Euston Road", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            deed      = new ProperityDeed(8, 40, 100, 300, 450, 600, 50, 50, 60);
            properity = new Properity(120, deed, ColorSets.lightblue);
            tile      = new ProperityTile("Pentonville Road", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            //TODO: change tile to utility
            tile = new SimpleTile("Jail/Just Visiting", this);
            base.GetTiles().Add(tile);

            deed      = new ProperityDeed(10, 50, 150, 450, 625, 750, 100, 100, 70);
            properity = new Properity(140, deed, ColorSets.pink);
            tile      = new ProperityTile("Pall Mall", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            //TODO: change tile to utility
            tile = new SimpleTile("Electric Company", this);
            base.GetTiles().Add(tile);

            deed      = new ProperityDeed(10, 50, 150, 450, 625, 750, 100, 100, 70);
            properity = new Properity(140, deed, ColorSets.pink);
            tile      = new ProperityTile("Whitehall", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            deed      = new ProperityDeed(12, 60, 180, 500, 700, 900, 100, 100, 80);
            properity = new Properity(160, deed, ColorSets.pink);
            tile      = new ProperityTile("Northumberland Avenue", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            //TODO: change tile to utility
            tile = new SimpleTile("Marylebone Station", this);
            base.GetTiles().Add(tile);


            deed      = new ProperityDeed(14, 70, 200, 550, 750, 950, 100, 100, 90);
            properity = new Properity(180, deed, ColorSets.orange);
            tile      = new ProperityTile("Bow Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            tile   = new SimpleTile("Community Chest", this);
            action = new CommunityChestPickCard("Pick Community Chest Card", GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);



            deed      = new ProperityDeed(14, 70, 200, 550, 750, 950, 100, 100, 90);
            properity = new Properity(180, deed, ColorSets.orange);
            tile      = new ProperityTile("Marlborough Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            deed      = new ProperityDeed(16, 80, 220, 600, 800, 1000, 100, 100, 100);
            properity = new Properity(200, deed, ColorSets.orange);
            tile      = new ProperityTile("Vine Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            tile = new SimpleTile("Free Parking", this);
            base.GetTiles().Add(tile);

            deed      = new ProperityDeed(18, 90, 250, 700, 875, 1050, 150, 150, 110);
            properity = new Properity(220, deed, ColorSets.red);
            tile      = new ProperityTile("Strand", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            tile   = new SimpleTile("Chance", this);
            action = new ChancePickACard("Pick Chance Card", GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);



            deed      = new ProperityDeed(18, 90, 250, 700, 875, 1050, 150, 150, 110);
            properity = new Properity(220, deed, ColorSets.red);
            tile      = new ProperityTile("Fleet Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            deed      = new ProperityDeed(20, 100, 300, 750, 925, 1100, 150, 150, 120);
            properity = new Properity(240, deed, ColorSets.red);
            tile      = new ProperityTile("Trafalgar Square", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            //TODO: change tile to utility
            tile = new SimpleTile("Fenchurch St. Station", this);
            base.GetTiles().Add(tile);

            deed      = new ProperityDeed(22, 110, 330, 800, 975, 1150, 150, 150, 150);
            properity = new Properity(260, deed, ColorSets.yellow);
            tile      = new ProperityTile("Leicester Square", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            deed      = new ProperityDeed(22, 110, 330, 800, 975, 1150, 150, 150, 150);
            properity = new Properity(260, deed, ColorSets.yellow);
            tile      = new ProperityTile("Coventry Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            //TODO: change tile to utility
            tile = new SimpleTile("Water Works", this);
            base.GetTiles().Add(tile);


            deed      = new ProperityDeed(22, 120, 360, 850, 1025, 1200, 140, 140, 150);
            properity = new Properity(280, deed, ColorSets.yellow);
            tile      = new ProperityTile("Piccadilly", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            //TODO: change tile to utility
            tile = new SimpleTile("Go to Jail", this);
            GetTiles().Add(tile);


            deed      = new ProperityDeed(26, 130, 390, 900, 1100, 1275, 150, 150, 200);
            properity = new Properity(300, deed, ColorSets.green);
            tile      = new ProperityTile("Regent Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            deed      = new ProperityDeed(26, 130, 390, 900, 1100, 1275, 150, 150, 200);
            properity = new Properity(300, deed, ColorSets.green);
            tile      = new ProperityTile("Oxford Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);


            tile   = new SimpleTile("Community Chest", this);
            action = new CommunityChestPickCard("Pick Community Chest Card", GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);


            deed      = new ProperityDeed(28, 150, 450, 1000, 1200, 1400, 160, 160, 200);
            properity = new Properity(320, deed, ColorSets.green);
            tile      = new ProperityTile("Bond Street", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);

            //TODO: change tile to utility
            tile = new SimpleTile("Liverpool Street Station", this);
            base.GetTiles().Add(tile);

            tile   = new SimpleTile("Chance", this);
            action = new ChancePickACard("Pick Chance Card", GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);


            deed      = new ProperityDeed(35, 175, 500, 1100, 1300, 1500, 200, 200, 175);
            properity = new Properity(350, deed, ColorSets.blue);
            tile      = new ProperityTile("Park Lane", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);



            tile   = new ActionTile("Super Tax (Pay £100)", this);
            action = new ReceiveMoneyAction("Super Tax(Pay £100)", -100, GetGame());
            tile.AddAction(action);
            base.GetTiles().Add(tile);

            deed      = new ProperityDeed(50, 200, 600, 1400, 1700, 2000, 200, 200, 200);
            properity = new Properity(400, deed, ColorSets.blue);
            tile      = new ProperityTile("Mayfair", this, properity);
            action    = new PayRent("Pay Rent", tile, GetGame());
            tile.AddAction(action);
            GetTiles().Add(tile);
        }
示例#5
0
    private static void ImportEditorMaps()
    {
        string path = EditorUtility.OpenFolderPanel("Import Sprite Editor Maps", "", "");

        string[]      mapFolders       = Directory.GetDirectories(path);
        List <string> foldersToProcess = new List <string>();

        // Determin Order of Import
        foreach (string mapFolder in mapFolders)
        {
            string unityFolder = mapFolder + "\\Unity";
            string mapName     = mapFolder.Substring(mapFolder.IndexOf("\\") + 1).Replace(" ", "_");

            if (Directory.Exists(unityFolder))
            {
                if (File.Exists(unityFolder + "\\" + mapName + ".png"))
                {
                    foldersToProcess.Insert(0, unityFolder);
                }
                else
                {
                    foldersToProcess.Add(unityFolder);
                }
            }
        }

        foreach (string unityFolder in foldersToProcess)
        {
            string mapFolder = unityFolder.Replace("\\Unity", "");
            string mapName   = mapFolder.Substring(mapFolder.IndexOf("\\") + 1).Replace(" ", "_");

            MapInfo   mapInfo        = null;
            Sheet     sheet          = null;
            Texture2D texture        = null;
            bool      hasSpriteSheet = false;

            bool needUpdate = ReadJsonFile(unityFolder, mapName, ref texture, ref sheet, ref mapInfo, ref hasSpriteSheet);

            if (needUpdate)
            {
                if (hasSpriteSheet)
                {
                    // Add the image to the assets library
                    texture.name = mapName;
                    var    bytes     = texture.EncodeToPNG();
                    string assetPath = "Assets/Resources/Maps/" + mapName + "/";

                    if (!Directory.Exists(assetPath))
                    {
                        Directory.CreateDirectory(assetPath);
                    }

                    string fileName = assetPath + mapName + ".png";
                    File.WriteAllBytes(fileName, bytes);
                    AssetDatabase.Refresh();
                    AssetDatabase.ImportAsset(fileName);
                    TextureImporter importer = AssetImporter.GetAtPath(fileName) as TextureImporter;
                    if (importer.spriteImportMode == SpriteImportMode.Multiple)
                    {
                        importer.spriteImportMode = SpriteImportMode.Single;
                        AssetDatabase.WriteImportSettingsIfDirty(fileName);
                    }
                    TextureImporterSettings settings = new TextureImporterSettings();
                    importer.ReadTextureSettings(settings);
                    settings.spriteGenerateFallbackPhysicsShape = false;
                    importer.SetTextureSettings(settings);

                    importer.spriteImportMode    = SpriteImportMode.Multiple;
                    importer.textureType         = TextureImporterType.Sprite;
                    importer.spritePixelsPerUnit = sheet.CellWidth;

                    // Build Sprite Sheet
                    Rect[] rects = InternalSpriteUtility.GenerateGridSpriteRectangles(texture, new Vector2(0, 0), new Vector2(sheet.CellWidth, sheet.CellHeight), new Vector2(0, 0), true);

                    var metas   = new List <SpriteMetaData>();
                    int rectNum = 0;

                    foreach (Rect rect in rects)
                    {
                        var meta = new SpriteMetaData();
                        meta.pivot     = Vector2.zero;
                        meta.alignment = (int)SpriteAlignment.Center;
                        meta.rect      = rect;
                        meta.name      = mapName + "_" + rectNum++;
                        metas.Add(meta);
                    }

                    importer.spritesheet = metas.ToArray();

                    AssetDatabase.ImportAsset(fileName, ImportAssetOptions.ForceUpdate);

                    // Set Physics Shapes
                    UnityEngine.Object[] sprites = AssetDatabase.LoadAllAssetsAtPath("Assets/Resources/Maps/" + mapName + "/" + mapName + ".png");

                    for (int i = 0; i < sprites.Length; i++)
                    {
                        Sprite sprite = sprites[i] as Sprite;

                        if (sprite != null)
                        {
                            try
                            {
                                int            idx    = Convert.ToInt32(sprite.name.Substring(sprite.name.LastIndexOf('_') + 1));
                                List <Vector2> points = new List <Vector2>();
                                if (sheet.Masks[idx].Count > 0)
                                {
                                    for (int e = 0; e < sheet.Masks[idx].Count; e++)
                                    {
                                        Vector2Int pt = sheet.MaskPoints[sheet.Masks[idx][e]];
                                        float      x  = (float)pt.x;
                                        if (x == (sheet.CellWidth / 2) - 1 || x == sheet.CellWidth - 1)
                                        {
                                            x++;
                                        }
                                        x = 0 - ((sheet.CellWidth / 2) - x);

                                        float y = (float)pt.y;
                                        if (y == (sheet.CellHeight / 2) - 1 || y == sheet.CellHeight - 1)
                                        {
                                            y++;
                                        }
                                        y = y + (sheet.CellHeight / 2);

                                        points.Add(new Vector2(x, sheet.CellHeight - y));
                                    }

                                    var spritePhysicsShapeImporter = new SpritePhysicsShapeImporter(importer);
                                    spritePhysicsShapeImporter.SetPhysicsShape(idx, new List <Vector2[]>()
                                    {
                                        points.ToArray()
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.LogError(ex.Message);
                            }
                        }
                    }

                    AssetDatabase.ImportAsset(fileName, ImportAssetOptions.ForceUpdate);

                    // Build Tiles
                    AssetDatabase.StartAssetEditing();

                    // Initialise Array
                    sprites = AssetDatabase.LoadAllAssetsAtPath("Assets/Resources/Maps/" + mapName + "/" + mapName + ".png");
                    List <Tile> tiles = new List <Tile>();
                    for (int i = 0; i < sprites.Length; i++)
                    {
                        tiles.Add(null);
                    }

                    for (int i = 0; i < sprites.Length; i++)
                    {
                        Sprite sprite = sprites[i] as Sprite;

                        if (sprite != null)
                        {
                            try
                            {
                                int        idx  = Convert.ToInt32(sprite.name.Substring(sprite.name.LastIndexOf('_') + 1));
                                ActionTile tile = ScriptableObject.CreateInstance <ActionTile>();
                                tile.colliderType = sheet.Masks[idx].Count == 0 ? Tile.ColliderType.None : Tile.ColliderType.Sprite;
                                tile.hideFlags    = HideFlags.None;
                                tile.sprite       = sprite;
                                tile.name         = sprite.name;

                                path = "Assets/Resources/Maps/" + mapName + "/" + mapName + "_Tile_" + idx.ToString() + ".asset";
                                AssetDatabase.CreateAsset(tile, path);
                            }
                            catch (Exception ex)
                            {
                                Debug.LogError(ex.Message);
                            }
                        }
                    }

                    AssetDatabase.StopAssetEditing();
                }

                // Create Map GameObject
                GameObject go  = new GameObject(mapName);
                MapObject  map = go.AddComponent <MapObject>();

                map.Name            = mapName;
                map.SpriteSheetName = mapInfo.SpriteSheetName;
                map.MapWidth        = mapInfo.MapWidth;
                map.MapHeight       = mapInfo.MapHeight;
                map.TileWidth       = mapInfo.CellWidth;
                map.TileHeight      = mapInfo.CellHeight;

                // Add Points of Interest
                foreach (PointOfInterest poi in mapInfo.POI)
                {
                    map.PointOfInterestNames.Add(poi.Name);
                    map.PointsOfInterest.Add(new POI()
                    {
                        Name = poi.Name, Location = new Vector2Int(poi.x, poi.y)
                    });
                }

                ////public Dictionary<string, NPCController.NPC> NPCs = new Dictionary<string, NPCController.NPC>();
                ////public List<List<bool>> PathFindingGrid = new List<List<bool>>();

                // Store Map Layers and Cells Information
                string json = JsonConvert.SerializeObject(mapInfo.Layers);
                map.LayersJson = json;

                // Store Tile Attributes Information
                if (hasSpriteSheet)
                {
                    json             = JsonConvert.SerializeObject(sheet.MetaData);
                    map.MetaDataJson = json;
                }

                // Store NPC Json
                map.NPCJson = JsonConvert.SerializeObject(mapInfo.NPC);

                // Create Prefab
                string localPath = "Assets/Resources/Maps/" + mapName + ".prefab";
                PrefabUtility.SaveAsPrefabAsset(go, localPath);

                // Delete Update file
                File.Delete(unityFolder + "\\" + mapName + "_update.txt");
            }
        }
    }