• Creating elements for a tile-based game
    10 replies, posted
[media]http://www.youtube.com/watch?v=zWgbDvYOyDM[/media] This is a puzzle game I'm working on with XNA and the FlatRedBall Engine (for easy rendering). My problem is that, basically, I have to hardcode into my game every interaction between elements. I would like to have a folder where I can store each element separately, in text files that contain the desired behaviour. I'd love to have something like this: [code][Init] Name = "Crate" ID = 1 [Properties] HorizonalMovement = True VerticalMovement = True Breakable = False [Behaviour] OnCollision -> "Pit" = "Pit" -> "Floor"[/code] What's the best solution to do this? In theory I would have all elements in a folder, load them up in the game, and every turn check for collisions and other shit. But I don't really have a clue on how to start.
You could write your own syntax of storage and create a parser for it. This is easy to do, mostly just separate the file into different parts and inside of your program just split the loaded file up and start parsing the file bit by bit. Another way would be to use a simple, pre-created scripting language like XML (Which C# has readers and writers built in for), JSON ([url]http://www.json.org/[/url]), or any others that may strike your fancy.
[QUOTE=Senney;17269404]You could write your own syntax of storage and create a parser for it. This is easy to do, mostly just separate the file into different parts and inside of your program just split the loaded file up and start parsing the file bit by bit. Another way would be to use a simple, pre-created scripting language like XML (Which C# has readers and writers built in for), JSON ([url]http://www.json.org/[/url]), or any others that may strike your fancy.[/QUOTE] If I choose to create my own parser, are there any "good habit" guidelines to follow?
[QUOTE=SupahVee;17269525]If I choose to create my own parser, are there any "good habit" guidelines to follow?[/QUOTE] As long as you keep it clean and don't go crazy with the amount of options, you'll be alright. It shouldn't be that difficult and to be honest it will help you a LOT. Also, this is your anonymous trusty website dude. Edit: I don't know C# that well but here's a tip (at the risk of failing): use regex. I have no idea how it works in C# but if it does, great expressions will help you reliably filter out your sections, fields, and variables.
Sql anyone?
SQL for something like this is not an ideal solution, a custom parser would be much better.
Suppose so.
I like your game
I would start by making a data structure to store elements, something like this: [code]STRING Name INT ID BOOL HorizontalMovement BOOL VerticalMovement BOOL Breakable EVENTS Events[/code] The above nonstandard type EVENTS would be a list([url=http://dotnetperls.com/list]?[/url]) of these: [code]STRING Event STRING Command[/code] I would then create a list([url=http://dotnetperls.com/list]?[/url]) of elements so that I can store an unbounded amount of instances of elements and of events for those elements. After that, I would get all the text files in the designated elements folder([url=http://dotnetperls.com/file-directory-list]?[/url]) and parse them([url=http://dotnetperls.com/streamreader]?[/url]). Once everything is parsed, I'd create the instances of these elements all over the game world. Every turn, instances would be checked to see if an event has been triggered. If so, the command for that event on that type of element would be executed. A command could be anywhere from a simple word to an intricate scripting language. I hope this was able to get you started. You should note that I don't know anything about C#, so don't rely on those links being the right way to do things. [b]Edit:[/b] [QUOTE=Senney;17269404]Another way would be to use a simple, pre-created scripting language like XML (Which C# has readers and writers built in for), JSON ([url]http://www.json.org/[/url]), or any others that may strike your fancy.[/QUOTE] XML and JSON aren't scripting languages, but they are data formats that will store bools, integers and strings. I use XML to read elements in some of my applications.
[QUOTE=WiZzArD;17280354]I would start by making a data structure to store elements, something like this: [code]STRING Name INT ID BOOL HorizontalMovement BOOL VerticalMovement BOOL Breakable EVENTS Events[/code] The above nonstandard type EVENTS would be a list([url=http://dotnetperls.com/list]?[/url]) of these: [code]STRING Event STRING Command[/code] I would then create a list([url=http://dotnetperls.com/list]?[/url]) of elements so that I can store an unbounded amount of instances of elements and of events for those elements. After that, I would get all the text files in the designated elements folder([url=http://dotnetperls.com/file-directory-list]?[/url]) and parse them([url=http://dotnetperls.com/streamreader]?[/url]). Once everything is parsed, I'd create the instances of these elements all over the game world. Every turn, instances would be checked to see if an event has been triggered. If so, the command for that event on that type of element would be executed. A command could be anywhere from a simple word to an intricate scripting language. I hope this was able to get you started. You should note that I don't know anything about C#, so don't rely on those links being the right way to do things. [b]Edit:[/b] XML and JSON aren't scripting languages, but they are data formats that will store bools, integers and strings. I use XML to read elements in some of my applications.[/QUOTE] Thanks, I will try this. I still have to hardcode some interactions though.
[QUOTE] XML and JSON aren't scripting languages, but they are data formats that will store bools, integers and strings. I use XML to read elements in some of my applications.[/QUOTE] Very true. At the time of my reply I was a little tired and couldn't think of what to call them :P
Sorry, you need to Log In to post a reply to this thread.