An Asteroids programming question

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:smile: :sad: :eek: :shock: :cool: :-x :razz: :oops: :evil: :twisted: :wink: :idea: :arrow: :neutral: :mrgreen:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: An Asteroids programming question

by Ice Cream Jonsey » Mon Oct 29, 2007 4:04 pm

Yeah, there are asteroids in Creeping Maw... or at least there will be... so this is all very consistent.

I asked the same question in the Vectrex newsgroup, and got an answer similar to Bruce's. (I just wanted to see discussion there and here on this.) I need to take a personal day to do the Satan's Hollow thing I've got planned.

by pinbacker » Mon Oct 29, 2007 12:48 pm

And then it's a short hop and a skip from changing the word "asteroid" in these conversations to the word "Creeping Maw"!

by Ice Cream Jonsey » Mon Oct 29, 2007 9:42 am

Thank you both. This WILL be dividends, I promise. You'll look back on this thread fondly. I swear it! Even those of you who use Linux, thanks to the wonders of "Blitz3D."

by pinbacker » Mon Oct 29, 2007 8:38 am

See? Math. WhaddI tell you.

by bruce » Fri Oct 26, 2007 8:01 pm

If your rocks are roughly circular, then use basically the same detection algorithm, only compare (where x and y are the coordinates of the bullet, x1 and y1 the coordinates of the rock's center, and r the radius of the rock) (x -x1)^2 + (y - y1)^2 <= r^2.

Using circles for the real rock footprint rather than squares makes it look less fakey, since you don't have the "shooting the corner which is nowhere near the rock" problem.

Also, you'll note that the real distance formula would take the square root of all those values. Fuck that; sqrt() is expensive. Multiplication is (usually) cheap.

Bruce

by pinbacker » Fri Oct 26, 2007 1:13 pm

Mine was in C, and written in 1990, and has been long gone too long to merely call it "long gone".

by Ice Cream Jonsey » Fri Oct 26, 2007 11:27 am

Do you have an Asteroids clone kicking around some place? I know for a fact that the one I did in .net is long gone, so if yours is long gone that's cool. We're just relaxing over here.

Re: An Asteroids programming question

by pinbacker » Fri Oct 26, 2007 10:12 am

Ice Cream Jonsey wrote:But how do you solve this for asteroids that are not square chunks? You can cheat by assigning it square space anyway.
That's what I did.
Does anyone recall or know how this collision-detection-based problem is (well... was, let's be honest) generally solved in 2D games?
Probably some math thing. If you know where all the "angles" are on your chunk of rock, you can probably use math to determine whether a point is inside it or out.

So that's my recommendation: Use MATH.

An Asteroids programming question

by Ice Cream Jonsey » Fri Oct 26, 2007 1:38 am

This can be pseudo-cody, so it's out there for anyone.

OK, imagine if you will an Asteroids game where all the Asteroids are squares and they don't rotate. We're also using vectors.

It is easy to determine if a bullet his the asteroid, because you can easily determine the size of the asteroid by simply knowing it's upper-left-hand position and whether it's a big, medium or small asteroid. If the bullet is drawn inside the area an asteroid must encompass, then run the routine (or jump to the area in the code) where the asteroid breaks up.

But how do you solve this for asteroids that are not square chunks? You can cheat by assigning it square space anyway. But eventually that's going to look like shit and the player will notice.

Does anyone recall or know how this collision-detection-based problem is (well... was, let's be honest) generally solved in 2D games?

Top