Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tanks game  (Read 2853 times)
0 Members and 1 Guest are viewing this topic.
Offline Cracktastic

Junior Newbie





« Posted 2008-11-21 17:24:03 »

Hello everyone,

I'm fairly new to java programming ( about 1 month ) and I have chosen to make a sort of "Battle city style" game ( the one in gameboy Smiley ). I am supposed to use a server, as it will be a multi-player using tcp/ip. I think I got the socket communication working for registering and logging a player in a server and I was thinking about starting to build 2D maps for the tanks to move. How exactly am I supposed to do that?

Thanks in advance,
Offline SunshineKiller

Junior Member





« Reply #1 - Posted 2008-11-21 18:23:18 »

basically a tiled map is an array [][]
like
0000000000000000000000000000000
0000111121121111223322111100000
0000111121121111223322111100000
0000111121121111223322111100000
0000111121121111223322111100000
0000111121121111223322111100000
0000000000000000000000000000000

where 0 would be the water, 1 is the grass, 2 is dirt etc... where you assign an Image to be 1 and 2 etc... and so you can either make your own map like that or use a map editor, such as Mappy, or TileD.


<b>Check out my Development Blog:</b> <a href="http://www.scottscreations.com">Scotts Creations</a> | <b>Games in Development: </b> <a href="http://mechwarfare.scottscreations.com">Mech Warfare</a> | Mech Warfare: Facebook Edition | Game Master
Offline Cracktastic

Junior Newbie





« Reply #2 - Posted 2008-11-28 17:47:02 »

I have made a map in TileD.  Now, how can I generate the code for that map in order to add that map to my game and, after that, put a tank moving there?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bad Sector

Senior Newbie





« Reply #3 - Posted 2008-11-28 22:55:08 »

You may use my Java/Swing-based 2D tilemap editor :-)
Offline Cracktastic

Junior Newbie





« Reply #4 - Posted 2008-12-05 15:26:39 »

which program do I use to load the maps TileD generates into java code?
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2008-12-05 19:13:42 »

I usually write my own editor or use a text file, both of which are pretty simple. Typically the text file approach works if you've got a game like Mario where each block is exactly the same from another block of the same type. An RPG where different characters have different messages they say and whatnot is not suitable for a text-based map.

A simple text file map for Mario might look like this, where s is sky, c is cloud, q is question block, g is ground block, k is koopa (enemy), and b is bush.
1  
2  
3  
4  
5  
6  
sssscssscssccsssscssscsssc
scssscssssccssssscssscssss
sscssscsqscsccsqscscssssss
sggbssbbskssbsksbssgggsbss
gggggggggggggggggggggggggg
gggggggggggggggggggggggggg


Then you simply read in the text file, and go through each character and create a new object of the correct type to match the letter that was put in.

The next level in complexity from a text file is an XML file, which is often used all over the place, even for many professional games. XML is basically just a way of structuring data, and Java has built in XML parsers to make it easy to turn that data into useable information for your map. Using this method you can get increasingly complicated and do things like have multiple things per tile (obviously only if your game supports it, though).

XML might be like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
<tile xPos="0" yPos = "0">
     <entity name="Brick" type="wall">
          <image url="images/brick.gif" />
          <vector type="dimension" x="50" y="50" />
          <vector type="position" x="0" y="0" />
     </entity>
</tile>
<tile xPos="1" yPos = "0">
     <entity name="Brick" type="wall">
          <image url="images/brick.gif" />
          <vector type="dimension" x="50" y="50" />
          <vector type="position" x="50" y="0" />
     </entity>
     <entity name="Sword" type="item">
          <image url="images/sword.gif" />
          <vector type="dimension" x="50" y="50" />
          <vector type="position" x="50" y="0" />
     </entity>
</tile>
<!-- Etc. etc. -->


Obviously the XML file will take a long time to write by hand and can lead to a lot of possible errors. One advantage to it though is that it can represent literally anything, is very clear to read externally, and can be edited by your players if they desire. XML is also... erm... extensible Wink and so can used anywhere for anything.

The final choice is to make your own editor, as I said previously, complete with a GUI, buttons, all that jazz. Obviously you can also use one like Bad Sector provided, but I would recommend rolling your own at first just to learn something. In many games early in my game programming career, before I made my own tile map editor, I used text files. Like that Mario example I actually did create several years ago. But then it turned out that it was too difficult to visualize my levels in text, so I made an editor. The editor originally just made text files. A small toolbar at the bottom drew out each type tile and had a letter overlayed the top it, then I'd press that letter to make that tile active. Then when I clicked and drew it would put that tile down wherever the mouse was. When I clicked save it would just become a text file again.

Over a multitude of games and experiments, my need grew so I slowly added onto my editor until it became capable of a staggering amount. The key to making this possible is ObjectInputStream and ObjectOutputStream, which I highly recommend you checking out. Basically, your editor creates the actual objects you will use, actually saves them in an array as you desire, and then writes that data to a file. You then read it later and put the array directly into memory. Easy and can do absolutely anything.

So anyway, my final suggestion is that you start with a text file and then work your way up like I did. You'll learn a lot in the process.

See my work:
OTC Software
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #6 - Posted 2008-12-05 19:17:11 »

Oh, here's an image of what my Mario level editor looked like:


See my work:
OTC Software
Offline Cracktastic

Junior Newbie





« Reply #7 - Posted 2008-12-12 17:12:37 »

So, what do I use then to make my game run the map and have a tank moving in it? some sort of array?

thanks in advance,
Offline Cracktastic

Junior Newbie





« Reply #8 - Posted 2008-12-13 16:33:56 »

I have most of the code written but I am experiencing a lot of lag.. I am using tcp/ip sockets
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (51 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!