My problem might be simple. I've spent most of today thinking of an algorithm(That will pretty probably be a couple if statements) that will determine the direction the mouse is pointing and shoot a bullet in that direction. I already tested the bullets to make sure they shoot by shooting in a defined direction.
how would i go about calculating if the mouse is on the left side of the player, the right side,top side, bottom side, or if it's on the corners of the player ?
Solved: Thanks for all your help but after a day of thinking I came up with a way my self. What I did is use the if statements to determine when I press the mouse down, is it going to be colliding with the top part of the player,bottom,right,left,or corners. Anyway, here is my code. P.S. I used the variable x1 as the mousex, y1 as mousey, x as playerx, and y as player y. The only other variable I have is dx and dy but you should know what those do.
//top
if (x1 > x && x1 < x + 40 && y1 > y - 250 && y1 < y){
dy = -1;
dx = 0;
}
//right
if (x1 > x + 40 && x1 < x + 250 && y1 > y && y1 < y + 40){
dx = 1;
dy = 0;
}
//bottom
if (x1 > x && x1 < x + 40 && y1 > y+40 && y1 < y+250){
dy = 1;
dx = 0;
}
//left
if (x1 < x && x1 > x - 250 && y1 > y && y1 < y + 40){
dx = -1;
dy = 0;
}
//top right corner
if (x1 > x + 40 && x1 < x + 250 && y1 > y - 250 && y1 < y){
dx = 1;
dy = -1;
}
//top left corner
if (x1 < x && x1 > x - 250 && y1 > y - 250 && y1 < y){
dx = -1;
dy = -1;
}
//bottom right corner
if (x1 > x + 40 && x1 < x + 250 && y1 > y + 40 && y1 < y + 250){
dx = 1;
dy = 1;
}
//bottom left corner
if (x1 < x && x1 > x - 250 && y1 > y + 40 && y1 < y + 250){
dx = -1;
dy = 1;
}