Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  Tiled Maps, or Position maps  (Read 1445 times)
0 Members and 1 Guest are viewing this topic.
Offline biro

Junior Member


Medals: 1
Projects: 1



« Posted 2011-05-21 08:27:45 »

Hello,
I'm thinking about the best way to write a strategie game. as far as my imagination gets me I can think about 2 ways to implement a 2D gameworld:
1) A Tiled Map, you make your board/field out of smaller fields, called tiles, these tiles each have the same hight and width, and are represented through an Object in your 2 Dimensional Array, that contains informations about units, buildings etc. on this tile.

2) A positionbased map, On this kind of map the building- and unitobjects have a position object, that tells us where it is, and they also have an radius or hight and width, when you move the units on this map you change their position Object and the render method does the remaining.

I believe, the Tiled Map is the easier one to implement, but not as multifunctional as the position map, what makes the Tiled Map (at least for me) easier is, the easier posibility to build a uniue terrain. On the Tiled Map you do it with an attribute of your tile object, that says what kind of terrain it is (I would do it so), but with an position map that gets a little bit harder. My way of doing it would be to create an 2D pixel-array, that says what terrain is on which pixel, and when I'm trying to build something I check for a collision (checking every coordiante in the range of the new building for the right terrain).

My Questions are:
1) What do you use?
2) Maybe what do you want to use, and why? (If it's different from question 1)
3) How large can this 2D pixel-array be, that it's still performant enough?
4) Everything else you know about this topic.

Reasons for me asking:
I'm thinking about writing a strategy game, that gives you as much freedom as possible, and for that I want to implement a "position map" that let's the user build and move everything as exact as possible.

Greetings
biro
Offline aazimon
« Reply #1 - Posted 2011-05-22 21:20:58 »

A tile map helps with rendering. You only need to render the part of the map that if visible on the screen. You can also make the tiles smaller. Say your objects are 32 pixels you can make each tile 16. This will give more flexibility with placement. (This is what I'm currently working with).
With a position based map, do you need to fill every pixel? As in, can you use a blanket background to cover the area, like grass, then only place elements that can't be built on, like mountains and trees. Doing that you would only need to check the collision of the objects, not every pixel.
Offline Jono
« Reply #2 - Posted 2011-05-22 22:54:00 »

I've just gone through exactly the same process. The solution I used was to create maps using tiles of terrain and then to allow per-pixel positioning and movement of entities on top of it. Each tile contains all its own per-pixel information that can be queried when an entity moves over it, but because tiles are being reused throughout the map it doesn't suffer the memory issues of an explicit huge 2D image.

From each entity's perspective the map is not tiled. Collision detection is done using a grid-based index that is independent of the underlying map.

I think the practical alternative to a tiled map is to use polygons to represent chunks of terrain. The only reason I didn't go down that path is that I couldn't think of a nice way to render terrain polygons. One plus of this approach is that you can reuse some of the polygon-based path finding code people have put on these forums (was it CommanderKeith?).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #3 - Posted 2011-05-23 01:33:59 »

I've used a Tiled map for my turn-based RPG with RTS-style control.

Some things are just easier with tiles such as collision detection or determining if a unit is surrounded.  Now my game is turn-based at heart and therefore tiles i.e. discrete movement makes the most sense.

I don't feel bound by tiles though.  I can animate smooth movement as a unit moves from one tile to another.

Is your game turn-based?
Offline biro

Junior Member


Medals: 1
Projects: 1



« Reply #4 - Posted 2011-05-23 07:53:13 »

Hello,
thanks for you answers.

@aazimon:
The point with the pixels is, that I don't want to create "Objects" like mountains and trees, I want to create more or less soils, like earth with minerals (gray color) for mines, green earth for farms, yellow for deserts, etc. Trees, you already correctly said, will be added through objects, that represent them and their whereabouts.

The important question to the pixels is: Is it possible to save the soils (for the pixels) in an 2D Array, that is let's say 10000*10000 or 100000*100000 times large?
How performant would that be?

On another note:
On this kind of map I would need to implement a more complex collision control for building units, and buildings, a simple way would be to check every already built building with the new building I want to buiild, if they collide i won't and can't build it.

Question:
How performant would this system be, when I have let's say 1000 building built, how long would it need until all buildings are checked for collision with the new one I want to build?

Greetings
biro

Offline loom_weaver

JGO Coder


Medals: 17



« Reply #5 - Posted 2011-05-23 11:39:40 »

The important question to the pixels is: Is it possible to save the soils (for the pixels) in an 2D Array, that is let's say 10000*10000 or 100000*100000 times large?
How performant would that be?

Probably best to start coding and find out.  If for whatever reason you end up iterating over every single pixel then 10k^2 or 100k^2 is going to suck.  But if you can avoid it through some kind of optimization the size won't be an issue.

Quote
How performant would this system be, when I have let's say 1000 building built, how long would it need until all buildings are checked for collision with the new one I want to build?

A 1000 objects is nothing for a modern computer.
Offline aazimon
« Reply #6 - Posted 2011-05-23 21:09:58 »

I haven't done a lot with collisions, but it may be better to divide the image up into more managable sections. When you place a building, only check collisions with the image for the section that the image is being placed in. If you're placing a building at 100x 89, there is no point to see if it collides with a point at 100000 x 89.
Offline Jono
« Reply #7 - Posted 2011-05-23 22:54:13 »

I haven't done a lot with collisions, but it may be better to divide the image up into more managable sections. When you place a building, only check collisions with the image for the section that the image is being placed in. If you're placing a building at 100x 89, there is no point to see if it collides with a point at 100000 x 89.

That's pretty standard, and what I meant by "grid-based index". You need to check not only the same section, but also adjacent sections (in case your entity is right near the boundary between two).
Offline aazimon
« Reply #8 - Posted 2011-05-24 18:27:32 »

The point with the pixels is, that I don't want to create "Objects" like mountains and trees, I want to create more or less soils, like earth with minerals (gray color) for mines, green earth for farms, yellow for deserts, etc. Trees, you already correctly said, will be added through objects, that represent them and their whereabouts.
If I'm understanding you correctly, is that you would have the image be the holder of information. Will the user work at the pixel level? Or would it be more like, he builds a farm "object" which is several pixels in size? Can you give me more information on how the game machanics work?
Offline biro

Junior Member


Medals: 1
Projects: 1



« Reply #9 - Posted 2011-05-24 18:40:05 »

Hello,
I don't want to work on the images.
I want to work on an 2 Dimensional Array that represents the underground material the field has, earth, water, sand, minerals...
This Array will be read from an File. After I've extracted the file to my Array I create the picture (pixel for pixel).
The building system should be very much like the on from the Settlers 4 if you don't know it watch a trailer on youtube. Only that it will have no heigth, like hills have.

At the moment I'm not entirely sure what kind of data this 2 Dimensional Array should contain per pixel. Should it only be the kind of background/soil or maybe a stock for it too? (like 20 coal), and how long does it need to create such an array, and is it's "jumping ability" affected by its size?

Greetings
biro
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.

TehJavaDev (11 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01: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!