You seem to be confused here. You can shoot in all directions even in a tile map. The only thing you need to figure out is where the bullet is in your tilemap.
starttilerow=playertilerow;
starttilecol=playertilecol;
then when the bullet is moving
bullettilerow=starttilerow+(int)(bulletx/tilesizex);
bullettilecol=starttilecol+(int)(bullety/tilesizey);
This will tell you which tile your bullet is in. For more collision detection simply put a bounding box around your sprites in the tiles and test against that.
My method will allow you to have smooth movement of bullets and at the same time correctly determine a hit or not.
Your method is too tile based. Your bullets would track very ugly and choppy.
So here is some code to help:
Code:
void FireBullet(Player *thePlayer)
{
//Convert player's angle to radians
double radangle=DEGTORAD(thePlayer->GetAngle());
//Extract x and y components of angle
double bx=cos(radangle);
double by=sin(radangle);
//Create new bullet with components
Bullet *theBullet=new Bullet(bx,by);
//Set bullet speed
theBullet->SetSpeed(2.0);
//Set bullet to active so it will be updated
theBullet->SetActive(TRUE);
//Add new bullet to bullet list
BulletTracker->Add(theBullet);
}
void FireBulletAt(Player *theShooter,NPC *theTarget)
{
//Get NPCs location
double npcx=theTarget->GetX();
double npcy=theTarget->GetY();
//Get Player's location
double px=theShooter->GetX();
double py=theShooter->GetY();
//Get differences of components
double diffx=px-npcx;
double diffy=py-npcy;
//Compute total distance
int dist=FastDist2D(diffx,diffy);
//Compute bullet components
double bx=diffx/(double)dist;
double by=diffy/(double)dist;
//Create new bullet
Bullet *theBullet=new Bullet(bx,by);
//Activate it
theBullet->SetActive(TRUE);
//Add to list
BulletTracker->AddBullet(theBullet);
}
Then to test for collisions you could extract the tile positions of each bullet.
int column=Bullet->Extract(COLUMN);
int row=Bullet->Extract(ROW);
or something like that.
Personally I would stick with the x,y coords of each object that way you don't have to know which tile the bullet is in. Just because it's a tile map does not mean that everything is tile based. Your sprites can still have x and y coordinates and this is what you should test against.
If you are shooting bullets at the mouse -> the mouse would be the NPC or the target. To make you sprite turn to face what you are shooting at is simply done by comparing the mouse x,y to your player's x,y:
if (mousex<playerx && mousey<playery) Player->SetPicture(NORTHWEST);
...
and so on for each of the 8 directions. For a perfect angle using 3D characters and exact angles -> you already know how to get the angle using arctangent.