You have to check the space between the gun and the mouse to see if the wall is in the path of it.
One way is to use a For loop and calculate the floor(distance(gunx,guny,mousex,mousey)) as the max value for the For loop.
Then in the loop, use the loopindex("nameofloop") expression while you check if a position is overlapping a wall. Get the angle, and then the distance to check from gun will be the loopindex("name")..
If it overlaps, then you have the position to stop the laser and you can stop the loop.
You can also divide the distance by 5 for example if you don't want to check every position, but then you have to multiply the position by 5 when you check if overlapping.