# Using logic gates for Sprite Collision Detection - humor an old fart please

Im an old coder who came back so to speak, learning Java I know what I want but I cannot find anyone asking it anywhere so here goes...

Im writing a basic tank game to code for practice but as is always the case my personal ambitions out pace my abilities.

Ive been reading up on the various methods used for collision detection using rectangles and point testing around the sprite for collisions but it all seems a little hap hazard and processor heavy to me.

I was thinking maybe a method would work by which I could logically compare two sprites -

So maybe I have a tank(me) and I come to a tile which is meant to be wall. OK so I can compare the square from an array and look up what type of tile is there and prevent movement in that direction, but again Im not happy with this because its not accurate enough. I mean what happens if I want that wall shootable, where it goes through several stages of destruction before its turned into a fully traversable square, it may have a few bits un-destroyed and I want to be able to detect even this.

So how about if I created a tank mask, black and white and grab the square the tank is entering and logically AND it with the tank sprite, creating zero unless a pixel appears in both locations, in which case it hit something.

Is this clear enough?

Do you think this would work and which coding direction do you recommend, Im still new to the syntax but as you can see I know what I want....I think!

• "Do you think this would work" logically, there's nothing to prevent it. Whether coding it has the simplicity and performance you're looking for is something you can evaluate for yourself by writing it. What do you need from us? We're likely to just recommend the same methods you've already found documented elsewhere. Aug 30, 2019 at 4:30
• This is in fact how it used to be done! I remember first reading about it in the book Sex, Lies, and Video Games. Aug 30, 2019 at 5:00
• The way you described will be more processor heavy by orders of magnitude compared to the rectangle approach, so first decide if you want speed (you really don't, it's 2019) or precision Aug 30, 2019 at 8:08
• The reason for asking is to see if Aug 30, 2019 at 16:38
• there might be something already - as I said my Java knowledge is buiding up but still lacking and I didn't want to go 'reinventing the wheel' if there was something someone knows about already - Aug 30, 2019 at 16:39