Ejemplo n.º 1
0
        OverworldObj CreateObj(Type type, Vector2 pos)
        {
            OverworldObj obj = (OverworldObj)Activator.CreateInstance(type);

            obj.Pos        = pos;
            obj.EditorMode = true;

            return(obj);
        }
Ejemplo n.º 2
0
        public static Terrain LoadMap(string fileName, bool editorMode)
        {
            foreach (OverworldObj obj in Objects.GetList <OverworldObj>())
            {
                Objects.Destroy(obj);
            }
            foreach (Terrain obj in Objects.GetList <Terrain>())
            {
                Objects.Destroy(obj);
            }


            byte[] buffer = File.ReadAllBytes(fileName);

            int pointer = 0;

            #region Loading terrain

            int terrW, terrH;

            terrW = ReadInt(buffer, ref pointer);
            terrH = ReadInt(buffer, ref pointer);

            Terrain terrain = new Terrain(terrW, terrH);

            for (var x = 0; x < terrW; x += 1)
            {
                for (var y = 0; y < terrH; y += 1)
                {
                    terrain.TileMap[x, y].Type            = (Tile.TileType)ReadInt(buffer, ref pointer);
                    terrain.TileMap[x, y].Char            = ReadChar(buffer, ref pointer);
                    terrain.TileMap[x, y].ForegroundColor = new Color(ReadUInt(buffer, ref pointer));
                    terrain.TileMap[x, y].BackgroundColor = new Color(ReadUInt(buffer, ref pointer));
                }
            }

            terrain.FixColors();
            #endregion Loading terrain


            #region Loading objects

            int objCount = ReadInt(buffer, ref pointer);

            for (var i = 0; i < objCount; i += 1)
            {
                int    strLen    = ReadInt(buffer, ref pointer);           // Class string length.
                string className = ReadString(buffer, ref pointer, strLen);

                Vector2 pos = Vector2.Zero;

                pos.X = ReadInt(buffer, ref pointer);
                pos.Y = ReadInt(buffer, ref pointer);

                strLen = ReadInt(buffer, ref pointer);                 // Class string length.
                string argument = ReadString(buffer, ref pointer, strLen);

                OverworldObj obj = (OverworldObj)Activator.CreateInstance(Type.GetType(className));
                obj.Pos        = pos;
                obj.EditorMode = editorMode;
                obj.Argument   = argument;
                if (!editorMode)
                {
                    obj.ProccessArgument();
                }
            }

            #endregion Loading objects

            return(terrain);
        }
Ejemplo n.º 3
0
        public override void Update()
        {
            #region Tiles
            if (CurrentMode == Mode.Tiles)
            {
                if ((Input.MouseCheck(Input.MB.Left) && !Input.KeyboardCheck(Keys.LeftControl)) ||
                    Input.MouseCheckPress(Input.MB.Left))
                {
                    if (Terrain.InBounds(TileMousePos))
                    {
                        Tile tile = Terrain.GetTile(TileMousePos);

                        if (Input.KeyboardCheck(TilePickHotkey))
                        {
                            CurrentChar = tile.Char;

                            for (var i = 0; i < Palettes.Length; i += 1)
                            {
                                if (Palettes[i][0] == tile.ForegroundColor && Palettes[i][1] == tile.BackgroundColor)
                                {
                                    CurrentPalette = i;
                                    break;
                                }
                            }
                            ClickBlock = true;
                        }
                        else
                        {
                            if (!Input.KeyboardCheck(Keys.LeftAlt))
                            {
                                tile.Char = CurrentChar;
                            }
                            tile.ForegroundColor = Palettes[CurrentPalette][0];
                            tile.BackgroundColor = Palettes[CurrentPalette][1];
                        }
                    }
                    else
                    {
                        ExpandMap();
                    }
                }


                if (Input.KeyboardCheckPress(PalettesHotkey))
                {
                    SelectionMenuActive = true;
                    SelectionMenuMode   = 0;
                }

                if (Input.KeyboardCheckPress(CharsHotkey))
                {
                    SelectionMenuActive = true;
                    SelectionMenuMode   = 1;
                }
            }
            #endregion Tiles



            #region Collision
            if (CurrentMode == Mode.Collision)
            {
                if (Input.MouseCheck(Input.MB.Left) || Input.MouseCheck(Input.MB.Right))
                {
                    if (Terrain.InBounds(TileMousePos))
                    {
                        Tile tile = Terrain.GetTile(TileMousePos);

                        if (Input.MouseCheck(Input.MB.Left))
                        {
                            tile.Type = Tile.TileType.Solid;
                        }
                        else
                        {
                            tile.Type = Tile.TileType.Passable;
                        }
                    }
                    else
                    {
                        ExpandMap();
                    }
                }
            }

            if (Input.KeyboardCheckPress(ToggleSolidDisplayHotkey))
            {
                Terrain.DisplaySolids = !Terrain.DisplaySolids;
            }
            #endregion Collision



            #region Objects
            if (CurrentMode == Mode.Objects)
            {
                // Creating object.
                if (Input.MouseCheckPress(Input.MB.Left))
                {
                    ObjectDragged = false;
                    foreach (OverworldObj obj in Objects.GetList <OverworldObj>())
                    {
                        if (obj.Pos == TileMousePos)
                        {
                            CurrentObject = obj;
                            ObjectDragged = true;
                            break;
                        }
                    }

                    if (!ObjectDragged)
                    {
                        OverworldObj obj = CreateObj(ObjectTypes[CurrentObjectType], TileMousePos);
                        CurrentObject = obj;
                        ObjectDragged = true;
                    }
                }
                // Creating object.

                // Moving object.
                if (ObjectDragged && CurrentObject != null)
                {
                    if (Input.MouseCheck(Input.MB.Left))
                    {
                        CurrentObject.Pos = TileMousePos;
                    }
                    else
                    {
                        ObjectDragged = false;
                    }
                }
                // Moving object.

                // Deleting object.
                if (Input.MouseCheckPress(Input.MB.Right))
                {
                    ObjectDragged = false;
                    foreach (OverworldObj obj in Objects.GetList <OverworldObj>())
                    {
                        if (obj.Pos == TileMousePos)
                        {
                            Objects.Destroy(obj);
                            CurrentObject = null;
                        }
                    }
                }
                // Deleting object.



                if (Input.KeyboardCheckPress(ObjArgumentHotkey) && CurrentObject != null)
                {
                    ObjArgumentMenuActive = true;
                }

                if (Input.KeyboardCheckPress(ObjSelectHotkey))
                {
                    ObjSelectMenuActive = true;
                }
            }
            #endregion Objects
        }