MAP storage format of game map editor

Source: Internet
Author: User

MAP storage format of game map editor

The most important part of the map editor module in the star wings is to determine the storage format of Map Files. Four solutions have been used to explore the format of map file storage: custom binary files, XML files, class serialization, and databases. Finally, the embedded database (SQLite) is selected based on the game requirements and technical level ).
(1) custom binary files: due to its technical limitations, it is difficult to store binary files with large changes. Finally, this map file organization method is abandoned.
(2) XML file: Because the XML file is too transparent to players, it is easy for players to modify the map file, resulting in extremely unstable Map Files and thus giving up custom binary files.
(3) Class serialization: Class serialization can well organize map files, but considering that the storage format of Map Files will change in the future, the scalability is not strong, the class definition needs to be modified each time.
(4) Database: Considering the continuous advancement of game development, continuous changes will make the overall structure of the game increasingly disordered, making the program hard to understand and maintain, game map is the link between the game's main program and the map editor. To maintain the stability of the map, the database can maintain the stability of the game map to a certain extent. The first database to be selected is access. However, considering that many players' computers do not necessarily have access drivers installed, we are glad to find the SQLite database. SQLite is so good that we only need a system. data. SQLite. DLL to use the database.
Currently, map files mainly store two types of information: static map backgrounds and dynamic enemies. It also includes some configuration information. The map editor is generally divided into two areas: one is the control menu area of the game map, and the other is the game map editing area. In the control menu area, you can select the background and genie categories. You can use the Background player to load your favorite background tile and add it to the map. You can use the genie to add custom enemies and set the movement, speed, attack power, life value, and attack mode of the enemies.
The advantage of using SQLite database is that it is easy to implement, easy to organize, and easy to expand.

The map file consists of three tables: Level, Sprite, and levelsprite.
(1) level: Describes the size, background image, Story information, and map size of the current game level.
(2) sprite: stores the details of all the genie in the current level.
(3) levelsprite: stores detailed information about enemies, Meteorite, and dynamic backgrounds of the current level, including detailed information such as the life value, attack power, movement speed, movement mode, attack mode, and location.
When the map editor generates a map, it adds the level, Sprite, and levelsprite table information to the map file and then reads the map information in the main game program.

Using SQLite to manage map data changes the map operation to database operations. The most important one is the storage of images. Here we will focus on the storage of images by SQLite.

Read Image

Sqliteconnection sqliteconn1 = new sqliteconnection ("Data Source =" + ofd. filename + "; new = false; compress = true; version = 3;"); // connect to the database <br/> sqliteconn1.open (); // open the connection <br/> sqlitecommand sqlcmd1 = new sqlitecommand (sqliteconn1); <br/> string cmd = "select * from level "; <br/> sqlitedataadapter SDA = new sqlitedataadapter (CMD, sqliteconn1); <br/> dataset DS = new dataset (); <br/> SDA. fill (DS); <br/> byte [] DATA = NULL; <br/> int map_width = 1; <br/> int map_height = 1; <br/> int title_width = 1; <br/> int title_height = 1; <br/> memorystream mystream = new memorystream (); <br/> foreach (datarow DR in DS. tables [0]. rows) // because the table only reads one row of data once, <br/> {<br/> DATA = (byte []) Dr ["level_background"]; <br/> map_width = int32.parse (Dr ["map_width"]. tostring (); <br/> map_height = int32.parse (Dr ["map_height"]. tostring (); <br/> title_width = int32.parse (Dr ["title_width"]. tostring (); <br/> title_height = int32.parse (Dr ["title_width"]. tostring (); <br/>}< br/> foreach (byte A in data) <br/>{< br/> mystream. writebyte (a); <br/>}< br/> bitmap BBG = new Bitmap (mystream); // BBG is a successfully read image </P> <p>

 

Store images

Memorystream MS = new memorystream (); <br/> tempbm. save (MS, imageformat. BMP); <br/> byte [] bitmapdata = Ms. toarray (); <br/> sqliteconnection sqliteconn = new sqliteconnection ("Data Source =" + mapconfig. mapsavepath + "; new = false; compress = true; version = 3;"); <br/> sqliteconn. open (); <br/> sqlitecommand sqlcmd = new sqlitecommand (sqliteconn); <br/> sqlcmd. commandtext = "insert into level (level_id, level_name, level_background, level_story, map_width, map_height, title_width, title_height) values (1,1, @ image, @ story, @ map_width, @ map_height, @ title_width, @ title_height) "; <br/> sqliteparameter param_m = new sqliteparameter (" @ image ", dbtype. binary, bitmapdata. length, parameterdirection. input, false, 0, 0, null, datarowversion. current, bitmapdata); <br/> sqlcmd. parameters. add (param_m); <br/> sqliteparameter param_ms = new sqliteparameter ("@ story", mapconfig. mapstory. tostring (); <br/> sqlcmd. parameters. add (param_ms); <br/> sqliteparameter param_mmw = new sqliteparameter ("@ map_width", mapconfig. mapwidth); <br/> sqlcmd. parameters. add (param_mmw); <br/> sqliteparameter param_mmh = new sqliteparameter ("@ map_height", mapconfig. mapheight); <br/> sqlcmd. parameters. add (param_mmh); <br/> sqliteparameter param_mtw = new sqliteparameter ("@ title_width", mapconfig. tilewidth); <br/> sqlcmd. parameters. add (param_mtw); <br/> sqliteparameter param_mth = new sqliteparameter ("@ title_height", mapconfig. titleheight); <br/> sqlcmd. parameters. add (param_mth); <br/> sqlcmd. executenonquery (); <br/> sqlcmd. dispose (); <br/> sqliteconn. dispose (); <br/> MS. dispose (); <br/> // The image is inserted successfully. <br/>

Map editor download author other source code download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.