Quote:
> Lately I have been having a problem with a game in development.
> The game only has simple blocks for it's graphics but the
> nitty-gritty stuff is almost done. However I can't figure out
> how to recognize which tank the bullet is hitting.
> Since for PUT you only specify one pixel, the bullet would have
> to hit that spot for the hit to register. Does anyone have any
> ideas? I am rather stumped.
-----------------------------------------------------------------
The concept you're searching for is sometimes refered to as
collision detection. There are a number of ways of handling it
and it can get complicated, depending on how you've coded your
graphics.
Take a simple case where you want to know if you've "hit" a
rectangular shape. "PUT" takes only one set of coordinates, but
the first two elements of the array (as specified by the indices
parameter) can be used to calculate the width and length of the
rectangular block of pixels being placed on the screen. The
coordinates specified are merely the upper left corner of that
block.
Say that the "bullet"'s position is Bx,By and the rectangular
block has opposing corners of X,Y and X+Width,Y+Length. You
know you've hit the block if Bx>=X AND Bx<=X+Width AND By>=Y AND
By<=Y+Length. This assumes a coordinate system that increases
from left to right and from top to bottom.
I don't know if this applies to your program, because I'm not
going to go to the trouble of downloading and decoding it this
time. Just a personal opinion, but I think most people would
prefer you save your code in ASCII format and post that rather
than using the "tokenized" format and UUEncoding.
----------------------------------------------------------------
Derek Asari