[HELP] Accurate Optimized Hittest
I'm currently working on a space shooter game, and am trying to figure out an accurate(and optimized) way of hittesting. They way I'm doing it so far only works with rectangle and squares and the code I'm using for that is code:
//Movement has already occured before this, so the x and y are updated(the enemy is going to be removed so I don't think it matters)
function shiptoenemytest(ob){
for (prop1 in enemylist){
if(_mathabs(ob.row-_mathceil(enemylist[prop1]._y/colandrowinfo.enemytoshiprow))<2){
if(_mathabs(ob.column-_mathceil(enemylist[prop1]._x/colandrowinfo.enemytoshipcol))<2){
hiTcollsions(ob,enemylist[prop1],prop1)
}}}}
function hiTcollsions(ob1,ob2,name){
if(ob1._x<=ob2._x){
if(ob1._x+ob1._width>ob2._x){
if(ob1._y<=ob2._y){
if(ob1._y+ob1._height>=ob2._y){
enemyrammed(ob1,ob2,name)
}
}else if(ob1._y<=ob2._y+ob2._height){
enemyrammed(ob1,ob2,name)}
}
}
else {
if(ob1._x<ob2._x+ob2._width){
if(ob1._y<=ob2._y){
//ob1 is lower
if(ob1._y+ob1._height>=ob2._y){
enemyrammed(ob1,ob2,name)}
}else if(ob1._y<=ob2._y+ob2._height){
enemyrammed(ob1,ob2,name)
}
}
}}
As you can probably tell(I hope)this only checks for the perimeters of the objects.
So what I'm planning to do is use something similar to this Kirupa tutorial. Except I'm planning to make a ring of dots every pixel around both objects and use a for in loop within a for in loop to test if the x and y coordinates of any of the dots are equal(or very very close). This check would be called where it says enemyrammed in the actionscript, after all the others...
What I want to know is, is there a better way of doing what I want, or is there a way of improving what I'm trying to do?
If this is really confusing just say so, and I'll try to clarify...
P.S. I'm trying not to use Hittest(the built in one) and find a more optimized way...