Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
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 864 times)
0 Members and 1 Guest are viewing this topic.
Offline Xenon

Senior Newbie





« Posted 2012-08-28 20: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
« Reply #1 - Posted 2012-08-28 20: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 20: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!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2012-08-28 20: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 20: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
« Reply #5 - Posted 2012-08-28 21: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
« Reply #6 - Posted 2012-08-28 22: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-28 23: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.

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

Tekkerue (26 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 (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
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!