collision detection problem

I’ve been working on a dropdown shooter game i’ve been working on this for a long time now i have not been able to solve one problem that’s stopping me from proggressing

my code : http://pastebin.java-gaming.org/e58cc3f9c3f

I know its too long but i cant really ask one part of it as it wouldnt make sense
i have an array of tiles the map which makes up the map each tile location ad rectangle is represented in borders[] array
and i have the bullet rectangle which changes continuesly
what i want is if bullet collides with any of the tiles it should dissappear you can see from my messy code that i’ve tried numerous ways

and any advice on how to improve my code would be greatly appreciated

and if i get to fix this i would share my game and maybe show people how easy it is to make one
any help is greatly appreciated since this is bugging me for days now
thanks in advance

Making stuff disappear is easy. Just set the missile position to null in your array and skip nulls on the draw and hit steps. You’ve got an array of borders, have one for missiles.

I see what you’re doing with all the rectangles for the map array, but you could try putting your missile rectangle into that space… I mean, if you know that your missile is somewhere within in the grids (2,2),(2,3), (3,2), (3,3), then you only need to check the rectangles of 4 grids instead of all of them.

ok so if i want to make it clear because i don’t think i have completely understood you
you’re telling me to make an array of missiles make it like the borders array so it only draws them where they should appear
lets say
0 0 1 (or nulls) 1 1 1
0 1 0 0 1 0
1 0 0 … if this is what you meant how do i check collision here if lets the borders are 0 0 0 then i would stop drawing at the 1 in the center? just to clarify

Two different peices here:

if you set a missile in the array to null you can skip drawing it, and dont try doing hit detection with it either.


Rectangle[] missles = new Rectangle[3];

for (Rectangle missile:missiles){

if (missile == null){
continue;
}
else {
   draw(missile);
}

}

And heres the other bit:
Lets say you know your missile has two corners: (20,20) and (30,30). If thats so, its going to be in the first grid in your map array since your rectangles are size 50x50… So why are you testing every single border object? You can narrow the search down. If you want to.