Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  Creating a level/map from an image using RGB and do collision detection  (Read 539 times)
0 Members and 1 Guest are viewing this topic.
Offline Xenon

Senior Newbie





« Posted 2012-08-28 22:23:44 »

hey guys Smiley i know java very well now but i have never actually made a proper game, so i wanted to start making a game Tongue and yea it did not take to long until i got stuck a few times xD well i have seen some people use images and convert them into maps/levels using RGB data and i would like to know more about how this works and especially how u collsion detects the "blocks"/tiles after rendering the map in-game

basicly:
gimme as much information as possible on this subject! xD
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #1 - Posted 2012-08-28 22:32:19 »

Hi

I do it in TUER/JFPSM:
Input:


Output:


My source code is under GPL, feel free to use it if you agree with the licensing terms.

Offline Xenon

Senior Newbie





« Reply #2 - Posted 2012-08-28 22:36:05 »

yea im more into 2D atm as i said its my first game Tongue and could u explain a litlle how it works ?
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #3 - Posted 2012-08-28 22:49:48 »

yea im more into 2D atm as i said its my first game Tongue and could u explain a litlle how it works ?
Sorry, maybe my program is a bit too difficult to understand for a newbie, I have worked on it since October 2006. Each color matches with a pattern. I read the image, I convert it into patterns with positions, I convert them into several meshes. The first image contains 256 * 256 pixels. The blue pixels are replaced by full walls (places in which you can't go) and green pixels are replaced by a piece of floor + a piece of ceiling + lateral walls (some useless lateral walls are optionally removed). You can see the level in Blender in the second picture, it is exported as an OBJ file in the alpha version and as an Ardor3D file in the pre-beta version.

Some people here spoke about a nice 2D tile editor some weeks ago, I have forgotten its name  Sad

Offline Xenon

Senior Newbie





« Reply #4 - Posted 2012-08-28 22:58:58 »

yes i see Tongue and yes it is to advanced lol i jsut want the barebones atm Wink back to topic:

uhmm yea i am really struggling with finding any resources on this Tongue could anyone maybe explain me the proccess of converting each pixel into RGB values and so on ? Tongue i really just want to know how to do this lol

EDIT: i started just messing around with pixels and shit for maybe an hour or so and made a method to read the getRGB of every pixel in an image and store it in a array as an integer Smiley the problem now is that this is a sample output:

328965

and i thought RGB was like "eee9e9" or "220-220-220" so idk how to use that when its not a "RGB" to me xD i hope someone can explain this Tongue
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #5 - Posted 2012-08-28 23:40:18 »

EDIT: i started just messing around with pixels and shit for maybe an hour or so and made a method to read the getRGB of every pixel in an image and store it in a array as an integer Smiley the problem now is that this is a sample output:

328965

and i thought RGB was like "eee9e9" or "220-220-220" so idk how to use that when its not a "RGB" to me xD i hope someone can explain this Tongue
I assume you get this value from BufferedImage.getRGB(). By default, it is in the ARGB format, it means that the first byte contains the alpha (for transparency), the second one contains the red component and so on...

You can do that:
1  
2  
3  
int red = (rgb >> 16) & 0x000000FF;
int green = (rgb >>8 ) & 0x000000FF;
int blue = (rgb) & 0x000000FF;

Offline jonjava

JGO Knight


Medals: 32



« Reply #6 - Posted 2012-08-29 00:11:13 »

http://www.java-gaming.org/topics/transparent-colors/26829/msg/238451/view.html#msg238451
http://www.java-gaming.org/topics/tile-rendering/27088/msg/241432/view.html#msg241432

Offline PixelDeBurner

Junior Member


Medals: 1



« Reply #7 - Posted 2012-08-29 01:11:00 »

this is how I do it, in my level class:

levelImg is 48x48 image with each pixel representing one tile, also I created Tile classes ( FloorTile, WallTile etc ).

getColor method :

1  
2  
3  
4  
5  
6  
7  
8  
9  
   private int getColor(int x, int y) {
      int col = levelImg.getRGB(x, y);

      int r = (col & 0xff0000) >> 16;
      int g = (col & 0x00ff00) >> 8;
      int b = (col & 0x0000ff);

      return r << 16 | g << 8 | b;
   }


Then create tile based on color :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
private void fromFile(String string) {
      try {
         levelImg = ImageIO.read(BlackGlass.class.getResource(string));

         for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
               int col = getColor(x, y);

               Tile tile = new FloorTile();
               if (col == 0xff0000) tile = new WallTile();

               tiles[x + y * w] = tile;
               tile.init(this, x, y);
            }
         }
      } catch (IOException e) {
         e.printStackTrace();
      }
   }


Basicaly, you just put 0x and then the hexadecimal color value, you can find out this in paint.net or photoshop or by loads of other software...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
hobbles (7 views)
2013-05-22 00:54:55

cubemaster21 (74 views)
2013-05-17 21:29:12

alaslipknot (86 views)
2013-05-16 21:24:48

gouessej (115 views)
2013-05-16 00:53:38

gouessej (110 views)
2013-05-16 00:17:58

theagentd (121 views)
2013-05-15 15:01:13

theagentd (110 views)
2013-05-15 15:00:54

StreetDoggy (155 views)
2013-05-14 15:56:26

kutucuk (177 views)
2013-05-12 17:10:36

kutucuk (175 views)
2013-05-12 15:36:09
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.136 seconds with 20 queries.