Game Development Community

How can I draw and collide with a random 2D sine wave landscape?

by John Klimek · in Torque Game Builder · 02/07/2006 (6:29 am) · 26 replies

I'm planning to make a Tanks / Scorched Earth game and I'm not sure how to draw the landscape in Torque 2D.

At first I started making this game in Macromedia Flash and was drawing the landscape like this:

for (var x:Number = 0; x < Stage.width; x++) {
_clip.lineTo(x, (Math.sin(x/34) * 36) + (Math.sin(x/23) * 29) + (Math.sin(x/27) * 37));
}

As you can see, I'm going through X value and adding together three sine waves to get a nice landscape. Eventually I'll be using random numbers inside the sine functions to generate random landscapes... (but for now I'm using static numbers)

How would I draw this in Torque 2D? Can I create/modify a bitmap image and use that?

On top of drawing the landscape/curve, I need to keep track of it for collisions (eg. when a bullet shot from a tank hits the ground it should blow up itself **AND** remove a part of the ground).

Any help at all would be GREATLY appriciated... (even if anybody can point me in the right direction of which functions to use that would be a huge help)

Thanks!
Page«First 1 2 Next»
#21
02/12/2006 (9:37 am)
That method works, but you will run into issues creating circle deformations in it.

Ya, the code doesn't draw as you'd expect it to. It draw a triangle fan from the first point. That sucks.

Your jaggies are there because you need antialiasing.
#22
02/12/2006 (3:57 pm)
Can T2D anti-alias the line for me or is the only solution to leave it looking jaggy?

Also, can I somehow fix my code so it won't draw a triangle and thus screw up the fillmode?

Thanks again.
#23
02/12/2006 (3:59 pm)
John - Jason gave you the solution... Instead of using one large poly... use 1 rectangel for each deviation... straight up.

It will take more trickery to make that work with circle deformations, but you'll figure it out.

You cant antialias. But you may be able to fake it by making a slightly larger poly for each one and make it translucent... I dunno.
#24
02/12/2006 (4:00 pm)
No it wont...

Just chop each rectangle it intersects into 2 pieces leaving the circular cut out
#25
02/22/2012 (1:03 am)
beautiful
#26
02/22/2012 (2:20 am)
Glenn - please don't resurrect old threads unless you have something important to contribute to them.
Page«First 1 2 Next»