Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  A Quick Question (2D Maps)  (Read 1154 times)
0 Members and 1 Guest are viewing this topic.
Offline tyeeeee1
« Posted 2012-12-12 19:34:22 »

Hey, I've recently joined JGO after lurking around for a few days and I figured I'd ask a question about one of the ideas that I've been throwing around. Without any more fluff I'll just ask my question.

When creating a map for a 2D top-down RPG what would be the best way to create the game world/the maps?

 My idea, which has probably been thought of before, would be to have two 2D arrays which would control which map tiles are where and which tiles you can/cannot walk on. The first array would simply hold a number, say 1 is flat and 2 is a hill, and then when you start up the game it would go through the array and spawn the flat tiles where the 1's are and the hill tiles where the 2's are. After that, when the player moves their character from tile to tile, the second array would be checked to see if the player can/cannot move onto the tile.
 (I've only learned the very basics IMO of Java so-far, but I figured that I might as well think about ways to get things to work for later on.)
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #1 - Posted 2012-12-12 19:35:57 »

There are many posts on this topic.

- Jonas
Offline tyeeeee1
« Reply #2 - Posted 2012-12-12 19:36:34 »

I wasn't too sure what to specifically look for so I made a new topic, sorry. =/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-12-12 19:41:38 »

Use a one dimensional array of Tile objects which contain various properties, such as image, rotation, isWalkable, isTrap, damageAmount, etc. The properties would be tailored to your game's needs. Then you would access the array like so:

1  
2  
3  
4  
5  
6  
7  
//get index from a x/y position
int index = x + (y * WIDTH);


//get x/y position from an index
int y = index / WIDTH;
int x = index - WIDTH*y;


Ideally you would use something like Tiled as it will make your life much easier, and extensions exist to import it into LibDX.

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #4 - Posted 2012-12-12 19:49:02 »

Well, its not always easy to find when searching. I'm even having trouble ^^
Are you using any sort of library, like Slick2D, libgdx or something?

I did this a while ago, and I ended up making a Tile-class. Each tile would have an ID, a "passable"-boolean, and a few other pieces of information. Then my maps would have an int[][] of the IDs, and I'd run through it drawing each tile separately.

1  
2  
3  
4  
5  
6  
7  
int tileWidth = 40, tileHeight = 40;
for( int i=0; i < currentMap.getHeight(); i++){
           for (int j = 0; j < currentMap.getWidth(); j++) {
              int ID = map.getTiles[i][j];
              g.drawImage(tileImages.get(ID), j*tileWidth, i*tileHeight, null);
         }
        }


Then you can make adjustments depending on where the movements of the player.

- Jonas
Offline tyeeeee1
« Reply #5 - Posted 2012-12-12 19:57:35 »

I'm just theorizing about how to do this, I'm far from being able to create a game at the moment but I enjoy trying to come up with ways to do things with what I do know. Thanks for all the tips so far!
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2012-12-12 20:01:47 »

Wha?! Guys, slow down Cheesy

What he wants to do is perfectly fine. And to speak directly to you: Do it like Nike does. Just do it.
In the beginning you'll learn from making 'mistakes'... even if I'd say this is far from being a mistake. This is what many people do in many games. And this is how you start off.

@davedes: Seems like premature optimization to me... I've got an implementation anyways Grin

@OP: I'd say you're able to create a game. When I was new to java (about a week or two after diving into it) I'd say I created something which could be called somehow near a game. Tho there was no gameplay...
I'm pretty sure one is able to create a game pretty early, as long as it is a small one.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline tyeeeee1
« Reply #7 - Posted 2012-12-12 21:08:44 »

Wha?! Guys, slow down Cheesy

What he wants to do is perfectly fine. And to speak directly to you: Do it like Nike does. Just do it.
In the beginning you'll learn from making 'mistakes'... even if I'd say this is far from being a mistake. This is what many people do in many games. And this is how you start off.

@davedes: Seems like premature optimization to me... I've got an implementation anyways Grin

@OP: I'd say you're able to create a game. When I was new to java (about a week or two after diving into it) I'd say I created something which could be called somehow near a game. Tho there was no gameplay...
I'm pretty sure one is able to create a game pretty early, as long as it is a small one.

Thanks for the advice, I think I might try creating a small game sooner or later but not before I learn even more! ^.^

I have one more, off-topic, question. I've noticed that people have given me 'medals' which I believe to be some sort of 'reputation' and I was wondering how I can give some out to people that have helped me.
Offline Damocles
« Reply #8 - Posted 2012-12-12 21:14:12 »

You could combine game making with learning (more business related) Swing GUI Programming
and try to create your own tile edior. Look up some 2D tile editors for what features they have.
(Placing graphical tiles, entities, triggers in a Gridlevel and arranging this in different layers, template brushes)

This way you learn tool programming (important part of game making) and also Swing GUI progamming (wich might later be useful in a more settled programming career)

With a good tool and optimized workflow your can create content much faster and convenient.
(Really needed since RPGs are very content intensive)

Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #9 - Posted 2012-12-12 21:49:20 »

I have one more, off-topic, question. I've noticed that people have given me 'medals' which I believe to be some sort of 'reputation' and I was wondering how I can give some out to people that have helped me.

The 'Appreciate'-Button next to the 'Quote'-Button next to the 'Reply'-Button Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

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

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

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

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

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

BurntPizza (54 views)
2014-09-19 03:14:18
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!