File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Game Development and the fly likes Area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Area" Watch "Area" New topic
Author

Area

Lambert Stein
Greenhorn

Joined: Oct 30, 2006
Posts: 14
Hi all...

I wanted to create the game called Tanks (Google it) in Java. I have been wondering how to represent the terrain:
I am thinking of creating a random polynomial and drawing its curve. This should work fine, except that when a bomb explodes, I don't know how to make a ditch.

Can anyone help?
Thanks a lot!
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi Lambert,

sounds like an interesting project.

How about the following:
You could represent the polynomial as a list of points (x,y) - and when the bomb hits the "ground" the points close to the point of impact will be affected.

Example:
Points: (0,10) - (5,15) - (10,20) - (15,15) - (20,10)
The bomb hits the point (10,20).. a few options:
a) decrease y value (i.e. (10,20) is changed to (10,15)
b) First decrease the points y value with, say 5, then decrease the value of the "neighbours points" (adjacenct points) with e.g. 2.

It is most likely not the most elegang solution, but it might be enough to get you started

/Svend Rost

/Svend Rost
Lambert Stein
Greenhorn

Joined: Oct 30, 2006
Posts: 14
Thanks a lot for the reply...

The problem is, that would make the drawing very jagged - the purpose of using a predefined polynomial is that it is not raster, and can be resized on demand without quality loss. This method loses quality, and it is hard to implement because if a bomb is exploded under the ground, the above has to fall.

Any ideas?

Thanks though...
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Yes - and no.

You can almost always design or code your way out of the problems. Hacking should ofcause be avioided.. at times it can be a good idea to use a simple solution (which will enable you to continue with the project instead).

As I mentioned, the terrain could be represented by a list of points. Remember, that this list could contain an abitraty number of points.


The above is ment to be simple and should just show you how it could be solved. When you are stuck with a problem it is often a good idea to, a) split the problem up in smaller bits and/or b) make a simpler solution. The above could be seen as a prototype landscape representation. As long as you design the game/system so that you encapsulate the terrain representation - changing it wont be that hard.

I'll try to think about a prettier way of representing the terrain.

/Svend Rost
[ April 27, 2007: Message edited by: Svend Rost ]
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Hi,
Perhaps you should keep a "cache" of small predfined polynomial curves and when a bomb hits a point x, you could overlay the centre of the predefiend curve at the point x.

So say you have a small curve c with 5 points, and the bomb hits at x on the main curve, then the centre of c (c2) could be lined up with x, the start of c (c0) could replace x-2 and so on though to x+2.

I dont know if this would be a case of just taking each x,y value and updating the terrain curve, or if you could do some sort of trim, or maybe some sort of transform directly onto the tarrain curve.

you could apply "hardness" transformation to the small curve c before you applied them to your terrain curve, say if the ground was concreate it might have a shallow curve, and if its sand a large curve. Also you could apply expolsive power transforms too, so if its a HESH round from the tank you might get a shallow wide area and if it is a DU round a deep small area affect.

Just a thought.

G
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Area