You could use BufferedImage.getRGB(int x, int y) to get the color of a certain pixel in a BufferedImage, but then you'll make everything depending on the color of the background. It could be a quick, simple and dirty solution, but it depends on how you plan to create your tracks and IMHO it won't be a good solution if you want your game to look good and be flexible.

You might want to make the background tiled (made up of small square images) so you have to check which tile your car is on to decide how to behave instead of checking for pixel colors.

I'm sure a couple of folks will jump in here now to plug their tile based libraries.

wow, didn't expect so much replies Anyway thx for tips. Meanwhile we have been able to make an applet that lets a car move over a certain field. The problem is now the collisions. How should we let the car folow a a circuit. Is there something like pixel recognition, pixelgrabber ? eg. the car should drive normal on tarmac ( grey) and should slow down or stop on gras, mud ...what do you guys suggest ?

You will pretty much end up having two maps - the "visual" one which you draw to the screen and the "virtual" one, which just differentiates between different terrains. This way, the visual one can be really pretty - even texture-mapped - and the virtual one is just for collision detection etc.

If I interpreted the GAGE posts correctly, it uses a virtual map made of 16x16 pixel squares? EDIT: I stand corrected - it can use arbitrary precision (which is obviously a very good thing, and shows how you can get better features out of a purpose-built API like GAGE rather than a generic one like J2D)

Personally, for the virtual map I'd use Java2D Shapes and Areas to define the different parts of your map (e.g. one Area for "tarmac" a different Area for each separate chunk of grass, etc). This gives you arbitrarily fine detail, and it's easy to use, built in to the standard libraries, and works. (I'm not suggesting you DON'T use GAGE or etc, just that personally I'd do it that way since I already know j2d, and have never used GAGE before).

Then you create a rectangle to represent each of your cars, and use the intersects() tests you were originally attempting to use .

> If I interpreted the GAGE posts correctly, it uses a virtual map made of 16x16 pixel squares?

Err, no. The idea is that the collision map can be as fine as you need it, right down to the pixel level. You'd tend to use a larger collision map for something like Pac-Man, where you have relatively large tiles. Also, the CollisionMap is a standalone piece of code I haven't yet folded into GAGE. It doesn't have any dependencies.

Given a collision map, the drag formula is:

distance += speed - getCollision(x, y)

In that case, zero would be road, while non-zero would introduce drag (e.g. 1 for grass, 2 for sand, etc). When collision value == speed, you'll hit a wall. When collision value > speed, you'll bounce off (like a tire-bumper wall).

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