Example #1
0
        private void Edit()
        {
            this.Map.Load();             // ゲーム中にマップを書き換える場合があるので、再ロードする。

            DDEngine.FreezeInput();
            DDUtils.SetMouseDispMode(true);
            LevelEditor.ShowDialog();

            int lastMouseX = DDMouse.X;
            int lastMouseY = DDMouse.Y;

            for (; ;)
            {
                if (LevelEditor.Dlg.XPressed)
                {
                    break;
                }

                // 廃止
                //if (DDKey.GetInput(DX.KEY_INPUT_E) == 1)
                //    break;

                I2Point cellPos = GameCommon.ToTablePoint(
                    DDGround.Camera.X + DDMouse.X,
                    DDGround.Camera.Y + DDMouse.Y
                    );

                MapCell cell = Game.I.Map.GetCell(cellPos);

                if (cell.IsDefault)
                {
                    // noop
                }
                else if (1 <= DDKey.GetInput(DX.KEY_INPUT_LSHIFT) && 1 <= DDKey.GetInput(DX.KEY_INPUT_LCONTROL)) // 左シフト・コントロール押下 -> 塗り潰し_L / 塗り潰し_R
                {
                    if (DDMouse.L.GetInput() == -1)                                                              // クリックを検出
                    {
                        this.Map.Save();                                                                         // 失敗を想定して、セーブしておく

                        switch (LevelEditor.Dlg.GetMode())
                        {
                        case LevelEditor.Mode_e.TILE:
                        {
                            string tileName = LevelEditor.Dlg.GetTile_L();

                            if (tileName != cell.TileName)
                            {
                                string targetTileName = cell.TileName;                                                 // cell.TileName は this.EditFill で変更される。

                                this.EditFill(
                                    cellPos,
                                    v => v.TileName == targetTileName,
                                    v =>
                                    {
                                        v.TileName = tileName;
                                        v.Tile     = TileCatalog.Create(tileName);
                                    }
                                    );
                            }
                        }
                        break;

                        case LevelEditor.Mode_e.ENEMY:
                        {
                            string enemyName = LevelEditor.Dlg.GetEnemy();

                            if (enemyName != cell.EnemyName)
                            {
                                string targetEnemyName = cell.EnemyName;                                                 // cell.EnemyName は this.EditFill で変更される。

                                this.EditFill(
                                    cellPos,
                                    v => v.EnemyName == targetEnemyName,
                                    v => v.EnemyName = enemyName
                                    );
                            }
                        }
                        break;

                        default:
                            throw null;                                     // never
                        }
                    }
                    else if (DDMouse.R.GetInput() == -1)         // クリックを検出
                    {
                        this.Map.Save();                         // 失敗を想定して、セーブしておく

                        switch (LevelEditor.Dlg.GetMode())
                        {
                        case LevelEditor.Mode_e.TILE:
                        {
                            string tileName = LevelEditor.Dlg.GetTile_R();

                            if (tileName != cell.TileName)
                            {
                                string targetTileName = cell.TileName;                                                 // cell.TileName は this.EditFill で変更される。

                                this.EditFill(
                                    cellPos,
                                    v => v.TileName == targetTileName,
                                    v =>
                                    {
                                        v.TileName = tileName;
                                        v.Tile     = TileCatalog.Create(tileName);
                                    }
                                    );
                            }
                        }
                        break;

                        case LevelEditor.Mode_e.ENEMY:
                            // none
                            break;

                        default:
                            throw null;                                     // never
                        }
                    }
                }
                else if (1 <= DDKey.GetInput(DX.KEY_INPUT_LSHIFT))                 // 左シフト押下 -> 移動 / none
                {
                    if (1 <= DDMouse.L.GetInput())
                    {
                        DDGround.Camera.X -= DDMouse.X - lastMouseX;
                        DDGround.Camera.Y -= DDMouse.Y - lastMouseY;

                        DDUtils.ToRange(ref DDGround.Camera.X, 0.0, this.Map.W * GameConsts.TILE_W - DDConsts.Screen_W);
                        DDUtils.ToRange(ref DDGround.Camera.Y, 0.0, this.Map.H * GameConsts.TILE_H - DDConsts.Screen_H);

                        DDGround.ICamera.X = SCommon.ToInt(DDGround.Camera.X);
                        DDGround.ICamera.Y = SCommon.ToInt(DDGround.Camera.Y);
                    }
                    else if (1 <= DDMouse.R.GetInput())
                    {
                        // none
                    }
                }
                else if (1 <= DDKey.GetInput(DX.KEY_INPUT_LCONTROL))                 // 左コントロール押下 -> スポイト_L / スポイト_R
                {
                    if (1 <= DDMouse.L.GetInput())
                    {
                        switch (LevelEditor.Dlg.GetMode())
                        {
                        case LevelEditor.Mode_e.TILE:
                            LevelEditor.Dlg.SetTile_L(cell.TileName);
                            break;

                        case LevelEditor.Mode_e.ENEMY:
                            LevelEditor.Dlg.SetEnemy(cell.EnemyName);
                            break;

                        default:
                            throw null;                                     // never
                        }
                    }
                    else if (1 <= DDMouse.R.GetInput())
                    {
                        switch (LevelEditor.Dlg.GetMode())
                        {
                        case LevelEditor.Mode_e.TILE:
                            LevelEditor.Dlg.SetTile_R(cell.TileName);
                            break;

                        case LevelEditor.Mode_e.ENEMY:
                            // none
                            break;

                        default:
                            throw null;                                     // never
                        }
                    }
                }
                else if (1 <= DDKey.GetInput(DX.KEY_INPUT_LALT))        // 左 ALT 押下 -> 自機ワープ / none
                {
                    if (DDMouse.L.GetInput() == -1)                     // クリックを検出
                    {
                        this.Player.X = cellPos.X * GameConsts.TILE_W + GameConsts.TILE_W / 2;
                        this.Player.Y = cellPos.Y * GameConsts.TILE_H + GameConsts.TILE_H / 2;

                        DDGround.EL.Add(SCommon.Supplier(Effects.中爆発(this.Player.X, this.Player.Y)));                         // アクションが分かるように
                    }
                    else if (1 <= DDMouse.R.GetInput())
                    {
                        // none
                    }
                }
                else                 // シフト系押下無し -> セット_L / セット_R (敵はクリア)
                {
                    if (1 <= DDMouse.L.GetInput())
                    {
                        switch (LevelEditor.Dlg.GetMode())
                        {
                        case LevelEditor.Mode_e.TILE:
                        {
                            string tileName = LevelEditor.Dlg.GetTile_L();

                            cell.TileName = tileName;
                            cell.Tile     = TileCatalog.Create(tileName);
                        }
                        break;

                        case LevelEditor.Mode_e.ENEMY:
                        {
                            string enemyName = LevelEditor.Dlg.GetEnemy();

                            cell.EnemyName = enemyName;
                        }
                        break;

                        default:
                            throw null;                                     // never
                        }
                    }
                    else if (1 <= DDMouse.R.GetInput())
                    {
                        switch (LevelEditor.Dlg.GetMode())
                        {
                        case LevelEditor.Mode_e.TILE:
                        {
                            string tileName = LevelEditor.Dlg.GetTile_R();

                            cell.TileName = tileName;
                            cell.Tile     = TileCatalog.Create(tileName);
                        }
                        break;

                        case LevelEditor.Mode_e.ENEMY:
                            cell.EnemyName = GameConsts.ENEMY_NONE;
                            break;

                        default:
                            throw null;                                     // never
                        }
                    }
                }

                if (DDKey.GetInput(DX.KEY_INPUT_S) == 1)                 // S キー --> Save
                {
                    this.Map.Save();

                    // 表示
                    {
                        int endFrame = DDEngine.ProcFrame + 60;

                        DDGround.EL.Add(() =>
                        {
                            DDPrint.SetDebug(0, 16);
                            DDPrint.SetBorder(new I3Color(0, 0, 0));
                            DDPrint.Print("セーブしました...");
                            DDPrint.Reset();

                            return(DDEngine.ProcFrame < endFrame);
                        });
                    }
                }
                if (DDKey.GetInput(DX.KEY_INPUT_L) == 1)                 // L キー --> Load
                {
                    this.Map.Load();

                    // 表示
                    {
                        int endFrame = DDEngine.ProcFrame + 60;

                        DDGround.EL.Add(() =>
                        {
                            DDPrint.SetDebug(0, 16);
                            DDPrint.SetBorder(new I3Color(0, 0, 0));
                            DDPrint.Print("ロードしました...");
                            DDPrint.Reset();

                            return(DDEngine.ProcFrame < endFrame);
                        });
                    }
                }

                DDCurtain.DrawCurtain();

                if (LevelEditor.Dlg.IsShowTile())
                {
                    this.DrawMap();
                }

                if (LevelEditor.Dlg.IsShowEnemy())
                {
                    LevelEditor.DrawEnemy();
                }

                lastMouseX = DDMouse.X;
                lastMouseY = DDMouse.Y;

                DDEngine.EachFrame();
            }
            DDEngine.FreezeInput();
            DDUtils.SetMouseDispMode(false);
            LevelEditor.CloseDialog();

            this.Map.Save();             // ★★★ マップをセーブする ★★★
        }
Example #2
0
        private static Map LoadMap(string[] mapLines, Dictionary <string, string> mapScripts)
        {
            if (mapLines.Length < 3)
            {
                throw new DDError();
            }

            if (mapLines.Length % 2 != 1)
            {
                throw new DDError();
            }

            if (mapLines.Select(line => line.Length).Distinct().Count() != 1)
            {
                throw new DDError();
            }

            for (int y = 0; y < mapLines.Length; y++)
            {
                string mapLine = mapLines[y];

                if (y == 0 || y == mapLines.Length - 1)
                {
                    if (Regex.IsMatch(mapLine, @"^\+(--\+)+$") == false)
                    {
                        throw new DDError();
                    }
                }
                else if (y % 2 == 0)
                {
                    if (Regex.IsMatch(mapLine, @"^\+((  |--|G-)\+)+$") == false)
                    {
                        throw new DDError();
                    }
                }
                else
                {
                    if (Regex.IsMatch(mapLine, @"^\|((  |[0-9A-Za-z]{2})[ \|G])+$") == false || mapLine.EndsWith("|") == false)
                    {
                        throw new DDError();
                    }
                }
            }
            int w = mapLines[0].Length / 3;
            int h = mapLines.Length / 2;

            Map map = new Map(w, h);

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    string s8 = mapLines[y * 2 + 0].Substring(x * 3 + 1, 2);
                    string s5 = mapLines[y * 2 + 1].Substring(x * 3 + 1, 2);
                    string s2 = mapLines[y * 2 + 2].Substring(x * 3 + 1, 2);
                    string s4 = mapLines[y * 2 + 1].Substring(x * 3 + 0, 1);
                    string s6 = mapLines[y * 2 + 1].Substring(x * 3 + 3, 1);

                    MapCell cell = map[x, y];

                    LoadWall_NS(cell.Wall_8, s8);
                    LoadWall_NS(cell.Wall_2, s2);
                    LoadWall_WE(cell.Wall_4, s4);
                    LoadWall_WE(cell.Wall_6, s6);

                    if (s5 == "  ")
                    {
                        // noop
                    }
                    else
                    {
                        string s5_2 = s5 + ":2";
                        string s5_4 = s5 + ":4";
                        string s5_6 = s5 + ":6";
                        string s5_8 = s5 + ":8";

                        LoadScript(mapScripts, s5_2, s => cell.Wall_2.Script = s);
                        LoadScript(mapScripts, s5_4, s => cell.Wall_4.Script = s);
                        LoadScript(mapScripts, s5_6, s => cell.Wall_6.Script = s);
                        LoadScript(mapScripts, s5_8, s => cell.Wall_8.Script = s);
                        LoadScript(mapScripts, s5, s => cell.Script          = s);
                    }
                }
            }
            return(map);
        }
Example #3
0
 public MapCell GetCell(I2Point pt, MapCell defCell)
 {
     return(this.GetCell(pt.X, pt.Y, defCell));
 }
Example #4
0
        public static void EachFrame()
        {
            I2Point pt   = Map.ToTablePoint(DDMouse.X + DDGround.ICamera.X, DDMouse.Y + DDGround.ICamera.Y);
            MapCell cell = Game.I.Map.GetCell(pt, null);

            if (cell == null)
            {
                return;
            }

            if (DDUtils.IsOutOfScreen(new D2Point(DDMouse.X, DDMouse.Y)))
            {
                return;
            }

            HideMenu = 1 <= DDKey.GetInput(DX.KEY_INPUT_LCONTROL) || 1 <= DDKey.GetInput(DX.KEY_INPUT_RCONTROL);

            if (HideMenu || DDUtils.IsOut(new D2Point(DDMouse.X, DDMouse.Y), MenuRect))
            {
                if (1 <= DDMouse.L.GetInput())
                {
                    if (InputWallFlag)
                    {
                        cell.Wall = Wall;
                    }
                    if (InputTileFlag)
                    {
                        cell.Tile = MapTileManager.GetTile(MapTileManager.GetNames()[TileIndex]);
                    }
                    if (InputEnemyFlag)
                    {
                        cell.EnemyLoader = EnemyManager.GetEnemyLoader(EnemyManager.GetNames()[EnemyIndex]);
                    }
                }
                if (1 <= DDMouse.R.GetInput())
                {
                    cell.Wall        = false;
                    cell.Tile        = null;
                    cell.EnemyLoader = null;
                }
            }
            else
            {
                int cursorMenuItemIndex = DDMouse.Y / 16;

                bool l = 1 <= DDMouse.L.GetInput();
                bool r = 1 <= DDMouse.R.GetInput();

                if (l || r)
                {
                    bool flag = l;

                    switch (cursorMenuItemIndex)
                    {
                    case 0: InputWallFlag = flag; break;

                    case 1: InputTileFlag = flag; break;

                    case 2: InputEnemyFlag = flag; break;

                    case 3: DisplayWallFlag = flag; break;

                    case 4: DisplayTileFlag = flag; break;

                    case 5: DisplayEnemyFlag = flag; break;

                    case 6: Wall = flag; break;

                    case 7:
                    case 8:
                        IntoInputTileMode();
                        break;

                    case 9:
                    case 10:
                        IntoInputEnemyMode();
                        break;
                    }
                }

                Rot += DDMouse.Rot;

                if (DDMouse.Rot == 0)
                {
                    NoRotFrame++;
                }
                else
                {
                    NoRotFrame = 0;
                }

                if (90 < NoRotFrame)
                {
                    Rot = 0;
                }

                switch (cursorMenuItemIndex)
                {
                case 7:
                case 8:
                    if (MenuItemRot(ref TileIndex, MapTileManager.GetCount()))
                    {
                        IntoInputTileMode();
                    }
                    break;

                case 9:
                case 10:
                    if (MenuItemRot(ref EnemyIndex, EnemyManager.GetCount()))
                    {
                        IntoInputEnemyMode();
                    }
                    break;
                }
            }

            if (DDKey.GetInput(DX.KEY_INPUT_C) == 1)
            {
                if (InputWallFlag)
                {
                    Wall = cell.Wall;
                }
                if (InputTileFlag)
                {
                    TileIndex = cell.Tile == null ? 0 : MapTileManager.GetNames().IndexOf(cell.Tile.Name);
                }
                if (InputEnemyFlag)
                {
                    EnemyIndex = cell.EnemyLoader == null ? 0 : EnemyManager.GetNames().IndexOf(cell.EnemyLoader.Name);
                }

                if (TileIndex == -1)                 // 2bs
                {
                    TileIndex = 0;
                }

                if (EnemyIndex == -1)                 // 2bs
                {
                    EnemyIndex = 0;
                }
            }
            if (DDKey.GetInput(DX.KEY_INPUT_S) == 1)
            {
                MapLoader.SaveToLastLoadedFile(Game.I.Map);
            }
        }
Example #5
0
        public static string LastLoadedFile = null;         // null == 未読み込み

        public static Map Load(string file)
        {
            LastLoadedFile = file;

            string[] lines = FileTools.TextToLines(Encoding.UTF8.GetString(DDResource.Load(file)));
            int      c     = 0;

            int w = int.Parse(lines[c++]);
            int h = int.Parse(lines[c++]);

            if (w < 1 || IntTools.IMAX < w)
            {
                throw new DDError();
            }
            if (h < 1 || IntTools.IMAX < h)
            {
                throw new DDError();
            }

            Map map = new Map(w, h);

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    if (lines.Length <= c)
                    {
                        goto endLoad;
                    }

                    MapCell cell   = map.GetCell(x, y);
                    var     tokens = new BluffList <string>(lines[c++].Split('\t')).FreeRange("");                // 項目が増えても良いように -> FreeRange("")
                    int     d      = 0;

                    cell.Wall        = int.Parse(tokens[d++]) != 0;
                    cell.Tile        = MapTileManager.GetTile(tokens[d++]);
                    cell.EnemyLoader = EnemyManager.GetEnemyLoader(tokens[d++]);

                    // 新しい項目をここへ追加...
                }
            }
            while (c < lines.Length)
            {
                // memo: Save()時にプロパティ部分も上書きされるので注意してね。

                var tokens = lines[c++].Split("=".ToArray(), 2);

                string name  = tokens[0].Trim();
                string value = tokens[1].Trim();

                if (name == "")
                {
                    throw new DDError();
                }
                if (value == "")
                {
                    throw new DDError();
                }

                map.AddProperty(name, value);
            }
endLoad:
            return(map);
        }