Two Things in a single grid area

Every object/enemy in my game are in a big [][] array, and then all the items are put in a [] array, and all the enemies are put in a different [] array,

I ve done the collision for my regular attack and ranged attack, and it works fine, but the problem is i haven’t animated the enemies yet,so they are just sitting there waiting to be attacked

because of that, no two enemies are in the same grid, so i can do collision quite easily

but enemies have to move lol…

my main character class has a column number int that is basically what column he is in, and my enemies has the same thing,

so there is two ways ii think i can do collision

  1. have a loop that goes through the entire enemyList and checks each enemie’s column number to see if it is the same as the characters, or if it is one in front of it (if character facing left, then check for the current column and one behind it).

  2. make a ArrayList that can hold several enemies, and make an ARRAY OF ARRAYLISTS for the entire level, and then each time an enemy moves, put him in the corresponding array index,
    then when i test for collision, I just test my character’s current col position against the current array index, and go through the entire arrayList to test (if !arrayList.isEmpty())

so which way would be faster or is there something better>?

So why exactly are you not using objects to represent your data such as the contents of a cell?

This isnt BASIC. This is OOP?

ugh, i have an element class and a enemy class that extends element…and a level class that process all that…

so i should make a class that holds everything instead of using arrayS?

disregarding me using objects or arrays, what is the best way to do what i said in the first post

For any sigfnificant number of objects, storing them by location and just checking those in the right lcoation for collision will be faster then checking them all.

This is called a “bucket” in the genreal sense.