• 15
• 15
• 11
• 9
• 10

[.net] Map Editor + C#

This topic is 3965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm making a map editor using C# for my online RPG game. Basically I have two loops which run through the x and y coordinates and get the values for each x,y coordinate. Some of the x,y coordinates in the various tables are empty because they relate to the base tiles for the map. For example, a world map would have a base tile of grass. Therefore in any world map table any tile which would have grass is empty. My first problem is I am trying to figure out is how to check in C# whether the row is present or empty. I'm using this as my mysql query:
OdbcComm = new System.Data.Odbc.OdbcCommand("SELECT * FROM "+maptable.SelectedItem.ToString()+" WHERE xvalue='"+y+"' AND yvalue='"+x+"';", OdbcCon);
OdbcDRm = OdbcComm.ExecuteReader();
Then I have
while (OdbcDRm.Read()) {
CODE HERE}
The second problem is, if an image tile isn't found (does not exist), I keep getting an error. I want to somehow make it so that if the tile does not exist at the current moment, that the image would be replaced with the default image does not exist image. I'm using this to get the image:
Image tile = Image.FromFile(tileimg+".bmp");
The third problem I am forseeing is I figure out a way to make each tile clickable, so that I can click the tile and it sends some data to a form element (input boxes, etc).

Share on other sites
First, I wouldn't use a database to store level data. I would use either a binary or text (possibly XML) file.

Second, trap for a FileNotFoundException when you load the bitmap and if it's thrown, load that tile with the one you want to use.

Third, how are you drawing the level? If it's on a control or form, you can use the MouseDown event which gives you the coords that were clicked on the object.

Share on other sites
There's nothing wrong with using a database to store development data. It can actually work quite well, especially in large teams. You can use standard queries to get reports on the state of the assets. You'd want to be able to convert the data to a binary format for release game code, but that is easy to do.

I've recently been looking into connecting a C# program to a database and found the mySQL system to works well. There's a handy .NET library that connects to server and converts the database objects into .NET DataSets which are easy to work with.

From the SQL statement you've got, your database design could be improved. Instead of having one table per map, treat a map as a row in map collection table and each tile is in a tiles table with a link to its owning map, so you'd get a SQL statement like:

SELECT tiles.* FROM maps INNER JOIN tiles ON maps.id=tiles.id WHERE map_name=<the map name> AND tiles.x=<x> AND tiles.y=<y>;

or something like that. Omitting the 'tiles.x=<x>' gets you all the tiles in a given row.

You can also use the MIN and MAX to get the extents of a map.

As for your second problem, Try 'bool System.IO.File.Exists (filename)' before calling Image.FromFile. Additionally, use a try-catch block to catch any problems loading the image file.

Skizz

Share on other sites
Quote:
 Original post by SkizzThere's nothing wrong with using a database to store development data. It can actually work quite well, especially in large teams. You can use standard queries to get reports on the state of the assets. You'd want to be able to convert the data to a binary format for release game code, but that is easy to do.

So your data access works differently in development than release?! Why would you do that?

Share on other sites
Okey I should clarify. Im making a browser based RPG using PHP thus the need of databases. The map editor is the back-end admin control system. I could do it through php, but its much more complicated and nasty looking.

Share on other sites
Quote:
Original post by Machaira
Quote:
 Original post by SkizzThere's nothing wrong with using a database to store development data. It can actually work quite well, especially in large teams. You can use standard queries to get reports on the state of the assets. You'd want to be able to convert the data to a binary format for release game code, but that is easy to do.

So your data access works differently in development than release?! Why would you do that?

Well, the most obvious reason is that many gamers don't have a SQL server to hand to host all the game data and getting them to install one is a bit of overkill. Also, during development, it is useful to be able to track the state of all the game assets which databases are quite good at (i.e. querying). You can also add tracking logs to see who did what and when. Using a transactional server would also allow you to have more than one person editing resources (two people can edit the same map at the same time). The released product doesn't need all this extra housekeeping data so you'd run a query over the database to extract and convert the game assets to their release format. Custom file formats will invariably load quicker than a generic database access, and the total file size will be smaller too.

Skizz

Share on other sites
Quote:
Original post by Machaira
Quote:
 Original post by SkizzThere's nothing wrong with using a database to store development data. It can actually work quite well, especially in large teams. You can use standard queries to get reports on the state of the assets. You'd want to be able to convert the data to a binary format for release game code, but that is easy to do.

So your data access works differently in development than release?! Why would you do that?

This is off-topic however we use databases for storing information about the game and game world. This is all accessible via our tools so that many people can collaborate on the same set of data. It always means that since everyone has access to the database or a clone of the database everyone can be fully up to date with the same information.

Map editing is also fully collaborative with editing done by locking "tiles". When we want to run the game we can either run direct from this raw data, or we run a build script takes the data and builds the binary assets for us which is the same process we'd us for a release build.

You data access methods shouldn't matter to your game, you should be able to load from binary final format, raw text and art assets, or a remote storage system like a database. There are performance penalties for the latter two but they're useful for development.

Andy