Creating a Tile Mapping System in Java from Scratch?

For discussions about game development that does not fit in any of the other topics.
Post Reply
Kennydin
Posts: 39
Joined: Sat Oct 31, 2009 12:47 am

Creating a Tile Mapping System in Java from Scratch?

Post by Kennydin »

Since I've been off with the PHP fairies for quite some time, I haven't really had chance to take a look at game development.

I would like to start with creating some kind of 2D game in Java, and progressively work to implementing a 3D version of this.
Could anyone explain to me what the best way of implementing a Map based on square tiles (possibly imported through an XML file) would be?
Almost like the 2D engines based off the Mirage Source work.
My initial plan would be to create a small Client and Server that I could load up a Map and log into multiple clients and run around with little sprites across the Map.

If anyone could help me out that would be great :D

I'd just like to get started properly in Java as I find the language a lot easier to come to terms with.
PHP/Python (amongst other things) Person - Big Fan of MVC Architecture. Love CakePHP and CodeIgniter.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Creating a Tile Mapping System in Java from Scratch?

Post by hallsofvallhalla »

I have said it once and will say it again. Java is a beast. Very hard to wrap head around it. I can offer no help there. I am not a fan of Java whatsoever. Javascript is my baby.
Kennydin
Posts: 39
Joined: Sat Oct 31, 2009 12:47 am

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Kennydin »

hallsofvallhalla wrote:I have said it once and will say it again. Java is a beast. Very hard to wrap head around it. I can offer no help there. I am not a fan of Java whatsoever. Javascript is my baby.
Bad experience with Java Halls? :cry: :P
PHP/Python (amongst other things) Person - Big Fan of MVC Architecture. Love CakePHP and CodeIgniter.
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Xaleph »

If you intend to use an XML document to create your map, you should first make an xml scheme for your game to work with. What kind of attributes do you want yout tiles to have? Once you have that, i would start writing a XMLParser to check your xml tree, create an TileObject for each element found in the XML and after all objects are created, push all objects ( in some order ) in a hashmap. Now all you have to do is create a TileView to style all tiles. I assume all tiles have a default width/height? X and Y should be stored in the XML and the current X and Y are based on the player.

To generate the map just use an offset for current X and Y and calculate the tiles you need ( if ordered properly, you can just use an index pointer and start working on your tiles from there )


Then agian, i never, ever created a game in Java, but that`s how i would do it.
Kennydin
Posts: 39
Joined: Sat Oct 31, 2009 12:47 am

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Kennydin »

Xaleph wrote:If you intend to use an XML document to create your map, you should first make an xml scheme for your game to work with. What kind of attributes do you want yout tiles to have? Once you have that, i would start writing a XMLParser to check your xml tree, create an TileObject for each element found in the XML and after all objects are created, push all objects ( in some order ) in a hashmap. Now all you have to do is create a TileView to style all tiles. I assume all tiles have a default width/height? X and Y should be stored in the XML and the current X and Y are based on the player.

To generate the map just use an offset for current X and Y and calculate the tiles you need ( if ordered properly, you can just use an index pointer and start working on your tiles from there )


Then agian, i never, ever created a game in Java, but that`s how i would do it.
Ahh thanks for the starting advice :)

If I get something working, I'll make sure to post it around somewhere :)
PHP/Python (amongst other things) Person - Big Fan of MVC Architecture. Love CakePHP and CodeIgniter.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Jackolantern »

Have you looked at C#? Java and C# are very similar, but I find some things just make more sense in C#, such as how you don't have the basically useless "throws clause" rule that you have in Java, among other things. C# also has XNA in its corner, which cuts out craploads of work that a Java game developer has to do on their own just to get going. You can publish your game on the PC just like any other language, but you can also easily convert your game to be sold on Xbox 360, or convert it to be sold or given away for free on the Windows Phone 7 platform.

I have always loved C#, and while I do have some experience in Java as well, I always prefer the former.
The indelible lord of tl;dr
Kennydin
Posts: 39
Joined: Sat Oct 31, 2009 12:47 am

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Kennydin »

I've never really looked in to C#, but that's because I'm completely Mac based in my household. C# is a windows things but I'm pretty sure it can be compiled/run through Mono however I don't think there is a stable IDE out for mac yet (correct me if I'm mistaken).
I'm guess then it would compile windows only executables too?

I'm tempted by it but the whole windows thing puts a bit of a downer on the aspect of C#.
PHP/Python (amongst other things) Person - Big Fan of MVC Architecture. Love CakePHP and CodeIgniter.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Jackolantern »

Ahh, yes, there is no way that I know of to run XNA on Mac, so that would be a problem lol.

What about native Mac development? I am supposing you are wanting the game to run in Windows as well. I mention this because, while I do like Java, as Halls mentioned, Java game development is a painful beast. There are very few useful engines and bits floating around out there, and you will be coding pretty closely to the level of OpenGL (200+ lines of code to get a single-color circle on the screen on a black background) in JOgl. It is rough, and very few game developers use it for that purpose.
The indelible lord of tl;dr
Kennydin
Posts: 39
Joined: Sat Oct 31, 2009 12:47 am

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Kennydin »

Ouuuuuch :( that sounds like a bit of a hefty price to pay just for Java. Thanks for the heads up!
I wonder if its worth Boot Camping my Macbook Pro ...hmmm I'll have to have a ponder over that one.

I'm also debating whether or not at having a deeper look into Unity3D just to have a mess around with it. Looks nice from the outside :)
But alas, I would like to create something worth spending time on in Java. Decisions decisions!
PHP/Python (amongst other things) Person - Big Fan of MVC Architecture. Love CakePHP and CodeIgniter.
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Creating a Tile Mapping System in Java from Scratch?

Post by Xaleph »

All very true. Java is considered a real pain in the *** for that reason. I also would recommend looking at C#. It tends to be less-hassle, quicker graphics kind of programming. I don`t know, it feels more graphical to program in C# then it is in Java.

Also, like Jack mentioned, Java has major issues on the whole throws clause. All runtime errors should be declared, while, well.. like it is said, runtime errors.. I don`t know.. i guess i also tend to favor C#, mostly for it`s simplicity and great IDE. Now, i never did game developing on it, but i hear XNA seems to work pretty cool, also, openGL can be used ( i believe someone created a lib for it ) and other than that, you have the whole .NET framework to yourself, which basicly means you have 100k+ lines of code written for you.. :)
Post Reply

Return to “General Development”