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  
  Questions about creating a 2D racing game  (Read 1798 times)
0 Members and 1 Guest are viewing this topic.
Offline bauerr

Junior Member




Java!!!!!!!!!!! !!!


« Posted 2005-02-28 03:57:40 »

Hi,

I'm thinking about creating a racing game. But I have two basic problems I didn't solve until now:

1. How can I check if the car has left the track? I don't even know a search term.  Embarrassed

2. What would be the best way of drawing the car? I'm thinking of drawing it with AffineTransform to an Image depending on its current angle? Would this work? Or would it slow down the game?

Ralf
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #1 - Posted 2005-02-28 09:58:54 »

I never wrote a 2d car game myself, but this is what I would do:

1. If your game will be tile-based, what you can do is define 2 tiles for each tile: One is the displayed bitmap, the other holds information for your collision detection. This can be a simplified version of the displayed bitmap, for example black = road, green = grass, white = building etc. but it can also be just raw data since we don't use it to draw to the screen.
So while you draw the background, you also 'draw' the tiles for collision data (but of course you won't draw them to the screen).
In your game loop, you check in the collision data what the car is driving on (road, grass, building) so how the car should respond.
I hope I'm making any sense here Smiley

2. I don't have experience with that, but I suspect AffineTransform will be slow. If it is, you can prerender an array of car images with different angles. Then in your game loop, simply select the correct image for the angle the car is driving in.
You could also consider using openGL, where rotation etc. is hardware accellerated so you won't need to pre-render rotated images.

Offline MasterOfDisaster

Junior Member




O_o


« Reply #2 - Posted 2005-02-28 12:15:44 »

i did it this way for NanoMachinez (the link is placed in my signature below).
i use an image that holds the resistance values for the terrain. each color represents a certain type of resistance (road, grass, ...). this can also be used for detecting if the finish line has been passed (in the correct direction).

i also use AffineTransform to rotate the car image. although this might be a bit slow it works well enough for my game.

pros: you don't have to render many car images, only one. with rendered car images you never have such smooth rotation unless you generate 360 car image or so...

cons: that the rotated image is not looking as good as the non-rotated one.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #3 - Posted 2005-03-01 01:03:07 »

I've never had a performance problem with AffineTransform under any circumstances.  As for rotation quality, here's a useful tip:

If the image gets scaled down, the rotated quality will improve.  So make your image 20% larger than normal, and have the AffineTransform object scale down 20% and rotate.  You'll see the quality actually improve!  The reason being is that it can use real pixels from the source image for the pixels that it would normally have to interpolate in the rotation.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline bauerr

Junior Member




Java!!!!!!!!!!! !!!


« Reply #4 - Posted 2005-03-01 03:48:51 »

The concept with the tiles sound very interessting but I'm not  sure if Iunderstand it completely. How would you treat tiles with different colors/undergrunds e. g. a tile that both contains part of a road and grass.
Do you create sub-tiles? Or is the type of resistance depends on the most commonly used color?

Ralf
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2005-03-01 12:38:07 »

It depends on how accurately you want to implement it. For a really inaccurate implementation, you could simply take the center point from the car and check the pixel of the 'collision tile' to see what the car is driving on and how it should behave. If you want some more accuracy, you could check 4 points to see what each wheel of the car is driving on and update the car's behaviour accordingly.

Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #6 - Posted 2005-03-01 15:46:55 »

extending on that idea, I'd like to clarify another idea you could use.  You could say that if a tile is road, there's a slowdown factor of 1.  If a tile is grass, there's a slowdown factor of .9 (you could multiply these to the momentum for a reduction in speed).  Then if a tile is grass and road in the same tile, the slowdown factor is .95, halfway inbetween the two.  I think that would work well.  Just have the slowdown factor associated with each tile type for easy reference.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline bauerr

Junior Member




Java!!!!!!!!!!! !!!


« Reply #7 - Posted 2005-03-01 16:45:52 »

Interesting, but this raises still more questions... Roll Eyes

@erikd:
If I want to check the color of a single pixel, how could I do that? I have no idea.  Sad

@Malohkan
Of what size of a tile are you're thinking? I suppose it should be not too big. 10 x 10 pixels? Or more. I think the bigger the tiles are the greater will be the loss of accuracy.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #8 - Posted 2005-03-01 17:13:23 »

For example, go to http://java.sun.com/j2se/1.4.2/docs/api/
Click on the class BufferedImage and check it's method int getRGB(int x, int y).

Mind you, the colours of the pixels in this "collision tile" don't have to be actual colours, it can also be slowdown values like Mahlokan described.
I'd do it per pixel and not per tile though, for the same reason you mentioned (loss of accuracy) but it will probably depend of the style of racing game you're making.

Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #9 - Posted 2005-03-02 01:28:11 »

*sigh*
No one spells my name right Smiley

bauerr, 10x10 is not a power of 2.  16x16 is and 32x32 is.  16x32 is also Smiley  2^n x 2^m is what you want.  It's not necessary that your tiles be of that size, but if you have plans to take advantage of OpenGL acceleration, you'd do best to build them that way.  Another OpenGL acceleration helpful trick would be to put them all in a single image and just draw sub-sections of them in drawImage Smiley

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bauerr

Junior Member




Java!!!!!!!!!!! !!!


« Reply #10 - Posted 2005-03-02 04:24:10 »

O.k. . Many ideas to think about.
Thank you all.

Ralf  Smiley
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #11 - Posted 2005-03-02 06:30:24 »

Quote
*sigh*
No one spells my name right


Oops

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 (45 views)
2014-09-23 14:38:19

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

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

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

moogie (41 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!