9 Replies - 2981 Views - Last Post: 25 August 2012 - 07:30 PM Rate Topic: -----

#1 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Java game development

Posted 25 August 2012 - 01:48 PM

Recently I decided to make a rogue-like game in java. I done a few things so far like make a key-bind class, and I looked into some basic animation stuff, and I ran into a problem. I can not figure out how to make the actual map, or level of the game. Any input or advise on how to do this would be much appreciated, I am not asking for exact code on how to do so, though if you want me use examples it would be very helpful. Thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Java game development

#2 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Java game development

Posted 25 August 2012 - 02:07 PM

I forgot to add in my post that I have done some research into how to do this via the search feature, and other website. I have figured out that I could use a two dimensional array, but if I were to add the images to a two 2d array, how would I interact with them, or even make them visible?
Was This Post Helpful? 0
  • +
  • -

#3 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Java game development

Posted 25 August 2012 - 03:28 PM

When coming up with a system to display tile-based maps, how you go about implementing it will depend on the level of complexity you desire. For example, an isometric title such as Diablo 2 has a much more intricate map system than Legend of Zelda.

Even assuming you're going with a Legend of Zelda map style, I do need to know how intricate a system you need - do you need event triggers, mob spawners, items to pick up, etc? Are entities in the game world going to be able to move freely (as in Legend of Zelda) or will they be constrained to move within grid squares (as in Pokémon)?

Putting entities aside, how many "layers" are you going to need for the map itself? Namely, will you have layers that you want to implement alpha transparency for the sake of having (for example) arches that the player walks under, or similar effects?

Your best bet would be to set up a tile system. You do not want to make a 2D array of images themselves, as that could quickly take up a lot of memory. Your best bet is to have one class holding each individual tile image (so for example, a tile for the floor and a tile for the walls), and then have your array (which is probably the best way to store the tile data) filled with references to their individual tiles.

As an example:
Say you have a Tileset class/structure (I'm not a Java programmer, I prefer C++, so bear with me a second)
Tileset
- Texture: contains the actual image data
- Solid: Boolean determining whether the player can move through this square or not

Then you have an array of the Tileset class, with one member for each different type of tile (floor, wall, lava)
Tileset[0] = Floor
Tileset[1] = Wall
Tileset[2] = Lava

Finally, let's say you have a 5x5 room: The outer tiles being Wall tiles, with a vertical strip of lava surrounded by two bits of floor. You can store each of these as an integer referencing the tile index in the Tileset array.

MapData[][]:
1 1 1 1 1
1 0 2 0 1
1 0 2 0 1
1 0 2 0 1
1 1 1 1 1

This is a very basic idea of how to do it. If you can give me more specifics on what kind of system you're looking for, I can help you a little bit more.
Was This Post Helpful? 1
  • +
  • -

#4 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Java game development

Posted 25 August 2012 - 04:29 PM

Okay, first I would like to thank you for all your help. As for specifics, I would like to make the game map have a series of separate rooms, and hallways. The idea is that you are in a dungeon you have to get to the bottom floor for what ever reason blah blah.... More to the point each floor needs rooms, and hallways, and a way to the next floor(like a ladder, or stairs) inside these room monsters need to spawn, and so do item which I plan to set up randomly. I already have the randomness figured out for the most part, and I am working on the animation of such entities. To sum this all up, my real question here is how would I go about displaying all of these separate rooms, and making multiple floors in this dungeon that holds separate rooms?
Was This Post Helpful? 0
  • +
  • -

#5 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Java game development

Posted 25 August 2012 - 06:22 PM

It would probably be best to treat each floor as a separate map, and load the new one whenever the player gets to the ladder/stairs (or if you wanted to pre-load, you might start asynchronously loading the next level when they got to a certain room instead, but that's a bit more complex a task).

I would recommend using 2D game engine to get you started, so that you can get a little more familiar with how things tend to work before jumping straight into programming your own system (you don't necessarily need to learn or use the engine itself, just understand how things work with it all).

So, based on what you've said here your best bet will be a fairly simple tile-based map system. Your best bet at this point would be to have a single-layer map, using the 2D array style I talked about earlier. What you'll want to do during your rendering is cycle through each tile, look at its ID and render the data in the tileset that corresponds to that index at that point.

Assuming you're using 16x16 tiles, it'll look something like this pseudocode:
// TILE_WIDTH = 16
// TILE_HEIGHT = 16
void RenderMap(Map map, Renderer renderer)
{
    for(y = 0 to map.HeightInTiles)
	{
		for(x = 0 to map.WidthInTiles)
		{
			Tile tileData = map.Tileset[map.MapData[y, x]];
			
			// Draw(int XInPixels, int YInPixels, texture)
			renderer.Draw(x * TILE_WIDTH, y * TILE_HEIGHT, tileData.Texture);
		}
	}
}


As far as handling entities, first we can break down the types of entities you have:
Ladder/Stairs: When the player runs into this entity, she is transferred to the next level (next floor).
Monster Spawn: These spawn mobs at a specific interval, up to a certain number of mobs in the world
Item Spawn: These spawn randomly throughout the level

Based on this, we can take the common elements (will need a position in the world, as well as a graphic and a response to player collision) and create an Entity class:
Entity:
- (integer) X (in Tiles)
- (integer) Y (in Tiles)
- (Texture) image
- (void function) onPlayerCollide(Player player)
- (void function) Render(Renderer renderer)


And then we can create subclasses that implement the specific functionality needed. Essentially, the render function works the same as the Tile rendering for determining the X & Y coordinates for rendering. In a system like this, going with a Pokemon-style movement system (where the player is always within a specific grid square), you can simply check X & Y coordinates in the grid for collisions rather than performing (slightly more expensive) Bounding Box collision detections.

If you're comfortable with reading C++ or C#, I can write up a little tutorial to try to explain things more clearly.

Edit
You're also going to want to look into what amounts to a 2D "Camera" system in order to implement a scrolling system, because I'm assuming your entire level isn't going to be small enough to fit the entire thing on one screen (or at least, not effectively).

This post has been edited by Mina-no-Hime: 25 August 2012 - 06:23 PM

Was This Post Helpful? 1
  • +
  • -

#6 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Java game development

Posted 25 August 2012 - 07:06 PM

I do not know c++ or C# but I got the general idea of what you were saying. From what I understand I should make each level a different map, my creating a class for each texture, and adding that texture to a 2d array. I got a little confused with some of what you said like when you were explaining the renderer function. I also get a little confused when you say things like bounding boxes. A tutorial would be really helpful, but I don't know how much I will get from c++ as I don't know it. I think I am starting to get the general idea, Thanks for all of your help. Lastly what 2d game engine should I use?
Was This Post Helpful? 0
  • +
  • -

#7 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Java game development

Posted 25 August 2012 - 07:13 PM

Unfortunately, I'm not familiar with any Java-specific game libraries. Still, using a tool such as Game Maker or an engine like Love (which uses Lua) with this tutorial may help.

It may help to ask in the Java Tutorial Request thread to see if anybody there can give you some Java-specific help with implementing the system.
Was This Post Helpful? 0
  • +
  • -

#8 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Java game development

Posted 25 August 2012 - 07:18 PM

Assuming I do use a game engine of sorts what benefits would I have by using it?
Was This Post Helpful? 0
  • +
  • -

#9 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Java game development

Posted 25 August 2012 - 07:23 PM

My suggestion at this point isn't to use the engine (specifically not those two) for the creation of the game you're talking about, but to learn how the systems function. For example, the tutorial I linked to shows how to create a tilemap system using the Love engine - experimenting with and learning these concepts can help you to translate that knowledge over to a Java environment. A basic understanding of how 2D tilemap systems work is language-agnostic, and is absolutely necessary if you hope to begin to implement one.
Was This Post Helpful? 1
  • +
  • -

#10 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Java game development

Posted 25 August 2012 - 07:30 PM

Okay, thanks for all of your help. I will look into how tile maps work, and such. I guess I will also go look around a bit more in the java section, or wait for someone with knowledge in java to come along. Thanks again for all your help I think I understand the basic concept of what to do here. I look forward to getting help, learning more some more java specific skills, and progressing in game development.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1